diff --git a/Modules/Segmentation/Controllers/mitkToolManagerProvider.cpp b/Modules/Segmentation/Controllers/mitkToolManagerProvider.cpp index f874bf9d72..92770a491f 100644 --- a/Modules/Segmentation/Controllers/mitkToolManagerProvider.cpp +++ b/Modules/Segmentation/Controllers/mitkToolManagerProvider.cpp @@ -1,39 +1,67 @@ /*=================================================================== 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. ===================================================================*/ #include "mitkToolManagerProvider.h" +//micro service includes +#include +#include -mitk::ToolManagerProvider::ToolManagerProvider() + +mitk::ToolManagerProvider::ToolManagerProvider(): + m_ToolManager(mitk::ToolManager::New(NULL)) { - this->m_ToolManager = mitk::ToolManager::New(NULL); } + mitk::ToolManagerProvider::~ToolManagerProvider() { this->m_ToolManager = NULL; } + mitk::ToolManager* mitk::ToolManagerProvider::GetToolManager() { return this->m_ToolManager; } + mitk::ToolManagerProvider* mitk::ToolManagerProvider::GetInstance() { - return NULL; + static ServiceReference serviceRef; + static ModuleContext* context = mitk::GetModuleContext(); + if (!serviceRef) + { + // This is either the first time GetInstance() was called, + // or a SingletonOneService instance has not yet been registered. + serviceRef = context->GetServiceReference(); + } + if (serviceRef) + { + // We have a valid service reference. It always points to the service + // with the lowest id (usually the one which was registered first). + // This still might return a null pointer, if all SingletonOneService + // instances have been unregistered (during unloading of the library, + // for example). + return context->GetService(serviceRef); + } + else + { + // No SingletonOneService instance was registered yet. + return 0; + } } diff --git a/Modules/Segmentation/Controllers/mitkToolManagerProvider.h b/Modules/Segmentation/Controllers/mitkToolManagerProvider.h index d1fa5ff83d..1e95417212 100644 --- a/Modules/Segmentation/Controllers/mitkToolManagerProvider.h +++ b/Modules/Segmentation/Controllers/mitkToolManagerProvider.h @@ -1,57 +1,61 @@ /*=================================================================== 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 MITK_TOOLMANAGERPROVIDER_H #define MITK_TOOLMANAGERPROVIDER_H +#include "SegmentationExports.h" + #include #include #include "mitkToolManager.h" #include #include //class SegmentationModuleActivator; namespace mitk { - class ToolManagerProvider : public itk::LightObject + class Segmentation_EXPORT ToolManagerProvider : public itk::LightObject { public: mitkClassMacro(ToolManagerProvider, itk::LightObject); itkNewMacro(ToolManagerProvider); virtual mitk::ToolManager* GetToolManager(); static mitk::ToolManagerProvider* GetInstance(); //friend class SegmentationModuleActivator; protected: //mitkClassMacro(ToolManagerProvider, itk::LightObject); //itkNewMacro(Self); ToolManagerProvider(); virtual ~ToolManagerProvider(); + ToolManagerProvider(const ToolManagerProvider&); + ToolManagerProvider& operator=(const ToolManagerProvider&); mitk::ToolManager::Pointer m_ToolManager; }; } US_DECLARE_SERVICE_INTERFACE(mitk::ToolManagerProvider, "org.mitk.services.ToolManagerProvider") #endif diff --git a/Modules/Segmentation/Testing/files.cmake b/Modules/Segmentation/Testing/files.cmake index 7bbba33b35..48b0901ced 100644 --- a/Modules/Segmentation/Testing/files.cmake +++ b/Modules/Segmentation/Testing/files.cmake @@ -1,39 +1,39 @@ set(MODULE_TESTS mitkContourMapper2DTest.cpp mitkContourTest.cpp mitkDataNodeSegmentationTest.cpp # mitkSegmentationInterpolationTest.cpp mitkOverwriteSliceFilterTest.cpp # mitkOverwriteSliceFilterObliquePlaneTest.cpp mitkContourModelTest.cpp mitkContourModelIOTest.cpp # mitkToolManagerTest.cpp mitkToolManagerProviderTest.cpp ) set(MODULE_IMAGE_TESTS mitkManualSegmentationToSurfaceFilterTest.cpp #only runs on images mitkOverwriteSliceImageFilterTest.cpp #only runs on images ) set(MODULE_CUSTOM_TESTS ) set(MODULE_TESTIMAGES US4DCyl.nrrd Pic3D.nrrd Pic2DplusT.nrrd BallBinary30x30x30.nrrd Png2D-bw.png ) # Create an artificial module initializing class for # usServices -set(testdriver_resources ) +set(testdriver_init_file ) usFunctionGenerateModuleInit(testdriver_init_file - NAME ${MODULE_NAME}TestDriver + NAME SegmentationTestDriver DEPENDS "Segmentation" VERSION "0.1.0" EXECUTABLE ) set(TEST_CPP_FILES ${testdriver_init_file}) diff --git a/Modules/Segmentation/Testing/mitkToolManagerProviderTest.cpp b/Modules/Segmentation/Testing/mitkToolManagerProviderTest.cpp index b0afcb8f57..9b85d3aea5 100644 --- a/Modules/Segmentation/Testing/mitkToolManagerProviderTest.cpp +++ b/Modules/Segmentation/Testing/mitkToolManagerProviderTest.cpp @@ -1,46 +1,49 @@ /*=================================================================== 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. ===================================================================*/ #include "mitkTestingMacros.h" #include "mitkToolManagerProvider.h" #include "itkLightObject.h" #include #include "mitkModuleContext.h" #include "mitkServiceReference.h" +#include "mitkGlobalInteraction.h" class mitkToolManagerProviderTestClass { public: static void RegisterService(){ mitk::GetModuleContext()->RegisterService(mitk::ToolManagerProvider::New().GetPointer()); } }; int mitkToolManagerProviderTest(int, char* []) { MITK_TEST_BEGIN("ToolManagerProvider") + mitk::GlobalInteraction::GetInstance()->Initialize("global"); + mitkToolManagerProviderTestClass::RegisterService(); - mitk::ServiceReference serviceRef = mitk::GetModuleContext()->GetServiceReference< mitk::ToolManagerProvider >(); - mitk::ToolManagerProvider* service = mitk::GetModuleContext()->GetService< mitk::ToolManagerProvider >(serviceRef); + + mitk::ToolManagerProvider* service = mitk::ToolManagerProvider::GetInstance(); MITK_TEST_CONDITION(service!=NULL,"Service was succesfully called"); - MITK_TEST_CONDITION((service->GetToolManager()) == NULL, "Dummy call"); + MITK_TEST_CONDITION((service->GetToolManager()) == (service->GetToolManager()), "Service singleton"); MITK_TEST_END() }