OpenWalnut  1.4.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | Friends
WModuleConnector Class Reference

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

#include <WModuleConnector.h>

+ Inheritance diagram for WModuleConnector:

List of all members.

Public Types

typedef boost::shared_ptr
< WModuleConnector
SPtr
 Shared pointer to this class.
typedef boost::shared_ptr
< const WModuleConnector
ConstSPtr
 Const shared pointer to this class.

Public Member Functions

 WModuleConnector (boost::shared_ptr< WModule > module, std::string name="", std::string description="")
 Constructor.
virtual ~WModuleConnector ()
 Destructor.
boost::shared_ptr< WModulegetModule () const
 Returns the module which owns this connector.
virtual void disconnect (boost::shared_ptr< WModuleConnector > con, bool removeFromOwnList=true)
 Disconnects this connector if connected.
virtual void disconnectAll ()
 Disconnects ALL connected connectors.
virtual void connect (boost::shared_ptr< WModuleConnector > con)
 Connects this Module Connector with another one.
bool isConnectedTo (boost::shared_ptr< WModuleConnector > con)
 Checks whether this connector is connected to the given one.
unsigned int isConnected ()
 Gets the count of connections currently established.
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.
const std::string getDescription () const
 Gives information about this connection.
void setDescription (std::string desc)
 Sets the connector's description.
const std::string getName () const
 Gives name of connection.
const std::string getCanonicalName () const
 Gives canonical name of connection.
void setName (std::string name)
 Sets the connector's name.
virtual bool connectable (boost::shared_ptr< WModuleConnector > con)=0
 Checks whether the specified connector is connectable to this one.
WCombinerTypes::WOneToOneCombiners getPossibleDisconnections ()
 Returns a list of possible disconnections for this connector.
boost::shared_ptr
< WModuleInputConnector
toInputConnector ()
 Tries to convert this instance to an input connector.
boost::shared_ptr
< WModuleOutputConnector
toOutputConnector ()
 Tries to convert this instance to an output connector.
virtual bool isInputConnector () const =0
 Returns true if this instance is an WModuleInputConnector.
virtual bool isOutputConnector () const =0
 Returns true if this instance is an WModuleOutputConnector.

Protected Member Functions

virtual void connectSignals (boost::shared_ptr< WModuleConnector > con)
 Connect additional signals.
virtual void disconnectSignals (boost::shared_ptr< WModuleConnector > con)
 Disconnect all signals subscribed by this connector from "con".
virtual const
t_GenericSignalHandlerType 
getSignalHandler (MODULE_CONNECTOR_SIGNAL signal)
 Gives the signal handler function responsible for a given signal.
virtual void notifyConnectionEstablished (boost::shared_ptr< WModuleConnector > here, boost::shared_ptr< WModuleConnector > there)
 Gets called whenever a connector gets connected to the specified input.
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.

Protected Attributes

std::set< boost::shared_ptr
< WModuleConnector > > 
m_connected
 List of connectors connected to this connector.
boost::shared_mutex m_connectionListLock
 Lock for avoiding concurrent write to m_Connected (multiple reader, single writer lock).
boost::weak_ptr< WModulem_module
 The Module this connector belongs to.
std::string m_moduleName
 The name of the module owning this connector.
t_GenericSignalType signal_ConnectionEstablished
 Signal emitted whenever connection has been established.
t_GenericSignalType signal_ConnectionClosed
 Signal emitted whenever connection has been closed.

Private Attributes

std::string m_name
 The connections name.
std::string m_description
 The connections description.

Friends

class WModuleConnectorTest
class WModuleProjectFileCombiner

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 50 of file WModuleConnector.h.


Member Typedef Documentation

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

Const shared pointer to this class.

Reimplemented in WModuleInputData< T >, WModuleOutputData< T >, and WModuleOutputForwardData< T >.

Definition at line 64 of file WModuleConnector.h.

typedef boost::shared_ptr< WModuleConnector > WModuleConnector::SPtr

Shared pointer to this class.

Reimplemented in WModuleInputData< T >, WModuleOutputData< T >, and WModuleOutputForwardData< T >.

Definition at line 59 of file WModuleConnector.h.


Constructor & Destructor Documentation

WModuleConnector::WModuleConnector ( boost::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 56 of file WModuleConnector.cpp.

References getSignalHandler(), m_description, m_module, m_moduleName, m_name, notifyConnectionClosed(), notifyConnectionEstablished(), signal_ConnectionClosed, signal_ConnectionEstablished, and subscribeSignal().

Destructor.

Definition at line 76 of file WModuleConnector.cpp.

References disconnectAll(), signal_ConnectionClosed, and signal_ConnectionEstablished.


Member Function Documentation

void WModuleConnector::connect ( boost::shared_ptr< WModuleConnector con) [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.
Exceptions:
WModuleConnectionFailedif connection can not be established.
Returns:
true if successful

Definition at line 115 of file WModuleConnector.cpp.

References WLogger::addLogMessage(), connectable(), connectSignals(), getCanonicalName(), WLogger::getLogger(), isConnectedTo(), isInputConnector(), m_connected, m_connectionListLock, m_module, and signal_ConnectionEstablished.

virtual bool WModuleConnector::connectable ( boost::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 >, WModuleInputData< T >, WModuleOutputConnector, and WModuleInputConnector.

Referenced by connect().

void WModuleConnector::connectSignals ( boost::shared_ptr< WModuleConnector con) [protected, virtual]

Connect additional signals.

Parameters:
conthe connector that requests connection.

Reimplemented in WModuleInputConnector.

Definition at line 212 of file WModuleConnector.cpp.

Referenced by connect().

void WModuleConnector::disconnect ( boost::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 >.

Definition at line 257 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().

void WModuleConnector::disconnectAll ( ) [virtual]

Disconnects ALL connected connectors.

Definition at line 324 of file WModuleConnector.cpp.

References disconnect(), m_connected, and m_connectionListLock.

Referenced by ~WModuleConnector().

void WModuleConnector::disconnectSignals ( boost::shared_ptr< WModuleConnector con) [protected, virtual]

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

Parameters:
conthe connector that gets disconnected.

Reimplemented in WModuleInputConnector.

Definition at line 219 of file WModuleConnector.cpp.

Referenced by disconnect().

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 355 of file WModuleConnector.cpp.

References getName(), and m_moduleName.

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

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

Gives information about this connection.

Returns:
The connection's description.

Definition at line 345 of file WModuleConnector.cpp.

References m_description.

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

Returns the module which owns this connector.

Returns:
the module owning the connector.

Definition at line 252 of file WModuleConnector.cpp.

References m_module.

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

Gives name of connection.

Returns:
The name of this connection

Definition at line 350 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.

Returns:
the possible disconnections.

Definition at line 373 of file WModuleConnector.cpp.

References m_connected, and m_connectionListLock.

const t_GenericSignalHandlerType WModuleConnector::getSignalHandler ( MODULE_CONNECTOR_SIGNAL  signal) [protected, virtual]

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 241 of file WModuleConnector.cpp.

References m_module.

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

Gets the count of connections currently established.

Returns:
the number of connections.

Definition at line 107 of file WModuleConnector.cpp.

References m_connected, and m_connectionListLock.

bool WModuleConnector::isConnectedTo ( boost::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 85 of file WModuleConnector.cpp.

References getCanonicalName(), m_connected, and m_connectionListLock.

Referenced by connect(), and disconnect().

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

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.

void WModuleConnector::notifyConnectionClosed ( boost::shared_ptr< WModuleConnector here,
boost::shared_ptr< WModuleConnector there 
) [protected, virtual]

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

Definition at line 396 of file WModuleConnector.cpp.

Referenced by WModuleConnector().

void WModuleConnector::notifyConnectionEstablished ( boost::shared_ptr< WModuleConnector here,
boost::shared_ptr< WModuleConnector there 
) [protected, virtual]

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 391 of file WModuleConnector.cpp.

Referenced by 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.

Parameters:
descthe new description.

Definition at line 363 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.

Parameters:
namethe new name.

Definition at line 368 of file WModuleConnector.cpp.

References m_name.

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 WModuleInputConnector, and WModuleOutputConnector.

Definition at line 224 of file WModuleConnector.cpp.

References signal_ConnectionClosed, and signal_ConnectionEstablished.

Referenced by WModuleConnector().

Tries to convert this instance to an input connector.

Returns:
this as input connector

Definition at line 401 of file WModuleConnector.cpp.

Tries to convert this instance to an output connector.

Returns:
this as output connector

Definition at line 406 of file WModuleConnector.cpp.


Member Data Documentation

std::set<boost::shared_ptr<WModuleConnector> > WModuleConnector::m_connected [protected]

List of connectors connected to this connector.

Definition at line 228 of file WModuleConnector.h.

Referenced by connect(), disconnect(), disconnectAll(), WModuleInputData< T >::getData(), getPossibleDisconnections(), isConnected(), and isConnectedTo().

boost::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<boost::shared_mutex> lock( m_ConnectionListLock );.

Definition at line 234 of file WModuleConnector.h.

Referenced by connect(), disconnect(), disconnectAll(), WModuleInputData< T >::getData(), getPossibleDisconnections(), isConnected(), and isConnectedTo().

std::string WModuleConnector::m_description [private]

The connections description.

Definition at line 307 of file WModuleConnector.h.

Referenced by getDescription(), setDescription(), and WModuleConnector().

boost::weak_ptr< WModule > WModuleConnector::m_module [protected]

The Module this connector belongs to.

Definition at line 265 of file WModuleConnector.h.

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

std::string WModuleConnector::m_moduleName [protected]

The name of the module owning this connector.

Definition at line 270 of file WModuleConnector.h.

Referenced by getCanonicalName(), and WModuleConnector().

std::string WModuleConnector::m_name [private]

The connections name.

Definition at line 302 of file WModuleConnector.h.

Referenced by getName(), setName(), and WModuleConnector().

t_GenericSignalType WModuleConnector::signal_ConnectionClosed [protected]
t_GenericSignalType WModuleConnector::signal_ConnectionEstablished [protected]

Signal emitted whenever connection has been established.

Definition at line 291 of file WModuleConnector.h.

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


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