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