OpenWalnut
1.4.0
|
Base class for modelling connections between kernel modules. More...
#include <WModuleConnector.h>
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< WModule > | getModule () 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< WModule > | m_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 |
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.
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.
WModuleConnector::WModuleConnector | ( | boost::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 56 of file WModuleConnector.cpp.
References getSignalHandler(), m_description, m_module, m_moduleName, m_name, notifyConnectionClosed(), notifyConnectionEstablished(), signal_ConnectionClosed, signal_ConnectionEstablished, and subscribeSignal().
WModuleConnector::~WModuleConnector | ( | ) | [virtual] |
Destructor.
Definition at line 76 of file WModuleConnector.cpp.
References disconnectAll(), signal_ConnectionClosed, and signal_ConnectionEstablished.
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.
con | the connector to connect. |
WModuleConnectionFailed | if connection can not be established. |
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.
con | the connector to check against. |
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.
con | the 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.
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 >.
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".
con | the 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.
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.
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.
Definition at line 252 of file WModuleConnector.cpp.
References m_module.
const std::string WModuleConnector::getName | ( | ) | const |
Gives name of 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.
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.
signal | the signal to get the handler for. |
Definition at line 241 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 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.
con | the connector to check connection with. |
WModuleConnectionInvalid | thrown 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.
Implemented in WModuleOutputConnector, and WModuleInputConnector.
Referenced by connect().
virtual bool WModuleConnector::isOutputConnector | ( | ) | const [pure virtual] |
Returns true if this instance is an 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.
here | the connector of THIS module getting disconnected. |
there | the 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.
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 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.
desc | the 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.
name | the 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.
WSignalSubscriptionFailed | thrown if the signal can't be connected. |
signal | the signal to connect to. |
notifier | the notifier function to bind. |
Reimplemented in WModuleInputConnector, and WModuleOutputConnector.
Definition at line 224 of file WModuleConnector.cpp.
References signal_ConnectionClosed, and signal_ConnectionEstablished.
Referenced by WModuleConnector().
boost::shared_ptr< WModuleInputConnector > WModuleConnector::toInputConnector | ( | ) |
Tries to convert this instance to an input connector.
Definition at line 401 of file WModuleConnector.cpp.
boost::shared_ptr< WModuleOutputConnector > WModuleConnector::toOutputConnector | ( | ) |
Tries to convert this instance to an output connector.
Definition at line 406 of file WModuleConnector.cpp.
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] |
Signal emitted whenever connection has been closed.
Definition at line 296 of file WModuleConnector.h.
Referenced by disconnect(), subscribeSignal(), WModuleConnector(), WModuleInputConnector::WModuleInputConnector(), ~WModuleConnector(), and WModuleInputConnector::~WModuleInputConnector().
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().