freControllerEvents.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freControllerEvents.h,v $
00007   Language:  C++
00008 
00009 
00010 
00011   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00012   Institute for Medical Biometry and Informatics, University of Heidelberg,
00013   Germany). All rights reserved.
00014   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00015   for details.
00016 
00017      This software is distributed WITHOUT ANY WARRANTY; without even 
00018      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00019      PURPOSE.  See the above copyright notices for more information.
00020 
00021 =========================================================================*/
00022 #ifndef __freControllerEvents_h
00023 #define __freControllerEvents_h
00024 
00025 #include "freEvents.h"
00026 #include "freIDPath.h"
00027 #include "freSessionComponentCache.h"
00028 
00029 #include "itkMutexLock.h"
00030 
00031 namespace FREE
00032 {
00033 
00050 class CallbackCtrlEventBase : public itk::LightObject
00051 {
00052 public:
00053    typedef long CallbackType;
00054    typedef bool (*CallEvent)(const IDPath& senderID, CallbackType callbackID,
00055                              void* pData, SessionComponentCache* pSender, long threadID);
00056 
00057    typedef CallbackCtrlEventBase Self;
00058    typedef itk::SmartPointer<Self> Pointer;
00059 
00060          freNewEventBaseMacro(CallbackCtrlEventBase,CallEvent);
00061          itkTypeMacro(CallbackEventBase,itk::LightObject);
00062 
00066    void SetACR(SessionComponentCache* pCache);
00067 
00069    SessionComponentCache* GetACR();
00070 
00073    bool IsLegalSender(SessionComponentCache* pSender);
00074 
00075 private:
00076   CallEvent m_CallEvent;
00077   SessionComponentCache* m_ACR;
00078 
00079   itk::SimpleMutexLock m_ACRMutex;
00080 
00081   CallbackCtrlEventBase(const Self&); //purposely not implemented
00082   void operator=(const Self&); //purposely not implemented
00083 
00084 protected:
00085   CallbackCtrlEventBase(CallEvent pCE);
00086   CallbackCtrlEventBase();
00087 
00088   itk::SimpleMutexLock m_ExecutionMutex;
00089 
00090 public:
00091 
00107    virtual bool Execute(const IDPath& senderID, CallbackType callbackID,
00108                         void* pData, SessionComponentCache* pSender, long threadID = 0);
00109 };
00110 
00125 class ProgressCtrlEventBase: public NotificationEventBase
00126 {
00127 public:
00128    typedef long StatusID;
00129    typedef void (*ProgEvent)(const IDPath& senderID,
00130                              const StatusID status,
00131                              const std::string& sComment,
00132                              SessionComponentCache* pSender,
00133                              long threadID);
00134 
00135    typedef ProgressCtrlEventBase Self;
00136    typedef itk::SmartPointer<Self> Pointer;
00137    
00138          freNewEventBaseMacro(ProgressCtrlEventBase,ProgEvent);
00139          itkTypeMacro(ProgressCtrlEventBase,NotificationEventBase);
00140 
00144    void SetACR(SessionComponentCache* pCache);
00145 
00147    SessionComponentCache* GetACR();
00148 
00151    bool IsLegalSender(SessionComponentCache* pSender);
00152 
00153 private:
00154    ProgEvent m_ProgressEvent;
00155   SessionComponentCache* m_ACR;
00156 
00157   itk::SimpleMutexLock m_ACRMutex;
00158 
00159   ProgressCtrlEventBase(const Self&); //purposely not implemented
00160   void operator=(const Self&); //purposely not implemented
00161 
00162 protected:
00163    ProgressCtrlEventBase(ProgEvent pPE);
00164    ProgressCtrlEventBase();
00165 
00166    itk::SimpleMutexLock m_ExecutionMutex;
00167 
00168 public:
00180    virtual void Execute(const IDPath& senderID,
00181                         const StatusID status,
00182                         const std::string& sComment,
00183                         SessionComponentCache* pSender,
00184                         long threadID = 0);
00185 };
00186 
00202 template <typename T>
00203 class CallbackCtrlEvent: public CallbackCtrlEventBase
00204 {
00205 public:  
00206    typedef bool (T::*CallEvent)(const IDPath& senderID, CallbackType callbackID,
00207                                 void* pData, SessionComponentCache* pSender,
00208                                 long threadID);
00209 
00210    typedef CallbackCtrlEvent<T>  Self;
00211    typedef itk::SmartPointer<Self> Pointer;
00212 
00213          freNewEventMacro(CallbackCtrlEvent, T, CallEvent);
00214          itkTypeMacro(CallbackCtrlEvent,CallbackCtrlEventBase);
00215 
00216 private:
00217   T* m_Object;
00218   CallEvent m_CallEvent;
00219 
00220   CallbackCtrlEvent(const Self&); //purposely not implemented
00221   void operator=(const Self&); //purposely not implemented
00222 
00223 protected:
00224    CallbackCtrlEvent(T* pObject, CallEvent pCE)
00225    {
00226           m_Object = pObject;
00227           m_CallEvent = pCE;
00228    };
00229 
00230 public:
00246    virtual bool Execute(const IDPath& senderID, CallbackType callbackID,
00247                         void* pData, SessionComponentCache* pSender, long threadID = 0)
00248    {
00249       if (!this->m_Object)return false;
00250       if (!this->m_CallEvent) return false;
00251 
00252       bool result = false;
00253 
00254       if (this->IsLegalSender(pSender))
00255       {
00256         this->m_ExecutionMutex.Lock();
00257                 result = (m_Object->*m_CallEvent)(senderID, callbackID, pData, pSender, threadID); 
00258         this->m_ExecutionMutex.Unlock();
00259       }
00260 
00261       return result;
00262    };
00263 };
00264 
00279 template <typename T>
00280 class ProgressCtrlEvent: public ProgressCtrlEventBase
00281 {
00282 public:
00283    typedef void (T::*ProgEvent)(const IDPath& senderID,
00284                                 const StatusID status,
00285                                 const std::string& sComment,
00286                                 SessionComponentCache* pSender,
00287                                 long threadID);
00288 
00289    typedef ProgressCtrlEvent<T>  Self;
00290    typedef itk::SmartPointer<Self> Pointer;
00291 
00292          freNewEventMacro(ProgressCtrlEvent, T, ProgEvent);
00293          itkTypeMacro(ProgressCtrlEvent,ProgressCtrlEventBase);
00294 
00295 private:
00296    T* m_Object;
00297    ProgEvent m_ProgressEvent;
00298 
00299   ProgressCtrlEvent(const Self&); //purposely not implemented
00300   void operator=(const Self&); //purposely not implemented
00301 
00302 protected:
00303          ProgressCtrlEvent(T* pObject, ProgEvent pPE)
00304    {
00305           m_Object = pObject;
00306           m_ProgressEvent = pPE;
00307    };
00308    
00309 public:
00321    virtual void Execute(const IDPath& senderID,
00322                         const StatusID status,
00323                         const std::string& sComment,
00324                         SessionComponentCache* pSender,
00325                         long threadID = 0)
00326    {
00327       if (!this->m_Object)return;
00328       if (!this->m_ProgressEvent) return;
00329 
00330       if (this->IsLegalSender(pSender))
00331       {
00332         this->m_ExecutionMutex.Lock();
00333           (m_Object->*m_ProgressEvent)(senderID, status, sComment, pSender, threadID);
00334         this->m_ExecutionMutex.Unlock();
00335       }
00336    };
00337 };
00338 
00339 } //end of namespace free
00340 #endif

Generated at Sat Oct 13 15:39:55 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000