OpenWalnut  1.4.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Private Attributes
WModuleContainer Class Reference

Class able to contain other modules. More...

#include <WModuleContainer.h>

+ Inheritance diagram for WModuleContainer:

List of all members.

Public Types

typedef std::vector
< boost::shared_ptr< WModule > > 
ModuleVectorType
 A vector of modules.
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 WModule::SPtr createAndAdd (std::string name)
 Convenience method to create a module instance with a given name and automatically add it to the container.
virtual void remove (boost::shared_ptr< WModule > module)
 Remove the given module from this container if it is associated with it.
virtual void removeAll ()
 Removes all modules from this 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.
WBatchLoader::SPtr loadDataSets (std::vector< std::string > filenames, bool suppressColormaps=false)
 Load specified datasets.
WBatchLoader::SPtr loadDataSetsSynchronously (std::vector< std::string > filenames, bool suppressColormaps=false)
 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 inside the container.
ModuleVectorType getModules (std::string name) const
 Queries the container to find all modules with a given name.
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.

Detailed Description

Class able to contain other modules.

It manages several tasks like finding appropriate modules, managing data modules and module initialization.

Definition at line 59 of file WModuleContainer.h.


Member Typedef Documentation

typedef std::set< boost::shared_ptr< WDataModule > > WModuleContainer::DataModuleListType

Simple type for WDataModule pointer lists.

Definition at line 268 of file WModuleContainer.h.

typedef ModuleContainerType::const_iterator WModuleContainer::ModuleConstIterator

The const iterator type of the container.

Definition at line 82 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 72 of file WModuleContainer.h.

typedef ModuleContainerType::iterator WModuleContainer::ModuleIterator

The iterator type of the container.

Definition at line 87 of file WModuleContainer.h.

The alias for a shared container.

Definition at line 77 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 415 of file WModuleContainer.h.

typedef ModuleSubscriptionsType::const_iterator WModuleContainer::ModuleSubscriptionsConstIterator [private]

The const iterator type of the container.

Definition at line 430 of file WModuleContainer.h.

typedef ModuleSubscriptionsType::iterator WModuleContainer::ModuleSubscriptionsIterator [private]

The iterator type of the container.

Definition at line 435 of file WModuleContainer.h.

The alias for a shared container.

Definition at line 425 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 420 of file WModuleContainer.h.

typedef std::vector< boost::shared_ptr< WModule > > WModuleContainer::ModuleVectorType

A vector of modules.

Definition at line 67 of file WModuleContainer.h.


Constructor & Destructor Documentation

WModuleContainer::WModuleContainer ( std::string  name = "Unnamed Module Container",
std::string  description = "Used as container for several modules." 
)

Constructor.

Initializes container.

Parameters:
namename of the container
descriptionshort description.

Definition at line 49 of file WModuleContainer.cpp.

References WLogger::addLogMessage(), WLogger::getLogger(), and getName().

Referenced by factory().

Destructor.

Definition at line 59 of file WModuleContainer.cpp.


Member Function Documentation

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.

Parameters:
modulethe module to add.
runtrue when the module should be run automatically after adding it.
Exceptions:
WModuleUninitializedthrown whenever someone wants to add a module not yet initialized.

Definition at line 77 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(), and createAndAdd().

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.

Parameters:
signalthe signal the notifier should get connected to
notifierthe notifier function

Definition at line 370 of file WModuleContainer.cpp.

References m_errorNotifiers, and m_errorNotifiersLock.

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.

Parameters:
signalthe signal the notifier should get connected to
notifierthe notifier function

Definition at line 342 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.

Notes:
This signal is only called for input connectors!
Parameters:
signalthe signal the notifier should get connected to
notifierthe notifier function

Definition at line 388 of file WModuleContainer.cpp.

References m_connectorClosedNotifiers, m_connectorEstablishedNotifiers, and m_connectorNotifiersLock.

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.

Notes:
use this to register threads whenever you start threads belonging to this container. This avoids shutting down the container while other threads depend upon it.
Parameters:
threadthe thread to add

Definition at line 485 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.

Parameters:
applyOnthe module which already has to be in the container and to apply the other one on.
whatthe prototype name of the module to apply on the other one specified.
tryOnlyIf 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.
Returns:
the newly created module connected with the one specified in applyOn. If the prototype could not be found and tryOnly was set to true it will return NULL.

Definition at line 411 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.

Parameters:
applyOnthe module which already has to be in the container and to apply the other one on.
prototypethe prototype of the module to apply on the other one specified.
Returns:
the newly created module connected with the one specified in applyOn.

Definition at line 431 of file WModuleContainer.cpp.

References add(), and WModuleFactory::getModuleFactory().

WModule::SPtr WModuleContainer::createAndAdd ( std::string  name) [virtual]

Convenience method to create a module instance with a given name and automatically add it to the container.

Parameters:
namethe prototype name to create
Returns:
the created and added module

Definition at line 184 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.

Returns:
the prototype used to create every module in OpenWalnut.

Implements WModule.

Definition at line 71 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.

Parameters:
threadthe thread.

Definition at line 492 of file WModuleContainer.cpp.

References m_pendingThreads, and m_pendingThreadsLock.

Returns a vector of pointers to the loaded data modules in the container.

Returns:
the list of data modules.

Definition at line 246 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.

Returns:
description to module.

Implements WPrototyped.

Definition at line 337 of file WModuleContainer.cpp.

References m_description.

Referenced by factory().

Method returns a read ticket allowing read-access to the list of modules inside the container.

Notes:
If done, ensure the ticket gets destroyed.
Returns:
the read ticket.

Definition at line 519 of file WModuleContainer.cpp.

References WSharedObject< T >::getReadTicket(), and m_modules.

Referenced by getModules(), and removeAll().

Queries the container to find all modules with a given name.

This can be useful to check for existence of certain modules inside the container.

Parameters:
namename of the modules to find
Returns:
the vector of modules. Empty if nothing was found.

Definition at line 524 of file WModuleContainer.cpp.

References getModules().

const std::string WModuleContainer::getName ( ) const [virtual]

Gives back the name of this module.

Returns:
the module's name.

Implements WPrototyped.

Definition at line 332 of file WModuleContainer.cpp.

References m_name.

Referenced by add(), factory(), remove(), 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.

Parameters:
modulethe module to which the possible connections should be returned
Returns:
the possible combinations of connectors.

Definition at line 545 of file WModuleContainer.cpp.

References WSharedObject< T >::getReadTicket(), and m_modules.

WBatchLoader::SPtr WModuleContainer::loadDataSets ( std::vector< std::string >  filenames,
bool  suppressColormaps = false 
)

Load specified datasets.

It immediately returns and starts another thread, which actually loads the data.

Parameters:
filenameslist of filenames to load. The registered notification handler for the root container will get notified on error and success.
suppressColormapsif true, the data modules are instructed to avoid registration of colormaps. This can be very handy if you combine multiple data loaders into one new data loader or data set
Returns:
the loader handling the load operation

Definition at line 466 of file WModuleContainer.cpp.

WBatchLoader::SPtr WModuleContainer::loadDataSetsSynchronously ( std::vector< std::string >  filenames,
bool  suppressColormaps = false 
)

Loads the specified files synchronously.

The returned batchloader can be queried for the list of data modules that have been added.

Parameters:
filenameslist of filenames to load. The registered notification handler for the root container will get notified on error and success.
suppressColormapsif true, the data modules are instructed to avoid registration of colormaps. This can be very handy if you combine multiple data loaders into one new data loader or data set
Returns:
the loader has handled the load operation

Definition at line 475 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.

Parameters:
modulethe module that has crashed.
exceptionthe exception.

Definition at line 499 of file WModuleContainer.cpp.

References WModule::errorLog(), WModule::infoLog(), m_crashIfModuleCrashes, WThreadedRunner::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 64 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 ).

Parameters:
modulethe module to remove.

Definition at line 197 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::removeAll ( ) [virtual]

Removes all modules from this container.

It uses a relatively laborious iterative approach becausewe can not delete modules recursively so far.

Definition at line 272 of file WModuleContainer.cpp.

References getModules().

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.

Parameters:
crashIfCrashedtrue if it also should crash.

Definition at line 514 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 299 of file WModuleContainer.cpp.

References WLogger::addLogMessage(), WLogger::getLogger(), getName(), WSharedObject< T >::getReadTicket(), WSharedObject< T >::getWriteTicket(), m_modules, m_pendingThreads, and m_pendingThreadsLock.


Member Data Documentation

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 356 of file WModuleContainer.h.

Referenced by add(), and addDefaultNotifier().

boost::shared_mutex WModuleContainer::m_associatedNotifiersLock [protected]

Lock for associated notifiers set.

Definition at line 351 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 381 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 376 of file WModuleContainer.h.

Referenced by add(), and addDefaultNotifier().

boost::shared_mutex WModuleContainer::m_connectorNotifiersLock [protected]

Lock for connector-notifiers set.

Definition at line 371 of file WModuleContainer.h.

Referenced by add(), and addDefaultNotifier().

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 407 of file WModuleContainer.h.

Referenced by moduleError(), and setCrashIfModuleCrashes().

std::string WModuleContainer::m_description [protected]

Description of the module.

Definition at line 326 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 336 of file WModuleContainer.h.

Referenced by add(), and addDefaultNotifier().

boost::shared_mutex WModuleContainer::m_errorNotifiersLock [protected]

Lock for error notifiers set.

Definition at line 331 of file WModuleContainer.h.

Referenced by add(), and addDefaultNotifier().

The modules associated with this container.

Definition at line 316 of file WModuleContainer.h.

Referenced by add(), getDataModules(), getModules(), getPossibleConnections(), remove(), and stop().

The module's signal subscriptions.

Definition at line 440 of file WModuleContainer.h.

Referenced by add(), and remove().

std::string WModuleContainer::m_name [protected]

Name of the module.

Definition at line 321 of file WModuleContainer.h.

Referenced by getName().

std::set< boost::shared_ptr< WThreadedRunner > > WModuleContainer::m_pendingThreads [protected]

Set of all threads that currently depend upon this container.

Definition at line 386 of file WModuleContainer.h.

Referenced by addPendingThread(), finishedPendingThread(), and stop().

boost::shared_mutex WModuleContainer::m_pendingThreadsLock [protected]

Lock for m_pendingThreads.

Definition at line 391 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 346 of file WModuleContainer.h.

Referenced by add(), and addDefaultNotifier().

boost::shared_mutex WModuleContainer::m_readyNotifiersLock [protected]

Lock for ready notifiers set.

Definition at line 341 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 366 of file WModuleContainer.h.

Referenced by addDefaultNotifier(), and remove().

boost::shared_mutex WModuleContainer::m_removedNotifiersLock [protected]

Lock for remove-notifiers set.

Definition at line 361 of file WModuleContainer.h.

Referenced by addDefaultNotifier(), and remove().


The documentation for this class was generated from the following files: