AirTSP Logo  1.01.10
C++ Simulated Airline Travel Solution Provider (TSP) Library
Loading...
Searching...
No Matches
AIRTSP_Service.cpp
Go to the documentation of this file.
1// //////////////////////////////////////////////////////////////////////
2// Import section
3// //////////////////////////////////////////////////////////////////////
4// STL
5#include <cassert>
6#include <sstream>
7// Boost
8#include <boost/make_shared.hpp>
9// StdAir
10#include <stdair/basic/BasChronometer.hpp>
11#include <stdair/bom/BomManager.hpp>
12#include <stdair/bom/BookingRequestStruct.hpp>
13#include <stdair/bom/TravelSolutionStruct.hpp>
14#include <stdair/service/Logger.hpp>
15#include <stdair/STDAIR_Service.hpp>
16// AirTSP
27
28namespace AIRTSP {
29
30 // ////////////////////////////////////////////////////////////////////
31 AIRTSP_Service::AIRTSP_Service() : _airtspServiceContext (NULL) {
32 assert (false);
33 }
34
35 // ////////////////////////////////////////////////////////////////////
36 AIRTSP_Service::AIRTSP_Service (const AIRTSP_Service& iService)
37 : _airtspServiceContext (NULL) {
38 assert (false);
39 }
40
41 // ////////////////////////////////////////////////////////////////////
42 AIRTSP_Service::AIRTSP_Service (const stdair::BasLogParams& iLogParams)
43 : _airtspServiceContext (NULL) {
44
45 // Initialise the STDAIR service handler
46 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
47 initStdAirService (iLogParams);
48
49 // Initialise the service context
50 initServiceContext();
51
52 // Add the StdAir service context to the Airtsp service context
53 // \note Airtsp owns the STDAIR service resources here.
54 const bool ownStdairService = true;
55 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
56
57 // Initialise the (remaining of the) context
58 initAirtspService();
59 }
60
61 // ////////////////////////////////////////////////////////////////////
62 AIRTSP_Service::AIRTSP_Service (const stdair::BasLogParams& iLogParams,
63 const stdair::BasDBParams& iDBParams)
64 : _airtspServiceContext (NULL) {
65
66 // Initialise the STDAIR service handler
67 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
68 initStdAirService (iLogParams, iDBParams);
69
70 // Initialise the service context
71 initServiceContext();
72
73 // Add the StdAir service context to the Airtsp service context
74 // \note Airtsp owns the STDAIR service resources here.
75 const bool ownStdairService = true;
76 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
77
78 // Initialise the (remaining of the) context
79 initAirtspService();
80 }
81
82 // ////////////////////////////////////////////////////////////////////
83 AIRTSP_Service::
84 AIRTSP_Service (stdair::STDAIR_ServicePtr_T ioSTDAIRServicePtr)
85 : _airtspServiceContext (NULL) {
86
87 // Initialise the service context
88 initServiceContext();
89
90 // Add the StdAir service context to the Airtsp service context.
91 // \note Airtsp does not own the STDAIR service resources here.
92 const bool doesNotOwnStdairService = false;
93 addStdAirService (ioSTDAIRServicePtr, doesNotOwnStdairService);
94
95 // Initialise the context
96 initAirtspService();
97 }
98
99 // ////////////////////////////////////////////////////////////////////
101 // Delete/Clean all the objects from memory
102 finalise();
103 }
104
105 // ////////////////////////////////////////////////////////////////////
106 void AIRTSP_Service::finalise() {
107 assert (_airtspServiceContext != NULL);
108 // Reset the (Boost.)Smart pointer pointing on the STDAIR_Service object.
109 _airtspServiceContext->reset();
110 }
111
112 // //////////////////////////////////////////////////////////////////////
113 void AIRTSP_Service::initServiceContext() {
114 // Initialise the service context
115 AIRTSP_ServiceContext& lAIRTSP_ServiceContext =
117 _airtspServiceContext = &lAIRTSP_ServiceContext;
118 }
119
120 // ////////////////////////////////////////////////////////////////////
121 void AIRTSP_Service::
122 addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
123 const bool iOwnStdairService) {
124
125 // Retrieve the Airtsp service context
126 assert (_airtspServiceContext != NULL);
127 AIRTSP_ServiceContext& lAIRTSP_ServiceContext =
128 *_airtspServiceContext;
129
130 // Store the STDAIR service object within the (Airtsp) service context
131 lAIRTSP_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
132 iOwnStdairService);
133 }
134
135 // //////////////////////////////////////////////////////////////////////
136 stdair::STDAIR_ServicePtr_T AIRTSP_Service::
137 initStdAirService (const stdair::BasLogParams& iLogParams) {
138
146 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
147 boost::make_shared<stdair::STDAIR_Service> (iLogParams);
148
149 return lSTDAIR_Service_ptr;
150 }
151
152 // //////////////////////////////////////////////////////////////////////
153 stdair::STDAIR_ServicePtr_T AIRTSP_Service::
154 initStdAirService (const stdair::BasLogParams& iLogParams,
155 const stdair::BasDBParams& iDBParams) {
156
164 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
165 boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
166
167 return lSTDAIR_Service_ptr;
168 }
169
170 // ////////////////////////////////////////////////////////////////////
171 void AIRTSP_Service::initAirtspService() {
172 // Do nothing at this stage. A sample BOM tree may be built by
173 // calling the buildSampleBom() method
174 }
175
176 // ////////////////////////////////////////////////////////////////////
178 parseAndLoad (const stdair::ScheduleFilePath& iScheduleInputFilePath) {
179
180 // Retrieve the BOM tree root
181 assert (_airtspServiceContext != NULL);
182 AIRTSP_ServiceContext& lAIRTSP_ServiceContext =
183 *_airtspServiceContext;
184 const bool doesOwnStdairService =
185 lAIRTSP_ServiceContext.getOwnStdairServiceFlag();
186
187 // Retrieve the StdAir service object from the (Airtsp) service context
188 stdair::STDAIR_Service& lSTDAIR_Service =
189 lAIRTSP_ServiceContext.getSTDAIR_Service();
190 stdair::BomRoot& lPersistentBomRoot =
191 lSTDAIR_Service.getPersistentBomRoot();
192
196 stdair::BasChronometer lINVGeneration; lINVGeneration.start();
197 ScheduleParser::generateInventories (iScheduleInputFilePath,
198 lPersistentBomRoot);
210 buildComplementaryLinks (lPersistentBomRoot);
211
212 const double lGenerationMeasure = lINVGeneration.elapsed();
213
218 if (doesOwnStdairService == true) {
219
220 //
222 }
223
224 // DEBUG
225 STDAIR_LOG_DEBUG ("Inventory generation time: " << lGenerationMeasure);
226 }
227
228 // ////////////////////////////////////////////////////////////////////
230 parseAndLoad (const stdair::ScheduleFilePath& iScheduleInputFilePath,
231 const stdair::ODFilePath& iODInputFilePath) {
232
233 // First, build the airline inventories from the schedule file
234 parseAndLoad (iScheduleInputFilePath);
235
236 // Retrieve the BOM tree root
237 assert (_airtspServiceContext != NULL);
238 AIRTSP_ServiceContext& lAIRTSP_ServiceContext =
239 *_airtspServiceContext;
240 const bool doesOwnStdairService =
241 lAIRTSP_ServiceContext.getOwnStdairServiceFlag();
242
243 // Retrieve the StdAir service object from the (Airtsp) service context
244 stdair::STDAIR_Service& lSTDAIR_Service =
245 lAIRTSP_ServiceContext.getSTDAIR_Service();
246 stdair::BomRoot& lPersistentBomRoot =
247 lSTDAIR_Service.getPersistentBomRoot();
248
252 stdair::BasChronometer lOnDGeneration; lOnDGeneration.start();
253 OnDParser::generateOnDPeriods (iODInputFilePath, lPersistentBomRoot);
254 const double lGenerationMeasure = lOnDGeneration.elapsed();
255
268 if (doesOwnStdairService == true) {
269
270 //
271 lSTDAIR_Service.clonePersistentBom ();
272 }
273
278 stdair::BomRoot& lBomRoot =
279 lSTDAIR_Service.getBomRoot();
280 buildComplementaryLinks (lBomRoot);
281
282 // DEBUG
283 STDAIR_LOG_DEBUG ("O&D generation time: " << lGenerationMeasure);
284 }
285
286 // //////////////////////////////////////////////////////////////////////
288
289 // Retrieve the Airtsp service context
290 if (_airtspServiceContext == NULL) {
291 throw stdair::NonInitialisedServiceException ("The Airtsp service has "
292 "not been initialised");
293 }
294 assert (_airtspServiceContext != NULL);
295
296 // Retrieve the Airtsp service context and whether it owns the Stdair
297 // service
298 AIRTSP_ServiceContext& lAIRTSP_ServiceContext =
299 *_airtspServiceContext;
300 const bool doesOwnStdairService =
301 lAIRTSP_ServiceContext.getOwnStdairServiceFlag();
302
303 // Retrieve the StdAir service object from the (Airtsp) service context
304 stdair::STDAIR_Service& lSTDAIR_Service =
305 lAIRTSP_ServiceContext.getSTDAIR_Service();
306
311 if (doesOwnStdairService == true) {
312 //
313 lSTDAIR_Service.buildSampleBom();
314 }
315
328 stdair::BomRoot& lPersistentBomRoot =
329 lSTDAIR_Service.getPersistentBomRoot();
330 buildComplementaryLinks (lPersistentBomRoot);
331
336 if (doesOwnStdairService == true) {
337
338 //
340 }
341 }
342
343 // ////////////////////////////////////////////////////////////////////
345
346 // Retrieve the Airtsp service context
347 if (_airtspServiceContext == NULL) {
348 throw stdair::NonInitialisedServiceException ("The Airtsp service has "
349 "not been initialised");
350 }
351 assert (_airtspServiceContext != NULL);
352
353 // Retrieve the Airtsp service context and whether it owns the Stdair
354 // service
355 AIRTSP_ServiceContext& lAIRTSP_ServiceContext =
356 *_airtspServiceContext;
357 const bool doesOwnStdairService =
358 lAIRTSP_ServiceContext.getOwnStdairServiceFlag();
359
360 // Retrieve the StdAir service object from the (Airtsp) service context
361 stdair::STDAIR_Service& lSTDAIR_Service =
362 lAIRTSP_ServiceContext.getSTDAIR_Service();
363
368 if (doesOwnStdairService == true) {
369
370 //
371 lSTDAIR_Service.clonePersistentBom ();
372 }
373
378 stdair::BomRoot& lBomRoot =
379 lSTDAIR_Service.getBomRoot();
380 buildComplementaryLinks (lBomRoot);
381 }
382
383 // ////////////////////////////////////////////////////////////////////
384 void AIRTSP_Service::buildComplementaryLinks (stdair::BomRoot& ioBomRoot) {
385
386 // Retrieve the Airtsp service context
387 if (_airtspServiceContext == NULL) {
388 throw stdair::NonInitialisedServiceException ("The Airtsp service has "
389 "not been initialised");
390 }
391 assert (_airtspServiceContext != NULL);
392
397 }
398
399 // ////////////////////////////////////////////////////////////////////
401 jsonExportFlightDateObjects (const stdair::AirlineCode_T& iAirlineCode,
402 const stdair::FlightNumber_T& iFlightNumber,
403 const stdair::Date_T& iDepartureDate) const {
404
405 // Retrieve the Airtsp service context
406 if (_airtspServiceContext == NULL) {
407 throw stdair::NonInitialisedServiceException ("The Airtsp service "
408 "has not been initialised");
409 }
410 assert (_airtspServiceContext != NULL);
411
412 // Retrieve the StdAir service object from the (Airtsp) service context
413 AIRTSP_ServiceContext& lAIRTSP_ServiceContext =
414 *_airtspServiceContext;
415 stdair::STDAIR_Service& lSTDAIR_Service =
416 lAIRTSP_ServiceContext.getSTDAIR_Service();
417
418 // Delegate the JSON export to the dedicated service
419 return lSTDAIR_Service.jsonExportFlightDateObjects (iAirlineCode,
420 iFlightNumber,
421 iDepartureDate);
422 }
423
424 // //////////////////////////////////////////////////////////////////////
425 std::string AIRTSP_Service::csvDisplay() const {
426
427 // Retrieve the Airtsp service context
428 if (_airtspServiceContext == NULL) {
429 throw stdair::NonInitialisedServiceException ("The Airtsp service has "
430 "not been initialised");
431 }
432 assert (_airtspServiceContext != NULL);
433
434 // Retrieve the STDAIR service object from the (Airtsp) service context
435 AIRTSP_ServiceContext& lAIRTSP_ServiceContext =
436 *_airtspServiceContext;
437 stdair::STDAIR_Service& lSTDAIR_Service =
438 lAIRTSP_ServiceContext.getSTDAIR_Service();
439 const stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
440
441 // Delegate the BOM building to the dedicated service
442 return lSTDAIR_Service.csvDisplay(lBomRoot);
443 }
444
445 // ////////////////////////////////////////////////////////////////////
447 csvDisplay (const stdair::AirlineCode_T& iAirlineCode,
448 const stdair::FlightNumber_T& iFlightNumber,
449 const stdair::Date_T& iDepartureDate) const {
450
451 // Retrieve the Airtsp service context
452 if (_airtspServiceContext == NULL) {
453 throw stdair::NonInitialisedServiceException ("The Airtsp service has "
454 "not been initialised");
455 }
456 assert (_airtspServiceContext != NULL);
457
458 // Retrieve the STDAIR service object from the (Airtsp) service context
459 AIRTSP_ServiceContext& lAIRTSP_ServiceContext =
460 *_airtspServiceContext;
461 stdair::STDAIR_Service& lSTDAIR_Service =
462 lAIRTSP_ServiceContext.getSTDAIR_Service();
463
464 // Delegate the BOM display to the dedicated service
465 return lSTDAIR_Service.csvDisplay (iAirlineCode, iFlightNumber,
466 iDepartureDate);
467 }
468
469 // ////////////////////////////////////////////////////////////////////
471
472 // Retrieve the Airtsp service context
473 if (_airtspServiceContext == NULL) {
474 throw stdair::NonInitialisedServiceException ("The Airtsp service has "
475 "not been initialised");
476 }
477 assert (_airtspServiceContext != NULL);
478
479 // Retrieve the BOM tree root
480 AIRTSP_ServiceContext& lAIRTSP_ServiceContext =
481 *_airtspServiceContext;
482 stdair::STDAIR_Service& lSTDAIR_Service =
483 lAIRTSP_ServiceContext.getSTDAIR_Service();
484 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
485
486 // Call the underlying Use Case (command)
487 stdair::BasChronometer lSimulateChronometer; lSimulateChronometer.start();
488 Simulator::simulate (lBomRoot);
489 const double lSimulateMeasure = lSimulateChronometer.elapsed();
490
491 // DEBUG
492 STDAIR_LOG_DEBUG ("Simulation: " << lSimulateMeasure << " - "
493 << lAIRTSP_ServiceContext.display());
494 }
495
496 // ////////////////////////////////////////////////////////////////////
498 buildSegmentPathList (stdair::TravelSolutionList_T& ioTravelSolutionList,
499 const stdair::BookingRequestStruct& iBookingRequest) {
500
501 if (_airtspServiceContext == NULL) {
502 throw stdair::NonInitialisedServiceException ("The Airtsp service has "
503 "not been initialised");
504 }
505 assert (_airtspServiceContext != NULL);
506
507 // Retrieve the BOM tree root
508 AIRTSP_ServiceContext& lAIRTSP_ServiceContext =
509 *_airtspServiceContext;
510 stdair::STDAIR_Service& lSTDAIR_Service =
511 lAIRTSP_ServiceContext.getSTDAIR_Service();
512 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
513
514 // Delegate the call to the dedicated command
515 stdair::BasChronometer lBuildChronometer; lBuildChronometer.start();
516 SegmentPathProvider::buildSegmentPathList (ioTravelSolutionList,
517 lBomRoot, iBookingRequest);
518 const double lBuildMeasure = lBuildChronometer.elapsed();
519
520 // DEBUG
521 STDAIR_LOG_DEBUG ("Segment-path build: " << lBuildMeasure << " - "
522 << lAIRTSP_ServiceContext.display());
523 }
524
525}
Class holding the context of the Airtsp services.
void buildComplementaryLinks(stdair::BomRoot &)
void parseAndLoad(const stdair::ScheduleFilePath &)
std::string csvDisplay() const
std::string jsonExportFlightDateObjects(const stdair::AirlineCode_T &, const stdair::FlightNumber_T &, const stdair::Date_T &iDepartureDate) const
void buildSegmentPathList(stdair::TravelSolutionList_T &, const stdair::BookingRequestStruct &)
static FacAIRTSPServiceContext & instance()
static void generateOnDPeriods(const stdair::ODFilePath &, stdair::BomRoot &)
Definition OnDParser.cpp:17
static void generateInventories(const stdair::ScheduleFilePath &, stdair::BomRoot &)
static void createSegmentPathNetwork(const stdair::BomRoot &)
static void simulate(stdair::BomRoot &)
Definition Simulator.cpp:19