fw4spl
ObjectService.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #pragma once
8 
9 #include "fwServices/config.hpp"
10 #include "fwServices/IService.hpp"
11 
12 #include <fwCom/HasSignals.hpp>
13 
14 #include <fwCore/LogicStamp.hpp>
15 #include <fwCore/mt/types.hpp>
16 
17 #include <fwTools/Failed.hpp>
18 #include <fwTools/Object.hpp>
19 
20 #include <boost/bimap.hpp>
21 #include <boost/bimap/multiset_of.hpp>
22 #include <boost/bimap/unordered_set_of.hpp>
23 #include <boost/static_assert.hpp>
24 #include <boost/type_traits.hpp>
25 
26 #include <map>
27 #include <unordered_map>
28 #include <set>
29 
30 namespace fwData
31 {
32 class Object;
33 }
34 
35 namespace fwServices
36 {
37 namespace registry
38 {
39 
46 class FWSERVICES_CLASS_API ObjectService : public ::fwCore::BaseObject,
47  public ::fwCom::HasSignals
48 {
49 public:
50 
53 
58  typedef ::boost::bimaps::bimap<
59  ::boost::bimaps::multiset_of< ::fwData::Object::cwptr, std::owner_less< ::fwData::Object::cwptr > >,
60  ::boost::bimaps::multiset_of< ::fwServices::IService::sptr >
62 
63  typedef std::set< CSPTR( ::fwData::Object ) > ObjectVectorType;
64  typedef std::set< SPTR( ::fwServices::IService ) > ServiceVectorType;
65 
66  typedef std::map< ::fwServices::IService::KeyType, WPTR( ::fwData::Object )> ObjectMapType;
67 
72  typedef ::fwCom::Signal< void (::fwData::Object::sptr, const std::string&) > RegisterSignalType;
74 
75  FWSERVICES_API static const ::fwCom::Signals::SignalKeyType s_REGISTERED_SIG;
76  FWSERVICES_API static const ::fwCom::Signals::SignalKeyType s_UNREGISTERED_SIG;
78 
80  FWSERVICES_API ObjectService();
81 
83  FWSERVICES_API std::string getRegistryInformation() const;
84 
89 
95  FWSERVICES_API void registerService( ::fwServices::IService::sptr service );
96 
105  FWSERVICES_API void registerService( ::fwData::Object::sptr object, ::fwServices::IService::sptr service );
106 
117  FWSERVICES_API void registerService(::fwData::Object::sptr object, const ::fwServices::IService::KeyType& objKey,
118  ::fwServices::IService::AccessType access,
119  ::fwServices::IService::sptr service);
120 
130  FWSERVICES_API void registerServiceInput(const ::fwData::Object::csptr& object,
131  const ::fwServices::IService::KeyType& objKey,
132  const ::fwServices::IService::sptr& service);
133 
141  FWSERVICES_API void registerServiceOutput(::fwData::Object::sptr object,
142  const ::fwServices::IService::KeyType& objKey,
143  ::fwServices::IService::sptr service);
145 
151 
157  FWSERVICES_API void unregisterService( ::fwServices::IService::sptr service );
158 
166  FWSERVICES_API void unregisterService( const ::fwServices::IService::KeyType& objKey,
167  ::fwServices::IService::AccessType access,
168  ::fwServices::IService::sptr service );
169 
176  FWSERVICES_API void unregisterServiceOutput( const ::fwServices::IService::KeyType& objKey,
177  ::fwServices::IService::sptr service );
178 
186  FWSERVICES_API bool isRegistered( const ::fwServices::IService::KeyType& objKey,
187  ::fwServices::IService::AccessType access,
188  ::fwServices::IService::sptr service) const;
189 
197  FWSERVICES_API ::fwData::Object::csptr getRegistered(const ::fwServices::IService::KeyType& objKey,
198  ::fwServices::IService::AccessType access,
199  IService::sptr service) const;
201 
207 
212  template<class SERVICE>
213  std::set< SPTR(SERVICE) > getServices() const;
214 
219  template<class SERVICE>
220  std::set< SPTR(SERVICE) > getServices(::fwData::Object::sptr obj) const;
221 
228  FWSERVICES_API ServiceVectorType getServices( const std::string& serviceType ) const;
229 
234  FWSERVICES_API ServiceVectorType getServices( ::fwData::Object::sptr obj, const std::string& serviceType ) const;
235 
240  FWSERVICES_API ServiceVectorType getServices( ::fwData::Object::sptr obj ) const;
241 
245  template<class SERVICE>
246  ObjectVectorType getObjects() const;
247 
251  FWSERVICES_API ObjectVectorType getObjects() const;
252 
254 
266  FWSERVICES_API bool has( ::fwData::Object::sptr obj, const std::string& srvType) const;
267 
269 
275 
280  FWSERVICES_API void swapService( ::fwData::Object::sptr objDst, ::fwServices::IService::sptr service );
281 
283 
284 protected:
285 
291  ServiceContainerType m_container;
292 
293  mutable ::fwCore::mt::ReadWriteMutex m_containerMutex;
294 
295 private:
296 
303  void internalRegisterService( ::fwData::Object::sptr obj, ::fwServices::IService::sptr service,
304  const ::fwServices::IService::KeyType& objKey,
305  ::fwServices::IService::AccessType access);
306 
313  void internalRegisterServiceInput( const ::fwData::Object::csptr& obj, const ::fwServices::IService::sptr& service,
314  const ::fwServices::IService::KeyType& objKey);
315 
321  void removeFromContainer( ::fwServices::IService::sptr service );
322 };
323 
324 } // namespace registry
325 
329 namespace OSR
330 {
331 
335 FWSERVICES_API ::fwServices::registry::ObjectService::sptr get();
336 
340 FWSERVICES_API ::fwServices::registry::ObjectService::ObjectVectorType getObjects();
341 
345 FWSERVICES_API std::string getRegistryInformation();
346 
350 template<class SERVICE>
351 std::set< SPTR(SERVICE) > getServices();
352 
356 template<class SERVICE>
357 std::set< SPTR(SERVICE) > getServices(::fwData::Object::sptr obj);
358 
362 FWSERVICES_API ::fwServices::registry::ObjectService::ServiceVectorType getServices( const std::string& serviceType );
363 
367 FWSERVICES_API ::fwServices::registry::ObjectService::ServiceVectorType getServices( ::fwData::Object::sptr obj,
368  const std::string& serviceType );
369 
373 FWSERVICES_API ::fwServices::registry::ObjectService::ServiceVectorType getServices( ::fwData::Object::sptr obj );
374 
382 FWSERVICES_API bool has( ::fwData::Object::sptr obj, const std::string& srvType);
383 
389 FWSERVICES_API void registerService( ::fwServices::IService::sptr service );
390 
402 FWSERVICES_API void registerService( ::fwData::Object::sptr obj, ::fwServices::IService::sptr service );
403 
414 FWSERVICES_API void registerService(::fwData::Object::sptr obj, const ::fwServices::IService::KeyType& objKey,
415  ::fwServices::IService::AccessType access, ::fwServices::IService::sptr service);
416 
426 FWSERVICES_API void registerServiceInput(::fwData::Object::csptr obj, const ::fwServices::IService::KeyType& objKey,
427  ::fwServices::IService::sptr service);
428 
436 FWSERVICES_API void registerServiceOutput(::fwData::Object::sptr obj, const ::fwServices::IService::KeyType& objKey,
437  ::fwServices::IService::sptr service);
438 
443 FWSERVICES_API void swapService( ::fwData::Object::sptr objDst, ::fwServices::IService::sptr service );
444 
450 FWSERVICES_API void unregisterService( ::fwServices::IService::sptr service );
451 
459 FWSERVICES_API void unregisterService( const ::fwServices::IService::KeyType& objKey,
460  ::fwServices::IService::AccessType access,
461  ::fwServices::IService::sptr service );
462 
469 FWSERVICES_API void unregisterServiceOutput( const ::fwServices::IService::KeyType& objKey,
470  ::fwServices::IService::sptr service );
471 
479 FWSERVICES_API bool isRegistered(const ::fwServices::IService::KeyType& objKey,
480  ::fwServices::IService::AccessType access,
481  ::fwServices::IService::sptr service);
482 
490 FWSERVICES_API ::fwData::Object::csptr getRegistered( const ::fwServices::IService::KeyType& objKey,
491  ::fwServices::IService::AccessType access,
492  ::fwServices::IService::sptr service );
493 
494 FWSERVICES_API SPTR( ::fwServices::registry::ObjectService::RegisterSignalType ) getRegisterSignal();
495 FWSERVICES_API SPTR( ::fwServices::registry::ObjectService::RegisterSignalType ) getUnregisterSignal();
496 
497 } // namespace OSR
498 
499 } // namespace fwServices
500 
501 #include "fwServices/registry/ObjectService.hxx"
#define SPTR(_cls_)
Contains fwAtomsFilter::registry details.
#define fwCoreNonInstanciableClassDefinitionsMacro(_classinfo_)
Generate common code for Non Instanciable classes (Interfaces, Abstract classes, ...)
std::set< std::shared_ptr< SERVICE > > getServices()
Wraps ObjectService::getServices.
FWSERVICES_API void unregisterService(::fwServices::IService::sptr service)
Remove the service (service) from the m_container.
Base class for all FW4SPL&#39;s classes.
Definition: BaseObject.hpp:22
Namespace fwServices is dedicated to (mimic) the dynamic affectation of methods to (pure data) object...
FWSERVICES_API void unregisterServiceOutput(const ::fwServices::IService::KeyType &objKey,::fwServices::IService::sptr service)
Emit the signal &#39;unregistered&#39;.
FWSERVICES_API void swapService(::fwData::Object::sptr objDst,::fwServices::IService::sptr service)
Wraps ObjectService::swapService.
FWSERVICES_API std::string getRegistryInformation()
Wraps ObjectService::getRegistryInformation.
maintain the relation between objects and services
FWSERVICES_API::fwServices::registry::ObjectService::ObjectVectorType getObjects()
Wraps ObjectService::getObjects.
FWSERVICES_API::fwData::Object::csptr getRegistered(const ::fwServices::IService::KeyType &objKey,::fwServices::IService::AccessType access,::fwServices::IService::sptr service)
Return the object pointer of a key of a given service.
static FWSERVICES_APIconst::fwCom::Signals::SignalKeyType s_REGISTERED_SIG
Type of signal m_sigRenderRequested.
FWSERVICES_API void registerService(::fwServices::IService::sptr service)
Register the service alone.
ServiceContainerType m_container
Object to service associations container.
static FWSERVICES_APIconst::fwCom::Signals::SignalKeyType s_UNREGISTERED_SIG
Type of signal m_sigRenderRequested.
#define fwCoreAllowSharedFromThis()
Generate getSptr and getConstSptr methods.
FWSERVICES_API void registerServiceOutput(::fwData::Object::sptr obj, const ::fwServices::IService::KeyType &objKey,::fwServices::IService::sptr service)
Emit the signal &#39;registered&#39;.
Contains the representation of the data objects used in the framework.
FWSERVICES_API void registerServiceInput(::fwData::Object::csptr obj, const ::fwServices::IService::KeyType &objKey,::fwServices::IService::sptr service)
Register the service (service) for the input object (obj) at the given service key. It also updates IService::m_associatedObject of service to point to obj removal at obj destruction.
FWSERVICES_API bool isRegistered(const ::fwServices::IService::KeyType &objKey,::fwServices::IService::AccessType access,::fwServices::IService::sptr service)
Return true if a key is registered for a given service.
::boost::bimaps::bimap< ::boost::bimaps::multiset_of< ::fwData::Object::cwptr, std::owner_less< ::fwData::Object::cwptr > >,::boost::bimaps::multiset_of< ::fwServices::IService::sptr > > ServiceContainerType
Service container keeps relation between objects identifiers and attached services.
This class proposes a mapping between a SignalKeyType and a SignalBase.
Definition: HasSignals.hpp:21