$treeview $search $mathjax
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/bom/BomManager.hpp> 00012 #include <stdair/bom/BookingRequestStruct.hpp> 00013 #include <stdair/bom/TravelSolutionStruct.hpp> 00014 #include <stdair/service/Logger.hpp> 00015 #include <stdair/STDAIR_Service.hpp> 00016 // AirTSP 00017 #include <airtsp/basic/BasConst_AIRTSP_Service.hpp> 00018 #include <airtsp/factory/FacAIRTSPServiceContext.hpp> 00019 #include <airtsp/command/Simulator.hpp> 00020 #include <airtsp/command/ScheduleParser.hpp> 00021 #include <airtsp/command/OnDParser.hpp> 00022 #include <airtsp/command/SegmentPathProvider.hpp> 00023 #include <airtsp/command/InventoryGenerator.hpp> 00024 #include <airtsp/command/SegmentPathGenerator.hpp> 00025 #include <airtsp/service/AIRTSP_ServiceContext.hpp> 00026 #include <airtsp/AIRTSP_Service.hpp> 00027 00028 namespace AIRTSP { 00029 00030 // //////////////////////////////////////////////////////////////////// 00031 AIRTSP_Service::AIRTSP_Service() : _airtspServiceContext (NULL) { 00032 assert (false); 00033 } 00034 00035 // //////////////////////////////////////////////////////////////////// 00036 AIRTSP_Service::AIRTSP_Service (const AIRTSP_Service& iService) 00037 : _airtspServiceContext (NULL) { 00038 assert (false); 00039 } 00040 00041 // //////////////////////////////////////////////////////////////////// 00042 AIRTSP_Service::AIRTSP_Service (const stdair::BasLogParams& iLogParams) 00043 : _airtspServiceContext (NULL) { 00044 00045 // Initialise the STDAIR service handler 00046 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = 00047 initStdAirService (iLogParams); 00048 00049 // Initialise the service context 00050 initServiceContext(); 00051 00052 // Add the StdAir service context to the Airtsp service context 00053 // \note Airtsp owns the STDAIR service resources here. 00054 const bool ownStdairService = true; 00055 addStdAirService (lSTDAIR_Service_ptr, ownStdairService); 00056 00057 // Initialise the (remaining of the) context 00058 initAirtspService(); 00059 } 00060 00061 // //////////////////////////////////////////////////////////////////// 00062 AIRTSP_Service::AIRTSP_Service (const stdair::BasLogParams& iLogParams, 00063 const stdair::BasDBParams& iDBParams) 00064 : _airtspServiceContext (NULL) { 00065 00066 // Initialise the STDAIR service handler 00067 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = 00068 initStdAirService (iLogParams, iDBParams); 00069 00070 // Initialise the service context 00071 initServiceContext(); 00072 00073 // Add the StdAir service context to the Airtsp service context 00074 // \note Airtsp owns the STDAIR service resources here. 00075 const bool ownStdairService = true; 00076 addStdAirService (lSTDAIR_Service_ptr, ownStdairService); 00077 00078 // Initialise the (remaining of the) context 00079 initAirtspService(); 00080 } 00081 00082 // //////////////////////////////////////////////////////////////////// 00083 AIRTSP_Service:: 00084 AIRTSP_Service (stdair::STDAIR_ServicePtr_T ioSTDAIRServicePtr) 00085 : _airtspServiceContext (NULL) { 00086 00087 // Initialise the service context 00088 initServiceContext(); 00089 00090 // Add the StdAir service context to the Airtsp service context. 00091 // \note Airtsp does not own the STDAIR service resources here. 00092 const bool doesNotOwnStdairService = false; 00093 addStdAirService (ioSTDAIRServicePtr, doesNotOwnStdairService); 00094 00095 // Initialise the context 00096 initAirtspService(); 00097 } 00098 00099 // //////////////////////////////////////////////////////////////////// 00100 AIRTSP_Service::~AIRTSP_Service() { 00101 // Delete/Clean all the objects from memory 00102 finalise(); 00103 } 00104 00105 // //////////////////////////////////////////////////////////////////// 00106 void AIRTSP_Service::finalise() { 00107 assert (_airtspServiceContext != NULL); 00108 // Reset the (Boost.)Smart pointer pointing on the STDAIR_Service object. 00109 _airtspServiceContext->reset(); 00110 } 00111 00112 // ////////////////////////////////////////////////////////////////////// 00113 void AIRTSP_Service::initServiceContext() { 00114 // Initialise the service context 00115 AIRTSP_ServiceContext& lAIRTSP_ServiceContext = 00116 FacAIRTSPServiceContext::instance().create(); 00117 _airtspServiceContext = &lAIRTSP_ServiceContext; 00118 } 00119 00120 // //////////////////////////////////////////////////////////////////// 00121 void AIRTSP_Service:: 00122 addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr, 00123 const bool iOwnStdairService) { 00124 00125 // Retrieve the Airtsp service context 00126 assert (_airtspServiceContext != NULL); 00127 AIRTSP_ServiceContext& lAIRTSP_ServiceContext = 00128 *_airtspServiceContext; 00129 00130 // Store the STDAIR service object within the (Airtsp) service context 00131 lAIRTSP_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr, 00132 iOwnStdairService); 00133 } 00134 00135 // ////////////////////////////////////////////////////////////////////// 00136 stdair::STDAIR_ServicePtr_T AIRTSP_Service:: 00137 initStdAirService (const stdair::BasLogParams& iLogParams) { 00138 00146 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = 00147 boost::make_shared<stdair::STDAIR_Service> (iLogParams); 00148 00149 return lSTDAIR_Service_ptr; 00150 } 00151 00152 // ////////////////////////////////////////////////////////////////////// 00153 stdair::STDAIR_ServicePtr_T AIRTSP_Service:: 00154 initStdAirService (const stdair::BasLogParams& iLogParams, 00155 const stdair::BasDBParams& iDBParams) { 00156 00164 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = 00165 boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams); 00166 00167 return lSTDAIR_Service_ptr; 00168 } 00169 00170 // //////////////////////////////////////////////////////////////////// 00171 void AIRTSP_Service::initAirtspService() { 00172 // Do nothing at this stage. A sample BOM tree may be built by 00173 // calling the buildSampleBom() method 00174 } 00175 00176 // //////////////////////////////////////////////////////////////////// 00177 void AIRTSP_Service:: 00178 parseAndLoad (const stdair::ScheduleFilePath& iScheduleInputFilePath) { 00179 00180 // Retrieve the BOM tree root 00181 assert (_airtspServiceContext != NULL); 00182 AIRTSP_ServiceContext& lAIRTSP_ServiceContext = 00183 *_airtspServiceContext; 00184 const bool doesOwnStdairService = 00185 lAIRTSP_ServiceContext.getOwnStdairServiceFlag(); 00186 00187 // Retrieve the StdAir service object from the (Airtsp) service context 00188 stdair::STDAIR_Service& lSTDAIR_Service = 00189 lAIRTSP_ServiceContext.getSTDAIR_Service(); 00190 stdair::BomRoot& lPersistentBomRoot = 00191 lSTDAIR_Service.getPersistentBomRoot(); 00192 00196 stdair::BasChronometer lINVGeneration; lINVGeneration.start(); 00197 ScheduleParser::generateInventories (iScheduleInputFilePath, 00198 lPersistentBomRoot); 00210 buildComplementaryLinks (lPersistentBomRoot); 00211 00212 const double lGenerationMeasure = lINVGeneration.elapsed(); 00213 00218 if (doesOwnStdairService == true) { 00219 00220 // 00221 clonePersistentBom (); 00222 } 00223 00224 // DEBUG 00225 STDAIR_LOG_DEBUG ("Inventory generation time: " << lGenerationMeasure); 00226 } 00227 00228 // //////////////////////////////////////////////////////////////////// 00229 void AIRTSP_Service:: 00230 parseAndLoad (const stdair::ScheduleFilePath& iScheduleInputFilePath, 00231 const stdair::ODFilePath& iODInputFilePath) { 00232 00233 // First, build the airline inventories from the schedule file 00234 parseAndLoad (iScheduleInputFilePath); 00235 00236 // Retrieve the BOM tree root 00237 assert (_airtspServiceContext != NULL); 00238 AIRTSP_ServiceContext& lAIRTSP_ServiceContext = 00239 *_airtspServiceContext; 00240 const bool doesOwnStdairService = 00241 lAIRTSP_ServiceContext.getOwnStdairServiceFlag(); 00242 00243 // Retrieve the StdAir service object from the (Airtsp) service context 00244 stdair::STDAIR_Service& lSTDAIR_Service = 00245 lAIRTSP_ServiceContext.getSTDAIR_Service(); 00246 stdair::BomRoot& lPersistentBomRoot = 00247 lSTDAIR_Service.getPersistentBomRoot(); 00248 00252 stdair::BasChronometer lOnDGeneration; lOnDGeneration.start(); 00253 OnDParser::generateOnDPeriods (iODInputFilePath, lPersistentBomRoot); 00254 const double lGenerationMeasure = lOnDGeneration.elapsed(); 00255 00268 if (doesOwnStdairService == true) { 00269 00270 // 00271 lSTDAIR_Service.clonePersistentBom (); 00272 } 00273 00278 stdair::BomRoot& lBomRoot = 00279 lSTDAIR_Service.getBomRoot(); 00280 buildComplementaryLinks (lBomRoot); 00281 00282 // DEBUG 00283 STDAIR_LOG_DEBUG ("O&D generation time: " << lGenerationMeasure); 00284 } 00285 00286 // ////////////////////////////////////////////////////////////////////// 00287 void AIRTSP_Service::buildSampleBom() { 00288 00289 // Retrieve the Airtsp service context 00290 if (_airtspServiceContext == NULL) { 00291 throw stdair::NonInitialisedServiceException ("The Airtsp service has " 00292 "not been initialised"); 00293 } 00294 assert (_airtspServiceContext != NULL); 00295 00296 // Retrieve the Airtsp service context and whether it owns the Stdair 00297 // service 00298 AIRTSP_ServiceContext& lAIRTSP_ServiceContext = 00299 *_airtspServiceContext; 00300 const bool doesOwnStdairService = 00301 lAIRTSP_ServiceContext.getOwnStdairServiceFlag(); 00302 00303 // Retrieve the StdAir service object from the (Airtsp) service context 00304 stdair::STDAIR_Service& lSTDAIR_Service = 00305 lAIRTSP_ServiceContext.getSTDAIR_Service(); 00306 00311 if (doesOwnStdairService == true) { 00312 // 00313 lSTDAIR_Service.buildSampleBom(); 00314 } 00315 00328 stdair::BomRoot& lPersistentBomRoot = 00329 lSTDAIR_Service.getPersistentBomRoot(); 00330 buildComplementaryLinks (lPersistentBomRoot); 00331 00336 if (doesOwnStdairService == true) { 00337 00338 // 00339 clonePersistentBom (); 00340 } 00341 } 00342 00343 // //////////////////////////////////////////////////////////////////// 00344 void AIRTSP_Service::clonePersistentBom () { 00345 00346 // Retrieve the Airtsp service context 00347 if (_airtspServiceContext == NULL) { 00348 throw stdair::NonInitialisedServiceException ("The Airtsp service has " 00349 "not been initialised"); 00350 } 00351 assert (_airtspServiceContext != NULL); 00352 00353 // Retrieve the Airtsp service context and whether it owns the Stdair 00354 // service 00355 AIRTSP_ServiceContext& lAIRTSP_ServiceContext = 00356 *_airtspServiceContext; 00357 const bool doesOwnStdairService = 00358 lAIRTSP_ServiceContext.getOwnStdairServiceFlag(); 00359 00360 // Retrieve the StdAir service object from the (Airtsp) service context 00361 stdair::STDAIR_Service& lSTDAIR_Service = 00362 lAIRTSP_ServiceContext.getSTDAIR_Service(); 00363 00368 if (doesOwnStdairService == true) { 00369 00370 // 00371 lSTDAIR_Service.clonePersistentBom (); 00372 } 00373 00378 stdair::BomRoot& lBomRoot = 00379 lSTDAIR_Service.getBomRoot(); 00380 buildComplementaryLinks (lBomRoot); 00381 } 00382 00383 // //////////////////////////////////////////////////////////////////// 00384 void AIRTSP_Service::buildComplementaryLinks (stdair::BomRoot& ioBomRoot) { 00385 00386 // Retrieve the Airtsp service context 00387 if (_airtspServiceContext == NULL) { 00388 throw stdair::NonInitialisedServiceException ("The Airtsp service has " 00389 "not been initialised"); 00390 } 00391 assert (_airtspServiceContext != NULL); 00392 00396 SegmentPathGenerator::createSegmentPathNetwork (ioBomRoot); 00397 } 00398 00399 // //////////////////////////////////////////////////////////////////// 00400 std::string AIRTSP_Service:: 00401 jsonExportFlightDateObjects (const stdair::AirlineCode_T& iAirlineCode, 00402 const stdair::FlightNumber_T& iFlightNumber, 00403 const stdair::Date_T& iDepartureDate) const { 00404 00405 // Retrieve the Airtsp service context 00406 if (_airtspServiceContext == NULL) { 00407 throw stdair::NonInitialisedServiceException ("The Airtsp service " 00408 "has not been initialised"); 00409 } 00410 assert (_airtspServiceContext != NULL); 00411 00412 // Retrieve the StdAir service object from the (Airtsp) service context 00413 AIRTSP_ServiceContext& lAIRTSP_ServiceContext = 00414 *_airtspServiceContext; 00415 stdair::STDAIR_Service& lSTDAIR_Service = 00416 lAIRTSP_ServiceContext.getSTDAIR_Service(); 00417 00418 // Delegate the JSON export to the dedicated service 00419 return lSTDAIR_Service.jsonExportFlightDateObjects (iAirlineCode, 00420 iFlightNumber, 00421 iDepartureDate); 00422 } 00423 00424 // ////////////////////////////////////////////////////////////////////// 00425 std::string AIRTSP_Service::csvDisplay() const { 00426 00427 // Retrieve the Airtsp service context 00428 if (_airtspServiceContext == NULL) { 00429 throw stdair::NonInitialisedServiceException ("The Airtsp service has " 00430 "not been initialised"); 00431 } 00432 assert (_airtspServiceContext != NULL); 00433 00434 // Retrieve the STDAIR service object from the (Airtsp) service context 00435 AIRTSP_ServiceContext& lAIRTSP_ServiceContext = 00436 *_airtspServiceContext; 00437 stdair::STDAIR_Service& lSTDAIR_Service = 00438 lAIRTSP_ServiceContext.getSTDAIR_Service(); 00439 const stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot(); 00440 00441 // Delegate the BOM building to the dedicated service 00442 return lSTDAIR_Service.csvDisplay(lBomRoot); 00443 } 00444 00445 // //////////////////////////////////////////////////////////////////// 00446 std::string AIRTSP_Service:: 00447 csvDisplay (const stdair::AirlineCode_T& iAirlineCode, 00448 const stdair::FlightNumber_T& iFlightNumber, 00449 const stdair::Date_T& iDepartureDate) const { 00450 00451 // Retrieve the Airtsp service context 00452 if (_airtspServiceContext == NULL) { 00453 throw stdair::NonInitialisedServiceException ("The Airtsp service has " 00454 "not been initialised"); 00455 } 00456 assert (_airtspServiceContext != NULL); 00457 00458 // Retrieve the STDAIR service object from the (Airtsp) service context 00459 AIRTSP_ServiceContext& lAIRTSP_ServiceContext = 00460 *_airtspServiceContext; 00461 stdair::STDAIR_Service& lSTDAIR_Service = 00462 lAIRTSP_ServiceContext.getSTDAIR_Service(); 00463 00464 // Delegate the BOM display to the dedicated service 00465 return lSTDAIR_Service.csvDisplay (iAirlineCode, iFlightNumber, 00466 iDepartureDate); 00467 } 00468 00469 // //////////////////////////////////////////////////////////////////// 00470 void AIRTSP_Service::simulate() { 00471 00472 // Retrieve the Airtsp service context 00473 if (_airtspServiceContext == NULL) { 00474 throw stdair::NonInitialisedServiceException ("The Airtsp service has " 00475 "not been initialised"); 00476 } 00477 assert (_airtspServiceContext != NULL); 00478 00479 // Retrieve the BOM tree root 00480 AIRTSP_ServiceContext& lAIRTSP_ServiceContext = 00481 *_airtspServiceContext; 00482 stdair::STDAIR_Service& lSTDAIR_Service = 00483 lAIRTSP_ServiceContext.getSTDAIR_Service(); 00484 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot(); 00485 00486 // Call the underlying Use Case (command) 00487 stdair::BasChronometer lSimulateChronometer; lSimulateChronometer.start(); 00488 Simulator::simulate (lBomRoot); 00489 const double lSimulateMeasure = lSimulateChronometer.elapsed(); 00490 00491 // DEBUG 00492 STDAIR_LOG_DEBUG ("Simulation: " << lSimulateMeasure << " - " 00493 << lAIRTSP_ServiceContext.display()); 00494 } 00495 00496 // //////////////////////////////////////////////////////////////////// 00497 void AIRTSP_Service:: 00498 buildSegmentPathList (stdair::TravelSolutionList_T& ioTravelSolutionList, 00499 const stdair::BookingRequestStruct& iBookingRequest) { 00500 00501 if (_airtspServiceContext == NULL) { 00502 throw stdair::NonInitialisedServiceException ("The Airtsp service has " 00503 "not been initialised"); 00504 } 00505 assert (_airtspServiceContext != NULL); 00506 00507 // Retrieve the BOM tree root 00508 AIRTSP_ServiceContext& lAIRTSP_ServiceContext = 00509 *_airtspServiceContext; 00510 stdair::STDAIR_Service& lSTDAIR_Service = 00511 lAIRTSP_ServiceContext.getSTDAIR_Service(); 00512 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot(); 00513 00514 // Delegate the call to the dedicated command 00515 stdair::BasChronometer lBuildChronometer; lBuildChronometer.start(); 00516 SegmentPathProvider::buildSegmentPathList (ioTravelSolutionList, 00517 lBomRoot, iBookingRequest); 00518 const double lBuildMeasure = lBuildChronometer.elapsed(); 00519 00520 // DEBUG 00521 STDAIR_LOG_DEBUG ("Segment-path build: " << lBuildMeasure << " - " 00522 << lAIRTSP_ServiceContext.display()); 00523 } 00524 00525 }