31 #include <boost/version.hpp>
32 #if ( BOOST_VERSION >= 104200 ) // exception.hpp is deprecated in Boost 1.42
33 #include <boost/exception/all.hpp>
35 #include <boost/exception.hpp>
38 #include <boost/signals2/signal.hpp>
39 #include <boost/signals2/connection.hpp>
41 #include "../common/exceptions/WSignalSubscriptionFailed.h"
43 #include "WModuleConnectorSignals.h"
44 #include "WModuleContainer.h"
45 #include "WModuleInputConnector.h"
46 #include "WModuleOutputConnector.h"
47 #include "combiner/WDisconnectCombiner.h"
48 #include "exceptions/WModuleConnectionFailed.h"
49 #include "exceptions/WModuleConnectionInvalid.h"
50 #include "exceptions/WModuleConnectorsIncompatible.h"
51 #include "exceptions/WModuleDisconnectFailed.h"
52 #include "exceptions/WModuleConnectorModuleLockFailed.h"
54 #include "WModuleConnector.h"
87 boost::shared_lock<boost::shared_mutex> slock;
92 slock = boost::shared_lock<boost::shared_mutex>( con->m_connectionListLock );
93 int c2 = con->m_connected.count( shared_from_this() );
100 s <<
"Connection between " <<
getCanonicalName() <<
" and " << con->getCanonicalName() <<
" failed.";
109 boost::shared_lock<boost::shared_mutex> slock = boost::shared_lock<boost::shared_mutex>(
m_connectionListLock );
117 boost::shared_ptr< WModule > module =
m_module.lock();
118 std::string containerName =
"Unknown";
121 boost::shared_ptr< WModuleContainer > container;
122 container = module->getAssociatedContainer();
123 containerName = container.get() ? container->getName() :
"Unknown";
126 "ModuleContainer (" + containerName +
")", LL_INFO );
129 if( !( con->connectable( shared_from_this() ) &&
connectable( con ) ) )
131 std::ostringstream s;
132 s <<
"Connection between " <<
getCanonicalName() <<
" and " << con->getCanonicalName() <<
" failed.";
140 "ModuleContainer (" + containerName +
")", LL_INFO );
144 boost::unique_lock<boost::shared_mutex> lock;
145 boost::unique_lock<boost::shared_mutex> lockRemote;
150 lockRemote = boost::unique_lock<boost::shared_mutex>( con->m_connectionListLock );
159 con->m_connected.insert( shared_from_this() );
171 con->m_connected.erase( con );
175 catch(
const std::exception& e )
182 con->m_connected.erase( con );
184 std::ostringstream s;
185 s <<
"Connection between " <<
getCanonicalName() <<
" and " << con->getCanonicalName() <<
" failed.";
188 catch(
const boost::exception& e )
195 con->m_connected.erase( con );
197 std::ostringstream s;
198 s <<
"Connection between " <<
getCanonicalName() <<
" and " << con->getCanonicalName() <<
" failed.";
204 con->connectSignals( shared_from_this() );
209 con->signal_ConnectionEstablished( con, shared_from_this() );
225 t_GenericSignalHandlerType notifier )
229 case CONNECTION_ESTABLISHED:
231 case CONNECTION_CLOSED:
234 std::ostringstream s;
235 s <<
"Could not subscribe to unknown signal. You need to implement this signal type explicitly.";
244 boost::shared_ptr< WModule > module =
m_module.lock();
249 return module->getSignalHandler( signal );
259 boost::shared_ptr< WModule > module =
m_module.lock();
260 std::string containerName =
"Unknown";
263 boost::shared_ptr< WModuleContainer > container;
264 container = module->getAssociatedContainer();
265 containerName = container.get() ? container->getName() :
"Unknown";
271 " not connected.",
"ModuleContainer (" + containerName +
")", LL_INFO );
276 "ModuleContainer (" + containerName +
")", LL_INFO );
279 boost::unique_lock<boost::shared_mutex> lock;
283 con->disconnectSignals( shared_from_this() );
287 if( removeFromOwnList )
296 lock = boost::unique_lock<boost::shared_mutex>( con->m_connectionListLock );
297 con->m_connected.erase( shared_from_this() );
304 con->signal_ConnectionClosed( shared_from_this(), con );
306 catch(
const std::exception& e )
310 std::ostringstream s;
311 s <<
"Unable to disconnect " <<
getCanonicalName() <<
" from " << con->getCanonicalName() <<
".";
314 catch(
const boost::exception& e )
318 std::ostringstream s;
319 s <<
"Unable to disconnect " <<
getCanonicalName() <<
" from " << con->getCanonicalName() <<
".";
332 for( std::set<boost::shared_ptr<WModuleConnector> >::iterator listIter =
m_connected.begin(); listIter !=
m_connected.end();
357 std::ostringstream s;
375 WCombinerTypes::WOneToOneCombiners l;
381 for( std::set<boost::shared_ptr<WModuleConnector> >::iterator listIter =
m_connected.begin(); listIter !=
m_connected.end(); ++listIter )
384 l.push_back( boost::shared_ptr< WDisconnectCombiner >(
new WDisconnectCombiner( shared_from_this(), ( *listIter ) ) ) );
t_GenericSignalType signal_ConnectionEstablished
Signal emitted whenever connection has been established.
General purpose exception and therefore base class for all kernel related exceptions.
virtual void disconnectAll()
Disconnects ALL connected connectors.
General purpose exception and therefore base class for all kernel related exceptions.
virtual bool isInputConnector() const =0
Returns true if this instance is an WModuleInputConnector.
General purpose exception and therefore base class for all kernel related exceptions.
const std::string getName() const
Gives name of connection.
boost::weak_ptr< WModule > m_module
The Module this connector belongs to.
static WLogger * getLogger()
Returns pointer to the currently running logger instance.
WModuleConnector(boost::shared_ptr< WModule > module, std::string name="", std::string description="")
Constructor.
std::string m_name
The connections name.
t_GenericSignalType signal_ConnectionClosed
Signal emitted whenever connection has been closed.
virtual void disconnect(boost::shared_ptr< WModuleConnector > con, bool removeFromOwnList=true)
Disconnects this connector if connected.
void addLogMessage(std::string message, std::string source="", LogLevel level=LL_DEBUG)
Appends a log message to the logging queue.
General purpose exception and therefore base class for all kernel related exceptions.
boost::shared_ptr< WModuleInputConnector > toInputConnector()
Tries to convert this instance to an input connector.
virtual void connect(boost::shared_ptr< WModuleConnector > con)
Connects this Module Connector with another one.
virtual bool connectable(boost::shared_ptr< WModuleConnector > con)=0
Checks whether the specified connector is connectable to this one.
unsigned int isConnected()
Gets the count of connections currently established.
General purpose exception and therefore base class for all kernel related exceptions.
std::string m_moduleName
The name of the module owning this connector.
void setDescription(std::string desc)
Sets the connector's description.
const std::string getDescription() const
Gives information about this connection.
void setName(std::string name)
Sets the connector's name.
virtual ~WModuleConnector()
Destructor.
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.
const std::string getCanonicalName() const
Gives canonical name of connection.
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.
Class implementing output connection functionality between modules.
boost::shared_mutex m_connectionListLock
Lock for avoiding concurrent write to m_Connected (multiple reader, single writer lock)...
WCombinerTypes::WOneToOneCombiners getPossibleDisconnections()
Returns a list of possible disconnections for this connector.
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 connectSignals(boost::shared_ptr< WModuleConnector > con)
Connect additional signals.
bool isConnectedTo(boost::shared_ptr< WModuleConnector > con)
Checks whether this connector is connected to the given one.
Combiner which disconnects the specified connection.
boost::shared_ptr< WModuleOutputConnector > toOutputConnector()
Tries to convert this instance to an output connector.
std::set< boost::shared_ptr< WModuleConnector > > m_connected
List of connectors connected to this connector.
std::string m_description
The connections description.
Base class for modelling connections between kernel modules.
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.
General purpose exception and therefore base class for all kernel related exceptions.
boost::shared_ptr< WModule > getModule() const
Returns the module which owns this connector.