Medical Imaging Interaction Toolkit  2025.12.02
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 
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
#define MITKCORE_EXPORT
A RAII helper class for core service objects.
CoreServicePointer(S *service, us::ModuleContext *context=us::GetModuleContext())
Access MITK core services.
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 bool Unget(S *service, us::ModuleContext *context=us::GetModuleContext())
Unget a previously acquired service instance.
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.
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
#define MITK_LOCAL
Definition: mitkCommon.h:193
#define MITK_ERROR
Definition: mitkLog.h:211
Find image slices visible on a given plane.
The IMimeTypeProvider service interface allows to query all registered mime types.