StdAir Logo  0.43.0
C++ Standard Airline IT Library
FacSupervisor.cpp
Go to the documentation of this file.
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     cleanBomLayer();
00029     cleanServiceLayer();
00030   }
00031 
00032   // //////////////////////////////////////////////////////////////////////
00033   void FacSupervisor::registerBomFactory (FacAbstract* ioFac_ptr) {
00034     _bomPool.push_back (ioFac_ptr);
00035   }
00036 
00037   // //////////////////////////////////////////////////////////////////////
00038   void FacSupervisor::registerServiceFactory (FacServiceAbstract* ioFac_ptr) {
00039     _svcPool.push_back (ioFac_ptr);
00040   }
00041 
00042   // //////////////////////////////////////////////////////////////////////
00043   void FacSupervisor::cleanBomLayer() {
00044     for (BomFactoryPool_T::const_iterator itFactory = _bomPool.begin();
00045          itFactory != _bomPool.end(); itFactory++) {
00046       const FacAbstract* currentFactory_ptr = *itFactory;
00047       assert (currentFactory_ptr != NULL);
00048 
00049       delete (currentFactory_ptr); currentFactory_ptr = NULL;
00050     }
00051 
00052     // Empty the pool of BOM factories
00053     _bomPool.clear();
00054   }
00055 
00056   // //////////////////////////////////////////////////////////////////////
00057   void FacSupervisor::cleanServiceLayer() {
00058     for (ServiceFactoryPool_T::const_iterator itFactory = _svcPool.begin();
00059          itFactory != _svcPool.end(); itFactory++) {
00060       const FacServiceAbstract* currentFactory_ptr = *itFactory;
00061       assert (currentFactory_ptr != NULL);
00062       
00063       delete (currentFactory_ptr); currentFactory_ptr = NULL;
00064     }
00065     
00066     // Empty the pool of Service Factories
00067     _svcPool.clear();
00068   }
00069 
00070   // //////////////////////////////////////////////////////////////////////
00071   void FacSupervisor::cleanLoggerService() {
00072     // Clean the static instance of the log service
00073     Logger::clean();
00074   }
00075 
00076   // //////////////////////////////////////////////////////////////////////
00077   void FacSupervisor::cleanDBSessionManager() {
00078     // Clean the static instance of the database service
00079     DBSessionManager::clean();
00080   }
00081   
00082   // //////////////////////////////////////////////////////////////////////
00083   void FacSupervisor::cleanAll() {
00084 
00085     // Clean the static instance of the database session manager
00086     cleanDBSessionManager();
00087 
00088     // Clean the static instance of the log service
00089     cleanLoggerService();
00090 
00091     // Clean the static instance of the FacSupervisor.
00092     // This in turn will invoke the destructor (~FacSupervisor() method)
00093     // of the static instance, thus cleaning both the BOM and service layers.
00094     delete _instance; _instance = NULL;
00095   }
00096 
00097 }