iLab Neuromorphic Robotics Toolkit
0.1
|
#include <nrt/Core/Model/Manager.H>
Manager of an entire model of Components.
A Manager should be the top-level Component of any hierarchy of Components. It is primarily responsible for handling the setting of Parameters via the command-line or otherwise.
Users should only need to construct a Manager, add any subComponents to it, and then call start(), which will parse all command line options (via parseCommandLine()), bind them to their relevant Parameters, and call start() on all subComponents (which in turn calls start() on all of their subComponents, etc.).
Beware that the Manager is not thread-safe so make sure only one thread at a time calls init(), start(), etc, typically this would be your main thread.
The Manager resets the nrt::CentralTimer at each start(), such that durations returned by the nrt::CentralTimer are since the last start().
Public Member Functions | |
Manager (std::string const &instanceID="TheManager") | |
Constructor without command-line args. More... | |
Manager (int argc, char const *argv[], std::string const &instanceID="TheManager") | |
Constructor. More... | |
void | setCommandLineArgs (int argc, char const *argv[]) |
Set the command-line arguments, call this before start() if args were not passed at construction. | |
virtual | ~Manager () |
Destructor. | |
std::vector< std::string > const & | remainingArgs () const |
Get the remaining arguments that were not parsed by the command line. More... | |
void | delayParseCommandLine () |
Do not parse command-line arguments during preInit() More... | |
template<> | |
std::shared_ptr< Component > | getComponent (std::string const &instanceName) const |
Component hierarchies | |
template<class Comp > | |
std::shared_ptr< Comp > | addComponent (std::string const &instanceName="") |
Pseudo-constructor: construct a top-level Component. More... | |
template<class Comp > | |
std::shared_ptr< Comp > | addSubComponent (std::string const &instanceName)=delete |
Use addComponent() on the Manager as opposed to nrt::Component::addSubComponent() | |
template<class Comp > | |
void | removeComponent (std::shared_ptr< Comp > &component) |
Remove a top-level Component from the Manager, by shared_ptr. More... | |
template<class Comp > | |
void | removeSubComponent (std::shared_ptr< Comp > &component)=delete |
Use removeComponent() on the Manager as opposed to nrt::Component::removeSubComponent() | |
void | removeComponent (std::string const &instanceName) |
Remove a top-level Component from the Manager, by instance name. | |
void | removeSubComponent (std::string const &instanceName)=delete |
Use removeComponent() on the Manager as opposed to nrt::Component::removeSubComponent() | |
template<class Comp = nrt::Component> | |
std::shared_ptr< Comp > | getComponent (std::string const &instanceName) const |
Get a top-level component by instance name. More... | |
template<class Comp > | |
std::shared_ptr< Comp > | getSubComponent (std::string const &instanceName) const =delete |
Use getComponent() on the Manager as opposed to nrt::Component::getSubComponent() | |
![]() | |
Component (std::string const &instanceName) | |
Constructor. More... | |
void | prepareForDeletion () |
Prepare for deletion: uninit and disconnect from our parent. More... | |
virtual | ~Component () |
Virtual destructor for safe inheritance. More... | |
template<> | |
std::shared_ptr< Component > | getSubComponent (std::string const &instanceName) const |
template<class Comp > | |
std::shared_ptr< Comp > | addSubComponent (std::string const &instanceName="") |
Pseudo-constructor: construct and add another component as a subcomponent of this one. More... | |
template<class Comp > | |
void | removeSubComponent (std::shared_ptr< Comp > &component) |
Remove a sub-Component from this Component, by shared_ptr. More... | |
void | removeSubComponent (std::string const &instanceName) |
Remove a sub-Component from this Component, by instance name. | |
template<class Comp = nrt::Component> | |
std::shared_ptr< Comp > | getSubComponent (std::string const &instanceName) const |
Get a sub-component by instance name. More... | |
bool | isTopLevel () const |
Returns true if this component is top-level, i.e., its parent is an nrt::Manager (including nrt::Blackboard) | |
bool | initialized () const |
Has this component been initialized yet? | |
bool | started () const |
Is this component started, i.e., it has passed the start() state and not yet entered the stop() state. | |
bool | running () const |
Is this component running, i.e., has passed start() and been launch()ed and not yet entered the stop() state. | |
void | wait () |
Wait until all run() functions decide on their own that they are finished. More... | |
Component::MetaInfo const & | meta () const |
Get the metainfo of this Component. More... | |
template<typename T > | |
std::vector< std::string > | setParamVal (std::string const ¶mdescriptor, T const &val) |
Set a parameter value. More... | |
template<typename T > | |
void | setParamValUnique (std::string const ¶mdescriptor, T const &val) |
Set a parameter value, simple version assuming only one parameter match. More... | |
template<typename T > | |
std::vector< std::pair < std::string, T > > | getParamVal (std::string const ¶mdescriptor) const |
Get parameter(s) value(s) by descriptor. More... | |
template<typename T > | |
T | getParamValUnique (std::string const ¶mdescriptor) const |
Get a parameter value, simple version assuming only one parameter match. More... | |
std::vector< std::string > | setParamString (std::string const ¶mdescriptor, std::string const &val) |
Set a parameter value, by string. More... | |
void | setParamStringUnique (std::string const ¶mdescriptor, std::string const &val) |
Set a parameter value by string, simple version assuming only one parameter match. More... | |
std::vector< std::pair < std::string, std::string > > | getParamString (std::string const ¶mdescriptor) const |
Get a parameter value, by string. More... | |
std::string | getParamStringUnique (std::string const ¶mdescriptor) const |
Get a parameter value by string, simple version assuming only one parameter match. More... | |
std::string | descriptor () const |
Get our full descriptor (including all parents) as [Classname-Instancename]:[...]:[...]. | |
std::string | parentModuleUID () const |
Get the ModuleUID (as string) of this Component's nearest parent Module, or an empty string. | |
void | prettyPrintTree (std::ostream &os, int indent=0) const |
Produce a nice textual hierarchy of this Component's sub-tree. | |
std::vector< std::pair < std::string, nrt::ParameterSummary > > | getParamSummary (std::string const ¶mdescriptor) const |
Return a list of parameter summaries for a given descriptor. More... | |
std::vector< std::pair < std::string, nrt::ParameterSummary > > | getParamSummary (bool skipsubmodules=false) const |
Return a list of parameter summaries for all parameters of this Component and its subcomponents. More... | |
void | setPath (std::string const &path) |
Assign a filesystem path to this component. | |
std::string | absolutePath (std::string const &path) |
If given path is relative (not starting with /), prepend the Component path to it; otherwise, no-op. | |
virtual void | notifyAllParamChanged (nrt::ParameterState const state) const |
This method is called by the Blackboard to refresh a ParamChangedListener. | |
virtual void | getAllParamSummaries (std::vector< nrt::ParameterSummary > &ps) const |
Recursively get all param summaries. | |
![]() | |
void | addParameter (ParameterBase *const param) |
The parameter class uses this method to register itself on construction with it's owning Component. | |
void | removeParameter (ParameterBase *const param) |
The parameter class uses this method to un-register itself on destruction with it's owning Component. | |
Protected Member Functions | |
void | preInit () |
Calls parseCommandLine() | |
void | postInit () |
Checks for the –help flag. | |
void | preStart () |
Resets the nrt::CentralTimer. | |
void | constructHelpMessage (std::ostream &out) const |
Constructs a help message from all parameters in the model, and outputs it to 'out'. | |
void | printHelpMessage () const |
Constructs a help message and tries to send it to /usr/bin/less. | |
![]() | |
virtual void | postStart () |
Called after all sub-Components are start()ed. | |
virtual void | run () |
Called in its own thread after all Components have been start()ed. More... | |
virtual void | preStop () |
Called before all sub-Components are stop()ed. | |
virtual void | postStop () |
Called after all sub-Components are stop()ed. | |
virtual void | preUninit () |
Called before all sub-Components are uninit()ed. | |
virtual void | postUninit () |
Called after all sub-Components are uninit()ed. | |
virtual void | notifyParamChanged (nrt::ParameterState const state, ParameterBase const *const param) const |
This method is called by a Parameter when it has been changed. Users should never overload this method. | |
void | populateHelpMessage (std::string const &cname, std::unordered_map< std::string, std::unordered_map< std::string, std::vector< std::pair< std::string, std::string > > > > &helplist) const |
Additional Inherited Members | |
![]() | |
boost::shared_mutex | itsMtx |
Mutex used to protect our internals other than subcomponents and parameters. | |
std::vector< std::shared_ptr < Component > > | itsSubComponents |
boost::shared_mutex | itsSubMtx |
Component *const | nrt_component_this |
nrt::Manager::Manager | ( | std::string const & | instanceID = "TheManager" ) |
Constructor without command-line args.
The command-line args should be passed later using setArgs(), before you init(), otherwise the manager will issue a non-fatal warning.
nrt::Manager::Manager | ( | int | argc, |
char const * | argv[], | ||
std::string const & | instanceID = "TheManager" |
||
) |
Constructor.
Creates the Manager, and optionally takes in the command line arguments.
|
inline |
Pseudo-constructor: construct a top-level Component.
A component of type Comp (which must derive from nrt::Component) will be created and added as a sub-component of the manager (making it a so-called top-level component). The child logically "belongs" to the Manager, and will automatically be deleted when the Manager is deleted. In addition to construction, the component will be brought to the same runstate as the Manager.
Definition at line 42 of file ManagerImpl.H.
References NRT_FATAL, and NRT_MODDEBUG.
Referenced by main().
void nrt::Manager::removeComponent | ( | std::shared_ptr< Comp > & | component) |
Remove a top-level Component from the Manager, by shared_ptr.
FIXME static_assert( ! std::is_base_of<nrt::ModuleBase, Mod>::value, "Use nrt::Blackboard::removeModule() for objects "
Definition at line 122 of file ManagerImpl.H.
References NRT_MODDEBUG, and NRT_WARNING.
|
inline |
Get a top-level component by instance name.
This method does a dynamic_pointer_cast to Comp if it is not the default (nrt::Component). Throws if component is not found by instance name, or it is found but not of type Comp (if Comp is specified). Note that once you hold a shared_ptr to a Component, it is guaranteed that the component will not be destroyed until that shared_ptr is released. If the NRT system tries to destroy the component (e.g., someone calls removeSubComponent()), the component will be un-initialized and its parent will be unset, so it will not be fully operational and will be actually deleted when the last shared_ptr to it runs out of scope.
Definition at line 83 of file ManagerImpl.H.
References NRT_FATAL.
std::vector<std::string> const& nrt::Manager::remainingArgs | ( | ) | const |
Get the remaining arguments that were not parsed by the command line.
Any command line arguments after a lone '–' will be available in remainingArgs()
void nrt::Manager::delayParseCommandLine | ( | ) |
Do not parse command-line arguments during preInit()
By default, the Manager automatically parses the command-line arguments and sets parameters during preInit(). In general, this is the best time to do this. In some applications where setting parameters could trigger Blackboard operations, however, preInit() is too early to start setting parameters. People who "know what they are doing" can use delayParseCommandLine() to prevent the automatic parsing during preInit() and instead do it during postInit(), at which point the Blackboard should be fully operational.