00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision$ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 #ifndef MITK_CALLBACK_WITHIN_GUI_TREAD_H_INCLUDGEWQ 00019 #define MITK_CALLBACK_WITHIN_GUI_TREAD_H_INCLUDGEWQ 00020 00021 #include<itkCommand.h> 00022 #include<itkEventObject.h> 00023 #include "mitkCommon.h" 00024 00025 namespace mitk 00026 { 00027 00031 template <class T> 00032 class CallbackEventOneParameter : public itk::AnyEvent 00033 { 00034 public: 00035 typedef CallbackEventOneParameter Self; 00036 typedef itk::AnyEvent Superclass; 00037 00038 CallbackEventOneParameter(const T t ) 00039 : m_Data(t) {} 00040 00041 virtual ~CallbackEventOneParameter() {} 00042 00043 virtual const char * GetEventName() const 00044 { 00045 return "CallbackEventOneParameter"; 00046 } 00047 00048 virtual bool CheckEvent(const ::itk::EventObject* e) const 00049 { 00050 return dynamic_cast<const Self*>(e); 00051 } 00052 00053 virtual ::itk::EventObject* MakeObject() const 00054 { 00055 return new Self( m_Data ); 00056 } 00057 00058 const T GetData() const 00059 { 00060 return m_Data; 00061 } 00062 00063 CallbackEventOneParameter(const Self& s) : itk::AnyEvent(s), m_Data(s.m_Data) {}; 00064 00065 protected: 00066 const T m_Data; 00067 00068 private: 00069 void operator=(const Self&); 00070 }; 00071 00072 00080 class MITK_CORE_EXPORT CallbackFromGUIThreadImplementation 00081 { 00082 public: 00083 00085 virtual void CallThisFromGUIThread(itk::Command*, itk::EventObject*) = 0; 00086 00087 virtual ~CallbackFromGUIThreadImplementation() {}; 00088 00089 protected: 00090 private: 00091 }; 00092 00177 class MITK_CORE_EXPORT CallbackFromGUIThread 00178 { 00179 public: 00180 00182 static CallbackFromGUIThread* GetInstance(); 00183 00185 static void RegisterImplementation(CallbackFromGUIThreadImplementation* implementation); 00186 00188 void CallThisFromGUIThread(itk::Command*, itk::EventObject* e = NULL); 00189 00190 protected: 00191 00193 CallbackFromGUIThread(); 00194 00195 private: 00196 00197 static CallbackFromGUIThreadImplementation* m_Implementation; 00198 static CallbackFromGUIThread* m_Instance; 00199 }; 00200 00201 } // namespace 00202 00203 #endif 00204 00205