Medical Imaging Interaction Toolkit  2026.06.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 IDataStorageService;
32  class INodeSelectionService;
33  class IPropertyAliases;
34  class IPropertyDescriptions;
35  class IPropertyDeserialization;
36  class IPropertyExtensions;
37  class IPropertyFilters;
38  class IPropertyPersistence;
39  class IPropertyRelations;
40  class IPropertyTransience;
41  class IPreferencesService;
42 
60  {
61  public:
62 
71 
78 
85 
92 
99 
106 
113 
120 
127 
134 
141 
149 
158  template <class S>
159  static bool Unget(S *service, us::ModuleContext *context = us::GetModuleContext())
160  {
161  return Unget(context, us_service_interface_iid<S>(), service);
162  }
163 
164  private:
165  static bool Unget(us::ModuleContext *context, const std::string &interfaceId, void *service);
166 
167  // purposely not implemented
168  CoreServices();
169  CoreServices(const CoreServices &);
170  CoreServices &operator=(const CoreServices &);
171  };
172 
195  template <class S>
197  {
198  public:
204  explicit CoreServicePointer(S *service, us::ModuleContext* context = us::GetModuleContext())
205  : m_Service(service),
206  m_Context(context)
207  {
208  }
209 
214  {
215  if (m_Service != nullptr)
216  {
217  try
218  {
219  CoreServices::Unget(m_Service, m_Context);
220  }
221  catch (const std::exception &e)
222  {
223  MITK_ERROR << e.what();
224  }
225  catch (...)
226  {
227  MITK_ERROR << "Ungetting core service failed.";
228  }
229  }
230  }
231 
236  explicit operator bool() const
237  {
238  return m_Service != nullptr;
239  }
240 
246  S *operator->() const
247  {
248  return m_Service;
249  }
250 
255  S *Get() const
256  {
257  return m_Service;
258  }
259 
260  // Non-copyable
263 
264  private:
265  S *const m_Service;
266  us::ModuleContext* m_Context;
267  };
268 }
269 
270 #endif
#define MITKCORE_EXPORT
RAII wrapper for core service objects.
~CoreServicePointer()
Destructor. Releases the managed service via CoreServices::Unget().
S * operator->() const
Dereference the managed service pointer.
CoreServicePointer & operator=(const CoreServicePointer &)=delete
CoreServicePointer(const CoreServicePointer &)=delete
S * Get() const
Get the raw service pointer.
CoreServicePointer(S *service, us::ModuleContext *context=us::GetModuleContext())
Construct a RAII wrapper around a service pointer.
Provides convenient static access to common MITK core service objects.
static IPropertyTransience * GetPropertyTransience(us::ModuleContext *context=us::GetModuleContext())
Get an IPropertyTransience instance.
static IPropertyPersistence * GetPropertyPersistence(us::ModuleContext *context=us::GetModuleContext())
Get an IPropertyPersistence instance.
static IPropertyDescriptions * GetPropertyDescriptions(us::ModuleContext *context=us::GetModuleContext())
Get an IPropertyDescriptions instance.
static IMimeTypeProvider * GetMimeTypeProvider(us::ModuleContext *context=us::GetModuleContext())
Get an IMimeTypeProvider instance.
static IPropertyRelations * GetPropertyRelations(us::ModuleContext *context=us::GetModuleContext())
Get an IPropertyRelations instance.
static IPropertyExtensions * GetPropertyExtensions(us::ModuleContext *context=us::GetModuleContext())
Get an IPropertyExtensions instance.
static IPreferencesService * GetPreferencesService(us::ModuleContext *context=us::GetModuleContext())
Get an IPreferencesService instance.
static INodeSelectionService * GetNodeSelectionService(us::ModuleContext *context=us::GetModuleContext())
Get an INodeSelectionsService instance.
static IPropertyDeserialization * GetPropertyDeserialization(us::ModuleContext *context=us::GetModuleContext())
Get an IPropertyDeserialization instance.
static IPropertyAliases * GetPropertyAliases(us::ModuleContext *context=us::GetModuleContext())
Get an IPropertyAliases instance.
static IPropertyFilters * GetPropertyFilters(us::ModuleContext *context=us::GetModuleContext())
Get an IPropertyFilters instance.
static IDataStorageService * GetDataStorageService(us::ModuleContext *context=us::GetModuleContext())
Get an IDataStorageService instance.
static bool Unget(S *service, us::ModuleContext *context=us::GetModuleContext())
Release a previously acquired service instance.
Service interface for managing DataStorage instances.
A simple messaging service for sending and receiving data node selections for certain contexts.
A service for persistent application preferences.
Interface of property aliases service.
Interface of property descriptions service.
Interface of property deserialization service.
Interface of property extensions service.
Interface of property filters service.
Interface of property persistence service.
Interface of property relations service.
Interface of the property transience service.
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
#define MITK_LOCAL
Definition: mitkCommon.h:224
#define MITK_ERROR
Log an error message.
Definition: mitkLog.h:372
Provides the MITK_DECLARE_SERVICE_INTERFACE macro for registering C++ interfaces with both the CppMic...
Find image slices visible on a given plane.
Service interface for querying all registered mime-types.