7 #include "fwServices/IHasServices.hpp" 9 #include "fwServices/IService.hpp" 10 #include <fwServices/registry/ObjectService.hpp> 25 SLM_ASSERT(
"Some sub-services were not unregistered, something is probably wrong. " 26 "Please use unregisterService() or unregisterServices() before destroying the sub-services owner.",
27 m_subServices.empty());
34 ::fwServices::IService::sptr srv;
35 for(
const auto& wService : m_subServices)
37 const ::fwServices::IService::sptr& service = wService.lock();
38 if(service && (service->getID() == _id))
51 for(
auto itSrv = m_subServices.begin(); itSrv != m_subServices.end(); )
53 const ::fwServices::IService::sptr& service = itSrv->lock();
54 if(service && (service->getID() == _id))
56 service->stop().wait();
57 ::fwServices::OSR::unregisterService(service);
58 itSrv = m_subServices.erase(itSrv);
71 auto iter = std::find_if(m_subServices.begin(), m_subServices.end(),
72 [ = ](const ::fwServices::IService::wptr& adaptor)
74 return adaptor.lock() == _service;
77 SLM_ASSERT(
"service '" + _service->getID() +
"' is not registered", iter != m_subServices.end());
78 m_subServices.erase(iter);
80 _service->stop().wait();
81 ::fwServices::OSR::unregisterService(_service);
88 auto srv = ::fwServices::add(_implType, _id);
89 m_subServices.push_back(srv);
98 for(
auto itSrv = m_subServices.begin(); itSrv != m_subServices.end(); )
100 const ::fwServices::IService::sptr& srv = itSrv->lock();
101 if(srv && (_classname.empty() || ( !_classname.empty() && srv->getClassname() == _classname)))
104 ::fwServices::OSR::unregisterService(srv);
105 itSrv = m_subServices.erase(itSrv);
Namespace fwServices is dedicated to (mimic) the dynamic affectation of methods to (pure data) object...
FWSERVICES_API void unregisterService(const ::fwTools::fwID::IDType &_id)
Unregister a specific service.
FWSERVICES_API std::shared_ptr< const ::fwServices::IService > getRegisteredService(const ::fwTools::fwID::IDType &_id) const
Return a specific registered service.
virtual FWSERVICES_API ~IHasServices() noexcept
Destructor.
FWSERVICES_API void unregisterServices(const std::string &_implType="")
Unregister all services linked to this service, optionally matches only a given type of services...
FWSERVICES_API std::shared_ptr< ::fwServices::IService > registerService(const std::string &_implType, const std::string &_id="")
Register a new service linked to this service.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWSERVICES_API IHasServices() noexcept
Constructor.