Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkPythonActivator.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 (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 #ifndef mitkPythonActivator_h
13 #define mitkPythonActivator_h
14 
15 // Microservices
16 #include <usModuleActivator.h>
17 #include "usModuleContext.h"
18 #include "mitkPythonService.h"
19 #include <usServiceRegistration.h>
20 
21 namespace mitk
22 {
27  class PythonActivator : public us::ModuleActivator
28  {
29  public:
30 
31  void Load(us::ModuleContext* context) override
32  {
33  MITK_DEBUG << "PythonActivator::Load";
34  // Registering PythonService as MicroService
35  m_PythonService = itk::SmartPointer<mitk::PythonService>(new PythonService());
36 
37  us::ServiceProperties _PythonServiceProps;
38  _PythonServiceProps["Name"] = std::string("PythonService");
39 
40  m_PythonServiceRegistration = context->RegisterService<mitk::IPythonService>(m_PythonService.GetPointer(), _PythonServiceProps);
41  }
42 
43  void Unload(us::ModuleContext*) override
44  {
45  MITK_DEBUG("PythonActivator") << "PythonActivator::Unload";
46  MITK_DEBUG("PythonActivator") << "m_PythonService GetReferenceCount " << m_PythonService->GetReferenceCount();
47  m_PythonServiceRegistration.Unregister();
48  m_PythonService->Delete();
49  MITK_DEBUG("PythonActivator") << "m_PythonService GetReferenceCount " << m_PythonService->GetReferenceCount();
50  }
51 
52  ~PythonActivator() override
53  {
54  }
55 
56  private:
58  us::ServiceRegistration<PythonService> m_PythonServiceRegistration;
59  };
60 }
61 
62 US_EXPORT_MODULE_ACTIVATOR(mitk::PythonActivator)
63 #endif
#define MITK_DEBUG
Definition: mitkLogMacros.h:22
DataCollection - Class to facilitate loading/accessing structured data.
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
#define US_EXPORT_MODULE_ACTIVATOR(_activator_type)
Export a module activator class.