diff --git a/Core/Code/DataManagement/mitkCommon.h b/Core/Code/DataManagement/mitkCommon.h index b5063273e7..dfb6154379 100644 --- a/Core/Code/DataManagement/mitkCommon.h +++ b/Core/Code/DataManagement/mitkCommon.h @@ -1,124 +1,109 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITK_COMMON_H_DEFINED #define MITK_COMMON_H_DEFINED #ifdef _MSC_VER // This warns about truncation to 255 characters in debug/browse info #pragma warning (disable : 4786) #pragma warning (disable : 4068 ) /* disable unknown pragma warnings */ #endif //add only those headers here that are really necessary for all classes! #include "itkObject.h" #include "mitkConfig.h" #include "mitkLogMacros.h" #include "mitkExportMacros.h" #ifndef MITK_UNMANGLE_IPPIC #define mitkIpPicDescriptor mitkIpPicDescriptor #endif typedef unsigned int MapperSlotId; #define mitkClassMacro(className,SuperClassName) \ typedef className Self; \ typedef SuperClassName Superclass; \ typedef itk::SmartPointer Pointer; \ typedef itk::SmartPointer ConstPointer; \ itkTypeMacro(className,SuperClassName) /** * Macro for Constructors with one parameter for classes derived from itk::Lightobject **/ #define mitkNewMacro1Param(classname,type) \ static Pointer New(type _arg) \ { \ Pointer smartPtr = new classname ( _arg ); \ smartPtr->UnRegister(); \ return smartPtr; \ } \ /** * Macro for Constructors with two parameters for classes derived from itk::Lightobject **/ #define mitkNewMacro2Param(classname,typea,typeb) \ static Pointer New(typea _arga, typeb _argb) \ { \ Pointer smartPtr = new classname ( _arga, _argb ); \ smartPtr->UnRegister(); \ return smartPtr; \ } \ /** * Macro for Constructors with three parameters for classes derived from itk::Lightobject **/ #define mitkNewMacro3Param(classname,typea,typeb,typec) \ static Pointer New(typea _arga, typeb _argb, typec _argc) \ { \ Pointer smartPtr = new classname ( _arga, _argb, _argc ); \ smartPtr->UnRegister(); \ return smartPtr; \ } \ /** * Macro for Constructors with three parameters for classes derived from itk::Lightobject **/ #define mitkNewMacro4Param(classname,typea,typeb,typec,typed) \ static Pointer New(typea _arga, typeb _argb, typec _argc, typed _argd) \ { \ Pointer smartPtr = new classname ( _arga, _argb, _argc, _argd ); \ smartPtr->UnRegister(); \ return smartPtr; \ } \ /** Get a smart const pointer to an object. Creates the member * Get"name"() (e.g., GetPoints()). */ #define mitkGetObjectMacroConst(name,type) \ virtual type * Get##name () const \ { \ itkDebugMacro("returning " #name " address " << this->m_##name ); \ return this->m_##name.GetPointer(); \ } /** Creates a Clone() method for "Classname". Returns a smartPtr of a clone of the calling object*/ #define mitkCloneMacro(classname) \ virtual Pointer Clone() const \ { \ Pointer smartPtr = new classname(*this); \ return smartPtr; \ } -#define MITK_EXPORT_MODULE_ACTIVATOR(moduleName, type) \ - extern "C" MITK_EXPORT mitk::ModuleActivator* _mitk_module_activator_instance_ ## moduleName () \ - { \ - struct ScopedPointer \ - { \ - ScopedPointer(mitk::ModuleActivator* activator = 0) : m_Activator(activator) {} \ - ~ScopedPointer() { delete m_Activator; } \ - mitk::ModuleActivator* m_Activator; \ - }; \ - \ - static ScopedPointer activatorPtr; \ - if (activatorPtr.m_Activator == 0) activatorPtr.m_Activator = new type; \ - return activatorPtr.m_Activator; \ - } - #endif // MITK_COMMON_H_DEFINED diff --git a/Core/Code/Service/mitkModuleActivator.h b/Core/Code/Service/mitkModuleActivator.h index 589ffb50c8..6a1727e4e4 100644 --- a/Core/Code/Service/mitkModuleActivator.h +++ b/Core/Code/Service/mitkModuleActivator.h @@ -1,95 +1,110 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKMODULEACTIVATOR_H_ #define MITKMODULEACTIVATOR_H_ namespace mitk { class ModuleContext; /** * \ingroup MicroServices * * Customizes the starting and stopping of a MITK module. *

* %ModuleActivator is an interface that can be implemented by * MITK modules. The MITK core can create instances of a * module's %ModuleActivator as required. If an instance's * moduleActivator::Load method executes successfully, it is * guaranteed that the same instance's %ModuleActivator::Unload * method will be called when the module is to be unloaded. The MITK core does * not concurrently call a %ModuleActivator object. * *

* %ModuleActivator is an abstract class interface whose implementations * must be exported via a special macro. Implementations are usually declared * and defined directly in .cpp files. * *

* \snippet uServices-activator/main.cpp 0 * *

* The class implementing the %ModuleActivator interface must have a public * default constructor so that a %ModuleActivator * object can be created by the MITK core. * */ struct ModuleActivator { public: virtual ~ModuleActivator() {} /** * Called when this module is loaded. This method * can be used to register services or to allocate any resources that this * module may need globally (during the whole module lifetime). * *

* This method must complete and return to its caller in a timely manner. * * @param context The execution context of the module being loaded. * @throws std::exception If this method throws an exception, this * module is marked as stopped and the framework will remove this * module's listeners, unregister all services registered by this * module, and release all services used by this module. */ virtual void Load(ModuleContext* context) = 0; /** * Called when this module is unloaded. In general, this * method should undo the work that the ModuleActivator::Load * method started. There should be no active threads that were started by * this module when this method returns. * *

* This method must complete and return to its caller in a timely manner. * * @param context The execution context of the module being unloaded. * @throws std::exception If this method throws an exception, the * module is still marked as unloaded, and the framework will remove * the module's listeners, unregister all services registered by the * module, and release all services used by the module. */ virtual void Unload(ModuleContext* context) = 0; }; } // end namespace mitk +#define MITK_EXPORT_MODULE_ACTIVATOR(moduleName, type) \ + extern "C" MITK_EXPORT mitk::ModuleActivator* _mitk_module_activator_instance_ ## moduleName () \ + { \ + struct ScopedPointer \ + { \ + ScopedPointer(mitk::ModuleActivator* activator = 0) : m_Activator(activator) {} \ + ~ScopedPointer() { delete m_Activator; } \ + mitk::ModuleActivator* m_Activator; \ + }; \ + \ + static ScopedPointer activatorPtr; \ + if (activatorPtr.m_Activator == 0) activatorPtr.m_Activator = new type; \ + return activatorPtr.m_Activator; \ + } + #endif /* MITKMODULEACTIVATOR_H_ */ diff --git a/Core/Code/Service/mitkServiceTrackerCustomizer.h b/Core/Code/Service/mitkServiceTrackerCustomizer.h index 8d055dc0db..7c2fb043d7 100644 --- a/Core/Code/Service/mitkServiceTrackerCustomizer.h +++ b/Core/Code/Service/mitkServiceTrackerCustomizer.h @@ -1,109 +1,111 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKSERVICETRACKERCUSTOMIZER_H #define MITKSERVICETRACKERCUSTOMIZER_H #include "mitkServiceReference.h" +namespace itk { class LightObject; } + namespace mitk { /** * \ingroup MicroServices * * The ServiceTrackerCustomizer interface allows a * ServiceTracker to customize the service objects that are * tracked. A ServiceTrackerCustomizer is called when a service is * being added to a ServiceTracker. The * ServiceTrackerCustomizer can then return an object for the * tracked service. A ServiceTrackerCustomizer is also called when * a tracked service is modified or has been removed from a * ServiceTracker. * *

* The methods in this interface may be called as the result of a * ServiceEvent being received by a ServiceTracker. * Since ServiceEvents are synchronously delivered, * it is highly recommended that implementations of these methods do * not register (ModuleContext::RegisterService), modify ( * ServiceRegistration::SetProperties) or unregister ( * ServiceRegistration::Unregister) a service while being * synchronized on any object. * *

* The ServiceTracker class is thread-safe. It does not call a * ServiceTrackerCustomizer while holding any locks. * ServiceTrackerCustomizer implementations must also be * thread-safe. * * \tparam T The type of the tracked object. * \remarks This class is thread safe. */ template struct ServiceTrackerCustomizer { virtual ~ServiceTrackerCustomizer() {} /** * A service is being added to the ServiceTracker. * *

* This method is called before a service which matched the search * parameters of the ServiceTracker is added to the * ServiceTracker. This method should return the service object * to be tracked for the specified ServiceReference. The * returned service object is stored in the ServiceTracker and * is available from the GetService and * GetServices methods. * * @param reference The reference to the service being added to the * ServiceTracker. * @return The service object to be tracked for the specified referenced * service or 0 if the specified referenced service * should not be tracked. */ virtual T AddingService(const ServiceReference& reference) = 0; /** * A service tracked by the ServiceTracker has been modified. * *

* This method is called when a service being tracked by the * ServiceTracker has had it properties modified. * * @param reference The reference to the service that has been modified. * @param service The service object for the specified referenced service. */ virtual void ModifiedService(const ServiceReference& reference, T service) = 0; /** * A service tracked by the ServiceTracker has been removed. * *

* This method is called after a service is no longer being tracked by the * ServiceTracker. * * @param reference The reference to the service that has been removed. * @param service The service object for the specified referenced service. */ virtual void RemovedService(const ServiceReference& reference, T service) = 0; }; } #endif // MITKSERVICETRACKERCUSTOMIZER_H