[Fawkes Git] branch/fzwilling/robot-memory: 3 revs updated. (0.5.0-3434-g7814803)

Frederik Zwilling zwilling at kbsg.rwth-aachen.de
Thu Nov 3 13:02:03 CET 2016


Changes have been pushed for the project "Fawkes Robotics Software Framework".

Gitweb: http://git.fawkesrobotics.org/fawkes.git
Trac:   http://trac.fawkesrobotics.org

The branch, fzwilling/robot-memory has been updated
        to  7814803c8ce13e0666c543396995a231d17c0445 (commit)
       via  f64cfa12b704ecc677ce5b96a190c52e69669f72 (commit)
       via  a0cafa1d28dabf7f1bf3971c23d33f8bd4265c5a (commit)
      from  d7a9d81267efdd9de03b433771d9b6c406f80d7b (commit)

http://git.fawkesrobotics.org/fawkes.git/fzwilling/robot-memory

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- *Log* ---------------------------------------------------------------
commit a0cafa1d28dabf7f1bf3971c23d33f8bd4265c5a
Author:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
AuthorDate: Thu Nov 3 11:14:24 2016 +0100
Commit:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
CommitDate: Thu Nov 3 13:01:49 2016 +0100

    robot-memory: error hint if mongod is running with wrong parameters

http://git.fawkesrobotics.org/fawkes.git/commit/a0cafa1
http://trac.fawkesrobotics.org/changeset/a0cafa1

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit f64cfa12b704ecc677ce5b96a190c52e69669f72
Author:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
AuthorDate: Thu Nov 3 11:51:17 2016 +0100
Commit:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
CommitDate: Thu Nov 3 13:01:52 2016 +0100

    robot-memory: compute all bb-interfaces when no id is given

http://git.fawkesrobotics.org/fawkes.git/commit/f64cfa1
http://trac.fawkesrobotics.org/changeset/f64cfa1

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit 7814803c8ce13e0666c543396995a231d17c0445
Author:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
AuthorDate: Thu Nov 3 13:00:06 2016 +0100
Commit:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
CommitDate: Thu Nov 3 13:01:56 2016 +0100

    robot-memory: require collection in interface msgs for testing

http://git.fawkesrobotics.org/fawkes.git/commit/7814803
http://trac.fawkesrobotics.org/changeset/7814803

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


- *Summary* -----------------------------------------------------------
 .../interfaces/RobotMemoryInterface.h}             |   24 +++-
 .../computables/blackboard_computable.cpp          |    6 +-
 .../interfaces/RobotMemoryInterface.cpp            |  146 +++++++++++++++++++-
 .../interfaces/RobotMemoryInterface.h_ext          |   24 +++-
 .../interfaces/RobotMemoryInterface.tolua          |   20 ++-
 .../interfaces/RobotMemoryInterface.xml            |    6 +-
 src/plugins/robot-memory/robot_memory_setup.cpp    |    5 +
 src/plugins/robot-memory/robot_memory_thread.cpp   |   18 ++-
 .../robot-memory/test-plugin/robot_memory_test.cpp |   18 +++
 9 files changed, 243 insertions(+), 24 deletions(-)
 copy src/{plugins/robot-memory/interfaces/RobotMemoryInterface.h_ext => libs/interfaces/RobotMemoryInterface.h} (84%)


- *Diffs* -------------------------------------------------------------

- *commit* a0cafa1d28dabf7f1bf3971c23d33f8bd4265c5a - - - - - - - - - -
Author:  Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
Date:    Thu Nov 3 11:14:24 2016 +0100
Subject: robot-memory: error hint if mongod is running with wrong parameters

 src/plugins/robot-memory/robot_memory_setup.cpp |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/robot-memory/robot_memory_setup.cpp b/src/plugins/robot-memory/robot_memory_setup.cpp
index db73a54..9d7f7c3 100644
--- a/src/plugins/robot-memory/robot_memory_setup.cpp
+++ b/src/plugins/robot-memory/robot_memory_setup.cpp
@@ -221,8 +221,13 @@ mongo::BSONObj RobotMemorySetup::run_mongo_command(unsigned int port, std::strin
   logger->log_info("RobotMemorySetup", "Executing db command: %s", command.c_str());
   con.runCommand("admin", mongo::fromjson(command), res);
   con.reset();
+
   if(res.getField("ok").type() != mongo::BSONType::NumberDouble || (res.getField("ok").Double() == 0.0 && res.getField("errmsg").String().compare(err_msg_to_ignore) != 0))
+  {
+    if(res.getField("errmsg").String() == "server is not running with --replSet")
+      logger->log_error("RobotMemorySetup", "The mongod instance which is already running is started with the wrong parameters. Stop it to let it start by the robot memory or change the mongod config and restart it.");
     throw PluginLoadException("robot-memory", std::string("Running DB command " + command + " failed: " + res.toString()).c_str());
+  }
   return res;
 }
 

- *commit* f64cfa12b704ecc677ce5b96a190c52e69669f72 - - - - - - - - - -
Author:  Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
Date:    Thu Nov 3 11:51:17 2016 +0100
Subject: robot-memory: compute all bb-interfaces when no id is given

 .../computables/blackboard_computable.cpp          |    6 ++++--
 .../robot-memory/test-plugin/robot_memory_test.cpp |   18 ++++++++++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/robot-memory/computables/blackboard_computable.cpp b/src/plugins/robot-memory/computables/blackboard_computable.cpp
index bf6c5c7..aff81c5 100644
--- a/src/plugins/robot-memory/computables/blackboard_computable.cpp
+++ b/src/plugins/robot-memory/computables/blackboard_computable.cpp
@@ -37,7 +37,7 @@ BlackboardComputable::BlackboardComputable(RobotMemory* robot_memory, fawkes::Bl
   logger_ = logger;
 
   //register computable
-  Query query = fromjson("{interface:{$exists:true}, id:{$exists:true}}");
+  Query query = fromjson("{interface:{$exists:true}}");
   computable = robot_memory_->register_computable(query, "robmem.blackboard", &BlackboardComputable::compute_interfaces, this);
 }
 
@@ -50,7 +50,9 @@ std::list<mongo::BSONObj> BlackboardComputable::compute_interfaces(mongo::BSONOb
 {
   std::list<mongo::BSONObj> res;
   std::string type = query.getField("interface").String();
-  std::string id = query.getField("id").String();
+  std::string id = "*";
+  if(query.hasField("id"))
+    id = query.getField("id").String();
   //get all matching interfaces
   for(Interface* interface : blackboard_->open_multiple_for_reading(type.c_str(), id.c_str()))
   {
diff --git a/src/plugins/robot-memory/test-plugin/robot_memory_test.cpp b/src/plugins/robot-memory/test-plugin/robot_memory_test.cpp
index d004258..823abfc 100644
--- a/src/plugins/robot-memory/test-plugin/robot_memory_test.cpp
+++ b/src/plugins/robot-memory/test-plugin/robot_memory_test.cpp
@@ -299,3 +299,21 @@ TEST_F(RobotMemoryTest, BlackboardComputable)
       "{interface:'Position3DInterface',id:'test',frame:'test_frame',translation:[1.1, 2.2, 3.3]}")));
   blackboard->close(if3d);
 }
+
+
+TEST_F(RobotMemoryTest, BlackboardComputableMultiple)
+{
+  Position3DInterface* if3d = blackboard->open_for_writing<Position3DInterface>("test");
+  if3d->set_frame("test_frame");
+  if3d->write();
+  Position3DInterface* if3d_2 = blackboard->open_for_writing<Position3DInterface>("test_2");
+  if3d_2->set_frame("test_frame");
+  if3d_2->write();
+  QResCursor qres = robot_memory->query(fromjson("{interface:'Position3DInterface',id:'test'}"), "robmem.blackboard");
+  ASSERT_TRUE(qres->more());
+  ASSERT_TRUE(contains_pairs(qres->next(), fromjson("{interface:'Position3DInterface'}")));
+  ASSERT_TRUE(qres->more());
+  ASSERT_TRUE(contains_pairs(qres->next(), fromjson("{interface:'Position3DInterface'}")));
+  blackboard->close(if3d);
+  blackboard->close(if3d_2);
+}

- *commit* 7814803c8ce13e0666c543396995a231d17c0445 - - - - - - - - - -
Author:  Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
Date:    Thu Nov 3 13:00:06 2016 +0100
Subject: robot-memory: require collection in interface msgs for testing

 .../interfaces/RobotMemoryInterface.h}             |   24 +++-
 .../interfaces/RobotMemoryInterface.cpp            |  146 +++++++++++++++++++-
 .../interfaces/RobotMemoryInterface.h_ext          |   24 +++-
 .../interfaces/RobotMemoryInterface.tolua          |   20 ++-
 .../interfaces/RobotMemoryInterface.xml            |    6 +-
 src/plugins/robot-memory/robot_memory_thread.cpp   |   18 ++-
 6 files changed, 216 insertions(+), 22 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/robot-memory/interfaces/RobotMemoryInterface.cpp b/src/plugins/robot-memory/interfaces/RobotMemoryInterface.cpp
index a60da8d..afacc39 100644
--- a/src/plugins/robot-memory/interfaces/RobotMemoryInterface.cpp
+++ b/src/plugins/robot-memory/interfaces/RobotMemoryInterface.cpp
@@ -56,7 +56,7 @@ RobotMemoryInterface::RobotMemoryInterface() : Interface()
   add_messageinfo("InsertMessage");
   add_messageinfo("UpdateMessage");
   add_messageinfo("RemoveMessage");
-  unsigned char tmp_hash[] = {0x57, 0x8, 0x55, 0x6b, 0x61, 0x8, 0xc9, 0x16, 0xf7, 0x68, 0xcc, 0x7e, 0xae, 0xe2, 0x42, 0xe};
+  unsigned char tmp_hash[] = {0x46, 0x15, 0x7a, 0xda, 0x53, 0x5, 0x42, 0x51, 0xa6, 0xd5, 0x3c, 0x1d, 0x56, 0xfa, 0x61, 0xba};
   set_hash(tmp_hash);
 }
 
@@ -177,8 +177,9 @@ RobotMemoryInterface::enum_tostring(const char *enumtype, int val) const
 
 /** Constructor with initial values.
  * @param ini_query initial value for query
+ * @param ini_collection initial value for collection
  */
-RobotMemoryInterface::QueryMessage::QueryMessage(const char * ini_query) : Message("QueryMessage")
+RobotMemoryInterface::QueryMessage::QueryMessage(const char * ini_query, const char * ini_collection) : Message("QueryMessage")
 {
   data_size = sizeof(QueryMessage_data_t);
   data_ptr  = malloc(data_size);
@@ -186,7 +187,9 @@ RobotMemoryInterface::QueryMessage::QueryMessage(const char * ini_query) : Messa
   data      = (QueryMessage_data_t *)data_ptr;
   data_ts   = (message_data_ts_t *)data_ptr;
   strncpy(data->query, ini_query, 1024);
+  strncpy(data->collection, ini_collection, 1024);
   add_fieldinfo(IFT_STRING, "query", 1024, data->query);
+  add_fieldinfo(IFT_STRING, "collection", 1024, data->collection);
 }
 /** Constructor */
 RobotMemoryInterface::QueryMessage::QueryMessage() : Message("QueryMessage")
@@ -197,6 +200,7 @@ RobotMemoryInterface::QueryMessage::QueryMessage() : Message("QueryMessage")
   data      = (QueryMessage_data_t *)data_ptr;
   data_ts   = (message_data_ts_t *)data_ptr;
   add_fieldinfo(IFT_STRING, "query", 1024, data->query);
+  add_fieldinfo(IFT_STRING, "collection", 1024, data->collection);
 }
 
 /** Destructor */
@@ -248,6 +252,36 @@ RobotMemoryInterface::QueryMessage::set_query(const char * new_query)
   strncpy(data->query, new_query, sizeof(data->query));
 }
 
+/** Get collection value.
+ * The collection to query
+ * @return collection value
+ */
+char *
+RobotMemoryInterface::QueryMessage::collection() const
+{
+  return data->collection;
+}
+
+/** Get maximum length of collection value.
+ * @return length of collection value, can be length of the array or number of 
+ * maximum number of characters for a string
+ */
+size_t
+RobotMemoryInterface::QueryMessage::maxlenof_collection() const
+{
+  return 1024;
+}
+
+/** Set collection value.
+ * The collection to query
+ * @param new_collection new collection value
+ */
+void
+RobotMemoryInterface::QueryMessage::set_collection(const char * new_collection)
+{
+  strncpy(data->collection, new_collection, sizeof(data->collection));
+}
+
 /** Clone this message.
  * Produces a message of the same type as this message and copies the
  * data to the new message.
@@ -267,8 +301,9 @@ RobotMemoryInterface::QueryMessage::clone() const
 
 /** Constructor with initial values.
  * @param ini_insert initial value for insert
+ * @param ini_collection initial value for collection
  */
-RobotMemoryInterface::InsertMessage::InsertMessage(const char * ini_insert) : Message("InsertMessage")
+RobotMemoryInterface::InsertMessage::InsertMessage(const char * ini_insert, const char * ini_collection) : Message("InsertMessage")
 {
   data_size = sizeof(InsertMessage_data_t);
   data_ptr  = malloc(data_size);
@@ -276,7 +311,9 @@ RobotMemoryInterface::InsertMessage::InsertMessage(const char * ini_insert) : Me
   data      = (InsertMessage_data_t *)data_ptr;
   data_ts   = (message_data_ts_t *)data_ptr;
   strncpy(data->insert, ini_insert, 1024);
+  strncpy(data->collection, ini_collection, 1024);
   add_fieldinfo(IFT_STRING, "insert", 1024, data->insert);
+  add_fieldinfo(IFT_STRING, "collection", 1024, data->collection);
 }
 /** Constructor */
 RobotMemoryInterface::InsertMessage::InsertMessage() : Message("InsertMessage")
@@ -287,6 +324,7 @@ RobotMemoryInterface::InsertMessage::InsertMessage() : Message("InsertMessage")
   data      = (InsertMessage_data_t *)data_ptr;
   data_ts   = (message_data_ts_t *)data_ptr;
   add_fieldinfo(IFT_STRING, "insert", 1024, data->insert);
+  add_fieldinfo(IFT_STRING, "collection", 1024, data->collection);
 }
 
 /** Destructor */
@@ -338,6 +376,36 @@ RobotMemoryInterface::InsertMessage::set_insert(const char * new_insert)
   strncpy(data->insert, new_insert, sizeof(data->insert));
 }
 
+/** Get collection value.
+ * The collection to query
+ * @return collection value
+ */
+char *
+RobotMemoryInterface::InsertMessage::collection() const
+{
+  return data->collection;
+}
+
+/** Get maximum length of collection value.
+ * @return length of collection value, can be length of the array or number of 
+ * maximum number of characters for a string
+ */
+size_t
+RobotMemoryInterface::InsertMessage::maxlenof_collection() const
+{
+  return 1024;
+}
+
+/** Set collection value.
+ * The collection to query
+ * @param new_collection new collection value
+ */
+void
+RobotMemoryInterface::InsertMessage::set_collection(const char * new_collection)
+{
+  strncpy(data->collection, new_collection, sizeof(data->collection));
+}
+
 /** Clone this message.
  * Produces a message of the same type as this message and copies the
  * data to the new message.
@@ -358,8 +426,9 @@ RobotMemoryInterface::InsertMessage::clone() const
 /** Constructor with initial values.
  * @param ini_query initial value for query
  * @param ini_update initial value for update
+ * @param ini_collection initial value for collection
  */
-RobotMemoryInterface::UpdateMessage::UpdateMessage(const char * ini_query, const char * ini_update) : Message("UpdateMessage")
+RobotMemoryInterface::UpdateMessage::UpdateMessage(const char * ini_query, const char * ini_update, const char * ini_collection) : Message("UpdateMessage")
 {
   data_size = sizeof(UpdateMessage_data_t);
   data_ptr  = malloc(data_size);
@@ -368,8 +437,10 @@ RobotMemoryInterface::UpdateMessage::UpdateMessage(const char * ini_query, const
   data_ts   = (message_data_ts_t *)data_ptr;
   strncpy(data->query, ini_query, 1024);
   strncpy(data->update, ini_update, 1024);
+  strncpy(data->collection, ini_collection, 1024);
   add_fieldinfo(IFT_STRING, "query", 1024, data->query);
   add_fieldinfo(IFT_STRING, "update", 1024, data->update);
+  add_fieldinfo(IFT_STRING, "collection", 1024, data->collection);
 }
 /** Constructor */
 RobotMemoryInterface::UpdateMessage::UpdateMessage() : Message("UpdateMessage")
@@ -381,6 +452,7 @@ RobotMemoryInterface::UpdateMessage::UpdateMessage() : Message("UpdateMessage")
   data_ts   = (message_data_ts_t *)data_ptr;
   add_fieldinfo(IFT_STRING, "query", 1024, data->query);
   add_fieldinfo(IFT_STRING, "update", 1024, data->update);
+  add_fieldinfo(IFT_STRING, "collection", 1024, data->collection);
 }
 
 /** Destructor */
@@ -462,6 +534,36 @@ RobotMemoryInterface::UpdateMessage::set_update(const char * new_update)
   strncpy(data->update, new_update, sizeof(data->update));
 }
 
+/** Get collection value.
+ * The collection to query
+ * @return collection value
+ */
+char *
+RobotMemoryInterface::UpdateMessage::collection() const
+{
+  return data->collection;
+}
+
+/** Get maximum length of collection value.
+ * @return length of collection value, can be length of the array or number of 
+ * maximum number of characters for a string
+ */
+size_t
+RobotMemoryInterface::UpdateMessage::maxlenof_collection() const
+{
+  return 1024;
+}
+
+/** Set collection value.
+ * The collection to query
+ * @param new_collection new collection value
+ */
+void
+RobotMemoryInterface::UpdateMessage::set_collection(const char * new_collection)
+{
+  strncpy(data->collection, new_collection, sizeof(data->collection));
+}
+
 /** Clone this message.
  * Produces a message of the same type as this message and copies the
  * data to the new message.
@@ -481,8 +583,9 @@ RobotMemoryInterface::UpdateMessage::clone() const
 
 /** Constructor with initial values.
  * @param ini_query initial value for query
+ * @param ini_collection initial value for collection
  */
-RobotMemoryInterface::RemoveMessage::RemoveMessage(const char * ini_query) : Message("RemoveMessage")
+RobotMemoryInterface::RemoveMessage::RemoveMessage(const char * ini_query, const char * ini_collection) : Message("RemoveMessage")
 {
   data_size = sizeof(RemoveMessage_data_t);
   data_ptr  = malloc(data_size);
@@ -490,7 +593,9 @@ RobotMemoryInterface::RemoveMessage::RemoveMessage(const char * ini_query) : Mes
   data      = (RemoveMessage_data_t *)data_ptr;
   data_ts   = (message_data_ts_t *)data_ptr;
   strncpy(data->query, ini_query, 1024);
+  strncpy(data->collection, ini_collection, 1024);
   add_fieldinfo(IFT_STRING, "query", 1024, data->query);
+  add_fieldinfo(IFT_STRING, "collection", 1024, data->collection);
 }
 /** Constructor */
 RobotMemoryInterface::RemoveMessage::RemoveMessage() : Message("RemoveMessage")
@@ -501,6 +606,7 @@ RobotMemoryInterface::RemoveMessage::RemoveMessage() : Message("RemoveMessage")
   data      = (RemoveMessage_data_t *)data_ptr;
   data_ts   = (message_data_ts_t *)data_ptr;
   add_fieldinfo(IFT_STRING, "query", 1024, data->query);
+  add_fieldinfo(IFT_STRING, "collection", 1024, data->collection);
 }
 
 /** Destructor */
@@ -552,6 +658,36 @@ RobotMemoryInterface::RemoveMessage::set_query(const char * new_query)
   strncpy(data->query, new_query, sizeof(data->query));
 }
 
+/** Get collection value.
+ * The collection to query
+ * @return collection value
+ */
+char *
+RobotMemoryInterface::RemoveMessage::collection() const
+{
+  return data->collection;
+}
+
+/** Get maximum length of collection value.
+ * @return length of collection value, can be length of the array or number of 
+ * maximum number of characters for a string
+ */
+size_t
+RobotMemoryInterface::RemoveMessage::maxlenof_collection() const
+{
+  return 1024;
+}
+
+/** Set collection value.
+ * The collection to query
+ * @param new_collection new collection value
+ */
+void
+RobotMemoryInterface::RemoveMessage::set_collection(const char * new_collection)
+{
+  strncpy(data->collection, new_collection, sizeof(data->collection));
+}
+
 /** Clone this message.
  * Produces a message of the same type as this message and copies the
  * data to the new message.
diff --git a/src/plugins/robot-memory/interfaces/RobotMemoryInterface.h_ext b/src/plugins/robot-memory/interfaces/RobotMemoryInterface.h_ext
index ddd2d0b..4be2a8c 100644
--- a/src/plugins/robot-memory/interfaces/RobotMemoryInterface.h_ext
+++ b/src/plugins/robot-memory/interfaces/RobotMemoryInterface.h_ext
@@ -62,13 +62,14 @@ class RobotMemoryInterface : public Interface
       int64_t timestamp_sec;  /**< Interface Unix timestamp, seconds */
       int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
       char query[1024]; /**< Query as JSON string */
+      char collection[1024]; /**< The collection to query */
     } QueryMessage_data_t;
 #pragma pack(pop)
 
     QueryMessage_data_t *data;
 
    public:
-    QueryMessage(const char * ini_query);
+    QueryMessage(const char * ini_query, const char * ini_collection);
     QueryMessage();
     ~QueryMessage();
 
@@ -77,6 +78,9 @@ class RobotMemoryInterface : public Interface
     char * query() const;
     void set_query(const char * new_query);
     size_t maxlenof_query() const;
+    char * collection() const;
+    void set_collection(const char * new_collection);
+    size_t maxlenof_collection() const;
     virtual Message * clone() const;
   };
 
@@ -89,13 +93,14 @@ class RobotMemoryInterface : public Interface
       int64_t timestamp_sec;  /**< Interface Unix timestamp, seconds */
       int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
       char insert[1024]; /**< Document to insert as JSON string */
+      char collection[1024]; /**< The collection to query */
     } InsertMessage_data_t;
 #pragma pack(pop)
 
     InsertMessage_data_t *data;
 
    public:
-    InsertMessage(const char * ini_insert);
+    InsertMessage(const char * ini_insert, const char * ini_collection);
     InsertMessage();
     ~InsertMessage();
 
@@ -104,6 +109,9 @@ class RobotMemoryInterface : public Interface
     char * insert() const;
     void set_insert(const char * new_insert);
     size_t maxlenof_insert() const;
+    char * collection() const;
+    void set_collection(const char * new_collection);
+    size_t maxlenof_collection() const;
     virtual Message * clone() const;
   };
 
@@ -117,13 +125,14 @@ class RobotMemoryInterface : public Interface
       int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
       char query[1024]; /**< Query as JSON string */
       char update[1024]; /**< Update as JSON string */
+      char collection[1024]; /**< The collection to query */
     } UpdateMessage_data_t;
 #pragma pack(pop)
 
     UpdateMessage_data_t *data;
 
    public:
-    UpdateMessage(const char * ini_query, const char * ini_update);
+    UpdateMessage(const char * ini_query, const char * ini_update, const char * ini_collection);
     UpdateMessage();
     ~UpdateMessage();
 
@@ -135,6 +144,9 @@ class RobotMemoryInterface : public Interface
     char * update() const;
     void set_update(const char * new_update);
     size_t maxlenof_update() const;
+    char * collection() const;
+    void set_collection(const char * new_collection);
+    size_t maxlenof_collection() const;
     virtual Message * clone() const;
   };
 
@@ -147,13 +159,14 @@ class RobotMemoryInterface : public Interface
       int64_t timestamp_sec;  /**< Interface Unix timestamp, seconds */
       int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
       char query[1024]; /**< Query as JSON string */
+      char collection[1024]; /**< The collection to query */
     } RemoveMessage_data_t;
 #pragma pack(pop)
 
     RemoveMessage_data_t *data;
 
    public:
-    RemoveMessage(const char * ini_query);
+    RemoveMessage(const char * ini_query, const char * ini_collection);
     RemoveMessage();
     ~RemoveMessage();
 
@@ -162,6 +175,9 @@ class RobotMemoryInterface : public Interface
     char * query() const;
     void set_query(const char * new_query);
     size_t maxlenof_query() const;
+    char * collection() const;
+    void set_collection(const char * new_collection);
+    size_t maxlenof_collection() const;
     virtual Message * clone() const;
   };
 
diff --git a/src/plugins/robot-memory/interfaces/RobotMemoryInterface.tolua b/src/plugins/robot-memory/interfaces/RobotMemoryInterface.tolua
index 67095b2..65f4672 100644
--- a/src/plugins/robot-memory/interfaces/RobotMemoryInterface.tolua
+++ b/src/plugins/robot-memory/interfaces/RobotMemoryInterface.tolua
@@ -8,7 +8,7 @@ class RobotMemoryInterface : public Interface
 
   class QueryMessage : public Message
   {
-    QueryMessage(char * ini_query);
+    QueryMessage(char * ini_query, char * ini_collection);
     QueryMessage();
     ~QueryMessage();
 
@@ -32,11 +32,14 @@ class RobotMemoryInterface : public Interface
     char * query();
     void set_query(const char * new_query);
     int maxlenof_query() const;
+    char * collection();
+    void set_collection(const char * new_collection);
+    int maxlenof_collection() const;
   };
 
   class InsertMessage : public Message
   {
-    InsertMessage(char * ini_insert);
+    InsertMessage(char * ini_insert, char * ini_collection);
     InsertMessage();
     ~InsertMessage();
 
@@ -60,11 +63,14 @@ class RobotMemoryInterface : public Interface
     char * insert();
     void set_insert(const char * new_insert);
     int maxlenof_insert() const;
+    char * collection();
+    void set_collection(const char * new_collection);
+    int maxlenof_collection() const;
   };
 
   class UpdateMessage : public Message
   {
-    UpdateMessage(char * ini_query, char * ini_update);
+    UpdateMessage(char * ini_query, char * ini_update, char * ini_collection);
     UpdateMessage();
     ~UpdateMessage();
 
@@ -91,11 +97,14 @@ class RobotMemoryInterface : public Interface
     char * update();
     void set_update(const char * new_update);
     int maxlenof_update() const;
+    char * collection();
+    void set_collection(const char * new_collection);
+    int maxlenof_collection() const;
   };
 
   class RemoveMessage : public Message
   {
-    RemoveMessage(char * ini_query);
+    RemoveMessage(char * ini_query, char * ini_collection);
     RemoveMessage();
     ~RemoveMessage();
 
@@ -119,6 +128,9 @@ class RobotMemoryInterface : public Interface
     char * query();
     void set_query(const char * new_query);
     int maxlenof_query() const;
+    char * collection();
+    void set_collection(const char * new_collection);
+    int maxlenof_collection() const;
   };
 
   char * error();
diff --git a/src/plugins/robot-memory/interfaces/RobotMemoryInterface.xml b/src/plugins/robot-memory/interfaces/RobotMemoryInterface.xml
index 498cda9..5058910 100644
--- a/src/plugins/robot-memory/interfaces/RobotMemoryInterface.xml
+++ b/src/plugins/robot-memory/interfaces/RobotMemoryInterface.xml
@@ -14,13 +14,15 @@
     <comment>
       Query to execute.
     </comment>
-    <field type="string"  length="1024" name="query">Query as JSON string</field>
+    <field type="string" length="1024" name="query">Query as JSON string</field>
+    <field type="string" length="1024" name="collection">The collection to query</field>
   </message>
   <message name="Insert">
     <comment>
       Message to insert a document into the database.
     </comment>
     <field type="string"  length="1024" name="insert">Document to insert as JSON string</field>
+    <field type="string" length="1024" name="collection">The collection to query</field>
   </message>
   <message name="Update">
     <comment>
@@ -28,12 +30,14 @@
     </comment>
     <field type="string"  length="1024" name="query">Query as JSON string</field>
     <field type="string"  length="1024" name="update">Update as JSON string</field>
+    <field type="string" length="1024" name="collection">The collection to query</field>
   </message>
   <message name="Remove">
     <comment>
       Message to remove documents matching the query.
     </comment>
     <field type="string"  length="1024" name="query">Query as JSON string</field>
+    <field type="string" length="1024" name="collection">The collection to query</field>
   </message>
 
 </interface>
diff --git a/src/plugins/robot-memory/robot_memory_thread.cpp b/src/plugins/robot-memory/robot_memory_thread.cpp
index ba82068..5cf279e 100644
--- a/src/plugins/robot-memory/robot_memory_thread.cpp
+++ b/src/plugins/robot-memory/robot_memory_thread.cpp
@@ -80,16 +80,26 @@ RobotMemoryThread::loop()
   while (! robot_memory->rm_if_->msgq_empty() ) {
     if (robot_memory->rm_if_->msgq_first_is<RobotMemoryInterface::QueryMessage>()) {
 	    RobotMemoryInterface::QueryMessage* msg = (RobotMemoryInterface::QueryMessage*) robot_memory->rm_if_->msgq_first();
-	    robot_memory->query(msg->query());
+	    QResCursor res = robot_memory->query(msg->query(), msg->collection());
+	    //output result
+	    std::string query = msg->query();
+	    std::string result = "Result of query " + query + ":\n";
+	    while(res->more())
+	    {
+	      mongo::BSONObj doc = res->next();
+	      result += doc.toString() + "\n";
+	    }
+	    logger->log_info(name(), result.c_str());
+	    robot_memory->rm_if_->set_result(result.c_str());
     } else if (robot_memory->rm_if_->msgq_first_is<RobotMemoryInterface::InsertMessage>()) {
 	    RobotMemoryInterface::InsertMessage* msg = (RobotMemoryInterface::InsertMessage*) robot_memory->rm_if_->msgq_first();
-	    robot_memory->insert(msg->insert());
+	    robot_memory->insert(msg->insert()), msg->collection();
     } else if (robot_memory->rm_if_->msgq_first_is<RobotMemoryInterface::UpdateMessage>()) {
 	    RobotMemoryInterface::UpdateMessage* msg = (RobotMemoryInterface::UpdateMessage*) robot_memory->rm_if_->msgq_first();
-	    robot_memory->update(msg->query(), msg->update());
+	    robot_memory->update(msg->query(), msg->update(), msg->collection());
     } else if (robot_memory->rm_if_->msgq_first_is<RobotMemoryInterface::RemoveMessage>()) {
 	    RobotMemoryInterface::RemoveMessage* msg = (RobotMemoryInterface::RemoveMessage*) robot_memory->rm_if_->msgq_first();
-	    robot_memory->remove(msg->query());
+	    robot_memory->remove(msg->query(), msg->collection());
     } else {
       logger->log_warn(name(), "Unknown message received");
     }




-- 
Fawkes Robotics Framework                 http://www.fawkesrobotics.org


More information about the fawkes-commits mailing list