Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkPersistenceActivator.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
20 {
21 }
22 
23 void mitk::PersistenceActivator::Load(us::ModuleContext *context)
24 {
25  MITK_DEBUG << "PersistenceActivator::Load";
26 
27  mitk::IPersistenceService *persistenceService = 0;
29  context->GetServiceReference<mitk::IPersistenceService>();
30  if (persistenceServiceRef)
31  {
32  persistenceService =
33  dynamic_cast<mitk::IPersistenceService *>(context->GetService<mitk::IPersistenceService>(persistenceServiceRef));
34  }
35 
36  bool instanceAlreadyAdded = persistenceService != 0;
37  if (instanceAlreadyAdded)
38  instanceAlreadyAdded = dynamic_cast<mitk::PersistenceService *>(persistenceService) != 0;
39 
40  if (instanceAlreadyAdded == false)
41  {
42  // Registering PersistenceService as MicroService
44  us::ServiceProperties _PersistenceServiceProps;
45  _PersistenceServiceProps["Name"] = std::string("PersistenceService");
46 
47  m_PersistenceServiceRegistration =
48  context->RegisterService<mitk::IPersistenceService>(m_PersistenceService, _PersistenceServiceProps);
49  }
50  else
51  {
53  << "Another Persistence instance already installed. Library was loaded twice. Please check configuration!";
54  }
55 }
56 
57 void mitk::PersistenceActivator::Unload(us::ModuleContext *context)
58 {
59  if (m_PersistenceService.IsNull())
60  return;
61 
62  MITK_DEBUG("PersistenceActivator") << "PersistenceActivator::Unload";
63  MITK_DEBUG("PersistenceActivator") << "m_PersistenceService GetReferenceCount "
64  << m_PersistenceService->GetReferenceCount();
65 
66  m_PersistenceServiceRegistration.Unregister();
67  m_PersistenceService->Unitialize();
68  m_PersistenceService->Delete();
69 }
70 
72 {
73 }
#define MITK_ERROR
Definition: mitkLogMacros.h:24
#define MITK_DEBUG
Definition: mitkLogMacros.h:26
void Load(us::ModuleContext *context) override
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
void Unload(us::ModuleContext *context) override