Medical Imaging Interaction Toolkit  2024.12.99-0da743f6
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 INodeSelectionService;
32  class IPropertyAliases;
33  class IPropertyDescriptions;
34  class IPropertyDeserialization;
35  class IPropertyExtensions;
36  class IPropertyFilters;
37  class IPropertyPersistence;
38  class IPropertyRelations;
39  class IPreferencesService;
40 
60  {
61  public:
62 
68  static INodeSelectionService* GetNodeSelectionService(us::ModuleContext* context = us::GetModuleContext());
69 
75  static IPropertyAliases *GetPropertyAliases(us::ModuleContext *context = us::GetModuleContext());
76 
82  static IPropertyDescriptions *GetPropertyDescriptions(us::ModuleContext *context = us::GetModuleContext());
83 
89  static IPropertyDeserialization* GetPropertyDeserialization(us::ModuleContext* context = us::GetModuleContext());
90 
96  static IPropertyExtensions *GetPropertyExtensions(us::ModuleContext *context = us::GetModuleContext());
97 
103  static IPropertyFilters *GetPropertyFilters(us::ModuleContext *context = us::GetModuleContext());
104 
110  static IPropertyPersistence *GetPropertyPersistence(us::ModuleContext *context = us::GetModuleContext());
111 
117  static IPropertyRelations *GetPropertyRelations(us::ModuleContext *context = us::GetModuleContext());
118 
124  static IMimeTypeProvider *GetMimeTypeProvider(us::ModuleContext *context = us::GetModuleContext());
125 
132  static IPreferencesService *GetPreferencesService(us::ModuleContext *context = us::GetModuleContext());
133 
140  template <class S>
141  static bool Unget(S *service, us::ModuleContext *context = us::GetModuleContext())
142  {
143  return Unget(context, us_service_interface_iid<S>(), service);
144  }
145 
146  private:
147  static bool Unget(us::ModuleContext *context, const std::string &interfaceId, void *service);
148 
149  // purposely not implemented
150  CoreServices();
151  CoreServices(const CoreServices &);
152  CoreServices &operator=(const CoreServices &);
153  };
154 
165  template <class S>
167  {
168  public:
169  explicit CoreServicePointer(S *service, us::ModuleContext* context = us::GetModuleContext())
170  : m_Service(service),
171  m_Context(context)
172  {
173  assert(service);
174  }
175 
177  {
178  try
179  {
180  CoreServices::Unget(m_Service, m_Context);
181  }
182  catch (const std::exception &e)
183  {
184  MITK_ERROR << e.what();
185  }
186  catch (...)
187  {
188  MITK_ERROR << "Ungetting core service failed.";
189  }
190  }
191 
192  S *operator->() const
193  {
194  return m_Service;
195  }
196 
197  private:
198  S *const m_Service;
199  us::ModuleContext* m_Context;
200  };
201 }
202 
203 #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:176
mitk::CoreServicePointer::CoreServicePointer
CoreServicePointer(S *service, us::ModuleContext *context=us::GetModuleContext())
Definition: mitkCoreServices.h:169
MITK_ERROR
#define MITK_ERROR
Definition: mitkLog.h:211
mitk::CoreServicePointer
A RAII helper class for core service objects.
Definition: mitkCoreServices.h:166
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:141
mitkCommon.h
mitkLog.h
mitk::INodeSelectionService
A simple messaging service for sending and receiving data node selections for certain contexts.
Definition: mitkINodeSelectionService.h:31
mitk::CoreServices
Access MITK core services.
Definition: mitkCoreServices.h:59
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:192