$treeview $search $mathjax
00001 // ////////////////////////////////////////////////////////////////////// 00002 // Import section 00003 // ////////////////////////////////////////////////////////////////////// 00004 // STL 00005 #include <cassert> 00006 // StdAir 00007 #include <stdair/factory/FacAbstract.hpp> 00008 #include <stdair/service/FacServiceAbstract.hpp> 00009 #include <stdair/service/FacSupervisor.hpp> 00010 #include <stdair/service/Logger.hpp> 00011 #include <stdair/service/DBSessionManager.hpp> 00012 00013 namespace stdair { 00014 00015 FacSupervisor* FacSupervisor::_instance = NULL; 00016 00017 // ////////////////////////////////////////////////////////////////////// 00018 FacSupervisor& FacSupervisor::instance() { 00019 if (_instance == NULL) { 00020 _instance = new FacSupervisor(); 00021 } 00022 00023 return *_instance; 00024 } 00025 00026 // ////////////////////////////////////////////////////////////////////// 00027 FacSupervisor::~FacSupervisor() { 00028 cleanPersistentBomLayer(); 00029 cleanCloneBomLayer(); 00030 cleanServiceLayer(); 00031 } 00032 00033 // ////////////////////////////////////////////////////////////////////// 00034 void FacSupervisor::registerPersistentBomFactory (FacAbstract* ioFac_ptr) { 00035 _persistentBomPool.push_back (ioFac_ptr); 00036 } 00037 00038 // ////////////////////////////////////////////////////////////////////// 00039 void FacSupervisor::registerCloneBomFactory (FacAbstract* ioFac_ptr) { 00040 _cloneBomPool.push_back (ioFac_ptr); 00041 } 00042 00043 // ////////////////////////////////////////////////////////////////////// 00044 void FacSupervisor::registerServiceFactory (FacServiceAbstract* ioFac_ptr) { 00045 _svcPool.push_back (ioFac_ptr); 00046 } 00047 00048 // ////////////////////////////////////////////////////////////////////// 00049 void FacSupervisor::cleanPersistentBomLayer() { 00050 for (PersistentBomFactoryPool_T::const_iterator itFactory = _persistentBomPool.begin(); 00051 itFactory != _persistentBomPool.end(); itFactory++) { 00052 const FacAbstract* currentFactory_ptr = *itFactory; 00053 assert (currentFactory_ptr != NULL); 00054 00055 delete (currentFactory_ptr); currentFactory_ptr = NULL; 00056 } 00057 // Empty the pool of BOM factories 00058 _persistentBomPool.clear(); 00059 } 00060 00061 // ////////////////////////////////////////////////////////////////////// 00062 void FacSupervisor::cleanCloneBomLayer() { 00063 for (CloneBomFactoryPool_T::const_iterator itFactory = _cloneBomPool.begin(); 00064 itFactory != _cloneBomPool.end(); itFactory++) { 00065 const FacAbstract* currentFactory_ptr = *itFactory; 00066 assert (currentFactory_ptr != NULL); 00067 00068 delete (currentFactory_ptr); currentFactory_ptr = NULL; 00069 } 00070 00071 // Empty the pool of BOM factories 00072 _cloneBomPool.clear(); 00073 } 00074 00075 // ////////////////////////////////////////////////////////////////////// 00076 void FacSupervisor::cleanServiceLayer() { 00077 for (ServiceFactoryPool_T::const_iterator itFactory = _svcPool.begin(); 00078 itFactory != _svcPool.end(); itFactory++) { 00079 const FacServiceAbstract* currentFactory_ptr = *itFactory; 00080 assert (currentFactory_ptr != NULL); 00081 00082 delete (currentFactory_ptr); currentFactory_ptr = NULL; 00083 } 00084 00085 // Empty the pool of Service Factories 00086 _svcPool.clear(); 00087 } 00088 00089 // ////////////////////////////////////////////////////////////////////// 00090 void FacSupervisor::cleanLoggerService() { 00091 // Clean the static instance of the log service 00092 Logger::clean(); 00093 } 00094 00095 // ////////////////////////////////////////////////////////////////////// 00096 void FacSupervisor::cleanDBSessionManager() { 00097 // Clean the static instance of the database service 00098 DBSessionManager::clean(); 00099 } 00100 00101 // ////////////////////////////////////////////////////////////////////// 00102 void FacSupervisor::cleanAll() { 00103 00104 // Clean the static instance of the database session manager 00105 cleanDBSessionManager(); 00106 00107 // Clean the static instance of the log service 00108 cleanLoggerService(); 00109 00110 // Clean the static instance of the FacSupervisor. 00111 // This in turn will invoke the destructor (~FacSupervisor() method) 00112 // of the static instance, thus cleaning both the BOM and service layers. 00113 delete _instance; _instance = NULL; 00114 } 00115 00116 }