ObjectManager.h
Go to the documentation of this file.
00001 
00021 #ifndef OBJECTMANAGER_HPP_
00022 #define OBJECTMANAGER_HPP_
00023 
00024 #include <ros/ros.h>
00025 #include <string>
00026 #include <map>
00027 #include "asr_object_database/ObjectMetaData.h"
00028 
00029 namespace object_database {
00030 
00031     using namespace asr_object_database;
00032 
00033     typedef ObjectMetaData::Response ObjectTypeResponse;
00034         typedef ObjectTypeResponse::Ptr ObjectTypeResponsePtr;
00035 
00039         class ObjectManager {
00040         private:
00041                 struct State {
00042                 private:
00043                         ros::NodeHandle mNodeHandle;
00044                 public:
00045                         ros::ServiceClient object_type_service_client;
00046             std::map<std::pair<std::string, std::string>, ObjectMetaData::Response::Ptr> object_type_cache;
00047 
00048                         State() : mNodeHandle() {
00049                 object_type_service_client = mNodeHandle.serviceClient<ObjectMetaData>("/asr_object_database/object_meta_data");
00050                         }
00051                 };
00052 
00053                 static boost::shared_ptr<State> InstancePtr() {
00054                         static const boost::shared_ptr<State> statePtr = boost::shared_ptr<State>(new State());
00055                         return statePtr;
00056                 }
00057 
00058 
00059         public:
00060                 ObjectManager() {}
00061 
00062         ObjectTypeResponsePtr get(std::string objectTypeName, std::string recognizer) {
00063                         boost::shared_ptr<State> statePtr = InstancePtr();
00064 
00065                         if (!statePtr->object_type_service_client.exists()) {
00066                                 return ObjectTypeResponsePtr();
00067                         }
00068 
00069             ObjectTypeResponsePtr responsePtr = statePtr->object_type_cache[std::make_pair(objectTypeName, recognizer)];
00070 
00071                         if (!responsePtr) {          
00072                 ObjectMetaData serviceCall;
00073                                 serviceCall.request.object_type = objectTypeName;
00074                 serviceCall.request.recognizer = recognizer;
00075                                 statePtr->object_type_service_client.call(serviceCall);
00076                                 if (!serviceCall.response.is_valid) {
00077                                         return ObjectTypeResponsePtr();
00078                                 }
00079 
00080                 responsePtr = ObjectTypeResponsePtr(new ObjectMetaData::Response(serviceCall.response));
00081                 statePtr->object_type_cache[std::make_pair(objectTypeName, recognizer)] = responsePtr;
00082                         }
00083                         return responsePtr;
00084                 }
00085         };
00086 }
00087 
00088 
00089 
00090 #endif /* OBJECTMANAGER_HPP_ */


asr_object_database
Author(s): Allgeyer Tobias, Aumann Florian, Borella Jocelyn, Braun Kai, Heizmann Heinrich, Heller Florian, Kasper Alexander, Marek Felix, Mehlhaus Jonas, Meißner Pascal, Schleicher Ralf, Stöckle Patrick, Walter Milena
autogenerated on Thu Jun 6 2019 21:11:02