Medical Imaging Interaction Toolkit  2024.12.99-0da743f6
Medical Imaging Interaction Toolkit
usServiceObjects.h
Go to the documentation of this file.
1 /*============================================================================
2 
3  Library: CppMicroServices
4 
5  Copyright (c) German Cancer Research Center (DKFZ)
6  All rights reserved.
7 
8  Licensed under the Apache License, Version 2.0 (the "License");
9  you may not use this file except in compliance with the License.
10  You may obtain a copy of the License at
11 
12  https://www.apache.org/licenses/LICENSE-2.0
13 
14  Unless required by applicable law or agreed to in writing, software
15  distributed under the License is distributed on an "AS IS" BASIS,
16  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  See the License for the specific language governing permissions and
18  limitations under the License.
19 
20 ============================================================================*/
21 
22 #ifndef USSERVICEOBJECTS_H
23 #define USSERVICEOBJECTS_H
24 
25 #include <usCoreExport.h>
26 
27 #include <usModuleContext.h>
29 #include <usServiceReference.h>
30 #include <usServiceProperties.h>
31 
33 
34 class ServiceObjectsBasePrivate;
35 
37 {
38 
39 private:
40 
41  ServiceObjectsBasePrivate* d;
42 
43 protected:
44 
45  ServiceObjectsBase(ModuleContext* context, const ServiceReferenceBase& reference);
46 
48 
50 
51  ServiceObjectsBase& operator=(const ServiceObjectsBase& other);
52 
53  // Called by ServiceObjects<S> with S != void
54  void* GetService() const;
55 
56  // Called by the ServiceObjects<void> specialization
57  InterfaceMap GetServiceInterfaceMap() const;
58 
59  // Called by ServiceObjects<S> with S != void
60  void UngetService(void* service);
61 
62  // Called by the ServiceObjects<void> specialization
63  void UngetService(const InterfaceMap& interfaceMap);
64 
65  ServiceReferenceBase GetReference() const;
66 
67 };
68 
85 template<class S>
87 {
88 
89 public:
90 
127  S* GetService() const
128  {
129  return reinterpret_cast<S*>(this->ServiceObjectsBase::GetService());
130  }
131 
163  void UngetService(S* service)
164  {
165  this->ServiceObjectsBase::UngetService(service);
166  }
167 
174  {
175  return this->ServiceObjectsBase::GetReference();
176  }
177 
178 private:
179 
180  friend class ModuleContext;
181 
182  ServiceObjects(ModuleContext* context, const ServiceReference<S>& reference)
183  : ServiceObjectsBase(context, reference)
184  {}
185 
186 };
187 
198 template<>
200 {
201 
202 public:
203 
222  InterfaceMap GetService() const;
223 
240  void UngetService(const InterfaceMap& service);
241 
247  ServiceReferenceU GetServiceReference() const;
248 
249 private:
250 
251  friend class ModuleContext;
252 
253  ServiceObjects(ModuleContext* context, const ServiceReferenceU& reference);
254 
255 };
256 
258 
259 #endif // USSERVICEOBJECTS_H
usServiceProperties.h
us::ServiceObjects
Definition: usServiceObjects.h:86
us::ServiceObjects::GetService
S * GetService() const
Definition: usServiceObjects.h:127
ModuleContext
Definition: usModuleContext.h:91
usPrototypeServiceFactory.h
usCoreExport.h
us::ServiceObjectsBase::UngetService
void UngetService(void *service)
us::ServiceObjectsBase::GetService
void * GetService() const
us::ServiceReference
Definition: usModule.h:40
us::ServiceReferenceBase
Definition: usServiceReferenceBase.h:43
usServiceReference.h
US_BEGIN_NAMESPACE
#define US_BEGIN_NAMESPACE
Definition: usGlobalConfig.h:76
usModuleContext.h
US_END_NAMESPACE
#define US_END_NAMESPACE
Definition: usGlobalConfig.h:77
us::ServiceObjectsBase
Definition: usServiceObjects.h:36
us::ServiceObjects::GetServiceReference
ServiceReference< S > GetServiceReference() const
Definition: usServiceObjects.h:173
US_Core_EXPORT
#define US_Core_EXPORT
Definition: usCoreExport.h:21
us::InterfaceMap
std::map< std::string, void * > InterfaceMap
Definition: usServiceInterface.h:138
us::ServiceObjects::UngetService
void UngetService(S *service)
Definition: usServiceObjects.h:163