Medical Imaging Interaction Toolkit  2018.04.99-def61b42
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 
115  template <class S>
116  static bool Unget(S *service, us::ModuleContext *context = us::GetModuleContext())
117  {
118  return Unget(context, us_service_interface_iid<S>(), service);
119  }
120 
121  private:
122  static bool Unget(us::ModuleContext *context, const std::string &interfaceId, void *service);
123 
124  // purposely not implemented
125  CoreServices();
126  CoreServices(const CoreServices &);
127  CoreServices &operator=(const CoreServices &);
128  };
129 
140  template <class S>
142  {
143  public:
144  explicit CoreServicePointer(S *service, us::ModuleContext* context = us::GetModuleContext())
145  : m_Service(service),
146  m_Context(context)
147  {
148  assert(service);
149  }
150 
152  {
153  try
154  {
155  CoreServices::Unget(m_Service, m_Context);
156  }
157  catch (const std::exception &e)
158  {
159  MITK_ERROR << e.what();
160  }
161  catch (...)
162  {
163  MITK_ERROR << "Ungetting core service failed.";
164  }
165  }
166 
167  S *operator->() const
168  {
169  return m_Service;
170  }
171 
172  private:
173  S *const m_Service;
174  us::ModuleContext* m_Context;
175  };
176 }
177 
178 #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.
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.