OpenWalnut  1.5.0dev
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | Friends | List of all members
WModuleConnector Class Referenceabstract

Base class for modelling connections between kernel modules. More...

#include <WModuleConnector.h>

+ Inheritance diagram for WModuleConnector:
+ Collaboration diagram for WModuleConnector:

Public Types

typedef std::shared_ptr< WModuleConnectorSPtr
 Shared pointer to this class. More...
 
typedef std::shared_ptr< const WModuleConnectorConstSPtr
 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< WModulegetModule () 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< WModuleInputConnectortoInputConnector ()
 Tries to convert this instance to an input connector. More...
 
std::shared_ptr< WModuleOutputConnectortoOutputConnector ()
 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< WConditiongetDataChangedCondition ()
 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< WModulem_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< WConditionm_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...
 

Detailed Description

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.

Member Typedef Documentation

◆ ConstSPtr

typedef std::shared_ptr< const WModuleConnector > WModuleConnector::ConstSPtr

Const shared pointer to this class.

Definition at line 65 of file WModuleConnector.h.

◆ SPtr

typedef std::shared_ptr< WModuleConnector > WModuleConnector::SPtr

Shared pointer to this class.

Definition at line 60 of file WModuleConnector.h.

Constructor & Destructor Documentation

◆ WModuleConnector()

WModuleConnector::WModuleConnector ( std::shared_ptr< WModule module,
std::string  name = "",
std::string  description = "" 
)

Constructor.

Parameters
modulethe module which is owner of this connector.
nameThe name of this connector.
descriptionShort description of this connector.

Definition at line 57 of file WModuleConnector.cpp.

References getSignalHandler(), notifyConnectionClosed(), notifyConnectionEstablished(), signal_ConnectionClosed, signal_ConnectionEstablished, and subscribeSignal().

+ Here is the call graph for this function:

◆ ~WModuleConnector()

WModuleConnector::~WModuleConnector ( )
virtual

Destructor.

Definition at line 81 of file WModuleConnector.cpp.

References disconnectAll(), signal_ConnectionClosed, and signal_ConnectionEstablished.

+ Here is the call graph for this function:

Member Function Documentation

◆ connect()

void WModuleConnector::connect ( std::shared_ptr< WModuleConnector con,
bool  force = false 
)
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.

Parameters
conthe connector to connect.
forceforce connection even if incompatible. Used primarily for project file loader. If true, only a lazyConnectable is used.
Exceptions
WModuleConnectionFailedif 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.

+ Here is the call graph for this function:

◆ connectable()

virtual bool WModuleConnector::connectable ( std::shared_ptr< WModuleConnector con)
pure virtual

Checks whether the specified connector is connectable to this one.

Parameters
conthe connector to check against.
Returns
true if compatible.

Implemented in WModuleOutputData< T >, WModuleOutputData< WDataSetSingle >, WModuleOutputConnector, WModuleInputData< T >, WModuleInputData< WDataSetSingle >, and WModuleInputConnector.

Referenced by connect().

+ Here is the caller graph for this function:

◆ connectSignals()

void WModuleConnector::connectSignals ( std::shared_ptr< WModuleConnector con)
protectedvirtual

Connect additional signals.

Parameters
conthe connector that requests connection.

Reimplemented in WModuleInputConnector.

Definition at line 231 of file WModuleConnector.cpp.

Referenced by connect(), and WModuleInputConnector::connectSignals().

+ Here is the caller graph for this function:

◆ disconnect()

void WModuleConnector::disconnect ( std::shared_ptr< WModuleConnector con,
bool  removeFromOwnList = true 
)
virtual

Disconnects this connector if connected.

If it is not connected: nothing happens.

Parameters
conthe connector to disconnect.
removeFromOwnListif 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ disconnectAll()

void WModuleConnector::disconnectAll ( )
virtual

Disconnects ALL connected connectors.

Definition at line 343 of file WModuleConnector.cpp.

References disconnect(), m_connected, and m_connectionListLock.

Referenced by ~WModuleConnector().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ disconnectSignals()

void WModuleConnector::disconnectSignals ( std::shared_ptr< WModuleConnector con)
protectedvirtual

Disconnect all signals subscribed by this connector from "con".

Parameters
conthe connector that gets disconnected.

Reimplemented in WModuleInputConnector.

Definition at line 238 of file WModuleConnector.cpp.

Referenced by disconnect(), and WModuleInputConnector::disconnectSignals().

+ Here is the caller graph for this function:

◆ getCanonicalName()

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.

Returns
The name of this connection

Definition at line 374 of file WModuleConnector.cpp.

References getName(), and m_moduleName.

Referenced by connect(), disconnect(), and isConnectedTo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDataChangedCondition()

std::shared_ptr< WCondition > WModuleConnector::getDataChangedCondition ( )

Gets the condition variable that gets fired whenever new data has been sent.

Returns
the condition

Definition at line 430 of file WModuleConnector.cpp.

References m_dataChangedCondition.

Referenced by WMTransferFunction1D::moduleMain(), and WMWriteTransferFunction::moduleMain().

+ Here is the caller graph for this function:

◆ getDescription()

const std::string WModuleConnector::getDescription ( ) const

Gives information about this connection.

Returns
The connection's description.

Definition at line 364 of file WModuleConnector.cpp.

References m_description.

◆ getModule()

std::shared_ptr< WModule > WModuleConnector::getModule ( ) const

Returns the module which owns this connector.

Returns
the module owning the connector.

Definition at line 271 of file WModuleConnector.cpp.

References m_module.

◆ getName()

const std::string WModuleConnector::getName ( ) const

Gives name of connection.

Returns
The name of this connection

Definition at line 369 of file WModuleConnector.cpp.

References m_name.

Referenced by getCanonicalName().

+ Here is the caller graph for this function:

◆ getPossibleDisconnections()

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.

Returns
the possible disconnections.

Definition at line 392 of file WModuleConnector.cpp.

References m_connected, and m_connectionListLock.

◆ getSignalHandler()

const t_GenericSignalHandlerType WModuleConnector::getSignalHandler ( MODULE_CONNECTOR_SIGNAL  signal)
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.

Parameters
signalthe signal to get the handler for.
Returns
the signal handler for "signal".

Definition at line 260 of file WModuleConnector.cpp.

References m_module.

Referenced by WModuleConnector(), and WModuleInputConnector::WModuleInputConnector().

+ Here is the caller graph for this function:

◆ isConnected()

unsigned int WModuleConnector::isConnected ( )

Gets the count of connections currently established.

Returns
the number of connections.

Definition at line 112 of file WModuleConnector.cpp.

References m_connected, and m_connectionListLock.

◆ isConnectedTo()

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.

Parameters
conthe connector to check connection with.
Returns
true if connected
Exceptions
WModuleConnectionInvalidthrown 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isInputConnector()

virtual bool WModuleConnector::isInputConnector ( ) const
pure virtual

Returns true if this instance is an WModuleInputConnector.

Returns
true if castable to WModuleInputConnector.

Implemented in WModuleOutputConnector, and WModuleInputConnector.

Referenced by connect().

+ Here is the caller graph for this function:

◆ isOutputConnector()

virtual bool WModuleConnector::isOutputConnector ( ) const
pure virtual

Returns true if this instance is an WModuleOutputConnector.

Returns
true if castable to WModuleOutputConnector.

Implemented in WModuleOutputConnector, and WModuleInputConnector.

◆ lazyConnectable()

virtual bool WModuleConnector::lazyConnectable ( std::shared_ptr< WModuleConnector con)
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.

Parameters
conthe connector to check against.
Returns
true if compatible.

Implemented in WModuleOutputConnector, and WModuleInputConnector.

Referenced by connect().

+ Here is the caller graph for this function:

◆ notifyConnectionClosed()

void WModuleConnector::notifyConnectionClosed ( std::shared_ptr< WModuleConnector here,
std::shared_ptr< WModuleConnector there 
)
protectedvirtual

Gets called whenever a connection between a remote and local connector gets closed.

Parameters
herethe connector of THIS module getting disconnected.
therethe 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().

+ Here is the caller graph for this function:

◆ notifyConnectionEstablished()

void WModuleConnector::notifyConnectionEstablished ( std::shared_ptr< WModuleConnector here,
std::shared_ptr< WModuleConnector there 
)
protectedvirtual

Gets called whenever a connector gets connected to the specified input.

Parameters
herethe connector of THIS module that got connected to "there"
therethe 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().

+ Here is the caller graph for this function:

◆ setDescription()

void WModuleConnector::setDescription ( std::string  desc)

Sets the connector's description.

This is not thread-safe! Do not use it outside the WModule thread.

Parameters
descthe new description.

Definition at line 382 of file WModuleConnector.cpp.

References m_description.

◆ setName()

void WModuleConnector::setName ( std::string  name)

Sets the connector's name.

This is not thread-safe! Do not use it outside the WModule thread.

Parameters
namethe new name.

Definition at line 387 of file WModuleConnector.cpp.

References m_name.

◆ subscribeSignal()

boost::signals2::connection WModuleConnector::subscribeSignal ( MODULE_CONNECTOR_SIGNAL  signal,
t_GenericSignalHandlerType  notifier 
)
virtual

Connects a specified notify function with a signal this module instance is offering.

Exceptions
WSignalSubscriptionFailedthrown if the signal can't be connected.
Parameters
signalthe signal to connect to.
notifierthe notifier function to bind.
Returns
connection descriptor.

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().

+ Here is the caller graph for this function:

◆ toInputConnector()

std::shared_ptr< WModuleInputConnector > WModuleConnector::toInputConnector ( )

Tries to convert this instance to an input connector.

Returns
this as input connector

Definition at line 420 of file WModuleConnector.cpp.

◆ toOutputConnector()

std::shared_ptr< WModuleOutputConnector > WModuleConnector::toOutputConnector ( )

Tries to convert this instance to an output connector.

Returns
this as output connector

Definition at line 425 of file WModuleConnector.cpp.

Friends And Related Function Documentation

◆ WModuleConnectorTest

friend class WModuleConnectorTest
friend

Access for test class.

Definition at line 53 of file WModuleConnector.h.

◆ WModuleProjectFileCombiner

friend class WModuleProjectFileCombiner
friend

Access for creating a module graph automatically.

Definition at line 54 of file WModuleConnector.h.

Member Data Documentation

◆ m_connected

std::set<std::shared_ptr<WModuleConnector> > WModuleConnector::m_connected
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().

◆ m_connectionListLock

std::shared_mutex WModuleConnector::m_connectionListLock
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().

◆ m_dataChangedCondition

std::shared_ptr< WCondition > WModuleConnector::m_dataChangedCondition
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().

◆ m_description

std::string WModuleConnector::m_description
private

The connections description.

Definition at line 329 of file WModuleConnector.h.

Referenced by getDescription(), and setDescription().

◆ m_module

std::weak_ptr< WModule > WModuleConnector::m_module
protected

The Module this connector belongs to.

Definition at line 282 of file WModuleConnector.h.

Referenced by connect(), disconnect(), getModule(), and getSignalHandler().

◆ m_moduleName

std::string WModuleConnector::m_moduleName
protected

The name of the module owning this connector.

Definition at line 287 of file WModuleConnector.h.

Referenced by getCanonicalName().

◆ m_name

std::string WModuleConnector::m_name
private

The connections name.

Definition at line 324 of file WModuleConnector.h.

Referenced by getName(), and setName().

◆ signal_ConnectionClosed

t_GenericSignalType WModuleConnector::signal_ConnectionClosed
protected

◆ signal_ConnectionEstablished

t_GenericSignalType WModuleConnector::signal_ConnectionEstablished
protected

Signal emitted whenever connection has been established.

Definition at line 308 of file WModuleConnector.h.

Referenced by connect(), subscribeSignal(), WModuleConnector(), and ~WModuleConnector().


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