23 #include "robot_memory_thread.h" 25 #include "interfaces/RobotMemoryInterface.h" 27 #include <core/threading/mutex.h> 28 #include <core/threading/mutex_locker.h> 42 :
Thread(
"RobotMemoryThread",
Thread::OPMODE_WAITFORWAKEUP),
70 delete blackboard_computable;
71 delete transform_computable;
80 while (!robot_memory->rm_if_->msgq_empty()) {
81 if (robot_memory->rm_if_->msgq_first_is<RobotMemoryInterface::QueryMessage>()) {
82 RobotMemoryInterface::QueryMessage *msg =
83 (RobotMemoryInterface::QueryMessage *)robot_memory->rm_if_->msgq_first();
84 QResCursor res = robot_memory->
query(msg->query(), msg->collection());
86 std::string query = msg->query();
87 std::string result =
"Result of query " + query +
":\n";
89 mongo::BSONObj doc = res->next();
90 result += doc.toString() +
"\n";
93 robot_memory->rm_if_->set_result(result.c_str());
94 }
else if (robot_memory->rm_if_->msgq_first_is<RobotMemoryInterface::InsertMessage>()) {
95 RobotMemoryInterface::InsertMessage *msg =
96 (RobotMemoryInterface::InsertMessage *)robot_memory->rm_if_->msgq_first();
97 robot_memory->
insert(msg->insert()), msg->collection();
98 }
else if (robot_memory->rm_if_->msgq_first_is<RobotMemoryInterface::UpdateMessage>()) {
99 RobotMemoryInterface::UpdateMessage *msg =
100 (RobotMemoryInterface::UpdateMessage *)robot_memory->rm_if_->msgq_first();
101 robot_memory->
update(msg->query(), msg->update(), msg->collection());
102 }
else if (robot_memory->rm_if_->msgq_first_is<RobotMemoryInterface::RemoveMessage>()) {
103 RobotMemoryInterface::RemoveMessage *msg =
104 (RobotMemoryInterface::RemoveMessage *)robot_memory->rm_if_->msgq_first();
105 robot_memory->
remove(msg->query(), msg->collection());
110 robot_memory->rm_if_->msgq_pop();
113 robot_memory->loop();
QResCursor query(mongo::Query query, const std::string &collection="")
Query information from the robot memory.
virtual void log_info(const char *component, const char *format,...)=0
Log informational message.
RobotMemoryThread()
Constructor for thread.
int remove(mongo::Query query, const std::string &collection="")
Remove documents from the robot memory.
Fawkes library namespace.
int update(mongo::Query query, mongo::BSONObj update, const std::string &collection="", bool upsert=false)
Updates documents in the robot memory.
Computable providing access to blackboard interfaces.
virtual void finalize()
Finalize the thread.
MongoDBConnCreator * mongodb_connmgr
Connection manager to retrieve more client connections from if necessary.
Thread class encapsulation of pthreads.
Logger * logger
This is the Logger member used to access the logger.
Clock * clock
By means of this member access to the clock is given.
virtual void init()
Initialize the thread.
int insert(mongo::BSONObj obj, const std::string &collection="")
Inserts a document into the robot memory.
Thread aspect to use blocked timing.
void set_robot_memory(RobotMemory *robot_memory)
Set the reference to the robot memory for the aspect.
virtual void loop()
Code to execute in the thread.
const char * name() const
Get name of thread.
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
Thread aspect provide a new aspect.
Access to the robot memory based on mongodb.
virtual ~RobotMemoryThread()
Destructor.
Configuration * config
This is the Configuration member used to access the configuration.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.