knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
MongoInterface.h
Go to the documentation of this file.
1 /*
2  * This file is part of KnowRob, please consult
3  * https://github.com/knowrob/knowrob for license details.
4  */
5 
6 #ifndef KNOWROB_MONGO_INTERFACE_H
7 #define KNOWROB_MONGO_INTERFACE_H
8 
9 #include <mongoc.h>
10 // STD
11 #include <map>
12 #include <memory>
13 // SWI Prolog
14 #define PL_SAFE_ARG_MACROS
15 #include <SWI-cpp.h>
16 
17 #include <map>
18 #include <string>
19 #include <mutex>
20 
21 #include <knowrob/storage/mongo/MongoException.h>
22 #include <knowrob/storage/mongo/Database.h>
23 #include <knowrob/storage/mongo/Collection.h>
24 #include <knowrob/storage/mongo/Cursor.h>
25 #include <knowrob/storage/mongo/QueryWatch.h>
26 #include "Connection.h"
27 
28 namespace knowrob::mongo {
29  class MongoInterface {
30  public:
31  static MongoInterface& get();
32 
33  std::shared_ptr<Database> connect(const PlTerm &dbTerm);
34 
35  std::shared_ptr<Collection> connect(const PlTerm &dbTerm, const char* collectionName);
36 
37  std::shared_ptr<Collection> connect(const char* db_uri, const char* db_name, const char* collectionName);
38 
39  std::shared_ptr<Cursor> cursor_create(const PlTerm &db_term, const char *coll_name);
40 
41  void cursor_destroy(const char *curser_id);
42 
43  std::shared_ptr<Cursor> cursor(const char *curser_id);
44 
45  private:
47  ~MongoInterface();
48 
49  MongoInterface(MongoInterface const&); // Don't Implement
50  void operator=(MongoInterface const&); // Don't implements
51 
52  std::shared_ptr<Connection> getOrCreateConnection(const char *uri_string_c);
53 
54  // maps URI to MongoDatabase for all previously accessed MongoDatabase's
55  std::map<std::string, std::shared_ptr<Connection>> connections_;
56  std::map<std::string, std::shared_ptr<Cursor>> cursors_;
57  std::map<long, std::shared_ptr<Connection>> watcher_;
58 
59  std::mutex mongo_mutex_;
60  };
61 }
62 
63 #endif //KNOWROB_MONGO_INTERFACE_H
std::shared_ptr< Cursor > cursor(const char *curser_id)
std::shared_ptr< Cursor > cursor_create(const PlTerm &db_term, const char *coll_name)
std::shared_ptr< Collection > connect(const PlTerm &dbTerm, const char *collectionName)
std::shared_ptr< Database > connect(const PlTerm &dbTerm)
std::shared_ptr< Collection > connect(const char *db_uri, const char *db_name, const char *collectionName)
static MongoInterface & get()
void cursor_destroy(const char *curser_id)