25 #ifndef WMODULECONTAINER_H
26 #define WMODULECONTAINER_H
32 #include <shared_mutex>
37 #include <boost/function.hpp>
38 #include <boost/signals2/signal.hpp>
39 #include <boost/thread.hpp>
41 #include "../common/WSharedObject.h"
42 #include "WBatchLoader.h"
44 #include "WModuleCombinerTypes.h"
45 #include "WModuleConnectorSignals.h"
46 #include "WModuleSignals.h"
97 std::string description =
"Used as container for several modules." );
112 virtual void add( std::shared_ptr< WModule > module,
bool run =
true );
131 virtual void remove( std::shared_ptr< WModule > module );
149 virtual const std::string
getName()
const;
163 virtual void addDefaultNotifier( MODULE_SIGNAL signal, t_ModuleErrorSignalHandlerType notifier );
171 virtual void addDefaultNotifier( MODULE_SIGNAL signal, t_ModuleGenericSignalHandlerType notifier );
181 virtual void addDefaultNotifier( MODULE_CONNECTOR_SIGNAL signal, t_GenericSignalHandlerType notifier );
195 virtual std::shared_ptr< WModule >
applyModule( std::shared_ptr< WModule > applyOn, std::string what,
bool tryOnly =
false );
206 virtual std::shared_ptr< WModule >
applyModule( std::shared_ptr< WModule > applyOn, std::shared_ptr< WModule > prototype );
263 virtual std::shared_ptr< WModule >
factory()
const;
std::shared_ptr< WBatchLoader > SPtr
Shared ptr abbreviation.
Base for all data loader modules.
Class able to contain other modules.
std::list< t_ModuleGenericSignalHandlerType > m_readyNotifiers
The ready notifiers connected to added modules by default.
void finishedPendingThread(std::shared_ptr< WThreadedRunner > thread)
The specified thread has finished and does not longer depend upon this container instance.
std::pair< std::shared_ptr< WModule >, boost::signals2::connection > ModuleSubscription
A type for mapping a module to all its subscriptions.
std::shared_mutex m_errorNotifiersLock
Lock for error notifiers set.
virtual const std::string getName() const
Gives back the name of this module.
virtual std::shared_ptr< WModule > factory() const
Due to the prototype design pattern used to build modules, this method returns a new instance of this...
std::string m_name
Name of the module.
std::list< t_ModuleErrorSignalHandlerType > m_errorNotifiers
The error notifiers connected to added modules by default.
std::list< t_GenericSignalHandlerType > m_connectorEstablishedNotifiers
The notifiers connected to added modules by default and fired whenever the module connectors got conn...
virtual void moduleMain()
Entry point after loading the module.
std::list< t_ModuleGenericSignalHandlerType > m_associatedNotifiers
The notifiers connected to added modules by default and fired whenever the module got associated.
ModuleContainerType::iterator ModuleIterator
The iterator type of the container.
std::list< t_GenericSignalHandlerType > m_connectorClosedNotifiers
The notifiers connected to added modules by default and fired whenever the module connectors got disc...
std::shared_mutex m_readyNotifiersLock
Lock for ready notifiers set.
std::set< std::shared_ptr< WModule > > ModuleContainerType
For shortening: a type defining a shared vector of WModule pointers.
void setCrashIfModuleCrashes(bool crashIfCrashed=true)
Sets a flag denoting whether the container (which also is a module) should be marked as "crashed" if ...
WSharedObject< ModuleSubscriptionsType > ModuleSubscriptionsSharedType
The alias for a shared container.
DataModuleListType getDataModules()
Returns a vector of pointers to the loaded data modules in the container.
std::shared_mutex m_associatedNotifiersLock
Lock for associated notifiers set.
ModuleSharedContainerType::ReadTicket getModules() const
Method returns a read ticket allowing read-access to the list of modules inside the container.
WBatchLoader::SPtr loadDataSetsSynchronously(std::vector< std::string > filenames, bool suppressColormaps=false)
Loads the specified files synchronously.
virtual WModule::SPtr createAndAdd(std::string name)
Convenience method to create a module instance with a given name and automatically add it to the cont...
std::shared_mutex m_connectorNotifiersLock
Lock for connector-notifiers set.
virtual const std::string getDescription() const
Gives back a description of this module.
std::shared_mutex m_pendingThreadsLock
Lock for m_pendingThreads.
virtual void stop()
Stops all modules inside this container.
std::list< t_ModuleGenericSignalHandlerType > m_removedNotifiers
The notifiers connected to added modules by default and fired whenever the module got removed again.
std::string m_description
Description of the module.
bool m_crashIfModuleCrashes
This flag denotes whether the whole container should be marked as crashed if one of the contained mod...
ModuleSharedContainerType m_modules
The modules associated with this container.
std::set< std::shared_ptr< WDataModule > > DataModuleListType
Simple type for WDataModule pointer lists.
void addPendingThread(std::shared_ptr< WThreadedRunner > thread)
Add the specified thread to the list of pending jobs.
WBatchLoader::SPtr loadDataSets(std::vector< std::string > filenames, bool suppressColormaps=false)
Load specified datasets.
std::multimap< std::shared_ptr< WModule >, boost::signals2::connection > ModuleSubscriptionsType
For shortening: a type defining a shared vector of subscriptions a module made to a notifier during a...
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.
std::set< std::shared_ptr< WThreadedRunner > > m_pendingThreads
Set of all threads that currently depend upon this container.
virtual void remove(std::shared_ptr< WModule > module)
Remove the given module from this container if it is associated with it.
std::shared_mutex m_removedNotifiersLock
Lock for remove-notifiers set.
virtual void removeAll()
Removes all modules from this container.
WCombinerTypes::WCompatiblesList getPossibleConnections(std::shared_ptr< WModule > module)
This method creates a list of combiner instances, for each possible connection that can be made betwe...
virtual std::shared_ptr< WModule > applyModule(std::shared_ptr< WModule > applyOn, std::string what, bool tryOnly=false)
Function combines two modules.
ModuleSubscriptionsType::iterator ModuleSubscriptionsIterator
The iterator type of the container.
ModuleSubscriptionsSharedType m_moduleSubscriptions
The module's signal subscriptions.
std::vector< std::shared_ptr< WModule > > ModuleVectorType
A vector of modules.
virtual void add(std::shared_ptr< WModule > module, bool run=true)
Add a module to this container and start it.
ModuleContainerType::const_iterator ModuleConstIterator
The const iterator type of the container.
ModuleSubscriptionsType::const_iterator ModuleSubscriptionsConstIterator
The const iterator type of the container.
virtual void moduleError(std::shared_ptr< WModule > module, const WException &exception)
This method is called whenever a module inside the container crashes.
virtual ~WModuleContainer()
Destructor.
WSharedObject< ModuleContainerType > ModuleSharedContainerType
The alias for a shared container.
Class representing a single module of OpenWalnut.
std::shared_ptr< WModule > SPtr
Shared pointer to a WModule.
friend class WModuleContainer
for proper management of m_container WModuleContainer needs access.
std::shared_ptr< WSharedObjectTicketRead< ModuleContainerType > > ReadTicket
Type for read tickets.
Base class for all classes needing to be executed in a separate thread.
virtual void run()
Run thread.