22 #ifndef FAWKES_SRC_PLUGINS_ROBOT_MEMORY_EVENT_TRIGGER_MANAGER_H_ 23 #define FAWKES_SRC_PLUGINS_ROBOT_MEMORY_EVENT_TRIGGER_MANAGER_H_ 25 #include "event_trigger.h" 27 #include <aspect/configurable.h> 28 #include <aspect/logging.h> 29 #include <core/threading/mutex_locker.h> 30 #include <plugin/loader.h> 31 #include <plugins/mongodb/aspect/mongodb_conncreator.h> 33 #include <boost/bind.hpp> 42 typedef std::unique_ptr<mongo::DBClientCursor> QResCursor;
66 std::string collection,
67 void (T::*callback)(mongo::BSONObj),
74 mongo::BSONObjBuilder query_builder;
75 query_builder.append(
"ns", collection);
77 for (mongo::BSONObjIterator it =
query.getFilter().begin(); it.more();) {
78 mongo::BSONElement elem = it.next();
79 query_builder.appendAs(elem, std::string(
"o.") + elem.fieldName());
81 mongo::Query oplog_query = query_builder.obj();
82 oplog_query.readPref(mongo::ReadPreference_Nearest, mongo::BSONArray());
85 mongo::DBClientBase *con;
87 oplog =
"local.oplog.rs";
88 if (std::find(dbnames_distributed_.begin(), dbnames_distributed_.end(),
get_db_name(collection))
89 != dbnames_distributed_.end()) {
96 new EventTrigger(oplog_query, collection, boost::bind(callback, obj, _1));
97 trigger->oplog_cursor = create_oplog_cursor(con, oplog, oplog_query);
98 triggers.push_back(trigger);
104 static std::string
get_db_name(
const std::string &ns);
108 QResCursor create_oplog_cursor(mongo::DBClientBase *con, std::string oplog, mongo::Query
query);
110 std::string name =
"RobotMemory EventTriggerManager";
117 mongo::DBClientBase *con_local_;
118 mongo::DBClientBase *con_replica_;
120 std::vector<std::string> dbnames_distributed_;
121 std::vector<std::string> dbnames_local_;
124 std::list<EventTrigger *> triggers;
127 #endif //FAWKES_SRC_PLUGINS_ROBOT_MEMORY_EVENT_TRIGGER_MANAGER_H_ QResCursor query(mongo::Query query, const std::string &collection="")
Query information from the robot memory.
Manager to realize triggers on events in the robot memory.
Class holding all information about an EventTrigger.
static std::string get_db_name(const std::string &ns)
Split database name from namespace.
Interface for a MongoDB connection creator.
void remove_trigger(EventTrigger *trigger)
Remove a previously registered trigger.
EventTrigger * register_trigger(mongo::Query query, std::string collection, void(T::*callback)(mongo::BSONObj), T *obj)
Register a trigger to be notified when the robot memory is updated and the updated document matches t...
Access to the robot memory based on mongodb.
EventTriggerManager(fawkes::Logger *logger, fawkes::Configuration *config, fawkes::MongoDBConnCreator *mongo_connection_manager)
Constructor for class managing EventTriggers.
Mutex mutual exclusion lock.
Interface for configuration handling.