00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #if defined(_MSC_VER)
00023 #pragma warning ( disable : 4786 )
00024 #endif
00025
00026 #include "freControllerCentral.h"
00027 #include "freExceptions.h"
00028
00029 #include "itkDynamicLoader.h"
00030 #include "itkDirectory.h"
00031 #include "itkVersion.h"
00032 #include "itksys/SystemTools.hxx"
00033
00034 namespace FREE
00035 {
00036
00041 typedef void (* FREE_GET_CONTROLLER_LIST_FUNCTION)(int& iCount, char**& pControllerIDs);
00042
00043 typedef GenericComponentController* (* FREE_CREATE_CONTROLLER_FUNCTION)(char* pControllerID);
00044
00045 typedef bool (* FREE_DELETE_CONTROLLER_FUNCTION)(GenericComponentController* pController);
00046
00047 typedef void (* FREE_LINK_CENTRAL_FUNCTION)(ControllerCentral::ControllerListType* pDedicatedControllerList,
00048 ControllerCentral::PointerListType* pDedicatedLibraryHandles,
00049 ProgressEventBase* pfnOnControl, ProgressEventBase* pfnOnBuild,
00050 ControllerCentral::CtrlCallbackListType* pCallbackList,
00051 ControllerCentral::CtrlProgressListType* pProgressList,
00052 itk::MutexLock* pGlobalCallbackMutex,
00053 itk::MutexLock* pGlobalProgressMutex);
00054
00055 class CleanUpControllerCentral
00056 {
00057 public:
00058 inline void Use()
00059 {
00060 }
00061 ~CleanUpControllerCentral()
00062 {
00063 ControllerCentral::UnRegisterCallbackEventList();
00064 ControllerCentral::UnRegisterProgressEventList();
00065 ControllerCentral::UnRegisterAllControllers();
00066 }
00067 };
00068 static CleanUpControllerCentral CleanUpControllerCentralGlobal;
00069
00073 ControllerCentral::ControllerListType* ControllerCentral::m_RegisteredControllers = NULL;
00074
00078 ControllerCentral::PointerListType* ControllerCentral::m_LibraryHandles = NULL;
00079
00083 ControllerCentral::CtrlCallbackListType* ControllerCentral::m_CtrlCallbacks = NULL;
00084
00088 ControllerCentral::CtrlProgressListType* ControllerCentral::m_CtrlProgress = NULL;
00089
00093 ProgressEventBase::Pointer ControllerCentral::m_fnOnControl = NULL;
00094 ProgressEventBase::Pointer ControllerCentral::m_fnOnBuild = NULL;
00095
00099 bool ControllerCentral::m_bControllersAreExternal = false;
00100
00101 itk::MutexLock::Pointer ControllerCentral::m_CallbackMutex = itk::MutexLock::New();
00102 itk::MutexLock::Pointer ControllerCentral::m_ProgressMutex = itk::MutexLock::New();
00103
00104 itk::MutexLock* ControllerCentral::m_GlobalCallbackMutex = 0;
00105 itk::MutexLock* ControllerCentral::m_GlobalProgressMutex = 0;
00106
00110 void
00111 ControllerCentral::
00112 Initialize()
00113 {
00114 try
00115 {
00116 if (!m_RegisteredControllers)
00117 {
00118 m_CallbackMutex->Lock();
00119 if (!m_CtrlCallbacks) m_CtrlCallbacks = new CtrlCallbackListType;
00120 m_CallbackMutex->Unlock();
00121
00122 m_ProgressMutex->Lock();
00123 if (!m_CtrlProgress) m_CtrlProgress = new CtrlProgressListType;
00124 m_ProgressMutex->Unlock();
00125
00126 m_RegisteredControllers = new ControllerListType;
00127 m_LibraryHandles = new PointerListType;
00128
00129 ControllerCentral::RegisterDefaults();
00130 ControllerCentral::LoadDynamicControllers();
00131 }
00132 }
00133 catchAllNPassStaticMacro("Unknown Exception, while initializing free::ControllerCentral.");
00134 };
00135
00136 void
00137 ControllerCentral::
00138 RegisterDefaults()
00139 {
00140 }
00141
00142 void
00143 ControllerCentral::
00144 LinkControllerCentralAsDedicated(ControllerListType* pDedicatedControllerList,
00145 PointerListType* pDedicatedLibraryHandles,
00146 ProgressEventBase* pfnOnControl,
00147 ProgressEventBase* pfnOnBuild,
00148 CtrlCallbackListType* pCtrlCallbackList,
00149 CtrlProgressListType* pCtrlProgressList,
00150 itk::MutexLock* pGlobalCallbackMutex,
00151 itk::MutexLock* pGlobalProgressMutex)
00152 {
00153 if (m_RegisteredControllers!=pDedicatedControllerList)
00154 {
00155 UnRegisterAllControllers();
00156 m_LibraryHandles = pDedicatedLibraryHandles;
00157 m_RegisteredControllers = pDedicatedControllerList;
00158 m_bControllersAreExternal = true;
00159 }
00160
00161 m_CallbackMutex->Lock();
00162 if (m_CtrlCallbacks!=pCtrlCallbackList)
00163 {
00164 ControllerCentral::UnRegisterCallbackEventList();
00165 m_CtrlCallbacks = pCtrlCallbackList;
00166 m_GlobalCallbackMutex = pGlobalCallbackMutex;
00167 }
00168 m_CallbackMutex->Unlock();
00169
00170 m_ProgressMutex->Lock();
00171 if (m_CtrlProgress!=pCtrlProgressList)
00172 {
00173 ControllerCentral::UnRegisterProgressEventList();
00174 m_CtrlProgress = pCtrlProgressList;
00175 m_GlobalProgressMutex = pGlobalProgressMutex;
00176 }
00177 m_ProgressMutex->Unlock();
00178
00179 m_fnOnControl = pfnOnControl;
00180 m_fnOnBuild = pfnOnBuild;
00181 };
00182
00186 void
00187 ControllerCentral::
00188 LoadDynamicControllers()
00189 {
00193 #ifdef _WIN32
00194 char cPathSeparator = ';';
00195 #else
00196 char cPathSeparator = ':';
00197 #endif
00198
00199 std::string sLoadPath = GetGeneralFREEPath();
00200 char* pcEnvironmentEntry = getenv(csFREEAutoLoadPath);
00201 if (pcEnvironmentEntry) sLoadPath += cPathSeparator+std::string(pcEnvironmentEntry);
00202
00203 std::string sCurrentDirectory = itksys::SystemTools::GetCurrentWorkingDirectory();
00204
00205 if (!sCurrentDirectory.empty())
00206 {
00207 sLoadPath += cPathSeparator+sCurrentDirectory;
00208 }
00209
00210 if(sLoadPath.size() == 0)
00211 {
00212 return;
00213 }
00214
00215 std::string::size_type endSeparatorPosition = 0;
00216 std::string::size_type startSeparatorPosition = 0;
00217
00218 while ( startSeparatorPosition != std::string::npos )
00219 {
00220 startSeparatorPosition = endSeparatorPosition;
00224 endSeparatorPosition = sLoadPath.find(cPathSeparator, startSeparatorPosition);
00225
00226 if(endSeparatorPosition == std::string::npos)
00227 {
00228 endSeparatorPosition = sLoadPath.size();
00229 }
00230
00231 std::string CurrentPath = sLoadPath.substr(startSeparatorPosition, endSeparatorPosition);
00232 ControllerCentral::LoadLibrariesInPath(CurrentPath.c_str());
00233
00237 if(endSeparatorPosition == sLoadPath.size())
00238 {
00239 startSeparatorPosition = std::string::npos;
00240 }
00241 else
00242 {
00243 endSeparatorPosition++;
00244 }
00245 }
00246 }
00247
00248
00253 static
00254 std::string
00255 CreateFullPath(const char* path, const char* file)
00256 {
00257 std::string ret;
00258
00259 #ifdef _WIN32
00260 const char sep = '\\';
00261 #else
00262 const char sep = '/';
00263 #endif
00264
00267 ret = path;
00268 if ( ret[ret.size()-1] != sep )
00269 {
00270 ret.append(1, sep);
00271 }
00272 ret.append(file);
00273 return ret;
00274 }
00275
00276
00283 inline bool
00284 NameIsSharedLibrary(const char* name)
00285 {
00286 std::string sname = name;
00287 if ( sname.find(itk::DynamicLoader::LibExtension()) != std::string::npos )
00288 {
00289 return true;
00290 }
00291 return false;
00292 }
00293
00294
00295 void
00296 ControllerCentral::
00297 LoadLibrariesInPath(const char* path)
00298 {
00299 itk::Directory::Pointer dir = itk::Directory::New();
00300 if ( !dir->Load(path) )
00301 {
00302 return;
00303 }
00304
00308 for ( unsigned int i = 0; i < dir->GetNumberOfFiles(); i++ )
00309 {
00310 const char* file = dir->GetFile(i);
00315 if ( NameIsSharedLibrary(file) )
00316 {
00317 std::string fullpath = CreateFullPath(path, file);
00318 itk::LibHandle lib = itk::DynamicLoader::OpenLibrary(fullpath.c_str());
00319
00320 if ( lib )
00321 {
00323 FREE_GET_CONTROLLER_LIST_FUNCTION pListFunction = (FREE_GET_CONTROLLER_LIST_FUNCTION)itk::DynamicLoader::GetSymbolAddress(lib, "FREEGetControllerList");
00324 FREE_CREATE_CONTROLLER_FUNCTION pLoadFunction = (FREE_CREATE_CONTROLLER_FUNCTION)itk::DynamicLoader::GetSymbolAddress(lib, "FREECreateController");
00325 FREE_LINK_CENTRAL_FUNCTION pLinkFunction = (FREE_LINK_CENTRAL_FUNCTION)itk::DynamicLoader::GetSymbolAddress(lib, "FREELinkCentralAsDedicated");
00326
00327 unsigned int iSymbolCount = 0;
00328 if (pListFunction!=NULL) iSymbolCount++;
00329 if (pLoadFunction!=NULL) iSymbolCount++;
00330 if (pLinkFunction!=NULL) iSymbolCount++;
00331
00332 if (iSymbolCount == 3)
00333 {
00334 int iCtrlCount = 0;
00335 char** pControllerIDs = 0;
00336
00337 TriggerControlEvent(2,"load components ("+fullpath+")...");
00338
00339 (*pListFunction)(iCtrlCount,pControllerIDs);
00340
00341 for (int index=0; index<iCtrlCount; index++)
00342 {
00343 char* pControllerID = pControllerIDs[index];
00344 if (!GetController(std::string(pControllerID)))
00345 {
00346 GenericComponentController* pNewController = (*pLoadFunction)(pControllerID);
00347 if (pNewController)
00348 {
00350 try
00351 {
00352 ControllerCentral::RegisterController(pNewController);
00353 m_LibraryHandles->push_back((void*)lib);
00354 }
00355 catch (ControllerException& e)
00356 {
00357 logException.AddEntry("External DLL error: "+std::string(e.what()));
00358 };
00359 }
00360 else logException.AddEntry("External DLL error: Controller missing. LoadController returns no controller for ControllerID:"+std::string(pControllerID));
00361 }
00362 else
00363 {
00364 logException.AddEntry("WARNING: Controller "+std::string(pControllerID)+" is already registered. Skip last one.");
00365 TriggerControlEvent(2,"WARNING: Controller "+std::string(pControllerID)+" is already registered. Skip last one.");
00366 }
00367 };
00368
00369 if (pControllerIDs) delete [] pControllerIDs;
00370
00371 if (!m_bControllersAreExternal)
00372 {
00373 (*pLinkFunction)(m_RegisteredControllers,
00374 m_LibraryHandles,
00375 m_fnOnControl,
00376 m_fnOnBuild,
00377 m_CtrlCallbacks,
00378 m_CtrlProgress,
00379 m_CallbackMutex,
00380 m_ProgressMutex);
00381 }
00382 else
00383 {
00384 (*pLinkFunction)(m_RegisteredControllers,
00385 m_LibraryHandles,
00386 m_fnOnControl,
00387 m_fnOnBuild,
00388 m_CtrlCallbacks,
00389 m_CtrlProgress,
00390 m_GlobalCallbackMutex,
00391 m_GlobalProgressMutex);
00392 }
00393 }
00394 else if (iSymbolCount>0)
00395 {
00396
00397
00398 if ( !pListFunction)
00399 {
00400 logException.AddEntry("External DLL error: DLL seems to be invalid because FREEGetControllerList symbol is missing.");
00401 TriggerControlEvent(2,"!!! WARNING: Invalid DLL ("+fullpath+"); FREEGetControllerList symbol is missing.");
00402 }
00403
00404 if ( !pLoadFunction)
00405 {
00406 logException.AddEntry("External DLL error: DLL seems to be invalid because FREECreateController symbol is missing.");
00407 TriggerControlEvent(2,"!!! WARNING: Invalid DLL ("+fullpath+"); FREECreateController symbol is missing.");
00408 }
00409
00410 if ( !pLinkFunction)
00411 {
00412 logException.AddEntry("External DLL error: DLL seems to be invalid because FREELinkCentralAsDedicated symbol is missing.");
00413 TriggerControlEvent(2,"!!! WARNING: Invalid DLL ("+fullpath+"); FREELinkCentralAsDedicated symbol is missing.");
00414 }
00415 };
00416 };
00417 };
00418 };
00419 };
00420
00421
00425 void
00426 ControllerCentral::
00427 ReHash()
00428 {
00429
00430
00431 m_ProgressMutex->Lock();
00432 if (m_bControllersAreExternal)
00433 {
00434 m_GlobalProgressMutex = 0;
00435 m_CtrlProgress = 0;
00436 }
00437 m_ProgressMutex->Unlock();
00438
00439 m_CallbackMutex->Lock();
00440 if (m_bControllersAreExternal)
00441 {
00442 m_GlobalCallbackMutex = 0;
00443 m_CtrlCallbacks = 0;
00444 }
00445 m_CallbackMutex->Unlock();
00446
00447
00448 ControllerCentral::UnRegisterAllControllers();
00449 ControllerCentral::Initialize();
00450 }
00451
00452
00456 ControllerCentral::
00457 ControllerCentral()
00458 {
00459 ControllerCentral::Initialize();
00460 }
00461
00462
00466 ControllerCentral::
00467 ~ControllerCentral()
00468 {
00469 }
00470
00471 void
00472 ControllerCentral::
00473 RegisterController(GenericComponentController* pController)
00474 {
00475 if (!m_RegisteredControllers) Initialize();
00476 if (!GetController(pController->ControllerID()))
00477 {
00478 m_RegisteredControllers->push_back(pController);
00479 TriggerControlEvent(1, pController->ControllerID() + " added", pController);
00480 }
00481 else
00482 {
00483 logException.AddEntry("WARNING: Try to register a controller that is already registered. ControllerID: "+std::string(pController->ControllerID()));
00484 TriggerControlEvent(2,"WARNING: Try to register a controller that is already registered. ControllerID: "+std::string(pController->ControllerID()));
00485 }
00486 }
00487
00488 void
00489 ControllerCentral::
00490 UnRegisterController(GenericComponentController* pController)
00491 {
00492 try
00493 {
00494 if (!m_bControllersAreExternal)
00495 {
00496 for (ControllerListType::iterator pos = m_RegisteredControllers->begin(); pos != m_RegisteredControllers->end(); pos++)
00497 {
00498 if ((*pos)==pController)
00499 {
00500 delete pController;
00501 m_RegisteredControllers->erase(pos);
00502 return;
00503 }
00504 }
00505 }
00506 }
00507 catchAllNPassStaticMacro("Unknown exception, while unregistering controller. ControllerID: " << pController->ControllerID());
00508 }
00509
00510 void
00511 ControllerCentral::
00512 UnRegisterAllControllers()
00513 {
00514 GenericComponentController* pController;
00515 std::string sControllerName;
00516
00517 if (!m_bControllersAreExternal)
00518 {
00519
00520 try
00521 {
00522 if (m_RegisteredControllers)
00523 {
00524 while ( m_RegisteredControllers->size()>0 )
00525 {
00526 sControllerName = "Unknown";
00527 pController = (*m_RegisteredControllers)[0];
00528 sControllerName = pController->ControllerID();
00529 m_RegisteredControllers->erase(m_RegisteredControllers->begin());
00530
00531 delete pController;
00532 }
00533
00534 delete m_RegisteredControllers;
00535 }
00536 }
00537 catchAllNPassStaticMacro("Unknown exception, while unregistering all controllers." << sControllerName);
00538
00539 try
00540 {
00541 if (m_LibraryHandles)
00542 {
00543 while (m_LibraryHandles->size() > 0)
00544 {
00545 itk::DynamicLoader::CloseLibrary((itk::LibHandle)(*m_LibraryHandles)[0]);
00546 m_LibraryHandles->erase(m_LibraryHandles->begin());
00547 }
00548
00549 delete m_LibraryHandles;
00550 }
00551 }
00552 catchAllNPassStaticMacro("Unknown exception while closing all all libraries.");
00553 }
00554
00555 m_bControllersAreExternal = false;
00556 m_RegisteredControllers = NULL;
00557 m_LibraryHandles = NULL;
00558 };
00559
00560 void
00561 ControllerCentral::
00562 UnRegisterCallbackEventList()
00563 {
00564 if(m_CallbackMutex.IsNotNull()) m_CallbackMutex->Lock();
00565 if (!m_bControllersAreExternal)
00566 {
00567 try
00568 {
00569 if (m_CtrlCallbacks)
00570 {
00571 delete m_CtrlCallbacks;
00572 }
00573 }
00574 catchAllNPassStaticMacro("Unknown exception while deleting callback list.");
00575 }
00576
00577 m_CtrlCallbacks = NULL;
00578 if(m_CallbackMutex.IsNotNull()) m_CallbackMutex->Unlock();
00579 };
00580
00581 void
00582 ControllerCentral::
00583 UnRegisterProgressEventList()
00584 {
00585 if(m_ProgressMutex.IsNotNull()) m_ProgressMutex->Lock();
00586
00587 if (!m_bControllersAreExternal)
00588 {
00589 try
00590 {
00591 if (m_CtrlProgress)
00592 {
00593 delete m_CtrlProgress;
00594 }
00595 }
00596 catchAllNPassStaticMacro("Unknown exception while deleting progress event list.");
00597 }
00598
00599 m_CtrlProgress = NULL;
00600
00601 if(m_ProgressMutex.IsNotNull()) m_ProgressMutex->Unlock();
00602 };
00603
00604 ControllerCentral::ControllerListType
00605 ControllerCentral::
00606 GetControllers()
00607 {
00608 if (!m_RegisteredControllers) Initialize();
00609
00610 return *m_RegisteredControllers;
00611 };
00612
00613 GenericComponentController*
00614 ControllerCentral::
00615 GetController(const std::string& sControllerName)
00616 {
00617 if (!m_RegisteredControllers) Initialize();
00618
00619 for( ControllerListType::iterator pos = m_RegisteredControllers->begin(); pos != m_RegisteredControllers->end(); pos++)
00620 {
00621 if ((*pos)->ControllerID()==sControllerName)
00622 {
00623 return (*pos);
00624 }
00625 }
00626 return NULL;
00627 };
00628
00629 GenericComponentController*
00630 ControllerCentral::
00631 GetResponsibleController(const GenericComponentType* pComponent)
00632 {
00633 if (!pComponent) return 0;
00634 if (!m_RegisteredControllers) Initialize();
00635
00636 for( ControllerListType::iterator pos = m_RegisteredControllers->begin(); pos != m_RegisteredControllers->end(); pos++)
00637 {
00638 if ((*pos)->ControllerIsResponsible(pComponent)) return (*pos);
00639 }
00640
00641 return 0;
00642 };
00643
00644 void
00645 ControllerCentral::
00646 SetOnControlEvent(ProgressEventBase* pOnControl)
00647 {
00648 m_fnOnControl = pOnControl;
00649 };
00650
00651 void
00652 ControllerCentral::
00653 SetOnBuildEvent(ProgressEventBase* pOnBuild)
00654 {
00655 m_fnOnBuild = pOnBuild;
00656 };
00657
00658
00659 void
00660 ControllerCentral::
00661 AddOnProgressEvent(ProgressCtrlEventBase* pOnProgress)
00662 {
00663 m_ProgressMutex->Lock();
00664 if (m_GlobalProgressMutex) m_GlobalProgressMutex->Lock();
00665 if ((!m_bControllersAreExternal)&&(!m_CtrlProgress)) m_CtrlProgress = new CtrlProgressListType;
00666
00667 if (m_CtrlProgress)
00668 {
00669 m_CtrlProgress->push_back(ProgressCtrlEventBase::Pointer(pOnProgress));
00670 }
00671 if (m_GlobalProgressMutex) m_GlobalProgressMutex->Unlock();
00672 m_ProgressMutex->Unlock();
00673 };
00674
00675 void
00676 ControllerCentral::
00677 RemoveOnProgressEvent(ProgressCtrlEventBase* pOnProgress)
00678 {
00679 m_ProgressMutex->Lock();
00680
00681 if (m_CtrlProgress)
00682 {
00683 if (m_GlobalProgressMutex) m_GlobalProgressMutex->Lock();
00684
00685 CtrlProgressListType::iterator pos = m_CtrlProgress->begin();
00686 while (pos != m_CtrlProgress->end())
00687 {
00688 if ((*pos).GetPointer()==pOnProgress)
00689 {
00690 pos = m_CtrlProgress->erase(pos);
00691 }
00692 else
00693 {
00694 ++pos;
00695 }
00696 }
00697
00698 if (m_GlobalProgressMutex) m_GlobalProgressMutex->Unlock();
00699 }
00700 m_ProgressMutex->Unlock();
00701 };
00702
00703 void
00704 ControllerCentral::
00705 ClearProgressEventList()
00706 {
00707 m_ProgressMutex->Lock();
00708
00709 if (m_CtrlProgress)
00710 {
00711 if (m_GlobalProgressMutex) m_GlobalProgressMutex->Lock();
00712 m_CtrlProgress->clear();
00713 if (m_GlobalProgressMutex) m_GlobalProgressMutex->Unlock();
00714 }
00715
00716 m_ProgressMutex->Unlock();
00717 };
00718
00719 void
00720 ControllerCentral::
00721 AddOnCallbackEvent(CallbackCtrlEventBase* pOnCallback)
00722 {
00723 m_CallbackMutex->Lock();
00724 if (m_GlobalCallbackMutex) m_GlobalCallbackMutex->Lock();
00725
00726 if ((!m_bControllersAreExternal)&&(!m_CtrlCallbacks))
00727 {
00728 m_CtrlCallbacks = new CtrlCallbackListType;
00729 }
00730
00731 if (m_CtrlCallbacks)
00732 {
00733 m_CtrlCallbacks->push_back(CallbackCtrlEventBase::Pointer(pOnCallback));
00734 }
00735
00736 if (m_GlobalCallbackMutex) m_GlobalCallbackMutex->Unlock();
00737
00738 m_CallbackMutex->Unlock();
00739 };
00740
00741 void
00742 ControllerCentral::
00743 RemoveOnCallbackEvent(CallbackCtrlEventBase* pOnCallback)
00744 {
00745 m_CallbackMutex->Lock();
00746
00747 if (m_CtrlCallbacks)
00748 {
00749 if (m_GlobalCallbackMutex) m_GlobalCallbackMutex->Lock();
00750
00751 CtrlCallbackListType::iterator pos = m_CtrlCallbacks->begin();
00752 while (pos != m_CtrlCallbacks->end())
00753 {
00754 if ((*pos).GetPointer()==pOnCallback)
00755 {
00756 pos = m_CtrlCallbacks->erase(pos);
00757 }
00758 else
00759 {
00760 ++pos;
00761 }
00762 }
00763
00764 if (m_GlobalCallbackMutex) m_GlobalCallbackMutex->Unlock();
00765 }
00766
00767 m_CallbackMutex->Unlock();
00768 };
00769
00770 void
00771 ControllerCentral::
00772 ClearCallbackList()
00773 {
00774 m_CallbackMutex->Lock();
00775
00776 if (m_CtrlCallbacks)
00777 {
00778 if (m_GlobalCallbackMutex) m_GlobalCallbackMutex->Lock();
00779 m_CtrlCallbacks->clear();
00780 if (m_GlobalCallbackMutex) m_GlobalCallbackMutex->Unlock();
00781 }
00782
00783 m_CallbackMutex->Unlock();
00784 };
00785
00786 bool
00787 ControllerCentral::
00788 TriggerControlEvent(const int iStatusID, const std::string& sComment, void* pSender, long threadID)
00789 {
00790 if (m_fnOnControl.IsNotNull())
00791 {
00792 m_fnOnControl->Execute(iStatusID, sComment, pSender, threadID);
00793 return true;
00794 }
00795 return false;
00796 };
00797
00798 bool
00799 ControllerCentral::
00800 TriggerBuildEvent(const int iStatusID, const std::string& sComment, void* pSender, long threadID)
00801 {
00802 if (m_fnOnBuild.IsNotNull())
00803 {
00804 m_fnOnBuild->Execute(iStatusID, sComment, pSender, threadID);
00805 return true;
00806 }
00807 return false;
00808 };
00809
00810 void
00811 ControllerCentral::
00812 TriggerControllerProgressEvent(const IDPath& senderID, const ProgressCtrlEventBase::StatusID status,
00813 const std::string& sComment,
00814 SessionComponentCache* pSender,
00815 long threadID)
00816 {
00817 m_ProgressMutex->Lock();
00818
00819 if (m_CtrlProgress)
00820 {
00821 if (m_GlobalProgressMutex) m_GlobalProgressMutex->Lock();
00822
00823
00824 for (CtrlProgressListType::iterator pos = m_CtrlProgress->begin(); pos != m_CtrlProgress->end(); pos++)
00825 {
00826 if ((*pos)->GetACR())
00827 {
00828 (*pos)->Execute(senderID,status,sComment,pSender,threadID);
00829 }
00830 }
00831
00832 for (CtrlProgressListType::iterator pos = m_CtrlProgress->begin(); pos != m_CtrlProgress->end(); pos++)
00833 {
00834 if (!(*pos)->GetACR())
00835 {
00836 (*pos)->Execute(senderID,status,sComment,pSender,threadID);
00837 }
00838 }
00839
00840 if (m_GlobalProgressMutex) m_GlobalProgressMutex->Unlock();
00841 }
00842
00843 m_ProgressMutex->Unlock();
00844 };
00845
00846 bool
00847 ControllerCentral::
00848 TriggerControllerCallback(const IDPath& senderID, CallbackCtrlEventBase::CallbackType callbackID,
00849 void* pData, SessionComponentCache* pSender, long threadID)
00850 {
00851 bool result = false;
00852
00853 m_CallbackMutex->Lock();
00854
00855 if (m_CtrlCallbacks)
00856 {
00857 if (m_GlobalProgressMutex) m_GlobalProgressMutex->Lock();
00858
00859
00860 for (CtrlCallbackListType::iterator pos = m_CtrlCallbacks->begin(); pos != m_CtrlCallbacks->end(); pos++)
00861 {
00862 if ((*pos)->GetACR())
00863 {
00864 if ((*pos)->Execute(senderID,callbackID,pData,pSender,threadID))
00865 {
00866 result = true;
00867 break;
00868 }
00869 }
00870 }
00871
00872 for (CtrlCallbackListType::iterator pos = m_CtrlCallbacks->begin(); pos != m_CtrlCallbacks->end(); pos++)
00873 {
00874 if (!(*pos)->GetACR())
00875 {
00876 if ((*pos)->Execute(senderID,callbackID,pData,pSender,threadID))
00877 {
00878 result = true;
00879 break;
00880 }
00881 }
00882 }
00883
00884 if (m_GlobalProgressMutex) m_GlobalProgressMutex->Unlock();
00885 }
00886
00887 m_CallbackMutex->Unlock();
00888
00889 return result;
00890 };
00891
00892 }