Medical Imaging Interaction Toolkit  2023.04.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 <mitkLogMacros.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 IPropertyExtensions;
34  class IPropertyFilters;
35  class IPropertyPersistence;
36  class IPropertyRelations;
37  class IPreferencesService;
38 
58  {
59  public:
60 
66  static IPropertyAliases *GetPropertyAliases(us::ModuleContext *context = us::GetModuleContext());
67 
73  static IPropertyDescriptions *GetPropertyDescriptions(us::ModuleContext *context = us::GetModuleContext());
74 
80  static IPropertyExtensions *GetPropertyExtensions(us::ModuleContext *context = us::GetModuleContext());
81 
87  static IPropertyFilters *GetPropertyFilters(us::ModuleContext *context = us::GetModuleContext());
88 
94  static IPropertyPersistence *GetPropertyPersistence(us::ModuleContext *context = us::GetModuleContext());
95 
101  static IPropertyRelations *GetPropertyRelations(us::ModuleContext *context = us::GetModuleContext());
102 
108  static IMimeTypeProvider *GetMimeTypeProvider(us::ModuleContext *context = us::GetModuleContext());
109 
116  static IPreferencesService *GetPreferencesService(us::ModuleContext *context = us::GetModuleContext());
117 
124  template <class S>
125  static bool Unget(S *service, us::ModuleContext *context = us::GetModuleContext())
126  {
127  return Unget(context, us_service_interface_iid<S>(), service);
128  }
129 
130  private:
131  static bool Unget(us::ModuleContext *context, const std::string &interfaceId, void *service);
132 
133  // purposely not implemented
134  CoreServices();
135  CoreServices(const CoreServices &);
136  CoreServices &operator=(const CoreServices &);
137  };
138 
149  template <class S>
151  {
152  public:
153  explicit CoreServicePointer(S *service, us::ModuleContext* context = us::GetModuleContext())
154  : m_Service(service),
155  m_Context(context)
156  {
157  assert(service);
158  }
159 
161  {
162  try
163  {
164  CoreServices::Unget(m_Service, m_Context);
165  }
166  catch (const std::exception &e)
167  {
168  MITK_ERROR << e.what();
169  }
170  catch (...)
171  {
172  MITK_ERROR << "Ungetting core service failed.";
173  }
174  }
175 
176  S *operator->() const
177  {
178  return m_Service;
179  }
180 
181  private:
182  S *const m_Service;
183  us::ModuleContext* m_Context;
184  };
185 }
186 
187 #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
MITK_ERROR
#define MITK_ERROR
Definition: mitkLogMacros.h:20
mitkServiceInterface.h
mitk::CoreServicePointer::~CoreServicePointer
~CoreServicePointer()
Definition: mitkCoreServices.h:160
mitk::CoreServicePointer::CoreServicePointer
CoreServicePointer(S *service, us::ModuleContext *context=us::GetModuleContext())
Definition: mitkCoreServices.h:153
mitk::CoreServicePointer
A RAII helper class for core service objects.
Definition: mitkCoreServices.h:150
us::GetModuleContext
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
Definition: usGetModuleContext.h:50
mitkLogMacros.h
mitk
DataCollection - Class to facilitate loading/accessing structured data.
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:125
mitkCommon.h
mitk::CoreServices
Access MITK core services.
Definition: mitkCoreServices.h:57
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:176