SEvMgr Logo  0.2.0
C++ Simulation-Oriented Discrete Event Management Library
SEVMGR_Service.cpp
Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 #include <sstream>
00007 // Boost
00008 #include <boost/make_shared.hpp>
00009 // StdAir
00010 #include <stdair/basic/BasChronometer.hpp>
00011 #include <stdair/basic/BasConst_General.hpp>
00012 #include <stdair/bom/BomRoot.hpp>
00013 #include <stdair/bom/BomDisplay.hpp>
00014 #include <stdair/bom/EventStruct.hpp>
00015 #include <stdair/bom/EventQueue.hpp>
00016 #include <stdair/service/Logger.hpp>
00017 #include <stdair/STDAIR_Service.hpp>
00018 // Sevmgr
00019 #include <sevmgr/basic/BasConst_SEVMGR_Service.hpp>
00020 #include <sevmgr/factory/FacSEVMGRServiceContext.hpp>
00021 #include <sevmgr/command/EventQueueManager.hpp>
00022 #include <sevmgr/service/SEVMGR_ServiceContext.hpp>
00023 #include <sevmgr/SEVMGR_Service.hpp>
00024 
00025 namespace SEVMGR {
00026 
00027   // //////////////////////////////////////////////////////////////////////
00028   SEVMGR_Service::SEVMGR_Service() : _sevmgrServiceContext (NULL) {
00029     assert (false);
00030   }
00031 
00032   // //////////////////////////////////////////////////////////////////////
00033   SEVMGR_Service::SEVMGR_Service (const SEVMGR_Service& iService) 
00034     : _sevmgrServiceContext (NULL) {
00035     assert (false);
00036   }
00037 
00038   // //////////////////////////////////////////////////////////////////////
00039   SEVMGR_Service::SEVMGR_Service (const stdair::BasLogParams& iLogParams,
00040                                   const stdair::BasDBParams& iDBParams)
00041     : _sevmgrServiceContext (NULL) {
00042     
00043     // Initialise the STDAIR service handler
00044     stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
00045       initStdAirService (iLogParams, iDBParams);
00046     
00047     // Initialise the service context
00048     initServiceContext();
00049 
00050     // Add the StdAir service context to the SEVMGR service context
00051     // \note SEVMGR owns the STDAIR service resources here.
00052     const bool ownStdairService = true;
00053     addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
00054 
00055     // Initialise the (remaining of the) context
00056     initSevmgrService();
00057   }
00058 
00059   // //////////////////////////////////////////////////////////////////////
00060   SEVMGR_Service::SEVMGR_Service (const stdair::BasLogParams& iLogParams)
00061     : _sevmgrServiceContext (NULL) {
00062     
00063     // Initialise the STDAIR service handler
00064     stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
00065       initStdAirService (iLogParams);
00066     
00067     // Initialise the service context
00068     initServiceContext();
00069 
00070     // Add the StdAir service context to the SEVMGR service context
00071     // \note SEVMGR owns the STDAIR service resources here.
00072     const bool ownStdairService = true;
00073     addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
00074 
00075     // Initialise the (remaining of the) context
00076     initSevmgrService();
00077   }
00078 
00079   // ////////////////////////////////////////////////////////////////////
00080   SEVMGR_Service::
00081   SEVMGR_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr)
00082     : _sevmgrServiceContext (NULL) {
00083 
00084     // Initialise the service context
00085     initServiceContext();
00086 
00087     // Add the StdAir service context to the SEVMGR service context
00088     // \note Sevmgr does not own the STDAIR service resources here.
00089     const bool doesNotOwnStdairService = false;
00090     addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
00091 
00092     // Initialise the context
00093     initSevmgrService();
00094   }
00095 
00096   // //////////////////////////////////////////////////////////////////////
00097   SEVMGR_Service::~SEVMGR_Service() {
00098     // Delete/Clean all the objects from memory
00099     finalise();
00100   }
00101 
00102   // ////////////////////////////////////////////////////////////////////
00103   void SEVMGR_Service::finalise() {
00104     assert (_sevmgrServiceContext != NULL);
00105     // Reset the (Boost.)Smart pointer pointing on the STDAIR_Service object.
00106     _sevmgrServiceContext->reset();
00107   }
00108 
00109   // //////////////////////////////////////////////////////////////////////
00110   void SEVMGR_Service::initServiceContext() {
00111     // Initialise the service context
00112     SEVMGR_ServiceContext& lSEVMGR_ServiceContext = 
00113       FacSEVMGRServiceContext::instance().create();
00114     _sevmgrServiceContext = &lSEVMGR_ServiceContext;
00115   }
00116 
00117   // ////////////////////////////////////////////////////////////////////
00118   void SEVMGR_Service::
00119   addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
00120                     const bool iOwnStdairService) {
00121     // Retrieve the Sevmgr service context
00122     assert (_sevmgrServiceContext != NULL);
00123     SEVMGR_ServiceContext& lSEVMGR_ServiceContext =
00124       *_sevmgrServiceContext;
00125 
00126     // Store the STDAIR service object within the (SEVMGR) service context
00127     lSEVMGR_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
00128                                               iOwnStdairService);
00129   }
00130   
00131   // //////////////////////////////////////////////////////////////////////
00132   stdair::STDAIR_ServicePtr_T SEVMGR_Service::
00133   initStdAirService (const stdair::BasLogParams& iLogParams,
00134                      const stdair::BasDBParams& iDBParams) {
00135 
00141     stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = 
00142       boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
00143     assert (lSTDAIR_Service_ptr != NULL);
00144 
00145     return lSTDAIR_Service_ptr;
00146   }
00147   
00148   // //////////////////////////////////////////////////////////////////////
00149   stdair::STDAIR_ServicePtr_T SEVMGR_Service::
00150   initStdAirService (const stdair::BasLogParams& iLogParams) {
00151 
00157     stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = 
00158       boost::make_shared<stdair::STDAIR_Service> (iLogParams);
00159     assert (lSTDAIR_Service_ptr != NULL);
00160 
00161     return lSTDAIR_Service_ptr;
00162   }
00163   
00164   // //////////////////////////////////////////////////////////////////////
00165   void SEVMGR_Service::initSevmgrService() {
00166     // Do nothing at this stage. A sample BOM tree may be built by
00167     // calling the buildSampleBom() method
00168   }
00169 
00170   // ////////////////////////////////////////////////////////////////////
00171   void SEVMGR_Service::buildSampleBom() {
00172 
00173     // Retrieve the Sevmgr service context
00174     if (_sevmgrServiceContext == NULL) {
00175       throw stdair::NonInitialisedServiceException ("The Sevmgr service has "
00176                                                     "not been initialised");
00177     }
00178     assert (_sevmgrServiceContext != NULL);
00179 
00180     //SEVMGR_ServiceContext& lSEVMGR_ServiceContext = *_sevmgrServiceContext;
00181 
00182     // Retrieve the STDAIR service object from the (Sevmgr) service context
00183     //stdair::STDAIR_Service& lSTDAIR_Service =
00184     // lSEVMGR_ServiceContext.getSTDAIR_Service();
00185 
00186     // Retrieve the event queue
00187     //stdair::EventQueue& lEventQueue = lSTDAIR_Service.getEventQueue();
00188   }
00189 
00190   // //////////////////////////////////////////////////////////////////////
00191   std::string SEVMGR_Service::csvDisplay() const {
00192 
00193     // Retrieve the Sevmgr service context
00194     if (_sevmgrServiceContext == NULL) {
00195       throw stdair::NonInitialisedServiceException ("The Sevmgr service has "
00196                                                     "not been initialised");
00197     }
00198     assert (_sevmgrServiceContext != NULL);
00199 
00200     SEVMGR_ServiceContext& lSEVMGR_ServiceContext = *_sevmgrServiceContext;
00201 
00202     // Retrieve the STDAIR service object from the (Sevmgr) service context
00203     stdair::STDAIR_Service& lSTDAIR_Service =
00204       lSEVMGR_ServiceContext.getSTDAIR_Service();
00205 
00206     // Retrieve the event queue
00207     stdair::EventQueue& lEventQueue = lSTDAIR_Service.getEventQueue();
00208 
00209     // Delegate the BOM building to the dedicated service
00210     return stdair::BomDisplay::csvDisplay (lEventQueue);
00211   }
00212 
00213   // ////////////////////////////////////////////////////////////////////
00214   stdair::ProgressStatusSet SEVMGR_Service::
00215   popEvent (stdair::EventStruct& ioEventStruct) const {
00216 
00217     // Retrieve the Sevmgr service context
00218     assert (_sevmgrServiceContext != NULL);
00219     SEVMGR_ServiceContext& lSEVMGR_ServiceContext = *_sevmgrServiceContext;
00220 
00221     // Retrieve the StdAir service context
00222     stdair::STDAIR_Service& lSTDAIR_Service =
00223       lSEVMGR_ServiceContext.getSTDAIR_Service();
00224 
00225     // Retrieve the event queue object instance
00226     stdair::EventQueue& lQueue = lSTDAIR_Service.getEventQueue();
00227     
00228     // Extract the next event from the queue
00229     return lQueue.popEvent (ioEventStruct);
00230   }
00231 
00232   // ////////////////////////////////////////////////////////////////////
00233   bool SEVMGR_Service::isQueueDone() const {
00234 
00235     // Retrieve the Sevmgr service context
00236     assert (_sevmgrServiceContext != NULL);
00237     SEVMGR_ServiceContext& lSEVMGR_ServiceContext =
00238       *_sevmgrServiceContext;
00239 
00240     // Retrieve the StdAir service context
00241     stdair::STDAIR_Service& lSTDAIR_Service =
00242       lSEVMGR_ServiceContext.getSTDAIR_Service();
00243 
00244     // Retrieve the event queue object instance
00245     const stdair::EventQueue& lQueue = lSTDAIR_Service.getEventQueue();
00246     
00247     // Calculates whether the event queue has been fully emptied
00248     const bool isQueueDone = lQueue.isQueueDone();
00249 
00250     //
00251     return isQueueDone;
00252   }
00253 
00254   // ////////////////////////////////////////////////////////////////////
00255   void SEVMGR_Service::reset() const {
00256 
00257     // Retrieve the Sevmgr service context
00258     assert (_sevmgrServiceContext != NULL);
00259     SEVMGR_ServiceContext& lSEVMGR_ServiceContext =
00260       *_sevmgrServiceContext;
00261 
00262     // Retrieve the StdAir service context
00263     stdair::STDAIR_Service& lSTDAIR_Service =
00264       lSEVMGR_ServiceContext.getSTDAIR_Service();
00265     // Retrieve the event queue object instance
00266     stdair::EventQueue& lQueue = lSTDAIR_Service.getEventQueue();
00267     
00268     // Delegate the call to the dedicated command
00269     EventQueueManager::reset (lQueue);
00270   }
00271 }
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines