$treeview $search $mathjax
SimCRS Logo  1.00.0
$projectbrief
$projectbrief
$searchbox

SIMCRS_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 // Standard Airline Object Model
00010 #include <stdair/stdair_exceptions.hpp>
00011 #include <stdair/stdair_basic_types.hpp>
00012 #include <stdair/stdair_json.hpp>
00013 #include <stdair/basic/BasChronometer.hpp>
00014 #include <stdair/basic/BasFileMgr.hpp>
00015 #include <stdair/bom/BomManager.hpp> 
00016 #include <stdair/bom/BookingRequestStruct.hpp>
00017 #include <stdair/bom/TravelSolutionStruct.hpp>
00018 #include <stdair/bom/CancellationStruct.hpp>
00019 #include <stdair/bom/BomRoot.hpp>
00020 #include <stdair/bom/Inventory.hpp>
00021 #include <stdair/service/Logger.hpp>
00022 #include <stdair/STDAIR_Service.hpp>
00023 // SEvMgr
00024 #include <sevmgr/SEVMGR_Service.hpp>
00025 // Airline Inventory
00026 #include <airinv/AIRINV_Master_Service.hpp>
00027 // Airline Schedule
00028 #include <airsched/AIRSCHED_Service.hpp>
00029 // Fare Quote
00030 #include <simfqt/SIMFQT_Service.hpp>
00031 // SimCRS
00032 #include <simcrs/basic/BasConst_SIMCRS_Service.hpp>
00033 #include <simcrs/command/DistributionManager.hpp>
00034 #include <simcrs/factory/FacSimcrsServiceContext.hpp>
00035 #include <simcrs/service/SIMCRS_ServiceContext.hpp>
00036 #include <simcrs/SIMCRS_Service.hpp>
00037 
00038 namespace SIMCRS {
00039 
00040   // ////////////////////////////////////////////////////////////////////
00041   SIMCRS_Service::SIMCRS_Service() : _simcrsServiceContext (NULL) {
00042     assert (false);
00043   }
00044 
00045   // ////////////////////////////////////////////////////////////////////
00046   SIMCRS_Service::SIMCRS_Service (const SIMCRS_Service& iService) {
00047     assert (false);
00048   }
00049 
00050   // ////////////////////////////////////////////////////////////////////
00051   SIMCRS_Service::SIMCRS_Service (const stdair::BasLogParams& iLogParams,
00052                                   const CRSCode_T& iCRSCode)
00053     : _simcrsServiceContext (NULL) {
00054     
00055     // Initialise the StdAir service handler
00056     stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
00057       initStdAirService (iLogParams);
00058     
00059     // Initialise the service context
00060     initServiceContext (iCRSCode);
00061     
00062     // Add the StdAir service context to the SimCRS service context
00063     // \note SIMCRS owns the STDAIR service resources here.
00064     const bool ownStdairService = true;
00065     addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
00066 
00067     // Initalise the SimFQT service.
00068     initSIMFQTService();
00069     
00070     // Initalise the AirSched service.
00071     initAIRSCHEDService();
00072     
00073     // Initalise the AirInv service.
00074     initAIRINVService();
00075     
00076     // Initialise the (remaining of the) context
00077     initSimcrsService();
00078   }
00079 
00080   // ////////////////////////////////////////////////////////////////////
00081   SIMCRS_Service::SIMCRS_Service (const stdair::BasLogParams& iLogParams,
00082                                   const stdair::BasDBParams& iDBParams,
00083                                   const CRSCode_T& iCRSCode)
00084     : _simcrsServiceContext (NULL) {
00085     
00086     // Initialise the STDAIR service handler
00087     stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
00088       initStdAirService (iLogParams, iDBParams);
00089     
00090     // Initialise the service context
00091     initServiceContext (iCRSCode);
00092     
00093     // Add the StdAir service context to the SIMCRS service context
00094     // \note SIMCRS owns the STDAIR service resources here.
00095     const bool ownStdairService = true;
00096     addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
00097 
00098     // Initalise the SIMFQT service.
00099     initSIMFQTService();
00100     
00101     // Initalise the AIRSCHED service.
00102     initAIRSCHEDService();
00103     
00104     // Initalise the AIRINV service.
00105     initAIRINVService();
00106     
00107     // Initialise the (remaining of the) context
00108     initSimcrsService();
00109   }
00110 
00111   // ////////////////////////////////////////////////////////////////////
00112   SIMCRS_Service::
00113   SIMCRS_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
00114                   SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_Service_ptr,
00115                   const CRSCode_T& iCRSCode)
00116     : _simcrsServiceContext (NULL) {
00117 
00118     // Initialise the service context
00119     initServiceContext (iCRSCode);
00120 
00121     // Store the STDAIR service object within the (AIRINV) service context
00122     // \note AirInv does not own the STDAIR service resources here.
00123     const bool doesNotOwnStdairService = false;
00124     addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService); 
00125 
00126     //Add the SEvMgr service to the TRADEMGEN service context. 
00127     const bool doesNotOwnSEVMGRService = false;
00128     addSEVMGRService (ioSEVMGR_Service_ptr, doesNotOwnSEVMGRService);
00129 
00130     // Initalise the SIMFQT service.
00131     initSIMFQTService();
00132     
00133     // Initalise the AIRSCHED service.
00134     initAIRSCHEDService();
00135     
00136     // Initalise the AIRINV service.
00137     initAIRINVService();
00138     
00139     // Initialise the (remaining of the) context
00140     initSimcrsService();
00141   }
00142 
00143   // ////////////////////////////////////////////////////////////////////
00144   SIMCRS_Service::~SIMCRS_Service() {
00145     // Delete/Clean all the objects from memory
00146     finalise();
00147   }
00148 
00149   // ////////////////////////////////////////////////////////////////////
00150   void SIMCRS_Service::finalise() {
00151     assert (_simcrsServiceContext != NULL);
00152     // Reset the (Boost.)Smart pointer pointing on the STDAIR_Service object.
00153     _simcrsServiceContext->reset();
00154   }
00155 
00156   // ////////////////////////////////////////////////////////////////////
00157   void SIMCRS_Service::initServiceContext (const CRSCode_T& iCRSCode) {
00158     // Initialise the service context
00159     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = 
00160       FacSimcrsServiceContext::instance().create (iCRSCode);
00161     _simcrsServiceContext = &lSIMCRS_ServiceContext;
00162   }
00163 
00164   // ////////////////////////////////////////////////////////////////////
00165   void SIMCRS_Service::
00166   addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
00167                     const bool iOwnStdairService) {
00168 
00169     // Retrieve the SimCRS service context
00170     assert (_simcrsServiceContext != NULL);
00171     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00172 
00173     // Store the StdAir service object within the (SimCRS) service context
00174     lSIMCRS_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
00175                                               iOwnStdairService);
00176   }  
00177 
00178   // ////////////////////////////////////////////////////////////////////
00179   void SIMCRS_Service::
00180   addSEVMGRService (SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_Service_ptr,
00181                     const bool iOwnSEVMGRService) {
00182 
00183     // Retrieve the SimCRS service context
00184     assert (_simcrsServiceContext != NULL);
00185     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00186 
00187     // Store the STDAIR service object within the (TRADEMGEN) service context
00188     lSIMCRS_ServiceContext.setSEVMGR_Service (ioSEVMGR_Service_ptr,
00189                                               iOwnSEVMGRService);
00190   }
00191   
00192   // ////////////////////////////////////////////////////////////////////
00193   stdair::STDAIR_ServicePtr_T SIMCRS_Service::
00194   initStdAirService (const stdair::BasLogParams& iLogParams) {
00195 
00203     stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = 
00204       boost::make_shared<stdair::STDAIR_Service> (iLogParams);
00205 
00206     return lSTDAIR_Service_ptr;
00207   }
00208   
00209   // ////////////////////////////////////////////////////////////////////
00210   stdair::STDAIR_ServicePtr_T SIMCRS_Service::
00211   initStdAirService (const stdair::BasLogParams& iLogParams,
00212                      const stdair::BasDBParams& iDBParams) {
00213 
00221     stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = 
00222       boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
00223     
00224     return lSTDAIR_Service_ptr;
00225   }
00226   
00227   // ////////////////////////////////////////////////////////////////////
00228   void SIMCRS_Service::initAIRSCHEDService() {
00229 
00230     // Retrieve the SimCRS service context
00231     assert (_simcrsServiceContext != NULL);
00232     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00233 
00234     // Retrieve the StdAir service context
00235     stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
00236       lSIMCRS_ServiceContext.getSTDAIR_ServicePtr();
00237 
00245     AIRSCHED::AIRSCHED_ServicePtr_T lAIRSCHED_Service_ptr = 
00246       boost::make_shared<AIRSCHED::AIRSCHED_Service> (lSTDAIR_Service_ptr);
00247     
00248     // Store the AIRSCHED service object within the (SimCRS) service context
00249     lSIMCRS_ServiceContext.setAIRSCHED_Service (lAIRSCHED_Service_ptr);
00250   }
00251   
00252   // ////////////////////////////////////////////////////////////////////
00253   void SIMCRS_Service::initSIMFQTService() {
00254 
00255     // Retrieve the SimCRS service context
00256     assert (_simcrsServiceContext != NULL);
00257     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00258 
00259     // Retrieve the StdAir service context
00260     stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
00261       lSIMCRS_ServiceContext.getSTDAIR_ServicePtr();
00262 
00270     SIMFQT::SIMFQT_ServicePtr_T lSIMFQT_Service_ptr = 
00271       boost::make_shared<SIMFQT::SIMFQT_Service> (lSTDAIR_Service_ptr);
00272     
00273     // Store the SIMFQT service object within the (SimCRS) service context
00274     lSIMCRS_ServiceContext.setSIMFQT_Service (lSIMFQT_Service_ptr);
00275   }
00276   
00277   // ////////////////////////////////////////////////////////////////////
00278   void SIMCRS_Service::initAIRINVService() {
00279 
00280     // Retrieve the SimCRS service context
00281     assert (_simcrsServiceContext != NULL);
00282     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00283 
00284     // Retrieve the StdAir service context
00285     stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
00286       lSIMCRS_ServiceContext.getSTDAIR_ServicePtr(); 
00287 
00295     AIRINV::AIRINV_Master_ServicePtr_T lAIRINV_Master_Service_ptr;
00296     const bool ownSEVMGRService = 
00297       lSIMCRS_ServiceContext.getOwnSEVMGRServiceFlag();
00298     if (ownSEVMGRService == false) { 
00299       // Retrieve the SEVMGR service
00300       SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
00301         lSIMCRS_ServiceContext.getSEVMGR_ServicePtr();
00302       assert (lSEVMGR_Service_ptr != NULL);
00303       lAIRINV_Master_Service_ptr = 
00304         boost::make_shared<AIRINV::AIRINV_Master_Service> (lSTDAIR_Service_ptr, 
00305                                                            lSEVMGR_Service_ptr);
00306     } else {
00307       lAIRINV_Master_Service_ptr = 
00308         boost::make_shared<AIRINV::AIRINV_Master_Service> (lSTDAIR_Service_ptr);
00309     }
00310     assert (lAIRINV_Master_Service_ptr != NULL);
00311     
00312     // Store the AIRINV service object within the (SimCRS) service context
00313     lSIMCRS_ServiceContext.setAIRINV_Service (lAIRINV_Master_Service_ptr);
00314   }
00315   
00316   // ////////////////////////////////////////////////////////////////////
00317   void SIMCRS_Service::initSimcrsService() {
00318     // Do nothing at this stage. A sample BOM tree may be built by
00319     // calling the buildSampleBom() method
00320   }
00321 
00322   // ////////////////////////////////////////////////////////////////////
00323   void SIMCRS_Service::
00324   parseAndLoad (const stdair::ScheduleFilePath& iScheduleInputFilepath,
00325                 const stdair::ODFilePath& iODInputFilepath,
00326                 const stdair::FRAT5FilePath& iFRAT5InputFilepath,
00327                 const stdair::FFDisutilityFilePath& iFFDisutilityInputFilepath,
00328                 const AIRRAC::YieldFilePath& iYieldInputFilepath,
00329                 const SIMFQT::FareFilePath& iFareInputFilepath) {
00330  
00331     // Retrieve the SimCRS service context
00332     if (_simcrsServiceContext == NULL) {
00333       throw stdair::NonInitialisedServiceException ("The SimCRS service "
00334                                                     "has not been initialised");
00335     }
00336     assert (_simcrsServiceContext != NULL);
00337 
00338     // Retrieve the SimCRS service context and whether it owns the Stdair
00339     // service
00340     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00341     const bool doesOwnStdairService =
00342       lSIMCRS_ServiceContext.getOwnStdairServiceFlag(); 
00343 
00344     // Retrieve the StdAir service object from the (SimCRS) service context
00345     stdair::STDAIR_Service& lSTDAIR_Service =
00346       lSIMCRS_ServiceContext.getSTDAIR_Service();
00347 
00348     // Retrieve the persistent BOM root object.
00349     stdair::BomRoot& lPersistentBomRoot = 
00350       lSTDAIR_Service.getPersistentBomRoot();
00351 
00361     AIRSCHED::AIRSCHED_Service& lAIRSCHED_Service =
00362       lSIMCRS_ServiceContext.getAIRSCHED_Service();
00363     lAIRSCHED_Service.parseAndLoad (iScheduleInputFilepath);
00364 
00371     AIRINV::AIRINV_Master_Service& lAIRINV_Service =
00372       lSIMCRS_ServiceContext.getAIRINV_Service();
00373     lAIRINV_Service.parseAndLoad (iScheduleInputFilepath, iODInputFilepath,
00374                                   iFRAT5InputFilepath,
00375                                   iFFDisutilityInputFilepath,
00376                                   iYieldInputFilepath);
00377 
00381     SIMFQT::SIMFQT_Service& lSIMFQT_Service =
00382       lSIMCRS_ServiceContext.getSIMFQT_Service();
00383     lSIMFQT_Service.parseAndLoad (iFareInputFilepath); 
00384 
00389     buildComplementaryLinks (lPersistentBomRoot);  
00390     
00395     if (doesOwnStdairService == true) {
00396       //
00397       clonePersistentBom ();
00398     }
00399   }
00400   
00401   // ////////////////////////////////////////////////////////////////////
00402   void SIMCRS_Service::buildSampleBom() {
00403 
00404     // Retrieve the SimCRS service context
00405     if (_simcrsServiceContext == NULL) {
00406       throw stdair::NonInitialisedServiceException ("The SimCRS service "
00407                                                     "has not been initialised");
00408     }
00409     assert (_simcrsServiceContext != NULL);
00410 
00411     // Retrieve the SimCRS service context and whether it owns the Stdair
00412     // service
00413     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00414     const bool doesOwnStdairService =
00415       lSIMCRS_ServiceContext.getOwnStdairServiceFlag();
00416 
00417     // Retrieve the StdAir service object from the (SimCRS) service context
00418     stdair::STDAIR_Service& lSTDAIR_Service =
00419       lSIMCRS_ServiceContext.getSTDAIR_Service();
00420 
00421     // Retrieve the persistent BOM root object.
00422     stdair::BomRoot& lPersistentBomRoot = 
00423       lSTDAIR_Service.getPersistentBomRoot();
00424 
00429     if (doesOwnStdairService == true) {
00430       //
00431       lSTDAIR_Service.buildSampleBom();
00432     }
00433 
00443     AIRSCHED::AIRSCHED_Service& lAIRSCHED_Service =
00444       lSIMCRS_ServiceContext.getAIRSCHED_Service();
00445     lAIRSCHED_Service.buildSampleBom();
00446 
00453     AIRINV::AIRINV_Master_Service& lAIRINV_Service =
00454       lSIMCRS_ServiceContext.getAIRINV_Service();
00455     lAIRINV_Service.buildSampleBom();
00456 
00460     SIMFQT::SIMFQT_Service& lSIMFQT_Service =
00461       lSIMCRS_ServiceContext.getSIMFQT_Service();
00462     lSIMFQT_Service.buildSampleBom();
00463 
00468     buildComplementaryLinks (lPersistentBomRoot);
00469 
00474     if (doesOwnStdairService == true) {
00475       //
00476       clonePersistentBom ();
00477     }
00478   } 
00479 
00480   // ////////////////////////////////////////////////////////////////////
00481   void SIMCRS_Service::clonePersistentBom () {   
00482 
00483     // Retrieve the SimCRS service context
00484     if (_simcrsServiceContext == NULL) {
00485       throw stdair::NonInitialisedServiceException ("The SimCRS service "
00486                                                     "has not been initialised");
00487     }
00488     assert (_simcrsServiceContext != NULL);
00489 
00490     // Retrieve the SimCRS service context and whether it owns the Stdair
00491     // service
00492     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00493     const bool doesOwnStdairService =
00494       lSIMCRS_ServiceContext.getOwnStdairServiceFlag();
00495 
00496     // Retrieve the StdAir service object from the (SimCRS) service context
00497     stdair::STDAIR_Service& lSTDAIR_Service =
00498       lSIMCRS_ServiceContext.getSTDAIR_Service();
00499  
00504     if (doesOwnStdairService == true) {
00505       //
00506       lSTDAIR_Service.clonePersistentBom ();
00507     } 
00508 
00518     AIRSCHED::AIRSCHED_Service& lAIRSCHED_Service =
00519       lSIMCRS_ServiceContext.getAIRSCHED_Service();
00520     lAIRSCHED_Service.clonePersistentBom ();
00521 
00528     AIRINV::AIRINV_Master_Service& lAIRINV_Service =
00529       lSIMCRS_ServiceContext.getAIRINV_Service();
00530     lAIRINV_Service.clonePersistentBom ();
00531 
00535     SIMFQT::SIMFQT_Service& lSIMFQT_Service =
00536       lSIMCRS_ServiceContext.getSIMFQT_Service();
00537     lSIMFQT_Service.clonePersistentBom ();    
00538   
00543     stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
00544     buildComplementaryLinks (lBomRoot);
00545   }
00546 
00547   // ////////////////////////////////////////////////////////////////////
00548   void SIMCRS_Service::buildComplementaryLinks (stdair::BomRoot& ioBomRoot) {
00549     // Currently, no more things to do by TravelCCM at that stage.
00550   }
00551 
00552   // //////////////////////////////////////////////////////////////////////
00553   void SIMCRS_Service::
00554   buildSampleTravelSolutions(stdair::TravelSolutionList_T& ioTravelSolutionList){
00555 
00556     // Retrieve the SimCRS service context
00557     if (_simcrsServiceContext == NULL) {
00558       throw stdair::NonInitialisedServiceException ("The SimCRS service "
00559                                                     "has not been initialised");
00560     }
00561     assert (_simcrsServiceContext != NULL);
00562 
00563     // Retrieve the StdAir service object from the (SimCRS) service context
00564     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00565     stdair::STDAIR_Service& lSTDAIR_Service =
00566       lSIMCRS_ServiceContext.getSTDAIR_Service();
00567 
00568     // Delegate the BOM building to the dedicated service
00569     lSTDAIR_Service.buildSampleTravelSolutions (ioTravelSolutionList);
00570   }
00571 
00572   // //////////////////////////////////////////////////////////////////////
00573   stdair::BookingRequestStruct SIMCRS_Service::
00574   buildSampleBookingRequest (const bool isForCRS) {
00575 
00576     // Retrieve the SimCRS service context
00577     if (_simcrsServiceContext == NULL) {
00578       throw stdair::NonInitialisedServiceException ("The SimCRS service "
00579                                                     "has not been initialised");
00580     }
00581     assert (_simcrsServiceContext != NULL);
00582 
00583     // Retrieve the StdAir service object from the (SimCRS) service context
00584     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00585     stdair::STDAIR_Service& lSTDAIR_Service =
00586       lSIMCRS_ServiceContext.getSTDAIR_Service();
00587 
00588     // Delegate the BOM building to the dedicated service
00589     return lSTDAIR_Service.buildSampleBookingRequest (isForCRS);
00590   }
00591 
00592   // ////////////////////////////////////////////////////////////////////
00593   bool SIMCRS_Service::sell (const std::string& iSegmentDateKey,
00594                              const stdair::ClassCode_T& iClassCode,
00595                              const stdair::PartySize_T& iPartySize) {
00596 
00597     // Retrieve the SimCRS service context
00598     if (_simcrsServiceContext == NULL) {
00599       throw stdair::NonInitialisedServiceException ("The SimCRS service "
00600                                                     "has not been initialised");
00601     }
00602     assert (_simcrsServiceContext != NULL);
00603     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00604 
00605     // Retrieve the AIRINV Master service.
00606     AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
00607       lSIMCRS_ServiceContext.getAIRINV_Service();
00608 
00609     return lAIRINV_Master_Service.sell (iSegmentDateKey, iClassCode,
00610                                         iPartySize);
00611   }
00612 
00613   // ////////////////////////////////////////////////////////////////////
00614   std::string SIMCRS_Service::
00615   jsonHandler (const stdair::JSONString& iJSONString) const {
00616 
00617     // Retrieve the SimCRS service context
00618     if (_simcrsServiceContext == NULL) {
00619       throw stdair::NonInitialisedServiceException ("The SimCRS service "
00620                                                     "has not been initialised");
00621     }
00622     assert (_simcrsServiceContext != NULL);
00623     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00624 
00625     // Retrieve the AIRINV Master service.
00626     AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
00627       lSIMCRS_ServiceContext.getAIRINV_Service();
00628 
00629     return lAIRINV_Master_Service.jsonHandler (iJSONString);
00630     
00631   }
00632 
00633   // ////////////////////////////////////////////////////////////////////
00634   void SIMCRS_Service::
00635   initSnapshotAndRMEvents (const stdair::Date_T& iStartDate,
00636                            const stdair::Date_T& iEndDate) {
00637 
00638     // Retrieve the SimCRS service context
00639     if (_simcrsServiceContext == NULL) {
00640       throw stdair::NonInitialisedServiceException ("The SimCRS service has "
00641                                                     "not been initialised");
00642     }
00643     assert (_simcrsServiceContext != NULL);
00644     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00645 
00646     // Retrieve the AIRINV Master service.
00647     AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
00648       lSIMCRS_ServiceContext.getAIRINV_Service();
00649 
00650     lAIRINV_Master_Service.initSnapshotAndRMEvents (iStartDate, iEndDate);
00651   }
00652   
00653   // //////////////////////////////////////////////////////////////////////
00654   std::string SIMCRS_Service::csvDisplay() const {
00655 
00656     // Retrieve the SimCRS service context
00657     if (_simcrsServiceContext == NULL) {
00658       throw stdair::NonInitialisedServiceException ("The SimCRS service "
00659                                                     "has not been initialised");
00660     }
00661     assert (_simcrsServiceContext != NULL);
00662 
00663     // Retrieve the StdAir service object from the (SimCRS) service context
00664     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00665     stdair::STDAIR_Service& lSTDAIR_Service =
00666       lSIMCRS_ServiceContext.getSTDAIR_Service(); 
00667     const stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
00668 
00669     // Delegate the BOM building to the dedicated service
00670     return lSTDAIR_Service.csvDisplay(lBomRoot);
00671   }
00672   
00673   // //////////////////////////////////////////////////////////////////////
00674   std::string SIMCRS_Service::
00675   csvDisplay (const stdair::TravelSolutionList_T& ioTravelSolutionList) const {
00676 
00677     // Retrieve the SimCRS service context
00678     if (_simcrsServiceContext == NULL) {
00679       throw stdair::NonInitialisedServiceException ("The SimCRS service "
00680                                                     "has not been initialised");
00681     }
00682     assert (_simcrsServiceContext != NULL);
00683 
00684     // Retrieve the StdAir service object from the (SimCRS) service context
00685     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00686     stdair::STDAIR_Service& lSTDAIR_Service =
00687       lSIMCRS_ServiceContext.getSTDAIR_Service();
00688 
00689     // Delegate the BOM building to the dedicated service
00690     return lSTDAIR_Service.csvDisplay (ioTravelSolutionList);
00691   }
00692 
00693   // ////////////////////////////////////////////////////////////////////
00694   std::string SIMCRS_Service::
00695   list (const stdair::AirlineCode_T& iAirlineCode,
00696         const stdair::FlightNumber_T& iFlightNumber) const {
00697 
00698     // Retrieve the SimCRS service context
00699     if (_simcrsServiceContext == NULL) {
00700       throw stdair::NonInitialisedServiceException ("The SimCRS service has "
00701                                                     "not been initialised");
00702     }
00703     assert (_simcrsServiceContext != NULL);
00704     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00705 
00706     // Retrieve the AIRINV Master service.
00707     AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
00708       lSIMCRS_ServiceContext.getAIRINV_Service();
00709 
00710     // Delegate the BOM display to the dedicated service
00711     return lAIRINV_Master_Service.list (iAirlineCode, iFlightNumber);
00712   }
00713 
00714   // ////////////////////////////////////////////////////////////////////
00715   std::string SIMCRS_Service::
00716   csvDisplay (const stdair::AirlineCode_T& iAirlineCode,
00717               const stdair::FlightNumber_T& iFlightNumber,
00718               const stdair::Date_T& iDepartureDate) const {
00719 
00720     // Retrieve the SimCRS service context
00721     if (_simcrsServiceContext == NULL) {
00722       throw stdair::NonInitialisedServiceException ("The SimCRS service has "
00723                                                     "not been initialised");
00724     }
00725     assert (_simcrsServiceContext != NULL);
00726     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00727 
00728     // Retrieve the AIRINV Master service.
00729     AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
00730       lSIMCRS_ServiceContext.getAIRINV_Service();
00731 
00732     // Delegate the BOM display to the dedicated service
00733     return lAIRINV_Master_Service.csvDisplay (iAirlineCode, iFlightNumber,
00734                                               iDepartureDate);
00735   }
00736    
00737   // ////////////////////////////////////////////////////////////////////
00738   stdair::TravelSolutionList_T SIMCRS_Service::
00739   calculateSegmentPathList(const stdair::BookingRequestStruct& iBookingRequest){
00740      
00741     // Retrieve the SimCRS service context
00742     if (_simcrsServiceContext == NULL) {
00743       throw stdair::NonInitialisedServiceException ("The SimCRS service "
00744                                                     "has not been initialised");
00745     }
00746     assert (_simcrsServiceContext != NULL);
00747 
00748     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00749 
00750     stdair::TravelSolutionList_T oTravelSolutionList;
00751     
00752     // Get a reference on the AIRSCHED service handler
00753     AIRSCHED::AIRSCHED_Service& lAIRSCHED_Service =
00754       lSIMCRS_ServiceContext.getAIRSCHED_Service();
00755     
00756     // Delegate the booking to the dedicated service
00757     stdair::BasChronometer lTravelSolutionRetrievingChronometer;
00758     lTravelSolutionRetrievingChronometer.start();
00759 
00760     lAIRSCHED_Service.buildSegmentPathList (oTravelSolutionList,
00761                                             iBookingRequest);
00762       
00763     // DEBUG
00764     const double lSegmentPathRetrievingMeasure =
00765       lTravelSolutionRetrievingChronometer.elapsed();
00766     STDAIR_LOG_DEBUG ("Travel solution retrieving: "
00767                       << lSegmentPathRetrievingMeasure << " - "
00768                       << lSIMCRS_ServiceContext.display());
00769 
00770     return oTravelSolutionList;
00771   }
00772 
00773   // ////////////////////////////////////////////////////////////////////
00774   void SIMCRS_Service::
00775   fareQuote (const stdair::BookingRequestStruct& iBookingRequest,
00776              stdair::TravelSolutionList_T& ioTravelSolutionList) {
00777      
00778     // Retrieve the SimCRS service context
00779     if (_simcrsServiceContext == NULL) {
00780       throw stdair::NonInitialisedServiceException ("The SimCRS service has "
00781                                                     "not been initialised");
00782     }
00783     assert (_simcrsServiceContext != NULL);
00784     
00785     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00786     
00787     // Get a reference on the SIMFQT service handler
00788     SIMFQT::SIMFQT_Service& lSIMFQT_Service =
00789       lSIMCRS_ServiceContext.getSIMFQT_Service();
00790       
00791     // Delegate the action to the dedicated command
00792     stdair::BasChronometer lFareQuoteRetrievalChronometer;
00793     lFareQuoteRetrievalChronometer.start();
00794 
00795     lSIMFQT_Service.quotePrices (iBookingRequest, ioTravelSolutionList);
00796 
00797     // DEBUG
00798     const double lFareQuoteRetrievalMeasure =
00799       lFareQuoteRetrievalChronometer.elapsed();
00800     STDAIR_LOG_DEBUG ("Fare Quote retrieving: " << lFareQuoteRetrievalMeasure
00801                       << " - " << lSIMCRS_ServiceContext.display());
00802   }
00803 
00804   // ////////////////////////////////////////////////////////////////////
00805   void SIMCRS_Service::
00806   calculateAvailability (stdair::TravelSolutionList_T& ioTravelSolutionList) {
00807 
00808     // Retrieve the SimCRS service context
00809     if (_simcrsServiceContext == NULL) {
00810       throw stdair::NonInitialisedServiceException ("The SimCRS service has "
00811                                                     "not been initialised");
00812     }
00813     assert (_simcrsServiceContext != NULL);
00814     
00815     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00816 
00817     // Retrieve the CRS code
00818     //const CRSCode_T& lCRSCode = lSIMCRS_ServiceContext.getCRSCode();
00819 
00820     // Retrieve the AIRINV Master service.
00821     AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
00822       lSIMCRS_ServiceContext.getAIRINV_Service();
00823     
00824     // Delegate the availability retrieval to the dedicated command
00825     stdair::BasChronometer lAvlChronometer;
00826     lAvlChronometer.start();
00827 
00828     DistributionManager::calculateAvailability (lAIRINV_Master_Service,
00829                                                 ioTravelSolutionList);
00830     
00831     // DEBUG
00832     const double lAvlMeasure = lAvlChronometer.elapsed();
00833     STDAIR_LOG_DEBUG ("Availability retrieval: " << lAvlMeasure << " - "
00834                       << lSIMCRS_ServiceContext.display());
00835   }
00836   
00837   // ////////////////////////////////////////////////////////////////////
00838   bool SIMCRS_Service::
00839   sell (const stdair::TravelSolutionStruct& iTravelSolution,
00840         const stdair::PartySize_T& iPartySize) {
00841     bool hasSaleBeenSuccessful = false;
00842 
00843     // Retrieve the SimCRS service context
00844     if (_simcrsServiceContext == NULL) {
00845       throw stdair::NonInitialisedServiceException ("The SimCRS service has "
00846                                                     "not been initialised");
00847     }
00848     assert (_simcrsServiceContext != NULL);
00849     
00850     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00851 
00852     // Retrieve the CRS code
00853     //const CRSCode_T& lCRSCode = lSIMCRS_ServiceContext.getCRSCode();
00854 
00855     // Retrieve the AIRINV Master service.
00856     AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
00857       lSIMCRS_ServiceContext.getAIRINV_Service();
00858     
00859     // Delegate the booking to the dedicated command
00860     stdair::BasChronometer lSellChronometer;
00861     lSellChronometer.start();
00862 
00863     hasSaleBeenSuccessful = DistributionManager::sell (lAIRINV_Master_Service,
00864                                                        iTravelSolution,
00865                                                        iPartySize);
00866 
00867     // DEBUG
00868     STDAIR_LOG_DEBUG ("Made a sell of " << iPartySize
00869                       << " persons on the following travel solution: "
00870                       << iTravelSolution.describe()
00871                       << " with the chosen fare option: "
00872                       << iTravelSolution.getChosenFareOption().describe()
00873                       << ". Successful? " << hasSaleBeenSuccessful);
00874       
00875     // DEBUG
00876     const double lSellMeasure = lSellChronometer.elapsed();
00877     STDAIR_LOG_DEBUG ("Booking sell: " << lSellMeasure << " - "
00878                       << lSIMCRS_ServiceContext.display());
00879 
00880     return hasSaleBeenSuccessful;
00881   }
00882 
00883   
00884   // ////////////////////////////////////////////////////////////////////
00885   bool SIMCRS_Service::
00886   playCancellation (const stdair::CancellationStruct& iCancellation) {
00887     bool hasCancellationBeenSuccessful = false;
00888 
00889     // Retrieve the SimCRS service context
00890     if (_simcrsServiceContext == NULL) {
00891       throw stdair::NonInitialisedServiceException ("The SimCRS service has "
00892                                                     "not been initialised");
00893     }
00894     assert (_simcrsServiceContext != NULL);
00895     
00896     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00897 
00898     // Retrieve the CRS code
00899     //const CRSCode_T& lCRSCode = lSIMCRS_ServiceContext.getCRSCode();
00900 
00901     // Retrieve the AIRINV Master service.
00902     AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
00903       lSIMCRS_ServiceContext.getAIRINV_Service();
00904     
00905     // Delegate the booking to the dedicated command
00906     stdair::BasChronometer lCancellationChronometer;
00907     lCancellationChronometer.start();
00908 
00909     hasCancellationBeenSuccessful =
00910       DistributionManager::playCancellation (lAIRINV_Master_Service,
00911                                              iCancellation);
00912                                              
00913     // DEBUG
00914     STDAIR_LOG_DEBUG ("Made a cancellation of " << iCancellation.describe());
00915       
00916     // DEBUG
00917     const double lCancellationMeasure = lCancellationChronometer.elapsed();
00918     STDAIR_LOG_DEBUG ("Booking cancellation: " << lCancellationMeasure << " - "
00919                       << lSIMCRS_ServiceContext.display());
00920 
00921     return hasCancellationBeenSuccessful;
00922   }
00923   
00924   // ////////////////////////////////////////////////////////////////////
00925   void SIMCRS_Service::takeSnapshots (const stdair::SnapshotStruct& iSnapshot) {
00926 
00927     // Retrieve the SimCRS service context
00928     if (_simcrsServiceContext == NULL) {
00929       throw stdair::NonInitialisedServiceException ("The SimCRS service has "
00930                                                     "not been initialised");
00931     }
00932     assert (_simcrsServiceContext != NULL);
00933     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00934 
00935     // Retrieve the AIRINV Master service.
00936     AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
00937       lSIMCRS_ServiceContext.getAIRINV_Service();
00938 
00939     lAIRINV_Master_Service.takeSnapshots (iSnapshot);
00940   }
00941 
00942   // ////////////////////////////////////////////////////////////////////
00943   void SIMCRS_Service::
00944   optimise (const stdair::RMEventStruct& iRMEvent) {
00945 
00946     // Retrieve the SimCRS service context
00947     if (_simcrsServiceContext == NULL) {
00948       throw stdair::NonInitialisedServiceException ("The SimCRS service has "
00949                                                     "not been initialised");
00950     }
00951     assert (_simcrsServiceContext != NULL);
00952     SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
00953 
00954     // Retrieve the AIRINV Master service.
00955     AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
00956       lSIMCRS_ServiceContext.getAIRINV_Service();
00957 
00958     lAIRINV_Master_Service.optimise (iRMEvent);
00959   }
00960 }