Medical Imaging Interaction Toolkit  2023.12.00
Medical Imaging Interaction Toolkit
mitkCoreServices.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 mitkCoreServices_h
14 #define mitkCoreServices_h
15 
16 #include "MitkCoreExports.h"
17 
18 #include <mitkCommon.h>
19 #include <mitkLog.h>
20 
21 #include <mitkServiceInterface.h>
22 #include <usGetModuleContext.h>
23 #include <usModuleContext.h>
24 #include <usServiceReference.h>
25 
26 #include <cassert>
27 
28 namespace mitk
29 {
30  struct IMimeTypeProvider;
31  class IPropertyAliases;
32  class IPropertyDescriptions;
33  class IPropertyDeserialization;
34  class IPropertyExtensions;
35  class IPropertyFilters;
36  class IPropertyPersistence;
37  class IPropertyRelations;
38  class IPreferencesService;
39 
59  {
60  public:
61 
67  static IPropertyAliases *GetPropertyAliases(us::ModuleContext *context = us::GetModuleContext());
68 
74  static IPropertyDescriptions *GetPropertyDescriptions(us::ModuleContext *context = us::GetModuleContext());
75 
81  static IPropertyDeserialization* GetPropertyDeserialization(us::ModuleContext* context = us::GetModuleContext());
82 
88  static IPropertyExtensions *GetPropertyExtensions(us::ModuleContext *context = us::GetModuleContext());
89 
95  static IPropertyFilters *GetPropertyFilters(us::ModuleContext *context = us::GetModuleContext());
96 
102  static IPropertyPersistence *GetPropertyPersistence(us::ModuleContext *context = us::GetModuleContext());
103 
109  static IPropertyRelations *GetPropertyRelations(us::ModuleContext *context = us::GetModuleContext());
110 
116  static IMimeTypeProvider *GetMimeTypeProvider(us::ModuleContext *context = us::GetModuleContext());
117 
124  static IPreferencesService *GetPreferencesService(us::ModuleContext *context = us::GetModuleContext());
125 
132  template <class S>
133  static bool Unget(S *service, us::ModuleContext *context = us::GetModuleContext())
134  {
135  return Unget(context, us_service_interface_iid<S>(), service);
136  }
137 
138  private:
139  static bool Unget(us::ModuleContext *context, const std::string &interfaceId, void *service);
140 
141  // purposely not implemented
142  CoreServices();
143  CoreServices(const CoreServices &);
144  CoreServices &operator=(const CoreServices &);
145  };
146 
157  template <class S>
159  {
160  public:
161  explicit CoreServicePointer(S *service, us::ModuleContext* context = us::GetModuleContext())
162  : m_Service(service),
163  m_Context(context)
164  {
165  assert(service);
166  }
167 
169  {
170  try
171  {
172  CoreServices::Unget(m_Service, m_Context);
173  }
174  catch (const std::exception &e)
175  {
176  MITK_ERROR << e.what();
177  }
178  catch (...)
179  {
180  MITK_ERROR << "Ungetting core service failed.";
181  }
182  }
183 
184  S *operator->() const
185  {
186  return m_Service;
187  }
188 
189  private:
190  S *const m_Service;
191  us::ModuleContext* m_Context;
192  };
193 }
194 
195 #endif
mitk::IPropertyFilters
Interface of property filters service.
Definition: mitkIPropertyFilters.h:34
mitk::IPropertyExtensions
Interface of property extensions service.
Definition: mitkIPropertyExtensions.h:32
mitk::IPropertyAliases
Interface of property aliases service.
Definition: mitkIPropertyAliases.h:31
mitkServiceInterface.h
mitk::CoreServicePointer::~CoreServicePointer
~CoreServicePointer()
Definition: mitkCoreServices.h:168
mitk::CoreServicePointer::CoreServicePointer
CoreServicePointer(S *service, us::ModuleContext *context=us::GetModuleContext())
Definition: mitkCoreServices.h:161
MITK_ERROR
#define MITK_ERROR
Definition: mitkLog.h:211
mitk::CoreServicePointer
A RAII helper class for core service objects.
Definition: mitkCoreServices.h:158
us::GetModuleContext
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
Definition: usGetModuleContext.h:50
mitk::IPropertyDeserialization
Interface of property deserialization service.
Definition: mitkIPropertyDeserialization.h:34
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
MitkCoreExports.h
mitk::IPropertyRelations
Interface of property relations service.
Definition: mitkIPropertyRelations.h:28
usServiceReference.h
mitk::IMimeTypeProvider
The IMimeTypeProvider service interface allows to query all registered mime types.
Definition: mitkIMimeTypeProvider.h:46
mitk::CoreServices::Unget
static bool Unget(S *service, us::ModuleContext *context=us::GetModuleContext())
Unget a previously acquired service instance.
Definition: mitkCoreServices.h:133
mitkCommon.h
mitkLog.h
mitk::CoreServices
Access MITK core services.
Definition: mitkCoreServices.h:58
usModuleContext.h
usGetModuleContext.h
MITK_LOCAL
#define MITK_LOCAL
Definition: mitkCommon.h:193
mitk::IPropertyDescriptions
Interface of property descriptions service.
Definition: mitkIPropertyDescriptions.h:29
mitk::IPreferencesService
A service for persistent application preferences.
Definition: mitkIPreferencesService.h:33
MITKCORE_EXPORT
#define MITKCORE_EXPORT
Definition: MitkCoreExports.h:15
mitk::IPropertyPersistence
Interface of property persistence service.
Definition: mitkIPropertyPersistence.h:33
mitk::CoreServicePointer::operator->
S * operator->() const
Definition: mitkCoreServices.h:184