32 #include <boost/version.hpp>
33 #if( BOOST_VERSION >= 104200 )
34 #include <boost/exception/all.hpp>
36 #include <boost/exception.hpp>
39 #include <boost/signals2/signal.hpp>
40 #include <boost/signals2/connection.hpp>
42 #include "../common/exceptions/WSignalSubscriptionFailed.h"
44 #include "WModuleConnectorSignals.h"
45 #include "WModuleContainer.h"
46 #include "WModuleInputConnector.h"
47 #include "WModuleOutputConnector.h"
48 #include "combiner/WDisconnectCombiner.h"
49 #include "exceptions/WModuleConnectionFailed.h"
50 #include "exceptions/WModuleConnectionInvalid.h"
51 #include "exceptions/WModuleConnectorsIncompatible.h"
52 #include "exceptions/WModuleDisconnectFailed.h"
53 #include "exceptions/WModuleConnectorModuleLockFailed.h"
55 #include "WModuleConnector.h"
60 m_moduleName( module->getName() ),
63 m_description( description )
70 boost::placeholders::_1,
71 boost::placeholders::_2 ) );
74 boost::placeholders::_1,
75 boost::placeholders::_2 ) );
92 boost::shared_lock<std::shared_mutex> slock;
97 slock = boost::shared_lock<std::shared_mutex>( con->m_connectionListLock );
98 int c2 = con->m_connected.count( shared_from_this() );
104 std::ostringstream s;
105 s <<
"Connection between " <<
getCanonicalName() <<
" and " << con->getCanonicalName() <<
" failed.";
114 boost::shared_lock<std::shared_mutex> slock = boost::shared_lock<std::shared_mutex>(
m_connectionListLock );
122 std::shared_ptr< WModule > module =
m_module.lock();
123 std::string containerName =
"Unknown";
126 std::shared_ptr< WModuleContainer > container;
127 container = module->getAssociatedContainer();
128 containerName = container.get() ? container->getName() :
"Unknown";
131 "ModuleContainer (" + containerName +
")", LL_INFO );
137 if( !( con->lazyConnectable( shared_from_this() ) &&
lazyConnectable( con ) ) )
139 std::ostringstream s;
140 s <<
"Connection between " <<
getCanonicalName() <<
" and " << con->getCanonicalName() <<
" failed.";
147 if( !( con->connectable( shared_from_this() ) &&
connectable( con ) ) )
149 std::ostringstream s;
150 s <<
"Connection between " <<
getCanonicalName() <<
" and " << con->getCanonicalName() <<
" failed.";
159 "ModuleContainer (" + containerName +
")", LL_INFO );
163 std::unique_lock<std::shared_mutex> lock;
164 std::unique_lock<std::shared_mutex> lockRemote;
169 lockRemote = std::unique_lock<std::shared_mutex>( con->m_connectionListLock );
178 con->m_connected.insert( shared_from_this() );
190 con->m_connected.erase( con );
194 catch(
const std::exception& e )
201 con->m_connected.erase( con );
203 std::ostringstream s;
204 s <<
"Connection between " <<
getCanonicalName() <<
" and " << con->getCanonicalName() <<
" failed.";
207 catch(
const boost::exception& e )
214 con->m_connected.erase( con );
216 std::ostringstream s;
217 s <<
"Connection between " <<
getCanonicalName() <<
" and " << con->getCanonicalName() <<
" failed.";
223 con->connectSignals( shared_from_this() );
228 con->signal_ConnectionEstablished( con, shared_from_this() );
244 t_GenericSignalHandlerType notifier )
248 case CONNECTION_ESTABLISHED:
250 case CONNECTION_CLOSED:
253 std::ostringstream s;
254 s <<
"Could not subscribe to unknown signal. You need to implement this signal type explicitly.";
263 std::shared_ptr< WModule > module =
m_module.lock();
268 return module->getSignalHandler( signal );
278 std::shared_ptr< WModule > module =
m_module.lock();
279 std::string containerName =
"Unknown";
282 std::shared_ptr< WModuleContainer > container;
283 container = module->getAssociatedContainer();
284 containerName = container.get() ? container->getName() :
"Unknown";
290 " not connected.",
"ModuleContainer (" + containerName +
")", LL_INFO );
295 "ModuleContainer (" + containerName +
")", LL_INFO );
298 std::unique_lock<std::shared_mutex> lock;
302 con->disconnectSignals( shared_from_this() );
306 if( removeFromOwnList )
315 lock = std::unique_lock<std::shared_mutex>( con->m_connectionListLock );
316 con->m_connected.erase( shared_from_this() );
323 con->signal_ConnectionClosed( shared_from_this(), con );
325 catch(
const std::exception& e )
329 std::ostringstream s;
330 s <<
"Unable to disconnect " <<
getCanonicalName() <<
" from " << con->getCanonicalName() <<
".";
333 catch(
const boost::exception& e )
337 std::ostringstream s;
338 s <<
"Unable to disconnect " <<
getCanonicalName() <<
" from " << con->getCanonicalName() <<
".";
351 for( std::set<std::shared_ptr<WModuleConnector> >::iterator listIter =
m_connected.begin(); listIter !=
m_connected.end();
376 std::ostringstream s;
394 WCombinerTypes::WOneToOneCombiners l;
400 for( std::set<std::shared_ptr<WModuleConnector> >::iterator listIter =
m_connected.begin(); listIter !=
m_connected.end(); ++listIter )
403 l.push_back( std::shared_ptr< WDisconnectCombiner >(
new WDisconnectCombiner( shared_from_this(), ( *listIter ) ) ) );
422 return std::dynamic_pointer_cast< WModuleInputConnector >( shared_from_this() );
427 return std::dynamic_pointer_cast< WModuleOutputConnector >( shared_from_this() );
Class to encapsulate boost::condition_variable_any.
Combiner which disconnects the specified connection.
void addLogMessage(std::string message, std::string source="", LogLevel level=LL_DEBUG)
Appends a log message to the logging queue.
static WLogger * getLogger()
Returns pointer to the currently running logger instance.
General purpose exception and therefore base class for all kernel related exceptions.
General purpose exception and therefore base class for all kernel related exceptions.
General purpose exception and therefore base class for all kernel related exceptions.
Base class for modelling connections between kernel modules.
const std::string getDescription() const
Gives information about this connection.
virtual bool isInputConnector() const =0
Returns true if this instance is an WModuleInputConnector.
virtual void disconnect(std::shared_ptr< WModuleConnector > con, bool removeFromOwnList=true)
Disconnects this connector if connected.
unsigned int isConnected()
Gets the count of connections currently established.
bool isConnectedTo(std::shared_ptr< WModuleConnector > con)
Checks whether this connector is connected to the given one.
std::string m_description
The connections description.
std::string m_moduleName
The name of the module owning this connector.
virtual const t_GenericSignalHandlerType getSignalHandler(MODULE_CONNECTOR_SIGNAL signal)
Gives the signal handler function responsible for a given signal.
std::shared_ptr< WModuleOutputConnector > toOutputConnector()
Tries to convert this instance to an output connector.
const std::string getCanonicalName() const
Gives canonical name of connection.
virtual void connectSignals(std::shared_ptr< WModuleConnector > con)
Connect additional signals.
std::shared_ptr< WCondition > getDataChangedCondition()
Gets the condition variable that gets fired whenever new data has been sent.
std::string m_name
The connections name.
t_GenericSignalType signal_ConnectionClosed
Signal emitted whenever connection has been closed.
virtual void disconnectAll()
Disconnects ALL connected connectors.
virtual void disconnectSignals(std::shared_ptr< WModuleConnector > con)
Disconnect all signals subscribed by this connector from "con".
t_GenericSignalType signal_ConnectionEstablished
Signal emitted whenever connection has been established.
std::shared_ptr< WModuleInputConnector > toInputConnector()
Tries to convert this instance to an input connector.
virtual bool connectable(std::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.
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.
virtual void notifyConnectionEstablished(std::shared_ptr< WModuleConnector > here, std::shared_ptr< WModuleConnector > there)
Gets called whenever a connector gets connected to the specified input.
std::shared_ptr< WCondition > m_dataChangedCondition
Condition fired whenever data changes.
const std::string getName() const
Gives name of connection.
std::set< std::shared_ptr< WModuleConnector > > m_connected
List of connectors connected to this connector.
std::shared_mutex m_connectionListLock
Lock for avoiding concurrent write to m_Connected (multiple reader, single writer lock).
void setName(std::string name)
Sets the connector's name.
void setDescription(std::string desc)
Sets the connector's description.
std::shared_ptr< WModule > getModule() const
Returns the module which owns this connector.
virtual void connect(std::shared_ptr< WModuleConnector > con, bool force=false)
Connects this Module Connector with another one.
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.
virtual ~WModuleConnector()
Destructor.
WModuleConnector(std::shared_ptr< WModule > module, std::string name="", std::string description="")
Constructor.
virtual bool lazyConnectable(std::shared_ptr< WModuleConnector > con)=0
Checks whether the specified connector is connectable to this one, but ignores compatibility the type...
std::weak_ptr< WModule > m_module
The Module this connector belongs to.
General purpose exception and therefore base class for all kernel related exceptions.
General purpose exception and therefore base class for all kernel related exceptions.
General purpose exception and therefore base class for all kernel related exceptions.