diff --git a/Modules/Persistence/mitkPersistenceActivator.cpp b/Modules/Persistence/mitkPersistenceActivator.cpp index 4de9e8acaf..c08e597e27 100644 --- a/Modules/Persistence/mitkPersistenceActivator.cpp +++ b/Modules/Persistence/mitkPersistenceActivator.cpp @@ -1,93 +1,70 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ -#ifndef mitkPersistenceActivator_h -#define mitkPersistenceActivator_h - -// Microservices -#include -#include "mitkPersistenceService.h" -#include - -namespace mitk -{ - /// - /// installs the PersistenceService - /// runs all initial commands (setting env paths etc) - /// - class PersistenceActivator : public us::ModuleActivator + +#include "mitkPersistenceActivator.h" + + mitk::PersistenceActivator::PersistenceActivator() + { + } + + void mitk::PersistenceActivator::Load(us::ModuleContext* context) + { + MITK_DEBUG << "PersistenceActivator::Load"; + + mitk::IPersistenceService* persistenceService = 0; + us::ServiceReference persistenceServiceRef + = context->GetServiceReference(); + if( persistenceServiceRef ) + { + persistenceService = dynamic_cast ( context->GetService(persistenceServiceRef) ); + } + + bool instanceAlreadyAdded = persistenceService != 0; + if( instanceAlreadyAdded ) + instanceAlreadyAdded = dynamic_cast(persistenceService) != 0; + + if( instanceAlreadyAdded == false ) + { + // Registering PersistenceService as MicroService + m_PersistenceService = itk::SmartPointer(new PersistenceService()); + us::ServiceProperties _PersistenceServiceProps; + _PersistenceServiceProps["Name"] = std::string("PersistenceService"); + + m_PersistenceServiceRegistration = context->RegisterService(m_PersistenceService, _PersistenceServiceProps); + } + else + { + MITK_ERROR << "Another Persistence instance already installed. Library was loaded twice. Please check configuration!"; + } + + } + + void mitk::PersistenceActivator::Unload(us::ModuleContext* context) + { + if( m_PersistenceService.IsNull() ) + return; + + MITK_DEBUG("PersistenceActivator") << "PersistenceActivator::Unload"; + MITK_DEBUG("PersistenceActivator") << "m_PersistenceService GetReferenceCount " << m_PersistenceService->GetReferenceCount(); + + m_PersistenceServiceRegistration.Unregister(); + m_PersistenceService->Unitialize(); + m_PersistenceService->Delete(); + } + + mitk::PersistenceActivator::~PersistenceActivator() { - public: - PersistenceActivator() - { - } - - void Load(us::ModuleContext* context) - { - MITK_DEBUG << "PersistenceActivator::Load"; - - mitk::IPersistenceService* persistenceService = 0; - us::ServiceReference persistenceServiceRef - = context->GetServiceReference(); - if( persistenceServiceRef ) - { - persistenceService = dynamic_cast ( context->GetService(persistenceServiceRef) ); - } - - bool instanceAlreadyAdded = persistenceService != 0; - if( instanceAlreadyAdded ) - instanceAlreadyAdded = dynamic_cast(persistenceService) != 0; - - if( instanceAlreadyAdded == false ) - { - // Registering PersistenceService as MicroService - m_PersistenceService = itk::SmartPointer(new PersistenceService()); - us::ServiceProperties _PersistenceServiceProps; - _PersistenceServiceProps["Name"] = std::string("PersistenceService"); - - m_PersistenceServiceRegistration = context->RegisterService(m_PersistenceService, _PersistenceServiceProps); - - } - else - { - MITK_ERROR << "Another Persistence instance already installed. Library was loaded twice. Please check configuration!"; - } - } - - void Unload(us::ModuleContext* context) - { - if( m_PersistenceService.IsNull() ) - return; - - MITK_DEBUG("PersistenceActivator") << "PersistenceActivator::Unload"; - MITK_DEBUG("PersistenceActivator") << "m_PersistenceService GetReferenceCount " << m_PersistenceService->GetReferenceCount(); - - m_PersistenceServiceRegistration.Unregister(); - m_PersistenceService->Unitialize(); - m_PersistenceService->Delete(); - } - - virtual ~PersistenceActivator() - { - } - - private: - itk::SmartPointer m_PersistenceService; - us::ServiceRegistration m_PersistenceServiceRegistration; - }; -} - -US_EXPORT_MODULE_ACTIVATOR(MitkPersistence, mitk::PersistenceActivator) -#endif + } diff --git a/Modules/Persistence/mitkPersistenceActivator.h b/Modules/Persistence/mitkPersistenceActivator.h new file mode 100644 index 0000000000..775c5227c7 --- /dev/null +++ b/Modules/Persistence/mitkPersistenceActivator.h @@ -0,0 +1,47 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ +#ifndef mitkPersistenceActivator_h +#define mitkPersistenceActivator_h + +#define MBILOG_ENABLE_DEBUG + +// Microservices +#include +#include "mitkPersistenceService.h" +#include + +namespace mitk +{ + /// + /// installs the PersistenceService + /// runs all initial commands (setting env paths etc) + /// + class PersistenceActivator : public us::ModuleActivator + { + public: + PersistenceActivator(); + void Load(us::ModuleContext* context); + void Unload(us::ModuleContext* context); + virtual ~PersistenceActivator(); + + private: + itk::SmartPointer m_PersistenceService; + us::ServiceRegistration m_PersistenceServiceRegistration; + }; +} + +US_EXPORT_MODULE_ACTIVATOR(MitkPersistence, mitk::PersistenceActivator) +#endif