rtt_rosservice_registry_service.cpp
Go to the documentation of this file.
1 
2 #include <rtt/RTT.hpp>
5 
8 
10 
12 {
13  if (!s_instance_) {
16  }
17  return s_instance_;
18 }
19 
21 {
22  s_instance_.reset();
23 }
24 
26  : Service("rosservice_registry", owner)
27 {
28  this->doc("Global RTT Service for registering ROS service types.");
33 }
34 
41 {
43  if(factory == NULL) {
44  RTT::log(RTT::Error) << "Failed to register ROS service factory: NULL pointer given." << RTT::endlog();
45  return false;
46  }
47 
48  const std::string &ros_service_type = factory->getType();
49 
50  // Check if the factory type has yet to be registered
51  if(factories_.find(ros_service_type) == factories_.end()) {
52  // Store a new factory
53  factories_[ros_service_type] = boost::shared_ptr<ROSServiceProxyFactoryBase>(factory);
54  } else {
55  // Reset the existing factory
56  factories_[ros_service_type].reset(factory);
57  }
58 
59  RTT::log(RTT::Info) << "Successfully registered ROS service factory for \"" << ros_service_type << "\"." << RTT::endlog();
60 
61  return true;
62 }
63 
64 bool ROSServiceRegistryService::hasServiceFactory(const std::string &service_type)
65 {
67  return factories_.find(service_type) != factories_.end();
68 }
69 
71 {
73  if(factories_.find(service_type) != factories_.end()) {
74  return factories_[service_type].get();
75  }
76 
77  RTT::log(RTT::Error)<<"Service type \""<<service_type<<"\" has not been registered with the rosservice_registry service."<<RTT::endlog();
78 
79  return NULL;
80 }
81 
83 {
85 
86  RTT::log(RTT::Info) << "Available ROS .srv types:" << RTT::endlog();
87  for(std::map<std::string, boost::shared_ptr<ROSServiceProxyFactoryBase> >::const_iterator it = factories_.begin();
88  it != factories_.end();
89  ++it)
90  {
91  RTT::log(RTT::Info) << " -- " << it->first << RTT::endlog();
92  }
93 }
94 
95 std::map<std::string, boost::shared_ptr<ROSServiceProxyFactoryBase> > ROSServiceRegistryService::factories_;
97 
99 {
100  // enforce instantiation of ROSServiceRegistryService singleton
102 }
103 
104 using namespace RTT;
105 extern "C" {
107  if (c != 0) return false;
109  return true;
110  }
111  std::string getRTTPluginName (){
112  return "rosservice_registry";
113  }
114  std::string getRTTTargetName (){
115  return OROCOS_TARGET_NAME;
116  }
117 }
ROSServiceProxyFactoryBase * getServiceFactory(const std::string &service_type)
static void loadROSServiceRegistryService()
std::string getRTTPluginName()
Operation< Signature > & addOperation(Operation< Signature > &op)
static std::map< std::string, boost::shared_ptr< ROSServiceProxyFactoryBase > > factories_
ROS service proxy factories.
ROSServiceRegistryService(RTT::TaskContext *owner)
static ROSServiceRegistryServicePtr Instance()
static ROSServiceRegistryServicePtr s_instance_
The singleton instance.
const std::string & doc() const
static RTT::os::MutexRecursive factory_lock_
std::string getRTTTargetName()
bool hasServiceFactory(const std::string &service_type)
Abstract factory for ROS Service Proxy Factories.
bool loadRTTPlugin(RTT::TaskContext *c)
static Logger & log()
const std::string & getType()
Get the ROS service type.
ClientThread
bool registerServiceFactory(ROSServiceProxyFactoryBase *factory)
Register a ROS service proxy factory.
static Logger::LogFunction endlog()
static RTT_API Service::shared_ptr Instance()


rtt_roscomm
Author(s): Ruben Smits, Jonathan Bohren
autogenerated on Mon May 10 2021 02:45:04