Medical Imaging Interaction Toolkit  2018.4.99-c7ee88da
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 
57  {
58  public:
59 
65  static IPropertyAliases *GetPropertyAliases(us::ModuleContext *context = us::GetModuleContext());
66 
72  static IPropertyDescriptions *GetPropertyDescriptions(us::ModuleContext *context = us::GetModuleContext());
73 
79  static IPropertyExtensions *GetPropertyExtensions(us::ModuleContext *context = us::GetModuleContext());
80 
86  static IPropertyFilters *GetPropertyFilters(us::ModuleContext *context = us::GetModuleContext());
87 
93  static IPropertyPersistence *GetPropertyPersistence(us::ModuleContext *context = us::GetModuleContext());
94 
100  static IPropertyRelations *GetPropertyRelations(us::ModuleContext *context = us::GetModuleContext());
101 
107  static IMimeTypeProvider *GetMimeTypeProvider(us::ModuleContext *context = us::GetModuleContext());
108 
114  template <class S>
115  static bool Unget(S *service, us::ModuleContext *context = us::GetModuleContext())
116  {
117  return Unget(context, us_service_interface_iid<S>(), service);
118  }
119 
120  private:
121  static bool Unget(us::ModuleContext *context, const std::string &interfaceId, void *service);
122 
123  // purposely not implemented
124  CoreServices();
125  CoreServices(const CoreServices &);
126  CoreServices &operator=(const CoreServices &);
127  };
128 
139  template <class S>
141  {
142  public:
143  explicit CoreServicePointer(S *service, us::ModuleContext* context = us::GetModuleContext())
144  : m_Service(service),
145  m_Context(context)
146  {
147  assert(service);
148  }
149 
151  {
152  try
153  {
154  CoreServices::Unget(m_Service, m_Context);
155  }
156  catch (const std::exception &e)
157  {
158  MITK_ERROR << e.what();
159  }
160  catch (...)
161  {
162  MITK_ERROR << "Ungetting core service failed.";
163  }
164  }
165 
166  S *operator->() const
167  {
168  return m_Service;
169  }
170 
171  private:
172  S *const m_Service;
173  us::ModuleContext* m_Context;
174  };
175 }
176 
177 #endif // MITKCORESERVICES_H
Interface of property relations service.
Interface of property aliases service.
#define MITKCORE_EXPORT
#define MITK_ERROR
Definition: mitkLogMacros.h:20
Access MITK core services.
DataCollection - Class to facilitate loading/accessing structured data.
Interface of property extensions service.
Interface of property descriptions service.
#define MITK_LOCAL
Definition: mitkCommon.h:197
The IMimeTypeProvider service interface allows to query all registered mime types.
mitk::PlanePositionManagerService * m_Service
Interface of property persistence service.
A RAII helper class for core service objects.
Interface of property filters service.
CoreServicePointer(S *service, us::ModuleContext *context=us::GetModuleContext())
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
static bool Unget(S *service, us::ModuleContext *context=us::GetModuleContext())
Unget a previously acquired service instance.