31 #ifndef HARDWARE_INTERFACE_INTERFACE_MANAGER_H 32 #define HARDWARE_INTERFACE_INTERFACE_MANAGER_H 37 #include <boost/ptr_container/ptr_vector.hpp> 55 static void callCM(
typename std::vector<C*>& managers, C* result,
typename C::resource_manager_type*)
57 std::vector<typename C::resource_manager_type*> managers_in;
59 for(
typename std::vector<C*>::iterator it = managers.begin(); it != managers.end(); ++it)
60 managers_in.push_back(static_cast<typename C::resource_manager_type*>(*it));
61 C::concatManagers(managers_in, result);
66 static void callCM(
typename std::vector<C*>& managers, C* result, ...) {}
70 { callCM<T>(managers, result, 0); }
75 static void callGR(std::vector<std::string> &resources, C* iface,
typename C::resource_manager_type*)
77 resources = iface->getNames();
82 static void callGR(std::vector<std::string> &resources, T* iface, ...) { }
86 {
return callGR<T>(resources, iface, 0); }
89 static T*
newCI(boost::ptr_vector<ResourceManagerBase> &guards,
typename C::resource_manager_type*)
91 T* iface_combo =
new T;
93 guards.push_back(static_cast<ResourceManagerBase*>(iface_combo));
99 static T*
newCI(boost::ptr_vector<ResourceManagerBase> &guards, ...) {
101 ROS_ERROR(
"You cannot register multiple interfaces of the same type which are " 102 "not of type ResourceManager. There is no established protocol " 103 "for combining them.");
109 return newCI<T>(guards, 0);
131 const std::string iface_name = internal::demangledTypeName<T>();
132 if (interfaces_.find(iface_name) != interfaces_.end())
134 ROS_WARN_STREAM(
"Replacing previously registered interface '" << iface_name <<
"'.");
136 interfaces_[iface_name] = iface;
142 interface_managers_.push_back(iface_man);
158 std::string type_name = internal::demangledTypeName<T>();
159 std::vector<T*> iface_list;
162 InterfaceMap::iterator it = interfaces_.find(type_name);
163 if (it != interfaces_.end()) {
164 T* iface =
static_cast<T*
>(it->second);
167 "'. This should never happen");
170 iface_list.push_back(iface);
174 for(InterfaceManagerVector::iterator it = interface_managers_.begin();
175 it != interface_managers_.end(); ++it) {
176 T* iface = (*it)->get<T>();
178 iface_list.push_back(iface);
181 if(iface_list.size() == 0)
184 if(iface_list.size() == 1)
185 return iface_list.front();
190 InterfaceMap::iterator it_combo = interfaces_combo_.find(type_name);
191 if(it_combo != interfaces_combo_.end() &&
192 num_ifaces_registered_[type_name] == iface_list.size()) {
196 iface_combo =
static_cast<T*
>(it_combo->second);
204 interfaces_combo_[type_name] = iface_combo;
205 num_ifaces_registered_[type_name] = iface_list.size();
208 ROS_ERROR(
"You cannot register multiple interfaces of the same type which are " 209 "not of type ResourceManager. There is no established protocol " 210 "for combining them.");
220 std::vector<std::string> out;
221 out.reserve(interfaces_.size());
222 for(InterfaceMap::const_iterator it = interfaces_.begin(); it != interfaces_.end(); ++it)
224 out.push_back(it->first);
238 std::vector<std::string> out;
239 ResourceMap::const_iterator it = resources_.find(iface_type);
240 if(it != resources_.end())
250 typedef std::map<std::string, size_t>
SizeMap;
251 typedef std::map<std::string, std::vector<std::string> >
ResourceMap;
264 #endif // header guard void registerInterface(T *iface)
Register an interface.
std::map< std::string, size_t > SizeMap
static T * newCI(boost::ptr_vector< ResourceManagerBase > &guards, typename C::resource_manager_type *)
static T * newCombinedInterface(boost::ptr_vector< ResourceManagerBase > &guards)
void registerInterfaceManager(InterfaceManager *iface_man)
InterfaceMap interfaces_combo_
std::vector< std::string > getNames() const
boost::ptr_vector< ResourceManagerBase > interface_destruction_list_
static T * newCI(boost::ptr_vector< ResourceManagerBase > &guards,...)
static void callCM(typename std::vector< C * > &managers, C *result, typename C::resource_manager_type *)
ResourceMap resources_
This will allow us to check the resources based on the demangled type name of the interface...
std::vector< InterfaceManager * > InterfaceManagerVector
InterfaceManagerVector interface_managers_
#define ROS_WARN_STREAM(args)
SizeMap num_ifaces_registered_
static void callCM(typename std::vector< C * > &managers, C *result,...)
static void callGR(std::vector< std::string > &resources, C *iface, typename C::resource_manager_type *)
std::map< std::string, std::vector< std::string > > ResourceMap
static const void callConcatManagers(typename std::vector< T * > &managers, T *result)
static void callGetResources(std::vector< std::string > &resources, T *iface)
std::vector< std::string > getInterfaceResources(std::string iface_type) const
Get the resource names registered to an interface, specified by type (as this class only stores one i...
#define ROS_ERROR_STREAM(args)
static void callGR(std::vector< std::string > &resources, T *iface,...)
std::map< std::string, void * > InterfaceMap