9 #include "fwServices/config.hpp" 10 #include "fwServices/factory/new.hpp" 11 #include "fwServices/helper/ProxyConnections.hpp" 13 #include <fwCom/helper/SigSlotConnection.hpp> 14 #include <fwCom/HasSignals.hpp> 15 #include <fwCom/HasSlots.hpp> 16 #include <fwCom/Slot.hpp> 17 #include <fwCom/Slots.hpp> 19 #include <fwData/Object.hpp> 21 #include <fwRuntime/ConfigurationElement.hpp> 23 #include <fwTools/Failed.hpp> 24 #include <fwTools/Object.hpp> 26 #include <boost/property_tree/ptree.hpp> 41 #define KEY_GROUP_NAME(key, index) (key + "#" + std::to_string(index) ) 74 typedef ::boost::property_tree::ptree ConfigType;
76 typedef std::string IdType;
77 typedef std::string KeyType;
78 typedef std::map< KeyType, CWPTR( ::fwData::Object )> InputMapType;
79 typedef std::map< KeyType, WPTR( ::fwData::Object )> InOutMapType;
80 typedef std::map< KeyType, SPTR( ::fwData::Object )> OutputMapType;
82 enum class AccessType : std::uint8_t
95 bool m_autoConnect {
false };
96 bool m_optional {
false };
104 bool m_globalAutoConnect {
false };
105 std::string m_worker;
106 std::vector<ObjectServiceConfig> m_objects;
107 std::map<std::string, size_t> m_groupSize;
152 FWSERVICES_API
static const ::fwCom::Slots::SlotKeyType s_STARTED_SIG;
155 FWSERVICES_API
static const ::fwCom::Slots::SlotKeyType s_UPDATED_SIG;
158 FWSERVICES_API
static const ::fwCom::Slots::SlotKeyType s_STOPPED_SIG;
174 FWSERVICES_API
static const ::fwCom::Slots::SlotKeyType
s_STOP_SLOT;
180 FWSERVICES_API
static const ::fwCom::Slots::SlotKeyType
s_SWAP_SLOT;
181 typedef ::fwCom::Slot<SharedFutureType(::fwData::Object::sptr)>
SwapSlotType;
184 typedef ::fwCom::Slot<SharedFutureType(const KeyType&, ::fwData::Object::sptr)>
SwapKeySlotType;
205 FWSERVICES_API
void setConfiguration( const ::
fwRuntime::ConfigurationElement::sptr _cfgElement );
212 FWSERVICES_API
void setConfiguration( const
Config& _configuration);
219 FWSERVICES_API
void setConfiguration( const ConfigType& ptree );
228 FWSERVICES_API
void configure();
234 FWSERVICES_API SharedFutureType start();
242 FWSERVICES_API SharedFutureType stop();
248 FWSERVICES_API SharedFutureType update();
263 FWSERVICES_API SharedFutureType swap( ::
fwData::Object::sptr _obj );
277 FWSERVICES_API SharedFutureType swapKey( const KeyType& _key, ::
fwData::Object::sptr _obj );
290 FWSERVICES_API GlobalStatus getStatus() const noexcept;
296 FWSERVICES_API
bool isStarted() const noexcept;
302 FWSERVICES_API
bool isStopped() const noexcept;
308 FWSERVICES_API ConfigurationStatus getConfigurationStatus() const noexcept;
314 FWSERVICES_API UpdatingStatus getUpdatingStatus() const noexcept;
327 FWSERVICES_API ::
fwRuntime::ConfigurationElement::sptr getConfiguration() const;
332 FWSERVICES_API ConfigType getConfigTree() const;
347 FWSERVICES_API ::
fwData::Object::sptr getObject();
357 template< class DATATYPE >
SPTR(DATATYPE) getObject();
363 FWSERVICES_API const InputMapType& getInputs() const;
369 FWSERVICES_API const InOutMapType& getInOuts() const;
375 FWSERVICES_API const OutputMapType& getOutputs() const;
383 FWSERVICES_API
std::vector< ::
fwData::Object::csptr > getObjects() const;
390 template< class DATATYPE >
CSPTR(DATATYPE) getInput(const KeyType& key) const;
397 template< class DATATYPE >
SPTR(DATATYPE) getInOut(const KeyType& key) const;
404 template< class DATATYPE >
SPTR(DATATYPE) getOutput(const KeyType& key) const;
411 template< class DATATYPE >
CSPTR(DATATYPE) getInput(const KeyType& keybase,
size_t index) const;
418 template< class DATATYPE >
SPTR(DATATYPE) getInOut(const KeyType& keybase,
size_t index) const;
425 template< class DATATYPE >
SPTR(DATATYPE) getOutput(const KeyType& keybase,
size_t index) const;
441 size_t getKeyGroupSize(const KeyType& keybase) const;
459 void push (
const KeyType& key,
460 const ::fwCom::Signals::SignalKeyType& sig,
461 const ::fwCom::Slots::SlotKeyType& slot)
463 m_keyConnectionsMap[key].push_back(std::make_pair(sig, slot));
466 typedef std::map< KeyType, KeyConnectionsType> KeyConnectionsMapType;
470 KeyConnectionsMapType::const_iterator find(
const KeyType& key)
const 472 return m_keyConnectionsMap.find(key);
476 KeyConnectionsMapType::const_iterator end()
const 478 return m_keyConnectionsMap.cend();
484 return m_keyConnectionsMap.empty();
490 return m_keyConnectionsMap.size();
494 std::map< KeyType, KeyConnectionsType> m_keyConnectionsMap;
517 FWSERVICES_API
friend std::ostream&
operator<<(std::ostream& _sstream,
IService& _service);
523 FWSERVICES_API
bool hasObjectId(
const KeyType& _key)
const;
528 FWSERVICES_API IdType getObjectId(
const KeyType& _key)
const;
533 FWSERVICES_API
void setObjectId(
const KeyType& _key,
const IdType& _id);
544 FWSERVICES_API
void registerInput(const ::fwData::Object::csptr& obj,
const std::string& key,
545 const bool autoConnect =
false,
const bool optional =
false);
555 FWSERVICES_API
void registerInOut(const ::fwData::Object::sptr& obj,
const std::string& key,
556 const bool autoConnect =
false,
const bool optional =
false);
579 FWSERVICES_API
virtual ~IService();
596 FWSERVICES_API
virtual void starting() = 0;
603 FWSERVICES_API
virtual void stopping() = 0;
635 FWSERVICES_API
virtual void configuring() = 0;
642 FWSERVICES_API
virtual void reconfiguring();
649 FWSERVICES_API
virtual void updating() = 0;
657 FWSERVICES_API
virtual void info( std::ostream& _sstream );
706 SharedFutureType startSlot();
707 SharedFutureType internalStart(
bool _async);
710 SharedFutureType stopSlot();
711 SharedFutureType internalStop(
bool _async);
714 SharedFutureType swapSlot(::
fwData::Object::sptr _obj);
715 SharedFutureType internalSwap(::
fwData::Object::sptr _obj,
bool _async);
718 SharedFutureType swapKeySlot(const KeyType& _key, ::
fwData::Object::sptr _obj);
719 SharedFutureType internalSwapKey(const KeyType& _key, ::
fwData::Object::sptr _obj,
bool _async);
722 SharedFutureType updateSlot();
723 SharedFutureType internalUpdate(
bool _async);
726 FWSERVICES_API
void connectToConfig();
729 FWSERVICES_API
void disconnectFromConfig();
732 FWSERVICES_API
void autoConnect();
735 FWSERVICES_API
void autoDisconnect();
738 FWSERVICES_API
void addProxyConnection(const helper::ProxyConnections& info);
743 InputMapType m_inputsMap;
748 InOutMapType m_inOutsMap;
753 OutputMapType m_outputsMap;
758 std::map<KeyType, IdType> m_idsMap;
763 std::map<
std::
string,
size_t> m_keyGroupSize;
768 GlobalStatus m_globalState;
773 UpdatingStatus m_updatingState;
778 ConfigurationStatus m_configurationState;
786 ::
fwCom::helper::SigSlotConnection m_srvConnections;
789 ::
fwCom::helper::SigSlotConnection m_autoConnections;
792 std::map<
std::
string, helper::ProxyConnections> m_proxies;
797 #include "fwServices/IService.hxx" Base class for all services.
Contains fwAtomsFilter::registry details.
This class is a helper to define the connections of a service and its data.
GlobalStatus
Defines all possible global status for a service, including transitions.
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_SWAPKEY_SLOT
Slot to call start method.
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_STOP_SLOT
Slot to call start method.
static FWSERVICES_API const std::string s_DEFAULT_OBJECT
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_START_SLOT
Slot to call start method.
Namespace containing fw4spl communication tools.
std::shared_future< void > SharedFutureType
Slot to call start method.
SwapKeySlotType::sptr m_slotSwapKey
Slot to call swap method.
Namespace fwServices is dedicated to (mimic) the dynamic affectation of methods to (pure data) object...
virtual void swapping(const KeyType &key)
Swap the service from an associated object to another object. The key in parameter indicates allows t...
This class provides an API to manage config template.
This class proposes a mapping between a SlotKeyType and a SlotBase.
virtual void swapping()
Swap the service from associated object to another object.
::fwCom::Slot< SharedFutureType()> UpdateSlotType
Slot to call start method.
SwapSlotType::sptr m_slotSwap
Slot to call swap method.
Defines the configuration element class.
maintain the relation between objects and services
::fwCom::Slot< SharedFutureType(::fwData::Object::sptr)> SwapSlotType
Slot to call start method.
Used to store object configuration in a service.
The namespace fwRuntime contains classes to manage bundle, configuration element, extension point in ...
UpdateSlotType::sptr m_slotUpdate
Slot to call update method.
std::packaged_task< void()> PackagedTaskType
Slot to call start method.
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
::fwCom::helper::SigSlotConnection::KeyConnectionsType KeyConnectionsType
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
::fwData::Object::wptr m_associatedObject
associated object of service
UpdatingStatus
Defines all possible status for an update process.
#define fwCoreAllowSharedFromThis()
Generate getSptr and getConstSptr methods.
#define fwCoreServiceClassDefinitionsMacro(_classinfo_)
Generate common code for services classes.
std::future< void > UniqueFutureType
Slot to call start method.
ConfigurationStatus
Defines all possible status for a configuration process.
Contains the representation of the data objects used in the framework.
StopSlotType::sptr m_slotStop
Slot to call stop method.
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_SWAP_SLOT
Slot to call start method.
::fwCom::Slot< SharedFutureType()> StopSlotType
Slot to call start method.
This class creates and manages a task loop. The default implementation create a loop in a new thread...
This namespace fwThread provides few tools to execute asynchronous tasks on different threads...
std::ostream & operator<<(std::ostream &_ostream, IService &_service)
Streaming a service.
StartSlotType::sptr m_slotStart
Slot to call start method.
::fwCom::Slot< SharedFutureType()> StartSlotType
Slot to call start method.
::fwCom::Slot< SharedFutureType(const KeyType &,::fwData::Object::sptr)> SwapKeySlotType
Slot to call start method.
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
Used to store a service configuration.
This class proposes a mapping between a SignalKeyType and a SignalBase.