Class able to contain other modules. More...
#include <WModuleContainer.h>
Public Types | |
typedef std::set < boost::shared_ptr< WModule > > | ModuleContainerType |
For shortening: a type defining a shared vector of WModule pointers. | |
typedef WSharedObject < ModuleContainerType > | ModuleSharedContainerType |
The alias for a shared container. | |
typedef ModuleContainerType::const_iterator | ModuleConstIterator |
The const iterator type of the container. | |
typedef ModuleContainerType::iterator | ModuleIterator |
The iterator type of the container. | |
typedef std::set < boost::shared_ptr < WDataModule > > | DataModuleListType |
Simple type for WDataModule pointer lists. | |
Public Member Functions | |
WModuleContainer (std::string name="Unnamed Module Container", std::string description="Used as container for several modules.") | |
Constructor. | |
virtual | ~WModuleContainer () |
Destructor. | |
virtual void | add (boost::shared_ptr< WModule > module, bool run=true) |
Add a module to this container and start it. | |
virtual void | remove (boost::shared_ptr< WModule > module) |
Remove the given module from this container if it is associated with it. | |
virtual void | removeDeep (boost::shared_ptr< WModule > module) |
As remove, it removes the module from the container. | |
virtual void | stop () |
Stops all modules inside this container. | |
virtual const std::string | getName () const |
Gives back the name of this module. | |
virtual const std::string | getDescription () const |
Gives back a description of this module. | |
virtual void | addDefaultNotifier (MODULE_SIGNAL signal, t_ModuleErrorSignalHandlerType notifier) |
Add a specified notifier to the list of default notifiers which get connected to each added module. | |
virtual void | addDefaultNotifier (MODULE_SIGNAL signal, t_ModuleGenericSignalHandlerType notifier) |
Add a specified notifier to the list of default notifiers which get connected to each added module. | |
virtual void | addDefaultNotifier (MODULE_CONNECTOR_SIGNAL signal, t_GenericSignalHandlerType notifier) |
Add a specified notifier to the list of default notifiers which get connected to each added module. | |
virtual boost::shared_ptr < WModule > | applyModule (boost::shared_ptr< WModule > applyOn, std::string what, bool tryOnly=false) |
Function combines two modules. | |
virtual boost::shared_ptr < WModule > | applyModule (boost::shared_ptr< WModule > applyOn, boost::shared_ptr< WModule > prototype) |
Function combines two modules. | |
boost::shared_ptr< WBatchLoader > | loadDataSets (std::vector< std::string > fileNames) |
Load specified datasets. | |
void | loadDataSetsSynchronously (std::vector< std::string > fileNames) |
Loads the specified files synchronously. | |
void | addPendingThread (boost::shared_ptr< WThreadedRunner > thread) |
Add the specified thread to the list of pending jobs. | |
void | finishedPendingThread (boost::shared_ptr< WThreadedRunner > thread) |
The specified thread has finished and does not longer depend upon this container instance. | |
void | setCrashIfModuleCrashes (bool crashIfCrashed=true) |
Sets a flag denoting whether the container (which also is a module) should be marked as "crashed" if a nested module crashes. | |
virtual boost::shared_ptr < WModule > | factory () const |
Due to the prototype design pattern used to build modules, this method returns a new instance of this method. | |
DataModuleListType | getDataModules () |
Returns a vector of pointers to the loaded data modules in the container. | |
ModuleSharedContainerType::ReadTicket | getModules () const |
Method returns a read ticket allowing read-access to the list of modules. | |
WCombinerTypes::WCompatiblesList | getPossibleConnections (boost::shared_ptr< WModule > module) |
This method creates a list of combiner instances, for each possible connection that can be made between the specified module and the module currently inside the container. | |
Protected Member Functions | |
virtual void | moduleMain () |
Entry point after loading the module. | |
virtual void | moduleError (boost::shared_ptr< WModule > module, const WException &exception) |
This method is called whenever a module inside the container crashes. | |
Protected Attributes | |
ModuleSharedContainerType | m_modules |
The modules associated with this container. | |
std::string | m_name |
Name of the module. | |
std::string | m_description |
Description of the module. | |
boost::shared_mutex | m_errorNotifiersLock |
Lock for error notifiers set. | |
std::list < t_ModuleErrorSignalHandlerType > | m_errorNotifiers |
The error notifiers connected to added modules by default. | |
boost::shared_mutex | m_readyNotifiersLock |
Lock for ready notifiers set. | |
std::list < t_ModuleGenericSignalHandlerType > | m_readyNotifiers |
The ready notifiers connected to added modules by default. | |
boost::shared_mutex | m_associatedNotifiersLock |
Lock for associated notifiers set. | |
std::list < t_ModuleGenericSignalHandlerType > | m_associatedNotifiers |
The notifiers connected to added modules by default and fired whenever the module got associated. | |
boost::shared_mutex | m_removedNotifiersLock |
Lock for remove-notifiers set. | |
std::list < t_ModuleGenericSignalHandlerType > | m_removedNotifiers |
The notifiers connected to added modules by default and fired whenever the module got removed again. | |
boost::shared_mutex | m_connectorNotifiersLock |
Lock for connector-notifiers set. | |
std::list < t_GenericSignalHandlerType > | m_connectorEstablishedNotifiers |
The notifiers connected to added modules by default and fired whenever the module connectors got connected. | |
std::list < t_GenericSignalHandlerType > | m_connectorClosedNotifiers |
The notifiers connected to added modules by default and fired whenever the module connectors got disconnected. | |
std::set< boost::shared_ptr < WThreadedRunner > > | m_pendingThreads |
Set of all threads that currently depend upon this container. | |
boost::shared_mutex | m_pendingThreadsLock |
Lock for m_pendingThreads. | |
bool | m_crashIfModuleCrashes |
This flag denotes whether the whole container should be marked as crashed if one of the contained modules crashes. | |
Private Types | |
typedef std::pair < boost::shared_ptr< WModule > , boost::signals2::connection > | ModuleSubscription |
A type for mapping a module to all its subscriptions. | |
typedef std::multimap < boost::shared_ptr< WModule > , boost::signals2::connection > | ModuleSubscriptionsType |
For shortening: a type defining a shared vector of subscriptions a module made to a notifier during add(). | |
typedef WSharedObject < ModuleSubscriptionsType > | ModuleSubscriptionsSharedType |
The alias for a shared container. | |
typedef ModuleSubscriptionsType::const_iterator | ModuleSubscriptionsConstIterator |
The const iterator type of the container. | |
typedef ModuleSubscriptionsType::iterator | ModuleSubscriptionsIterator |
The iterator type of the container. | |
Private Attributes | |
ModuleSubscriptionsSharedType | m_moduleSubscriptions |
The module's signal subscriptions. |
Class able to contain other modules.
It manages several tasks like finding appropriate modules, managing data modules and module initialization.
Definition at line 58 of file WModuleContainer.h.
typedef std::set< boost::shared_ptr< WDataModule > > WModuleContainer::DataModuleListType |
Simple type for WDataModule pointer lists.
Definition at line 250 of file WModuleContainer.h.
typedef ModuleContainerType::const_iterator WModuleContainer::ModuleConstIterator |
The const iterator type of the container.
Definition at line 77 of file WModuleContainer.h.
typedef std::set< boost::shared_ptr< WModule > > WModuleContainer::ModuleContainerType |
For shortening: a type defining a shared vector of WModule pointers.
Definition at line 67 of file WModuleContainer.h.
typedef ModuleContainerType::iterator WModuleContainer::ModuleIterator |
The iterator type of the container.
Definition at line 82 of file WModuleContainer.h.
The alias for a shared container.
Definition at line 72 of file WModuleContainer.h.
typedef std::pair< boost::shared_ptr< WModule >, boost::signals2::connection > WModuleContainer::ModuleSubscription [private] |
A type for mapping a module to all its subscriptions.
Definition at line 389 of file WModuleContainer.h.
typedef ModuleSubscriptionsType::const_iterator WModuleContainer::ModuleSubscriptionsConstIterator [private] |
The const iterator type of the container.
Definition at line 404 of file WModuleContainer.h.
typedef ModuleSubscriptionsType::iterator WModuleContainer::ModuleSubscriptionsIterator [private] |
The iterator type of the container.
Definition at line 409 of file WModuleContainer.h.
typedef WSharedObject< ModuleSubscriptionsType > WModuleContainer::ModuleSubscriptionsSharedType [private] |
The alias for a shared container.
Definition at line 399 of file WModuleContainer.h.
typedef std::multimap< boost::shared_ptr< WModule >, boost::signals2::connection > WModuleContainer::ModuleSubscriptionsType [private] |
For shortening: a type defining a shared vector of subscriptions a module made to a notifier during add().
Definition at line 394 of file WModuleContainer.h.
WModuleContainer::WModuleContainer | ( | std::string | name = "Unnamed Module Container" , |
|
std::string | description = "Used as container for several modules." | |||
) |
Constructor.
Initializes container.
name | name of the container | |
description | short description. |
Definition at line 51 of file WModuleContainer.cpp.
References WLogger::addLogMessage(), WLogger::getLogger(), and getName().
Referenced by factory().
WModuleContainer::~WModuleContainer | ( | ) | [virtual] |
Destructor.
Definition at line 61 of file WModuleContainer.cpp.
void WModuleContainer::add | ( | boost::shared_ptr< WModule > | module, | |
bool | run = true | |||
) | [virtual] |
Add a module to this container and start it.
Please note, that a module can be added only once. If it already is associated with this container nothing happens.
module | the module to add. | |
run | true when the module should be run automatically after adding it. |
WModuleUninitialized | thrown whenever someone wants to add a module not yet initialized. |
Definition at line 79 of file WModuleContainer.cpp.
References WLogger::addLogMessage(), WLogger::getLogger(), getName(), WSharedObject< T >::getWriteTicket(), m_associatedNotifiers, m_associatedNotifiersLock, m_connectorClosedNotifiers, m_connectorEstablishedNotifiers, m_connectorNotifiersLock, m_errorNotifiers, m_errorNotifiersLock, m_modules, m_moduleSubscriptions, WModule::m_progress, m_readyNotifiers, m_readyNotifiersLock, and moduleError().
Referenced by applyModule().
void WModuleContainer::addDefaultNotifier | ( | MODULE_SIGNAL | signal, | |
t_ModuleGenericSignalHandlerType | notifier | |||
) | [virtual] |
Add a specified notifier to the list of default notifiers which get connected to each added module.
signal | the signal the notifier should get connected to | |
notifier | the notifier function |
Definition at line 312 of file WModuleContainer.cpp.
References m_associatedNotifiers, m_associatedNotifiersLock, m_readyNotifiers, m_readyNotifiersLock, m_removedNotifiers, and m_removedNotifiersLock.
void WModuleContainer::addDefaultNotifier | ( | MODULE_CONNECTOR_SIGNAL | signal, | |
t_GenericSignalHandlerType | notifier | |||
) | [virtual] |
Add a specified notifier to the list of default notifiers which get connected to each added module.
This is especially used for all the connector related events like connect and disconnect.
signal | the signal the notifier should get connected to | |
notifier | the notifier function |
Definition at line 358 of file WModuleContainer.cpp.
References m_connectorClosedNotifiers, m_connectorEstablishedNotifiers, and m_connectorNotifiersLock.
void WModuleContainer::addDefaultNotifier | ( | MODULE_SIGNAL | signal, | |
t_ModuleErrorSignalHandlerType | notifier | |||
) | [virtual] |
Add a specified notifier to the list of default notifiers which get connected to each added module.
signal | the signal the notifier should get connected to | |
notifier | the notifier function |
Definition at line 340 of file WModuleContainer.cpp.
References m_errorNotifiers, and m_errorNotifiersLock.
void WModuleContainer::addPendingThread | ( | boost::shared_ptr< WThreadedRunner > | thread | ) |
Add the specified thread to the list of pending jobs.
Only this ensures, that ALL pending threads get stopped before the container gets stopped.
thread | the thread to add |
Definition at line 456 of file WModuleContainer.cpp.
References m_pendingThreads, and m_pendingThreadsLock.
boost::shared_ptr< WModule > WModuleContainer::applyModule | ( | boost::shared_ptr< WModule > | applyOn, | |
std::string | what, | |||
bool | tryOnly = false | |||
) | [virtual] |
Function combines two modules.
This runs synchronously. It might take some time to finish since combination of modules is allowed only with modules marked as "ready" which might take some time.
applyOn | the module which already has to be in the container and to apply the other one on. | |
what | the prototype name of the module to apply on the other one specified. | |
tryOnly | If set to false and the prototype "what" does not exist this will throw an exception. If set to true and the prototype does not exist, the nothing will happen. |
Definition at line 381 of file WModuleContainer.cpp.
References WModuleFactory::getModuleFactory().
boost::shared_ptr< WModule > WModuleContainer::applyModule | ( | boost::shared_ptr< WModule > | applyOn, | |
boost::shared_ptr< WModule > | prototype | |||
) | [virtual] |
Function combines two modules.
This runs synchronously. It might take some time to finish since combination of modules is allowed only with modules marked as "ready" which might take some time.
applyOn | the module which already has to be in the container and to apply the other one on. | |
prototype | the prototype of the module to apply on the other one specified. |
Definition at line 401 of file WModuleContainer.cpp.
References add(), and WModuleFactory::getModuleFactory().
boost::shared_ptr< WModule > WModuleContainer::factory | ( | ) | const [virtual] |
Due to the prototype design pattern used to build modules, this method returns a new instance of this method.
NOTE: it should never be initialized or modified in some other way. A simple new instance is required.
Implements WModule.
Definition at line 73 of file WModuleContainer.cpp.
References getDescription(), getName(), and WModuleContainer().
void WModuleContainer::finishedPendingThread | ( | boost::shared_ptr< WThreadedRunner > | thread | ) |
The specified thread has finished and does not longer depend upon this container instance.
thread | the thread. |
Definition at line 463 of file WModuleContainer.cpp.
References m_pendingThreads, and m_pendingThreadsLock.
WModuleContainer::DataModuleListType WModuleContainer::getDataModules | ( | ) |
Returns a vector of pointers to the loaded data modules in the container.
Definition at line 243 of file WModuleContainer.cpp.
References WSharedObject< T >::getReadTicket(), and m_modules.
const std::string WModuleContainer::getDescription | ( | ) | const [virtual] |
Gives back a description of this module.
Definition at line 307 of file WModuleContainer.cpp.
References m_description.
Referenced by factory().
WModuleContainer::ModuleSharedContainerType::ReadTicket WModuleContainer::getModules | ( | ) | const |
Method returns a read ticket allowing read-access to the list of modules.
Definition at line 490 of file WModuleContainer.cpp.
References WSharedObject< T >::getReadTicket(), and m_modules.
const std::string WModuleContainer::getName | ( | ) | const [virtual] |
Gives back the name of this module.
Definition at line 302 of file WModuleContainer.cpp.
References m_name.
Referenced by add(), factory(), remove(), removeDeep(), stop(), and WModuleContainer().
WCombinerTypes::WCompatiblesList WModuleContainer::getPossibleConnections | ( | boost::shared_ptr< WModule > | module | ) |
This method creates a list of combiner instances, for each possible connection that can be made between the specified module and the module currently inside the container.
It might be possible that a module which is contained in the returned list is not associated anymore if the combiner gets applied.
module | the module to which the possible connections should be returned |
Definition at line 495 of file WModuleContainer.cpp.
References WSharedObject< T >::getReadTicket(), and m_modules.
boost::shared_ptr< WBatchLoader > WModuleContainer::loadDataSets | ( | std::vector< std::string > | fileNames | ) |
Load specified datasets.
It immediately returns and starts another thread, which actually loads the data.
fileNames | list of filenames to load. The registered notification handler for the root container will get notified on error and success. |
Definition at line 436 of file WModuleContainer.cpp.
void WModuleContainer::loadDataSetsSynchronously | ( | std::vector< std::string > | fileNames | ) |
Loads the specified files synchronously.
fileNames | list of filenames to load. The registered notification handler for the root container will get notified on error and success. |
Definition at line 446 of file WModuleContainer.cpp.
void WModuleContainer::moduleError | ( | boost::shared_ptr< WModule > | module, | |
const WException & | exception | |||
) | [protected, virtual] |
This method is called whenever a module inside the container crashes.
By default, this method does nothing but forwarding the using WModule's signals.
module | the module that has crashed. | |
exception | the exception. |
Definition at line 470 of file WModuleContainer.cpp.
References WModule::errorLog(), WModule::infoLog(), m_crashIfModuleCrashes, WModule::m_isCrashed, WThreadedRunner::requestStop(), and WModule::signal_error.
Referenced by add().
void WModuleContainer::moduleMain | ( | ) | [protected, virtual] |
Entry point after loading the module.
Runs in separate thread. The module container does not use this method. It simply returns.
Implements WModule.
Definition at line 66 of file WModuleContainer.cpp.
References WModule::ready().
void WModuleContainer::remove | ( | boost::shared_ptr< WModule > | module | ) | [virtual] |
Remove the given module from this container if it is associated with it.
It only provides flat removal. It does not remove depending modules. Please be aware that this method does NOT stop the module. It just removes it from the container. If you release the shared pointer after removing from the container, the instance gets freed although it still might run. To also wait for the module to quit, use module->wait( true ).
module | the module to remove. |
Definition at line 186 of file WModuleContainer.cpp.
References WLogger::addLogMessage(), WLogger::getLogger(), getName(), WSharedObject< T >::getWriteTicket(), m_modules, m_moduleSubscriptions, WModule::m_progress, m_removedNotifiers, and m_removedNotifiersLock.
void WModuleContainer::removeDeep | ( | boost::shared_ptr< WModule > | module | ) | [virtual] |
As remove, it removes the module from the container.
In contrast to remove, it also removes all the depending modules from the container.
module | the module which should be removed including all depending modules |
Definition at line 235 of file WModuleContainer.cpp.
References WLogger::addLogMessage(), WLogger::getLogger(), and getName().
void WModuleContainer::setCrashIfModuleCrashes | ( | bool | crashIfCrashed = true |
) |
Sets a flag denoting whether the container (which also is a module) should be marked as "crashed" if a nested module crashes.
crashIfCrashed | true if it also should crash. |
Definition at line 485 of file WModuleContainer.cpp.
References m_crashIfModuleCrashes.
void WModuleContainer::stop | ( | ) | [virtual] |
Stops all modules inside this container.
Note that this function could take some time, since it waits until the last module has quit.
Definition at line 269 of file WModuleContainer.cpp.
References WLogger::addLogMessage(), WLogger::getLogger(), getName(), WSharedObject< T >::getReadTicket(), WSharedObject< T >::getWriteTicket(), m_modules, m_pendingThreads, and m_pendingThreadsLock.
std::list< t_ModuleGenericSignalHandlerType > WModuleContainer::m_associatedNotifiers [protected] |
The notifiers connected to added modules by default and fired whenever the module got associated.
Definition at line 329 of file WModuleContainer.h.
Referenced by add(), and addDefaultNotifier().
boost::shared_mutex WModuleContainer::m_associatedNotifiersLock [protected] |
Lock for associated notifiers set.
Definition at line 324 of file WModuleContainer.h.
Referenced by add(), and addDefaultNotifier().
std::list< t_GenericSignalHandlerType > WModuleContainer::m_connectorClosedNotifiers [protected] |
The notifiers connected to added modules by default and fired whenever the module connectors got disconnected.
Definition at line 354 of file WModuleContainer.h.
Referenced by add(), and addDefaultNotifier().
std::list< t_GenericSignalHandlerType > WModuleContainer::m_connectorEstablishedNotifiers [protected] |
The notifiers connected to added modules by default and fired whenever the module connectors got connected.
Definition at line 349 of file WModuleContainer.h.
Referenced by add(), and addDefaultNotifier().
boost::shared_mutex WModuleContainer::m_connectorNotifiersLock [protected] |
Lock for connector-notifiers set.
Definition at line 344 of file WModuleContainer.h.
Referenced by add(), and addDefaultNotifier().
bool WModuleContainer::m_crashIfModuleCrashes [protected] |
This flag denotes whether the whole container should be marked as crashed if one of the contained modules crashes.
By default, this is true. The root container (the container not nested in any other container) sets this to false explicitly. Modules using the container to encapsulate a whole bunch of modules can decide, but by default they crash too.
Definition at line 380 of file WModuleContainer.h.
Referenced by moduleError(), and setCrashIfModuleCrashes().
std::string WModuleContainer::m_description [protected] |
Description of the module.
Definition at line 299 of file WModuleContainer.h.
Referenced by getDescription().
std::list< t_ModuleErrorSignalHandlerType > WModuleContainer::m_errorNotifiers [protected] |
The error notifiers connected to added modules by default.
Definition at line 309 of file WModuleContainer.h.
Referenced by add(), and addDefaultNotifier().
boost::shared_mutex WModuleContainer::m_errorNotifiersLock [protected] |
Lock for error notifiers set.
Definition at line 304 of file WModuleContainer.h.
Referenced by add(), and addDefaultNotifier().
ModuleSharedContainerType WModuleContainer::m_modules [protected] |
The modules associated with this container.
Definition at line 289 of file WModuleContainer.h.
Referenced by add(), getDataModules(), getModules(), getPossibleConnections(), remove(), and stop().
The module's signal subscriptions.
Definition at line 414 of file WModuleContainer.h.
std::string WModuleContainer::m_name [protected] |
std::set< boost::shared_ptr< WThreadedRunner > > WModuleContainer::m_pendingThreads [protected] |
Set of all threads that currently depend upon this container.
Definition at line 359 of file WModuleContainer.h.
Referenced by addPendingThread(), finishedPendingThread(), and stop().
boost::shared_mutex WModuleContainer::m_pendingThreadsLock [protected] |
Lock for m_pendingThreads.
Definition at line 364 of file WModuleContainer.h.
Referenced by addPendingThread(), finishedPendingThread(), and stop().
std::list< t_ModuleGenericSignalHandlerType > WModuleContainer::m_readyNotifiers [protected] |
The ready notifiers connected to added modules by default.
Definition at line 319 of file WModuleContainer.h.
Referenced by add(), and addDefaultNotifier().
boost::shared_mutex WModuleContainer::m_readyNotifiersLock [protected] |
Lock for ready notifiers set.
Definition at line 314 of file WModuleContainer.h.
Referenced by add(), and addDefaultNotifier().
std::list< t_ModuleGenericSignalHandlerType > WModuleContainer::m_removedNotifiers [protected] |
The notifiers connected to added modules by default and fired whenever the module got removed again.
Definition at line 339 of file WModuleContainer.h.
Referenced by addDefaultNotifier(), and remove().
boost::shared_mutex WModuleContainer::m_removedNotifiersLock [protected] |
Lock for remove-notifiers set.
Definition at line 334 of file WModuleContainer.h.
Referenced by addDefaultNotifier(), and remove().