21 #ifndef _PLUGINS_ROBOT_MEMORY_ROBOT_MEMORY_H_
22 #define _PLUGINS_ROBOT_MEMORY_ROBOT_MEMORY_H_
24 #include "computables/computables_manager.h"
25 #include "event_trigger_manager.h"
27 #include <aspect/blackboard.h>
28 #include <aspect/clock.h>
29 #include <aspect/configurable.h>
30 #include <aspect/logging.h>
31 #include <core/threading/mutex.h>
32 #include <plugins/mongodb/aspect/mongodb_conncreator.h>
34 #include <bsoncxx/json.hpp>
40 class RobotMemoryInterface;
41 #ifdef USE_TIMETRACKER
60 mongocxx::cursor
query(bsoncxx::document::view
query,
61 const std::string & collection_name =
"",
62 mongocxx::options::find query_options = mongocxx::options::find());
63 bsoncxx::document::value
aggregate(
const std::vector<bsoncxx::document::view> &pipeline,
64 const std::string & collection =
"");
66 int insert(bsoncxx::document::view,
const std::string &collection =
"");
67 int insert(std::vector<bsoncxx::document::view> v_obj,
const std::string &collection =
"");
68 int insert(
const std::string &obj_str,
const std::string &collection =
"");
70 const bsoncxx::document::view &
update,
71 const std::string & collection =
"",
74 const std::string & update_str,
75 const std::string & collection =
"",
78 const bsoncxx::document::view &
update,
79 const std::string & collection,
81 bool return_new =
true);
82 int remove(
const bsoncxx::document::view &
query,
const std::string &collection =
"");
83 bsoncxx::document::value
mapreduce(
const bsoncxx::document::view &
query,
84 const std::string & collection,
85 const std::string & js_map_fun,
86 const std::string & js_reduce_fun);
87 mongocxx::cursor
aggregate(bsoncxx::document::view pipeline,
const std::string &collection =
"");
91 const std::string &directory =
"@CONFDIR@/robot-memory");
93 const std::string &directory =
"@CONFDIR@/robot-memory");
95 const std::string & collection =
"",
105 bool mutex_try_lock(
const std::string &
name,
const std::string &identity,
bool force =
false);
118 template <
typename T>
121 const std::string & collection,
122 void (T::*callback)(
const bsoncxx::document::view &),
135 template <
typename T>
138 const std::string &collection,
139 void (T::*callback)(bsoncxx::document::value),
142 return register_trigger(bsoncxx::from_json(query_str), collection, callback, _obj);
157 template <
typename T>
160 const std::string & collection,
161 std::list<bsoncxx::document::value> (
162 T::*compute_func)(
const bsoncxx::document::view &,
const std::string &),
164 double caching_time = 0.0,
168 std::move(query_to_compute), collection, compute_func, obj, caching_time, priority);
174 mongocxx::client * mongodb_client_local_;
175 mongocxx::client * mongodb_client_distributed_;
182 const char * name_ =
"RobotMemory";
183 std::string database_name_;
184 std::string default_collection_;
187 fawkes::RobotMemoryInterface *rm_if_;
190 std::vector<std::string> distributed_dbs_;
192 unsigned int cfg_startup_grace_period_;
193 std::string cfg_coord_database_;
194 std::string cfg_coord_mutex_collection_;
200 void log(
const std::string &what,
const std::string &level =
"info");
201 void log_deb(
const std::string &what,
const std::string &level =
"info");
202 void log(
const bsoncxx::document::view &
query,
203 const std::string & what,
204 const std::string & level =
"info");
205 void log_deb(
const bsoncxx::document::view &
query,
206 const std::string & what,
207 const std::string & level =
"info");
209 bool is_distributed_database(
const std::string &dbcollection);
210 mongocxx::client * get_mongodb_client(
const std::string &collection);
211 mongocxx::collection get_collection(
const std::string &dbcollection);
213 #ifdef USE_TIMETRACKER
215 unsigned int tt_loopcount_;
216 unsigned int ttc_events_;
217 unsigned int ttc_cleanup_;