54 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(managers.begin(), managers.end());
58 C::concatManagers(managers_in, result);
63 static void callCM(
typename std::vector<C*>& , C* , ...) {}
67 { callCM<T>(managers, result,
nullptr); }
72 static void callGR(std::vector<std::string> &resources, C* iface,
typename C::resource_manager_type*)
74 resources = iface->getNames();
79 static void callGR(std::vector<std::string> &, T* , ...) { }
83 {
return callGR<T>(resources, iface,
nullptr); }
86 static T*
newCI(std::vector<ResourceManagerBase*> &guards,
typename C::resource_manager_type*)
88 T* iface_combo =
new T;
90 guards.push_back(static_cast<ResourceManagerBase*>(iface_combo));
96 static T*
newCI(std::vector<ResourceManagerBase*> &, ...) {
98 ROS_ERROR(
"You cannot register multiple interfaces of the same type which are " 99 "not of type ResourceManager. There is no established protocol " 100 "for combining them.");
106 return newCI<T>(guards,
nullptr);
140 const std::string iface_name = internal::demangledTypeName<T>();
141 if (interfaces_.find(iface_name) != interfaces_.end())
143 ROS_WARN_STREAM(
"Replacing previously registered interface '" << iface_name <<
"'.");
145 interfaces_[iface_name] = iface;
159 interface_managers_.push_back(iface_man);
185 std::string type_name = internal::demangledTypeName<T>();
186 std::vector<T*> iface_list;
189 InterfaceMap::iterator it = interfaces_.find(type_name);
190 if (it != interfaces_.end()) {
191 T* iface =
static_cast<T*
>(it->second);
194 "'. This should never happen");
197 iface_list.push_back(iface);
201 for (
const auto& interface_manager : interface_managers_) {
202 T* iface = interface_manager->get<T>();
204 iface_list.push_back(iface);
207 if(iface_list.size() == 0)
210 if(iface_list.size() == 1)
211 return iface_list.front();
216 InterfaceMap::iterator it_combo = interfaces_combo_.find(type_name);
217 if(it_combo != interfaces_combo_.end() &&
218 num_ifaces_registered_[type_name] == iface_list.size()) {
222 iface_combo =
static_cast<T*
>(it_combo->second);
230 interfaces_combo_[type_name] = iface_combo;
231 num_ifaces_registered_[type_name] = iface_list.size();
235 iface_combo =
nullptr;
252 std::vector<std::string> out;
253 out.reserve(interfaces_.size());
254 for (
const auto& interface : interfaces_)
256 out.push_back(interface.first);
259 for (
const auto& interface_manager : interface_managers_)
262 for (
const auto& interface_name : interface_manager->getNames())
264 if (std::find(out.begin(), out.end(), interface_name) == out.end())
266 out.push_back(interface_name);
285 std::vector<std::string> out;
286 ResourceMap::const_iterator it = resources_.find(iface_type);
287 if(it != resources_.end())
292 for (
const auto& interface_manager : interface_managers_)
294 std::vector<std::string> resources = interface_manager->getInterfaceResources(iface_type);
295 out.insert(out.end(), resources.begin(), resources.end());
304 typedef std::map<std::string, size_t>
SizeMap;
305 typedef std::map<std::string, std::vector<std::string> >
ResourceMap;
void registerInterface(T *iface)
Register an interface.
std::map< std::string, size_t > SizeMap
static void callCM(typename std::vector< C *> &managers, C *result, typename C::resource_manager_type *)
void registerInterfaceManager(InterfaceManager *iface_man)
Register another interface manager.
InterfaceMap interfaces_combo_
std::vector< ResourceManagerBase * > interface_destruction_list_
std::vector< std::string > getInterfaceResources(std::string iface_type) const
Get the resource names registered to an interface, specified by type.
static void callCM(typename std::vector< C *> &, C *,...)
static T * newCI(std::vector< ResourceManagerBase *> &guards, typename C::resource_manager_type *)
static void callConcatManagers(typename std::vector< T *> &managers, T *result)
ResourceMap resources_
This will allow us to check the resources based on the demangled type name of the interface...
static T * newCI(std::vector< ResourceManagerBase *> &,...)
static T * newCombinedInterface(std::vector< ResourceManagerBase *> &guards)
std::vector< InterfaceManager * > InterfaceManagerVector
std::vector< std::string > getNames() const
Lists the demangled names of all registered interfaces.
InterfaceManagerVector interface_managers_
#define ROS_WARN_STREAM(args)
SizeMap num_ifaces_registered_
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 void callGetResources(std::vector< std::string > &resources, T *iface)
#define ROS_ERROR_STREAM(args)
Manager for hardware interface registrations.
static void callGR(std::vector< std::string > &, T *,...)
std::map< std::string, void * > InterfaceMap