freControllerCentral.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: freControllerCentral.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 __freControllerCentral_h
00023 #define __freControllerCentral_h
00024 
00025 #include "freElementals.h"
00026 #include "freEvents.h"
00027 #include "freSetup.h"
00028 #include "freControllerEvents.h"
00029 #include "freControllerBase.h"
00030 
00031 #include "itkMutexLock.h"
00032 #include "itkDynamicLoader.h"
00033 
00034 namespace FREE
00035 {
00036 
00037 class ControllerInfo
00038 {
00039 public:
00040   typedef itk::LibHandle LibraryHandleType;
00041 
00042   const std::string& GetControllerID() const
00043   {return m_ControllerID;};
00044 
00045   GenericComponentController* GetController() const
00046   { return m_pController;};
00047 
00048   const LibraryHandleType& GetLibraryHandle() const
00049   { return m_LibraryHandle;};
00050 
00051   const std::string& GetLibraryFile() const
00052   { return m_LibraryFile;};
00053 
00054   bool IsOwnedByLibrary() const
00055   { return m_bOwnedByLibrary;};
00056 
00057   ControllerInfo(GenericComponentController* pController,
00058                  const LibraryHandleType& libraryHandle,
00059                  const std::string& sLibraryFile);
00060 
00061   ControllerInfo(GenericComponentController* pController);
00062 
00063 protected:
00064   std::string m_ControllerID;
00065   GenericComponentController* m_pController;
00066   LibraryHandleType m_LibraryHandle;
00067   std::string m_LibraryFile;
00068   bool m_bOwnedByLibrary;
00069 };
00070 
00087 class ControllerCentral
00088 {
00089 public:  
00090   typedef std::vector<ControllerInfo*> ControllerListType;
00091   typedef ControllerInfo::LibraryHandleType LibraryHandleType;
00092   typedef std::vector<LibraryHandleType> LibraryHandleListType;
00093   typedef std::vector<CallbackCtrlEventBase::Pointer> CtrlCallbackListType;
00094   typedef std::vector<ProgressCtrlEventBase::Pointer> CtrlProgressListType;
00095 
00097   typedef ControllerCentral Self;
00098 
00101   static void ReHash(); 
00102 
00110   static void RegisterController(GenericComponentController* pController,
00111                                  const LibraryHandleType& handle,
00112                                  const std::string& sLibraryFile);
00113 
00118   static void RegisterController(GenericComponentController* pController);
00119 
00122   static void UnRegisterController(GenericComponentController* pController);
00123 
00125   static void UnRegisterAllControllers();
00126   
00128   static void UnRegisterCallbackEventList();
00130   static void UnRegisterProgressEventList();
00131 
00137   static GenericComponentController* GetController(const std::string&  sControllerName);
00138 
00144   static ControllerInfo* GetControllerInfo(const std::string&  sControllerName);
00145 
00151   static GenericComponentController* GetResponsibleController(const GenericComponentType* pComponent);
00152 
00156   static ControllerListType GetControllers();
00157 
00158   ControllerCentral();
00159   ~ControllerCentral();
00160 
00164         static void SetOnControlEvent(ProgressEventBase* pOnControl);
00165 
00169         static void SetOnBuildEvent(ProgressEventBase* pOnBuild);
00170 
00174         static void AddOnProgressEvent(ProgressCtrlEventBase* pOnProgress);
00177         static void RemoveOnProgressEvent(ProgressCtrlEventBase* pOnProgress);
00178   static void ClearProgressEventList();
00179 
00183         static void AddOnCallbackEvent(CallbackCtrlEventBase* pOnCallback);
00186         static void RemoveOnCallbackEvent(CallbackCtrlEventBase* pOnCallback);
00187   static void ClearCallbackList();
00188 
00196   static void TriggerControllerProgressEvent(const IDPath& senderID,
00197                                              const ProgressCtrlEventBase::StatusID status,
00198                                              const std::string& sComment,
00199                                              SessionComponentCache* pSender,
00200                                              long threadID);
00201 
00213   static bool TriggerControllerCallback(const IDPath& senderID,
00214                                         CallbackCtrlEventBase::CallbackType callbackID,
00215                                         void* pData,
00216                                         SessionComponentCache* pSender,
00217                                         long threadID);
00218 
00219 
00228   static bool TriggerControlEvent(const int iStatusID, const std::string& sComment, void* pSender = 0, long threadID = 0);
00229 
00238   static bool TriggerBuildEvent(const int iStatusID, const std::string& sComment, void* pSender = 0, long threadID = 0);
00239 
00261   static void LinkControllerCentralAsDedicated(ControllerListType* pDedicatedControllerList,
00262                                               LibraryHandleListType* pDedicatedLibraryHandles,
00263                                               ProgressEventBase* pfnOnControl,
00264                                               ProgressEventBase* pfnOnBuild,
00265                                               CtrlCallbackListType* pCallbackList,
00266                                               CtrlProgressListType* pProgressList,
00267                                               itk::MutexLock* pGlobalCallbackMutex,
00268                                               itk::MutexLock* pGlobalProgressMutex);
00269 
00270 private:
00271   friend class CleanUpControllerCentral;
00272 
00275   static void Initialize();
00276 
00278   static void RegisterDefaults();
00279 
00281   static void LoadDynamicControllers();
00282 
00284   static void LoadLibrariesInPath( const char*);
00285 
00287   static ControllerListType* m_RegisteredControllers; 
00288 
00291   static LibraryHandleListType* m_LibraryHandles;
00292 
00296   static CtrlCallbackListType* m_CtrlCallbacks;
00297 
00300   static CtrlProgressListType* m_CtrlProgress;
00301   
00304         static ProgressEventBase::Pointer m_fnOnControl;
00305 
00308         static ProgressEventBase::Pointer m_fnOnBuild;
00309 
00310   static itk::MutexLock::Pointer m_CallbackMutex;
00311   static itk::MutexLock::Pointer m_ProgressMutex;
00312 
00315   static itk::MutexLock* m_GlobalCallbackMutex;
00318   static itk::MutexLock* m_GlobalProgressMutex;
00319 
00322   static bool m_bControllersAreExternal;
00323 };
00324 
00325 
00333 typedef void (* FREE_GET_CONTROLLER_LIST_FUNCTION)(int& iCount, char**& pControllerIDs);
00334 
00338 typedef GenericComponentController* (* FREE_CREATE_CONTROLLER_FUNCTION)(char* pControllerID);
00339 
00344 typedef bool (* FREE_DELETE_CONTROLLER_FUNCTION)(GenericComponentController* pController);
00345 
00350 typedef void (* FREE_LINK_CENTRAL_FUNCTION)(ControllerCentral::ControllerListType* pDedicatedControllerList,
00351                                             ControllerCentral::LibraryHandleListType* pDedicatedLibraryHandles,
00352                                             ProgressEventBase* pfnOnControl, ProgressEventBase* pfnOnBuild,
00353                                             ControllerCentral::CtrlCallbackListType* pCallbackList,
00354                                             ControllerCentral::CtrlProgressListType* pProgressList,
00355                                             itk::MutexLock* pGlobalCallbackMutex,
00356                                             itk::MutexLock* pGlobalProgressMutex);
00357 
00358 
00359 } //end of namespace free;
00360 
00361 #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