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 ) ) ) );