fw4spl
ObjectService.hxx
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/IService.hpp"
10 
11 #include <fwCom/Signal.hxx>
12 
13 namespace fwServices
14 {
15 
16 //------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------
18 
19 namespace OSR
20 {
21 
22 //------------------------------------------------------------------------------
23 
24 template<class SERVICE>
25 std::set< SPTR(SERVICE) > getServices()
26 {
27  return ::fwServices::OSR::get()->getServices< SERVICE >();
28 }
29 
30 //------------------------------------------------------------------------------
31 
32 template<class SERVICE>
33 std::set< SPTR(SERVICE) > getServices(::fwData::Object::sptr obj)
34 {
35  return ::fwServices::OSR::get()->getServices< SERVICE >(obj);
36 }
37 
39 {
40  return ::fwServices::OSR::get()->signal< ::fwServices::registry::ObjectService::RegisterSignalType >
42 }
43 
44 inline SPTR( ::fwServices::registry::ObjectService::RegisterSignalType ) getUnregisterSignal()
45 {
46  return ::fwServices::OSR::get()->signal< ::fwServices::registry::ObjectService::RegisterSignalType >
48 }
49 
50 } //namespace OSR
51 
52 //------------------------------------------------------------------------------
53 //------------------------------------------------------------------------------
54 
55 namespace registry
56 {
57 
58 //------------------------------------------------------------------------------
59 
60 template<class SERVICE>
61 std::set< SPTR(SERVICE) > ObjectService::getServices() const
62 {
63  std::set< SPTR(SERVICE) > services;
64  const ServiceContainerType::right_map& right = m_container.right;
65  for( const ServiceContainerType::right_map::value_type& elt: right)
66  {
67  SPTR(SERVICE) service = std::dynamic_pointer_cast< SERVICE >( elt.first );
68  if ( service )
69  {
70  services.insert( service );
71  }
72  }
73  SLM_DEBUG_IF("No service registered", services.empty());
74  return services;
75 }
76 
77 //------------------------------------------------------------------------------
78 
79 template<class SERVICE>
80 std::set< SPTR(SERVICE) > ObjectService::getServices(::fwData::Object::sptr obj) const
81 {
82  FW_DEPRECATED_MSG("'ObjectService::getServices(object)' is deprecated.", "20.0");
83 
84  std::set< SPTR(SERVICE) > services;
85  if(m_container.left.find(obj) != m_container.left.end())
86  {
87  ServiceContainerType::left_map::const_iterator iter;
88  ServiceContainerType::left_map::const_iterator firstElement = m_container.left.lower_bound(obj);
89  ServiceContainerType::left_map::const_iterator lastElement = m_container.left.upper_bound(obj);
90  for (iter = firstElement; iter != lastElement; ++iter)
91  {
92  SPTR(SERVICE) service = std::dynamic_pointer_cast< SERVICE >( iter->second );
93  if ( service)
94  {
95  services.insert( service );
96  }
97  }
98  }
99  return services;
100 }
101 
102 //------------------------------------------------------------------------------
103 
104 template<class SERVICE>
105 ObjectService::ObjectVectorType ObjectService::getObjects() const
106 {
107  ObjectVectorType objects;
108  const ServiceContainerType::right_map& right = m_container.right;
109  for( const ServiceContainerType::right_map::value_type& elt : right)
110  {
111  SPTR(SERVICE) service = std::dynamic_pointer_cast< SERVICE >( elt.first );
112  if ( service && std::find(objects.begin(), objects.end(), service->getObject()) == objects.end() )
113  {
114  objects.insert( service->getObject() );
115  }
116  }
117  SLM_WARN_IF( "No object registered for the requested type of service", objects.empty() );
118  return objects;
119 }
120 
121 //------------------------------------------------------------------------------
122 
123 } // end registry
124 } // end fwServices
#define SPTR(_cls_)
Contains fwAtomsFilter::registry details.
std::set< std::shared_ptr< SERVICE > > getServices()
Wraps ObjectService::getServices.
#define SLM_DEBUG_IF(message, cond)
Definition: spyLog.hpp:243
Namespace fwServices is dedicated to (mimic) the dynamic affectation of methods to (pure data) object...
#define FW_DEPRECATED_MSG(message, version)
Use this macro when deprecating a function to warn the developer.
Definition: spyLog.hpp:360
static FWSERVICES_APIconst::fwCom::Signals::SignalKeyType s_REGISTERED_SIG
Type of signal m_sigRenderRequested.
static FWSERVICES_APIconst::fwCom::Signals::SignalKeyType s_UNREGISTERED_SIG
Type of signal m_sigRenderRequested.
#define SLM_WARN_IF(message, cond)
Definition: spyLog.hpp:265