ObjectManager.h
Go to the documentation of this file.
1 
21 #ifndef OBJECTMANAGER_HPP_
22 #define OBJECTMANAGER_HPP_
23 
24 #include <ros/ros.h>
25 #include <string>
26 #include <map>
27 #include "asr_object_database/ObjectMetaData.h"
28 
29 namespace object_database {
30 
31  using namespace asr_object_database;
32 
33  typedef ObjectMetaData::Response ObjectTypeResponse;
34  typedef ObjectTypeResponse::Ptr ObjectTypeResponsePtr;
35 
39  class ObjectManager {
40  private:
41  struct State {
42  private:
44  public:
46  std::map<std::pair<std::string, std::string>, ObjectMetaData::Response::Ptr> object_type_cache;
47 
48  State() : mNodeHandle() {
49  object_type_service_client = mNodeHandle.serviceClient<ObjectMetaData>("/asr_object_database/object_meta_data");
50  }
51  };
52 
54  static const boost::shared_ptr<State> statePtr = boost::shared_ptr<State>(new State());
55  return statePtr;
56  }
57 
58 
59  public:
61 
62  ObjectTypeResponsePtr get(std::string objectTypeName, std::string recognizer) {
63  boost::shared_ptr<State> statePtr = InstancePtr();
64 
65  if (!statePtr->object_type_service_client.exists()) {
66  return ObjectTypeResponsePtr();
67  }
68 
69  ObjectTypeResponsePtr responsePtr = statePtr->object_type_cache[std::make_pair(objectTypeName, recognizer)];
70 
71  if (!responsePtr) {
72  ObjectMetaData serviceCall;
73  serviceCall.request.object_type = objectTypeName;
74  serviceCall.request.recognizer = recognizer;
75  statePtr->object_type_service_client.call(serviceCall);
76  if (!serviceCall.response.is_valid) {
77  return ObjectTypeResponsePtr();
78  }
79 
80  responsePtr = ObjectTypeResponsePtr(new ObjectMetaData::Response(serviceCall.response));
81  statePtr->object_type_cache[std::make_pair(objectTypeName, recognizer)] = responsePtr;
82  }
83  return responsePtr;
84  }
85  };
86 }
87 
88 
89 
90 #endif /* OBJECTMANAGER_HPP_ */
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
ros::ServiceClient object_type_service_client
Definition: ObjectManager.h:45
ObjectTypeResponse::Ptr ObjectTypeResponsePtr
Definition: ObjectManager.h:34
ObjectMetaData::Response ObjectTypeResponse
Definition: ObjectManager.h:33
::xsd::cxx::tree::string< char, simple_type > string
static boost::shared_ptr< State > InstancePtr()
Definition: ObjectManager.h:53
std::map< std::pair< std::string, std::string >, ObjectMetaData::Response::Ptr > object_type_cache
Definition: ObjectManager.h:46


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 Wed Jan 8 2020 03:12:13