25 template <
class Comp,
typename... Args>
inline 31 static_assert(std::is_base_of<jevois::Component, Comp>::value,
"Comp must derive from jevois::Component");
33 std::shared_ptr<Comp> subComp;
37 boost::unique_lock<boost::shared_mutex> ulck(itsSubMtx);
41 subComp.reset(
new Comp(computeInstanceName(instance, jevois::demangledName<Comp>()), std::forward<Args>(args)...));
44 LDEBUG(
"Adding Component [" << subComp->instanceName() <<
']');
45 itsSubComponents.push_back(subComp);
46 subComp->itsParent =
this;
53 if (itsInitialized) subComp->init();
59 template <
class Comp>
inline 65 static_assert(std::is_base_of<jevois::Component, Comp>::value,
"Comp must derive from jevois::Component");
67 boost::shared_lock<boost::shared_mutex> lck(itsSubMtx);
69 for (std::shared_ptr<jevois::Component> c : itsSubComponents)
70 if (c->instanceName() == instance)
72 std::shared_ptr<Comp> ret = std::dynamic_pointer_cast<Comp>(c);
74 LFATAL(
"Component [" << instance <<
"] is not of type [" << jevois::demangledName<Comp>() <<
']');
77 LFATAL(
"Component [" << instance <<
"] not found");
82 #ifndef JEVOIS_DOXYGEN 86 std::shared_ptr<Component> Manager::getComponent<Component>(std::string
const & instance)
const 88 boost::shared_lock<boost::shared_mutex> lck(itsSubMtx);
90 for (std::shared_ptr<Component> c : itsSubComponents)
91 if (c->instanceName() == instance)
return c;
93 LFATAL(
"Component [" << instance <<
"] not found");
102 static_assert(std::is_base_of<jevois::Component, Comp>::value,
"Comp must derive from jevois::Component");
104 boost::upgrade_lock<boost::shared_mutex> uplck(itsSubMtx);
106 for (
auto itr = itsSubComponents.begin(); itr != itsSubComponents.end(); ++itr)
107 if (itr->get() == component.get())
114 doRemoveSubComponent(itr, uplck,
"Component");
118 LERROR(
"Component [" << component->instanceName() <<
"] not found. Ignored.");
#define LDEBUG(msg)
Convenience macro for users to print out console or syslog messages, DEBUG level. ...
std::shared_ptr< Comp > addComponent(std::string const &instanceName, Args &&...args)
Pseudo-constructor: construct a top-level Component.
void removeComponent(std::shared_ptr< Comp > &component)
Remove a top-level Component from the Manager, by shared_ptr.
#define LERROR(msg)
Convenience macro for users to print out console or syslog messages, ERROR level. ...
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level. ...
std::string absolutePath(std::string const &path="")
If given path is relative (not starting with /), prepend the Component path to it.
std::shared_ptr< Comp > getComponent(std::string const &instanceName) const
Get a top-level component by instance name.