Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
usServiceObjects.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef USSERVICEOBJECTS_H
14 #define USSERVICEOBJECTS_H
15 
16 #include <usGlobalConfig.h>
18 
19 #include <usModuleContext.h>
21 #include <usServiceReference.h>
22 #include <usServiceProperties.h>
23 
24 namespace us {
25 
26 class ServiceObjectsBasePrivate;
27 
38 {
39 
40 private:
41 
42  ServiceObjectsBasePrivate* d;
43 
44 protected:
45 
52 
55 
58 
61 
63  void* GetService() const;
64 
67 
69  void UngetService(void* service);
70 
72  void UngetService(const InterfaceMap& interfaceMap);
73 
76 
77 };
78 
95 template<class S>
97 {
98 
99 public:
100 
137  S* GetService() const
138  {
139  return reinterpret_cast<S*>(this->ServiceObjectsBase::GetService());
140  }
141 
173  void UngetService(S* service)
174  {
175  this->ServiceObjectsBase::UngetService(service);
176  }
177 
184  {
185  return this->ServiceObjectsBase::GetReference();
186  }
187 
188 private:
189 
190  friend class ModuleContext;
191 
192  ServiceObjects(ModuleContext* context, const ServiceReference<S>& reference)
193  : ServiceObjectsBase(context, reference)
194  {}
195 
196 };
197 
208 template<>
210 {
211 
212 public:
213 
233 
250  void UngetService(const InterfaceMap& service);
251 
258 
259 private:
260 
261  friend class ModuleContext;
262 
263  ServiceObjects(ModuleContext* context, const ServiceReferenceU& reference);
264 
265 };
266 
267 }
268 
269 #endif // USSERVICEOBJECTS_H
#define MITKCPPMICROSERVICES_EXPORT
Base class for ServiceObjects providing type-erased service object management.
void UngetService(void *service)
Called by ServiceObjects<S> with S != void to release a service object.
void UngetService(const InterfaceMap &interfaceMap)
Called by the ServiceObjects<void> specialization to release a service InterfaceMap.
ServiceObjectsBase(ModuleContext *context, const ServiceReferenceBase &reference)
Constructs a ServiceObjectsBase instance.
void * GetService() const
Called by ServiceObjects<S> with S != void to get a service object.
ServiceObjectsBase & operator=(const ServiceObjectsBase &other)
Copy assignment operator.
~ServiceObjectsBase()
Destructor.
ServiceObjectsBase(const ServiceObjectsBase &other)
Copy constructor.
InterfaceMap GetServiceInterfaceMap() const
Called by the ServiceObjects<void> specialization to get a service InterfaceMap.
ServiceReferenceBase GetReference() const
Returns the ServiceReferenceBase for this ServiceObjects object.
ServiceReferenceU GetServiceReference() const
Returns the ServiceReference for this ServiceObjects object.
void UngetService(const InterfaceMap &service)
Releases a service object for the referenced service.
InterfaceMap GetService() const
Returns a service object as a InterfaceMap instance for the referenced service.
Allows multiple service objects for a service to be obtained.
S * GetService() const
Returns a service object for the referenced service.
void UngetService(S *service)
Releases a service object for the referenced service.
ServiceReference< S > GetServiceReference() const
Returns the ServiceReference for this ServiceObjects object.
std::map< std::string, void * > InterfaceMap
A map containing interfaces ids and their corresponding service object pointers.