OpenWalnut
1.5.0dev
|
Base class for modelling connections between kernel modules. More...
#include <WModuleConnector.h>
Public Types | |
typedef std::shared_ptr< WModuleConnector > | SPtr |
Shared pointer to this class. More... | |
typedef std::shared_ptr< const WModuleConnector > | ConstSPtr |
Const shared pointer to this class. More... | |
Public Member Functions | |
WModuleConnector (std::shared_ptr< WModule > module, std::string name="", std::string description="") | |
Constructor. More... | |
virtual | ~WModuleConnector () |
Destructor. More... | |
std::shared_ptr< WModule > | getModule () const |
Returns the module which owns this connector. More... | |
virtual void | disconnect (std::shared_ptr< WModuleConnector > con, bool removeFromOwnList=true) |
Disconnects this connector if connected. More... | |
virtual void | disconnectAll () |
Disconnects ALL connected connectors. More... | |
virtual void | connect (std::shared_ptr< WModuleConnector > con, bool force=false) |
Connects this Module Connector with another one. More... | |
bool | isConnectedTo (std::shared_ptr< WModuleConnector > con) |
Checks whether this connector is connected to the given one. More... | |
unsigned int | isConnected () |
Gets the count of connections currently established. More... | |
virtual boost::signals2::connection | subscribeSignal (MODULE_CONNECTOR_SIGNAL signal, t_GenericSignalHandlerType notifier) |
Connects a specified notify function with a signal this module instance is offering. More... | |
const std::string | getDescription () const |
Gives information about this connection. More... | |
void | setDescription (std::string desc) |
Sets the connector's description. More... | |
const std::string | getName () const |
Gives name of connection. More... | |
const std::string | getCanonicalName () const |
Gives canonical name of connection. More... | |
void | setName (std::string name) |
Sets the connector's name. More... | |
virtual bool | connectable (std::shared_ptr< WModuleConnector > con)=0 |
Checks whether the specified connector is connectable to this one. More... | |
virtual bool | lazyConnectable (std::shared_ptr< WModuleConnector > con)=0 |
Checks whether the specified connector is connectable to this one, but ignores compatibility the type to be transferred. More... | |
WCombinerTypes::WOneToOneCombiners | getPossibleDisconnections () |
Returns a list of possible disconnections for this connector. More... | |
std::shared_ptr< WModuleInputConnector > | toInputConnector () |
Tries to convert this instance to an input connector. More... | |
std::shared_ptr< WModuleOutputConnector > | toOutputConnector () |
Tries to convert this instance to an output connector. More... | |
virtual bool | isInputConnector () const =0 |
Returns true if this instance is an WModuleInputConnector. More... | |
virtual bool | isOutputConnector () const =0 |
Returns true if this instance is an WModuleOutputConnector. More... | |
std::shared_ptr< WCondition > | getDataChangedCondition () |
Gets the condition variable that gets fired whenever new data has been sent. More... | |
Protected Member Functions | |
virtual void | connectSignals (std::shared_ptr< WModuleConnector > con) |
Connect additional signals. More... | |
virtual void | disconnectSignals (std::shared_ptr< WModuleConnector > con) |
Disconnect all signals subscribed by this connector from "con". More... | |
virtual const t_GenericSignalHandlerType | getSignalHandler (MODULE_CONNECTOR_SIGNAL signal) |
Gives the signal handler function responsible for a given signal. More... | |
virtual void | notifyConnectionEstablished (std::shared_ptr< WModuleConnector > here, std::shared_ptr< WModuleConnector > there) |
Gets called whenever a connector gets connected to the specified input. More... | |
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. More... | |
Protected Attributes | |
std::set< std::shared_ptr< WModuleConnector > > | m_connected |
List of connectors connected to this connector. More... | |
std::shared_mutex | m_connectionListLock |
Lock for avoiding concurrent write to m_Connected (multiple reader, single writer lock). More... | |
std::weak_ptr< WModule > | m_module |
The Module this connector belongs to. More... | |
std::string | m_moduleName |
The name of the module owning this connector. More... | |
t_GenericSignalType | signal_ConnectionEstablished |
Signal emitted whenever connection has been established. More... | |
t_GenericSignalType | signal_ConnectionClosed |
Signal emitted whenever connection has been closed. More... | |
std::shared_ptr< WCondition > | m_dataChangedCondition |
Condition fired whenever data changes. More... | |
Private Attributes | |
std::string | m_name |
The connections name. More... | |
std::string | m_description |
The connections description. More... | |
Friends | |
class | WModuleConnectorTest |
Access for test class. More... | |
class | WModuleProjectFileCombiner |
Access for creating a module graph automatically. More... | |
Base class for modelling connections between kernel modules.
It contains several pure virtual member functions and can therefore not instantiated directly.
Definition at line 51 of file WModuleConnector.h.
typedef std::shared_ptr< const WModuleConnector > WModuleConnector::ConstSPtr |
Const shared pointer to this class.
Definition at line 65 of file WModuleConnector.h.
typedef std::shared_ptr< WModuleConnector > WModuleConnector::SPtr |
Shared pointer to this class.
Definition at line 60 of file WModuleConnector.h.
WModuleConnector::WModuleConnector | ( | std::shared_ptr< WModule > | module, |
std::string | name = "" , |
||
std::string | description = "" |
||
) |
Constructor.
module | the module which is owner of this connector. |
name | The name of this connector. |
description | Short description of this connector. |
Definition at line 57 of file WModuleConnector.cpp.
References getSignalHandler(), notifyConnectionClosed(), notifyConnectionEstablished(), signal_ConnectionClosed, signal_ConnectionEstablished, and subscribeSignal().
|
virtual |
Destructor.
Definition at line 81 of file WModuleConnector.cpp.
References disconnectAll(), signal_ConnectionClosed, and signal_ConnectionEstablished.
|
virtual |
Connects this Module Connector with another one.
During connection process, just the connectibility flag from WModuleConnector::connectable is used to determine whether the connection is possible or not.
con | the connector to connect. |
force | force connection even if incompatible. Used primarily for project file loader. If true, only a lazyConnectable is used. |
WModuleConnectionFailed | if connection can not be established. |
Definition at line 120 of file WModuleConnector.cpp.
References WLogger::addLogMessage(), connectable(), connectSignals(), getCanonicalName(), WLogger::getLogger(), isConnectedTo(), isInputConnector(), lazyConnectable(), m_connected, m_connectionListLock, m_module, and signal_ConnectionEstablished.
|
pure virtual |
Checks whether the specified connector is connectable to this one.
con | the connector to check against. |
Implemented in WModuleOutputData< T >, WModuleOutputData< WDataSetSingle >, WModuleOutputConnector, WModuleInputData< T >, WModuleInputData< WDataSetSingle >, and WModuleInputConnector.
Referenced by connect().
|
protectedvirtual |
Connect additional signals.
con | the connector that requests connection. |
Reimplemented in WModuleInputConnector.
Definition at line 231 of file WModuleConnector.cpp.
Referenced by connect(), and WModuleInputConnector::connectSignals().
|
virtual |
Disconnects this connector if connected.
If it is not connected: nothing happens.
con | the connector to disconnect. |
removeFromOwnList | if true the specified connection is also removed from the own connection list. If false it won't. |
Reimplemented in WModuleInputData< T >, and WModuleInputData< WDataSetSingle >.
Definition at line 276 of file WModuleConnector.cpp.
References WLogger::addLogMessage(), disconnectSignals(), getCanonicalName(), WLogger::getLogger(), isConnectedTo(), m_connected, m_connectionListLock, m_module, and signal_ConnectionClosed.
Referenced by WModuleInputData< T >::disconnect(), and disconnectAll().
|
virtual |
Disconnects ALL connected connectors.
Definition at line 343 of file WModuleConnector.cpp.
References disconnect(), m_connected, and m_connectionListLock.
Referenced by ~WModuleConnector().
|
protectedvirtual |
Disconnect all signals subscribed by this connector from "con".
con | the connector that gets disconnected. |
Reimplemented in WModuleInputConnector.
Definition at line 238 of file WModuleConnector.cpp.
Referenced by disconnect(), and WModuleInputConnector::disconnectSignals().
const std::string WModuleConnector::getCanonicalName | ( | ) | const |
Gives canonical name of connection.
The canonical name is a descriptor including module name. The description is ModuleName:ConnectorName.
Definition at line 374 of file WModuleConnector.cpp.
References getName(), and m_moduleName.
Referenced by connect(), disconnect(), and isConnectedTo().
std::shared_ptr< WCondition > WModuleConnector::getDataChangedCondition | ( | ) |
Gets the condition variable that gets fired whenever new data has been sent.
Definition at line 430 of file WModuleConnector.cpp.
References m_dataChangedCondition.
Referenced by WMTransferFunction1D::moduleMain(), and WMWriteTransferFunction::moduleMain().
const std::string WModuleConnector::getDescription | ( | ) | const |
Gives information about this connection.
Definition at line 364 of file WModuleConnector.cpp.
References m_description.
std::shared_ptr< WModule > WModuleConnector::getModule | ( | ) | const |
Returns the module which owns this connector.
Definition at line 271 of file WModuleConnector.cpp.
References m_module.
const std::string WModuleConnector::getName | ( | ) | const |
Gives name of connection.
Definition at line 369 of file WModuleConnector.cpp.
References m_name.
Referenced by getCanonicalName().
WCombinerTypes::WOneToOneCombiners WModuleConnector::getPossibleDisconnections | ( | ) |
Returns a list of possible disconnections for this connector.
Please be aware that the connections might change during the life-time of the returned DisconnectCombiner instances.
Definition at line 392 of file WModuleConnector.cpp.
References m_connected, and m_connectionListLock.
|
protectedvirtual |
Gives the signal handler function responsible for a given signal.
Modules defining own signal handlers should overwrite this function. This function is protected since boost::functions are callable, which is what is not wanted here. Just signals should call them.
signal | the signal to get the handler for. |
Definition at line 260 of file WModuleConnector.cpp.
References m_module.
Referenced by WModuleConnector(), and WModuleInputConnector::WModuleInputConnector().
unsigned int WModuleConnector::isConnected | ( | ) |
Gets the count of connections currently established.
Definition at line 112 of file WModuleConnector.cpp.
References m_connected, and m_connectionListLock.
bool WModuleConnector::isConnectedTo | ( | std::shared_ptr< WModuleConnector > | con | ) |
Checks whether this connector is connected to the given one.
If there is the strange case where one connector is connected with the other one but not vice versa it will throw an exception.
con | the connector to check connection with. |
WModuleConnectionInvalid | thrown if one connector thinks it is connected but the other one not. |
Definition at line 90 of file WModuleConnector.cpp.
References getCanonicalName(), m_connected, and m_connectionListLock.
Referenced by connect(), and disconnect().
|
pure virtual |
Returns true if this instance is an WModuleInputConnector.
Implemented in WModuleOutputConnector, and WModuleInputConnector.
Referenced by connect().
|
pure virtual |
Returns true if this instance is an WModuleOutputConnector.
Implemented in WModuleOutputConnector, and WModuleInputConnector.
|
pure virtual |
Checks whether the specified connector is connectable to this one, but ignores compatibility the type to be transferred.
If you implement your own connectors, please override and check for compatibility with your matching connectors, but ignore the transfer type.
con | the connector to check against. |
Implemented in WModuleOutputConnector, and WModuleInputConnector.
Referenced by connect().
|
protectedvirtual |
Gets called whenever a connection between a remote and local connector gets closed.
here | the connector of THIS module getting disconnected. |
there | the connector of the other module getting disconnected. |
Reimplemented in WModuleInputForwardData< T >, and WModuleInputForwardData< WDataSetScalar >.
Definition at line 415 of file WModuleConnector.cpp.
Referenced by WModuleInputForwardData< T >::notifyConnectionClosed(), and WModuleConnector().
|
protectedvirtual |
Gets called whenever a connector gets connected to the specified input.
here | the connector of THIS module that got connected to "there" |
there | the connector that has been connected with the connector "here" of this module. |
Reimplemented in WModuleInputConnector.
Definition at line 410 of file WModuleConnector.cpp.
Referenced by WModuleInputConnector::notifyConnectionEstablished(), and WModuleConnector().
void WModuleConnector::setDescription | ( | std::string | desc | ) |
Sets the connector's description.
This is not thread-safe! Do not use it outside the WModule thread.
desc | the new description. |
Definition at line 382 of file WModuleConnector.cpp.
References m_description.
void WModuleConnector::setName | ( | std::string | name | ) |
Sets the connector's name.
This is not thread-safe! Do not use it outside the WModule thread.
name | the new name. |
Definition at line 387 of file WModuleConnector.cpp.
References m_name.
|
virtual |
Connects a specified notify function with a signal this module instance is offering.
WSignalSubscriptionFailed | thrown if the signal can't be connected. |
signal | the signal to connect to. |
notifier | the notifier function to bind. |
Reimplemented in WModuleOutputConnector, and WModuleInputConnector.
Definition at line 243 of file WModuleConnector.cpp.
References signal_ConnectionClosed, and signal_ConnectionEstablished.
Referenced by WModuleInputConnector::subscribeSignal(), WModuleOutputConnector::subscribeSignal(), and WModuleConnector().
std::shared_ptr< WModuleInputConnector > WModuleConnector::toInputConnector | ( | ) |
Tries to convert this instance to an input connector.
Definition at line 420 of file WModuleConnector.cpp.
std::shared_ptr< WModuleOutputConnector > WModuleConnector::toOutputConnector | ( | ) |
Tries to convert this instance to an output connector.
Definition at line 425 of file WModuleConnector.cpp.
|
friend |
Access for test class.
Definition at line 53 of file WModuleConnector.h.
|
friend |
Access for creating a module graph automatically.
Definition at line 54 of file WModuleConnector.h.
|
protected |
List of connectors connected to this connector.
Definition at line 245 of file WModuleConnector.h.
Referenced by connect(), disconnect(), disconnectAll(), WModuleInputData< T >::getData(), getPossibleDisconnections(), isConnected(), and isConnectedTo().
|
protected |
Lock for avoiding concurrent write to m_Connected (multiple reader, single writer lock).
The read lock can be acquired using the boost::shared_lock<std::shared_mutex> lock( m_ConnectionListLock );.
Definition at line 251 of file WModuleConnector.h.
Referenced by connect(), disconnect(), disconnectAll(), WModuleInputData< T >::getData(), getPossibleDisconnections(), isConnected(), and isConnectedTo().
|
protected |
Condition fired whenever data changes.
Proper calling is made in subclasses.
Definition at line 318 of file WModuleConnector.h.
Referenced by getDataChangedCondition(), WModuleInputConnector::notifyDataChange(), WModuleOutputConnector::propagateDataChange(), and WModuleInputConnector::WModuleInputConnector().
|
private |
The connections description.
Definition at line 329 of file WModuleConnector.h.
Referenced by getDescription(), and setDescription().
|
protected |
The Module this connector belongs to.
Definition at line 282 of file WModuleConnector.h.
Referenced by connect(), disconnect(), getModule(), and getSignalHandler().
|
protected |
The name of the module owning this connector.
Definition at line 287 of file WModuleConnector.h.
Referenced by getCanonicalName().
|
private |
The connections name.
Definition at line 324 of file WModuleConnector.h.
|
protected |
Signal emitted whenever connection has been closed.
Definition at line 313 of file WModuleConnector.h.
Referenced by disconnect(), subscribeSignal(), WModuleConnector(), WModuleInputConnector::WModuleInputConnector(), ~WModuleConnector(), and WModuleInputConnector::~WModuleInputConnector().
|
protected |
Signal emitted whenever connection has been established.
Definition at line 308 of file WModuleConnector.h.
Referenced by connect(), subscribeSignal(), WModuleConnector(), and ~WModuleConnector().