7 #include "fwCom/helper/SigSlotConnection.hpp" 9 #include <fwCom/SignalBase.hpp> 10 #include <fwCom/exception/AlreadyConnected.hpp> 11 #include <fwCom/exception/BadSlot.hpp> 15 #include <fwTools/Object.hpp> 17 #include <boost/foreach.hpp> 40 const ::fwCom::HasSlots::csptr& hasSlots, ::fwCom::Slots::SlotKeyType slotKey )
44 ::fwCom::Connection connection = hasSignals->signal( signalKey )->connect( hasSlots->slot( slotKey ) );
49 OSLM_ERROR(
"Can't connect signal '" + signalKey +
"' with slot '" + slotKey +
"' : " << e.what() <<
".");
53 const ::fwTools::Object::csptr source = ::fwTools::Object::dynamicCast(hasSignals);
54 auto sourceID = source ? source->getID() :
"";
56 const ::fwTools::Object::csptr target = ::fwTools::Object::dynamicCast(hasSlots);
57 auto targetID = target ? target->getID() :
"";
59 OSLM_ERROR(
"Can't connect signal '" + sourceID +
"/" + signalKey +
"' with slot '" 60 + targetID +
"/" + slotKey +
"' : " << e.what() <<
".");
67 const ::fwCom::HasSlots::csptr& hasSlots,
68 const KeyConnectionsType& keyConnections )
70 SLM_ASSERT(
"Signal source is NULL", hasSignals);
71 SLM_ASSERT(
"Slot destination is NULL", hasSlots);
73 for(
const KeyConnectionType& keys : keyConnections )
75 auto signal = hasSignals->signal( keys.first );
76 SLM_ASSERT(
"Signal '" + keys.first +
"' not found.", signal);
77 auto slot = hasSlots->slot( keys.second );
78 SLM_ASSERT(
"Slot '" + keys.second +
"' not found.", slot);
87 OSLM_ERROR(
"Can't connect signal '" + keys.first +
"' with slot '" + keys.second +
"' : " 92 const ::fwTools::Object::csptr source = ::fwTools::Object::dynamicCast(hasSignals);
93 auto sourceID = source ? source->getID() :
"";
95 const ::fwTools::Object::csptr target = ::fwTools::Object::dynamicCast(hasSlots);
96 auto targetID = target ? target->getID() :
"";
98 OSLM_ERROR(
"Can't connect signal '" + sourceID +
"/" + keys.first +
"' with slot '" 99 + targetID +
"/" + keys.second +
"' : " << e.what() <<
".");
ConnectionContainerType m_connections
Connections storage.
FWCOM_API SigSlotConnection()
Constructor, do nothing.
FWCOM_API void disconnect()
Disconnect all registered connections and clear m_connections.
Namespace containing fw4spl communication tools.
FWCOM_API void addConnection(::fwCom::Connection connection)
Add a connection.
virtual FWCOM_API ~SigSlotConnection()
Destructor, call disconnect()
Class managing Signal-Slot connections.
#define OSLM_ERROR(message)
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWCOM_API void connect(const ::fwCom::HasSignals::csptr &hasSignals,::fwCom::Signals::SignalKeyType signalKey, const ::fwCom::HasSlots::csptr &hasSlots,::fwCom::Slots::SlotKeyType slotKey)
Connect signal to slot, and register this new connection in m_connections.
void disconnect()
Disconnect related Connection.
This file defines SpyLog macros. These macros are used to log messages to a file or to the console du...