Пример #1
0
    def query_messages_ros_srv(self, req):
        """
        Returns t
        """
        collection = self._mongo_client[req.database][req.collection]

        # build the query doc

        # load serialised json

        if len(req.message_query) > 0 and req.message_query[
                0].first == dc_srv.MongoQueryMsgRequest.JSON_QUERY:
            obj_query = json.loads(req.message_query[0].second)
        # else use the string pairs
        else:
            obj_query = dict(
                (pair.first, pair.second) for pair in req.message_query)

        # load serialised json for meta
        if len(req.meta_query) > 0 and req.meta_query[
                0].first == dc_srv.MongoQueryMsgRequest.JSON_QUERY:
            meta_query = json.loads(req.meta_query[0].second)
            # prefix all keys with "_meta." to make it
            for old_key in meta_query:
                meta_query["_meta." + old_key] = meta_query.pop(old_key)
                obj_query.update(meta_query)
        # else use the string pairs
        else:
            obj_query.update(
                dict(("_meta." + pair.first, pair.second)
                     for pair in req.meta_query))

        # restrict results to have the type asked for
        obj_query["_meta.stored_type"] = req.type

        # TODO start using some string constants!

        rospy.loginfo("query document: %s", obj_query)

        # this is a list of entries in dict format including meta
        entries = dc_util.query_message(collection, obj_query, req.single)

        serialised_messages = ()

        for entry in entries:
            # load the class object for this type
            # TODO this should be the same for every item in the list, so could reuse
            cls = dc_util.load_class(entry["_meta"]["stored_class"])
            # instantiate the ROS message object from the dictionary retrieved from the db
            message = dc_util.dictionary_to_message(entry, cls)
            # the serialise this object in order to be sent in a generic form
            serialised_messages = serialised_messages + (
                dc_util.serialise_message(message), )

        return [serialised_messages]
Пример #2
0
    def query_messages_ros_srv(self, req):
        """
        Returns t
        """
        collection = self._mongo_client[req.database][req.collection]


        # build the query doc 
        
        # load serialised json

        if len(req.message_query) > 0 and req.message_query[0].first == dc_srv.MongoQueryMsgRequest.JSON_QUERY:
            obj_query = json.loads(req.message_query[0].second)
        # else use the string pairs
        else:
            obj_query = dict((pair.first, pair.second) for pair in req.message_query)
        

        # load serialised json for meta
        if len(req.meta_query) > 0 and req.meta_query[0].first == dc_srv.MongoQueryMsgRequest.JSON_QUERY:
            meta_query = json.loads(req.meta_query[0].second)
            # prefix all keys with "_meta." to make it 
            for old_key in meta_query:
                meta_query["_meta." + old_key] = meta_query.pop(old_key)
                obj_query.update(meta_query)
        # else use the string pairs
        else:
            obj_query.update(dict(("_meta." + pair.first, pair.second) for pair in req.meta_query))


        # restrict results to have the type asked for
        obj_query["_meta.stored_type"] = req.type

        # TODO start using some string constants!

        rospy.loginfo("query document: %s", obj_query) 
        

        # this is a list of entries in dict format including meta
        entries =  dc_util.query_message(collection, obj_query, req.single)

        serialised_messages = ()

        for entry in entries:
            # load the class object for this type
            # TODO this should be the same for every item in the list, so could reuse
            cls = dc_util.load_class(entry["_meta"]["stored_class"])
            # instantiate the ROS message object from the dictionary retrieved from the db
            message = dc_util.dictionary_to_message(entry, cls)            
            # the serialise this object in order to be sent in a generic form
            serialised_messages = serialised_messages + (dc_util.serialise_message(message), )
       
        return [serialised_messages]
Пример #3
0
 def insert(self, message, meta={}):
     # assume meta is a dict, convert k/v to tuple pairs
     meta_tuple = tuple(StringPair(k, v) for k, v in meta.iteritems())
     serialised_msg = dc_util.serialise_message(message)
     self.insert_srv(self.database, self.collection, serialised_msg, meta_tuple)
Пример #4
0
 def insert(self, message, meta={}):
     # assume meta is a dict, convert k/v to tuple pairs
     meta_tuple = tuple(StringPair(k, v) for k, v in meta.iteritems())
     serialised_msg = dc_util.serialise_message(message)
     self.insert_srv(self.database, self.collection, serialised_msg,
                     meta_tuple)