30 #include <boost/shared_ptr.hpp>
31 #include <boost/uuid/uuid.hpp>
32 #include <boost/uuid/uuid_generators.hpp>
33 #include <boost/uuid/uuid_io.hpp>
35 #include "WModuleInputConnector.h"
36 #include "WModuleOutputConnector.h"
37 #include "WModuleInputData.h"
38 #include "WModuleOutputData.h"
39 #include "WModuleConnectorSignals.h"
40 #include "WModuleContainer.h"
41 #include "WModuleFactory.h"
42 #include "WModuleMetaInformation.h"
43 #include "exceptions/WModuleConnectorInitFailed.h"
44 #include "exceptions/WModuleConnectorNotFound.h"
45 #include "exceptions/WModuleUninitialized.h"
46 #include "exceptions/WModuleRequirementNotMet.h"
47 #include "../common/WException.h"
48 #include "../common/exceptions/WNameNotUnique.h"
49 #include "../common/exceptions/WSignalUnknown.h"
50 #include "../common/exceptions/WSignalSubscriptionFailed.h"
51 #include "../common/WLogger.h"
52 #include "../common/WCondition.h"
53 #include "../common/WConditionOneShot.h"
54 #include "../common/WConditionSet.h"
55 #include "../common/WPathHelper.h"
56 #include "../common/WProgressCombiner.h"
57 #include "../common/WPredicateHelper.h"
71 m_restoreMode( false ),
72 m_readyProgress( boost::shared_ptr<
WProgress >( new
WProgress(
"Initializing Module" ) ) ),
78 m_infoProperties = boost::shared_ptr< WProperties >(
new WProperties(
"Informational Properties",
"Module's information properties" ) );
79 m_infoProperties->setPurpose( PV_PURPOSE_INFORMATION );
81 m_runtimeName =
m_properties->addProperty(
"Name",
"The name of the module defined by the user. This is, by default, the module name but "
82 "can be changed by the user to provide some kind of simple identification upon many modules.",
83 std::string(
"" ),
false );
85 m_active =
m_properties->addProperty(
"active",
"Determines whether the module should be activated.",
true,
true );
94 m_container = boost::shared_ptr< WModuleContainer >();
122 throw WNameNotUnique( std::string(
"Could not add the connector " + con->getCanonicalName() +
" since names must be unique." ) );
141 throw WNameNotUnique( std::string(
"Could not add the connector " + con->getCanonicalName() +
" since names must be unique." ) );
153 ( *listIter )->disconnectAll();
158 ( *listIter )->disconnectAll();
164 WCombinerTypes::WDisconnectList discons;
170 WCombinerTypes::WDisconnectGroup g = WCombinerTypes::WDisconnectGroup( ( *listIter )->getName(),
171 ( *listIter )->getPossibleDisconnections() );
173 if( g.second.size() )
175 discons.push_back( g );
183 WCombinerTypes::WDisconnectGroup g = WCombinerTypes::WDisconnectGroup( ( *listIter )->getName(),
184 ( *listIter )->getPossibleDisconnections() );
186 if( g.second.size() )
188 discons.push_back( g );
241 std::string(
". Reason: already initialized." ) );
285 return MODULE_ARBITRARY;
305 if( ( name == ( *listIter )->getCanonicalName() ) || ( name == ( *listIter )->getName() ) )
307 return ( *listIter );
311 return boost::shared_ptr< WModuleInputConnector >();
321 std::string(
"\" does not exist in the module \"" ) +
getName() + std::string(
"\"." ) );
334 if( ( name == ( *listIter )->getCanonicalName() ) || ( name == ( *listIter )->getName() ) )
336 return ( *listIter );
340 return boost::shared_ptr< WModuleOutputConnector >();
350 std::string(
"\" does not exist in the module \"" ) +
getName() +
351 std::string(
"\"." ) );
372 boost::shared_ptr< WModuleConnector > p =
findConnector( name );
377 std::string(
"\" does not exist in the module \"" ) +
getName() +
378 std::string(
"\"." ) );
391 std::ostringstream s;
392 s <<
"Could not subscribe to unknown signal.";
405 std::ostringstream s;
406 s <<
"Could not subscribe to unknown signal.";
416 case CONNECTION_ESTABLISHED:
418 case CONNECTION_CLOSED:
423 std::ostringstream s;
424 s <<
"Could not subscribe to unknown signal. You need to implement this signal type explicitly in your module.";
462 boost::shared_ptr< WModuleConnector > )
468 boost::shared_ptr< WModuleConnector > )
474 boost::shared_ptr< WModuleConnector > )
497 static const char * o_xpm[] =
518 if( !( *i )->isComplied() )
665 boost::uuids::random_generator gen;
666 m_uuid = boost::uuids::to_string( gen() );
t_ModuleErrorSignalType signal_error
Signal fired whenever a module main thread throws an exception/error.
WStreamedLogger error(const std::string &source)
Logging an error message.
virtual boost::signals2::connection subscribeSignal(MODULE_SIGNAL signal, t_ModuleGenericSignalHandlerType notifier)
Connects a specified notify function with a signal this module instance is offering.
boost::shared_ptr< WModuleContainer > m_container
The container this module belongs to.
void reportRestoreComplete()
Called by loaders to tell the module that loading has been completed.
virtual const std::string getName() const =0
Gets the name of this prototype.
wlog::WStreamedLogger errorLog() const
Logger instance for comfortable error logging.
virtual void connectors()
Initialize connectors in this function.
virtual WModuleMetaInformation::ConstSPtr getMetaInformation() const
The meta information of this module.
void setUUID(std::string uuid)
Set a uuid.
WBoolFlag m_isReadyOrCrashed
It is true whenever m_isReady or WThreadedRunner::m_isCrashed is true.
void ready()
Call this whenever your module is ready and can react on property changes.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
WStreamedLogger info(const std::string &source)
Logging an information message.
virtual void moduleMain()=0
Entry point after loading the module.
virtual void onThreadException(const WException &e)
This method is called if an exception was caught, which came from the custom thread code...
boost::shared_ptr< WProperties > getProperties() const
Return a pointer to the properties object of the module.
void removeConnectors()
Removes all connectors properly.
Class managing progress inside of modules.
WBoolFlag m_isUsable
True if associated && initialized.
std::vector< boost::shared_ptr< WModuleOutputConnector > > OutputConnectorList
The type for the list of output connectors.
void setAssociatedContainer(boost::shared_ptr< WModuleContainer > container)
Sets the container this module is associated with.
void setLibPath(boost::filesystem::path path)
Set the path to the library which contains this module.
boost::shared_ptr< WCondition > getCondition()
Returns the condition that is used by this flag.
virtual void add(boost::shared_ptr< WCondition > condition)
Adds another condition to the set of conditions to wait for.
static WLogger * getLogger()
Returns pointer to the currently running logger instance.
WModuleMetaInformation::SPtr m_meta
Lock for m_inputConnectors.
boost::shared_ptr< WModuleOutputConnector > getOutputConnector(std::string name)
Finds the named connector for the module.
WBoolFlag m_isRunning
True if the module currently is running.
std::string getPackageName() const
Returns the name of the package the module belongs to, The package name basically is the name of the ...
boost::shared_ptr< WModuleConnector > findConnector(std::string name)
Finds the named connector for the module.
bool isRestoreNeeded() const
Check whether this module is in restore mode.
boost::shared_ptr< WProperties > getInformationProperties() const
Return a pointer to the information properties object of the module.
void addLogMessage(std::string message, std::string source="", LogLevel level=LL_DEBUG)
Appends a log message to the logging queue.
boost::shared_ptr< WProgressCombiner > m_progress
Progress indicator used as parent for all progress' of this module.
void waitRestored()
This method waits for the module to be restored completely.
boost::filesystem::path getLocalPath() const
Returns the local path of the module.
const WBoolFlag & isReadyOrCrashed() const
This is the logical or of isReady and isCrashed.
Implements a WCondition, but can be fired only ONCE.
WCombinerTypes::WDisconnectList getPossibleDisconnections()
Gives a list of all WDisconnectCombiners possible.
virtual void notifyConnectionClosed(boost::shared_ptr< WModuleConnector > here, boost::shared_ptr< WModuleConnector > there)
Gets called whenever a connection between a remote and local connector gets closed.
General purpose exception and therefore base class for all kernel related exceptions.
static SPtr findByUUID(std::string uuid)
Find a module instance by UUID.
WPropBool m_active
True whenever the module should be active.
virtual void activate()
Callback for m_active.
void handleDeadlyException(const WException &e, std::string sender="WThreadedRunner")
Handle the specified exception which was not caught in the thread, which basically means the thread h...
General purpose exception and therefore base class for all kernel related exceptions.
virtual void requirements()
Initialize requirements in this function.
Interface class for the concept "Prototype".
Singleton class helping to find files and paths.
Base class for all classes needing to be executed in a separate thread.
const WBoolFlag & isReady() const
Checks whether this module is ready.
virtual void properties()
Initialize properties in this function.
void setRestoreNeeded(bool restore=true)
Change the restore mode.
Thrown whenever a module should be run but its requirements are not completely met.
WBoolFlag m_isReady
True if ready() was called.
virtual ~WModule()
Destructor.
static WModule::SPtr findByUUID(std::string uuid)
Find a module instance by UUID.
boost::shared_ptr< WModuleContainer > getAssociatedContainer() const
The container this module is associated with.
General purpose exception and therefore base class for all kernel related exceptions.
Base class for all kinds of progress combinations.
Resource class for streamed logging.
const InputConnectorList & getInputConnectors() const
Gives back input connectors.
Class allowing multiple conditions to be used for one waiting cycle.
WBoolFlag m_isAssociated
True if container got associated with this flag.
boost::filesystem::path m_localPath
The path where the module binary resides in.
const OutputConnectorList & getOutputConnectors() const
Gives back output connectors.
void setResetable(bool resetable=true, bool autoReset=true)
Sets the resetable flag.
Base class for all possible kinds of requirements.
boost::shared_ptr< WProperties > m_properties
The property object for the module.
void disconnect()
Completely disconnects all connected connectors of this module.
virtual MODULE_TYPE getType() const
Gets the type of the module.
boost::shared_ptr< WModuleOutputConnector > findOutputConnector(std::string name)
Finds the named connector for the module.
WModule()
Constructs a new WModule instance.
Class to manage properties of an object and to provide convenience methods for easy access and manipu...
std::string m_packageName
The name of the lib/the package containing this module.
const WRequirement * checkRequirements() const
This method checks whether all the requirements of the module are complied.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
boost::filesystem::path m_libPath
The absolute path to the library containing this module.
WBoolFlag m_isCrashed
True whenever an exception is thrown during threadMain.
const WBoolFlag & isRunning() const
Returns a flag denoting whether the thread currently is running or nor.
virtual std::string deprecated() const
This function allows module programmers to mark their modules deprecated in a user-friendly way...
virtual void wait() const
Wait for the flag to change its value.
boost::filesystem::path getLibPath() const
Returns the absolute path to the library containing this module.
Indicates that a given name is not unique in a group of names.
boost::shared_ptr< WModule > SPtr
Shared pointer to a WModule.
Class to encapsulate boost::condition_variable_any.
void initialize()
Manages initialization.
boost::shared_ptr< WProperties > m_infoProperties
The property object for the module containing only module whose purpose is "PV_PURPOSE_INFORMNATION"...
WBoolFlag m_initialized
True if everything is initialized and ready to be used.
boost::shared_ptr< WModuleInputConnector > getInputConnector(std::string name)
Finds the named connector for the module.
virtual bool set(const T &value, bool suppressNotification=false)
Sets the new value for this flag.
std::vector< boost::shared_ptr< WModuleInputConnector > > InputConnectorList
The type for the list of input connectors.
const WBoolFlag & isUseable() const
Checks whether the module instance is ready to be used.
General purpose exception and therefore base class for all kernel related exceptions.
void setThreadName(std::string name)
Set the name of the thread.
virtual boost::shared_ptr< WProgressCombiner > getRootProgressCombiner()
Gets the modules base progress.
virtual void cleanup()
Called whenever the module should shutdown.
WPropString m_runtimeName
This property holds a user specified name for the current module instance.
wlog::WStreamedLogger warnLog() const
Logger instance for comfortable warning- logs.
boost::shared_ptr< WModuleConnector > getConnector(std::string name)
Finds the named connector for the module.
std::string getDeprecationMessage() const
Queries the deprecation message of a module if specified.
void setPackageName(std::string name)
Set the package name.
const std::string & getUUID() const
Get the UUID of the module instance.
wlog::WStreamedLogger infoLog() const
Logger instance for comfortable info logging.
InputConnectorList m_inputConnectors
Set of input connectors associated with this module.
const WBoolFlag & isAssociated() const
Checks whether this module is associated with an container.
virtual void notifyConnectionEstablished(boost::shared_ptr< WModuleConnector > here, boost::shared_ptr< WModuleConnector > there)
Gets called whenever a connector gets connected to the specified input.
void setLocalPath(boost::filesystem::path path)
Sets the local module path.
t_ModuleGenericSignalType signal_ready
Signal fired whenever a module main thread is ready.
Requirements m_requirements
The list of requirements.
WBoolFlag m_isLoadFinished
Flag to denote whether the module container and the project loader have finished their work...
const WBoolFlag & isInitialized() const
Determines whether the module instance is properly initialized.
bool m_restoreMode
Flag denoting the current restore mode.
WConditionSet m_moduleState
The internal state of the module.
virtual void notifyDataChange(boost::shared_ptr< WModuleConnector > input, boost::shared_ptr< WModuleConnector > output)
Gets called when the data on one input connector changed.
void addConnector(boost::shared_ptr< WModuleInputConnector > con)
Adds the specified connector to the list of inputs.
WStreamedLogger debug(const std::string &source)
Logging a debug message.
boost::shared_ptr< WModuleInputConnector > findInputConnector(std::string name)
Finds the named connector for the module.
This class tests against the getName() method of the instances of type T.
void threadMain()
Thread entry point.
WStreamedLogger warn(const std::string &source)
Logging a warning message.
boost::shared_ptr< WProgress > m_readyProgress
Progress indicator for the "ready" state.
bool isDeprecated() const
Checks whether the module was marked as deprecated.
std::string m_uuid
The unique ID of the module instance.
wlog::WStreamedLogger debugLog() const
Logger instance for comfortable debug logging.
OutputConnectorList m_outputConnectors
Set of output connectors associated with this module.
virtual const t_GenericSignalHandlerType getSignalHandler(MODULE_CONNECTOR_SIGNAL signal)
Gives the signal handler function responsible for a given signal.