AirInv Logo  1.00.0
C++ Simulated Airline Inventory Management System library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AIRINV_Master_Service.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <cmath>
7 // Boost
8 #include <boost/make_shared.hpp>
9 // StdAir
10 #include <stdair/stdair_json.hpp>
11 #include <stdair/basic/BasChronometer.hpp>
12 #include <stdair/basic/EventType.hpp>
13 #include <stdair/bom/BomKeyManager.hpp>
14 #include <stdair/bom/SnapshotStruct.hpp>
15 #include <stdair/bom/RMEventStruct.hpp>
16 #include <stdair/service/Logger.hpp>
17 #include <stdair/STDAIR_Service.hpp>
18 // SEvMgr
19 #include <sevmgr/SEVMGR_Service.hpp>
20 // AirInv
28 
29 namespace AIRINV {
30 
31  // ////////////////////////////////////////////////////////////////////
32  AIRINV_Master_Service::AIRINV_Master_Service()
33  : _airinvMasterServiceContext (NULL) {
34  assert (false);
35  }
36 
37  // ////////////////////////////////////////////////////////////////////
38  AIRINV_Master_Service::
39  AIRINV_Master_Service (const AIRINV_Master_Service& iService)
40  : _airinvMasterServiceContext (NULL) {
41  assert (false);
42  }
43 
44  // ////////////////////////////////////////////////////////////////////
45  AIRINV_Master_Service::
46  AIRINV_Master_Service (const stdair::BasLogParams& iLogParams,
47  const stdair::BasDBParams& iDBParams)
48  : _airinvMasterServiceContext (NULL) {
49 
50  // Initialise the STDAIR service handler
51  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
52  initStdAirService (iLogParams, iDBParams);
53 
54  // Initialise the service context
55  initServiceContext();
56 
57  // Add the StdAir service context to the AIRINV service context
58  // \note RMOL owns the STDAIR service resources here.
59  const bool ownStdairService = true;
60  addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
61 
62  // Initialise the (remaining of the) context
63  initSlaveAirinvService();
64  }
65 
66  // ////////////////////////////////////////////////////////////////////
67  AIRINV_Master_Service::
68  AIRINV_Master_Service (const stdair::BasLogParams& iLogParams)
69  : _airinvMasterServiceContext (NULL) {
70 
71  // Initialise the STDAIR service handler
72  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
73  initStdAirService (iLogParams);
74 
75  // Initialise the service context
76  initServiceContext();
77 
78  // Add the StdAir service context to the AIRINV service context
79  // \note RMOL owns the STDAIR service resources here.
80  const bool ownStdairService = true;
81  addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
82 
83  // Initialise the (remaining of the) context
84  initSlaveAirinvService();
85  }
86 
87  // ////////////////////////////////////////////////////////////////////
88  AIRINV_Master_Service::
89  AIRINV_Master_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr)
90  : _airinvMasterServiceContext (NULL) {
91 
92  // Initialise the service context
93  initServiceContext();
94 
95  // Store the STDAIR service object within the (AIRINV) service context
96  // \note AirInv does not own the STDAIR service resources here.
97  const bool doesNotOwnStdairService = false;
98  addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
99 
100  // Initialise the (remaining of the) context
101  initSlaveAirinvService();
102  }
103 
104  // ////////////////////////////////////////////////////////////////////
105  AIRINV_Master_Service::
106  AIRINV_Master_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
107  SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_Service_ptr)
108  : _airinvMasterServiceContext (NULL) {
109 
110  // Initialise the service context
111  initServiceContext();
112 
113  // Store the STDAIR service object within the (AIRINV) service context
114  // \note AirInv does not own the STDAIR service resources here.
115  const bool doesNotOwnStdairService = false;
116  addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
117 
118  //Add the SEvMgr service to the TRADEMGEN service context.
119  const bool doesNotOwnSEVMGRService = false;
120  addSEVMGRService (ioSEVMGR_Service_ptr, doesNotOwnSEVMGRService);
121 
122  // Initialise the (remaining of the) context
123  initSlaveAirinvService();
124  }
125 
126  // ////////////////////////////////////////////////////////////////////
128  // Delete/Clean all the objects from memory
129  finalise();
130  }
131 
132  // ////////////////////////////////////////////////////////////////////
133  void AIRINV_Master_Service::finalise() {
134  assert (_airinvMasterServiceContext != NULL);
135  // Reset the (Boost.)Smart pointer pointing on the STDAIR_Service object.
136  _airinvMasterServiceContext->reset();
137  }
138 
139  // ////////////////////////////////////////////////////////////////////
140  void AIRINV_Master_Service::initServiceContext() {
141  // Initialise the context
142  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
144  _airinvMasterServiceContext = &lAIRINV_Master_ServiceContext;
145  }
146 
147  // ////////////////////////////////////////////////////////////////////
148  void AIRINV_Master_Service::
149  addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
150  const bool iOwnStdairService) {
151 
152  // Retrieve the AirInv Master service context
153  assert (_airinvMasterServiceContext != NULL);
154  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
155  *_airinvMasterServiceContext;
156 
157  // Store the STDAIR service object within the (AIRINV) service context
158  lAIRINV_Master_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
159  iOwnStdairService);
160  }
161 
162 // ////////////////////////////////////////////////////////////////////
163  void AIRINV_Master_Service::
164  addSEVMGRService (SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_Service_ptr,
165  const bool iOwnSEVMGRService) {
166 
167  // Retrieve the AirInv Master service context
168  assert (_airinvMasterServiceContext != NULL);
169  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
170  *_airinvMasterServiceContext;
171 
172  // Store the STDAIR service object within the (TRADEMGEN) service context
173  lAIRINV_Master_ServiceContext.setSEVMGR_Service (ioSEVMGR_Service_ptr,
174  iOwnSEVMGRService);
175  }
176 
177  // ////////////////////////////////////////////////////////////////////
178  stdair::STDAIR_ServicePtr_T AIRINV_Master_Service::
179  initStdAirService (const stdair::BasLogParams& iLogParams,
180  const stdair::BasDBParams& iDBParams) {
181 
189  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
190  boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
191 
192  return lSTDAIR_Service_ptr;
193  }
194 
195  // ////////////////////////////////////////////////////////////////////
196  stdair::STDAIR_ServicePtr_T AIRINV_Master_Service::
197  initStdAirService (const stdair::BasLogParams& iLogParams) {
198 
206  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
207  boost::make_shared<stdair::STDAIR_Service> (iLogParams);
208 
209  return lSTDAIR_Service_ptr;
210  }
211 
212  // ////////////////////////////////////////////////////////////////////
213  void AIRINV_Master_Service::initSlaveAirinvService() {
214 
215  // Retrieve the AirInv Master service context
216  assert (_airinvMasterServiceContext != NULL);
217  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
218  *_airinvMasterServiceContext;
219 
220  // Retrieve the StdAir service
221  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
222  lAIRINV_Master_ServiceContext.getSTDAIR_ServicePtr();
223  assert (lSTDAIR_Service_ptr != NULL);
224 
234  AIRINV_ServicePtr_T lAIRINV_Service_ptr;
235  const bool ownSEVMGRService =
236  lAIRINV_Master_ServiceContext.getOwnSEVMGRServiceFlag();
237  if (ownSEVMGRService == false) {
238  // Retrieve the SEVMGR service
239  SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
240  lAIRINV_Master_ServiceContext.getSEVMGR_ServicePtr();
241  assert (lSEVMGR_Service_ptr != NULL);
242  lAIRINV_Service_ptr = boost::make_shared<AIRINV_Service> (lSTDAIR_Service_ptr,
243  lSEVMGR_Service_ptr);
244  } else {
245  lAIRINV_Service_ptr = boost::make_shared<AIRINV_Service> (lSTDAIR_Service_ptr);
246  }
247  assert (lAIRINV_Service_ptr != NULL);
248 
249  // Store the AIRINV service object within the AIRINV Master service context.
250  lAIRINV_Master_ServiceContext.setAIRINV_Service (lAIRINV_Service_ptr);
251  }
252 
253  // ////////////////////////////////////////////////////////////////////
255  parseAndLoad (const InventoryFilePath& iInventoryInputFilename) {
256 
257  // Retrieve the AirInv Master service context
258  if (_airinvMasterServiceContext == NULL) {
259  throw stdair::NonInitialisedServiceException ("The AirInvMaster service "
260  "has not been initialised");
261  }
262  assert (_airinvMasterServiceContext != NULL);
263 
264  // Retrieve the AirInv service context and whether it owns the Stdair
265  // service
266  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
267  *_airinvMasterServiceContext;
268  const bool doesOwnStdairService =
269  lAIRINV_Master_ServiceContext.getOwnStdairServiceFlag();
270 
271  // Retrieve the slave AIRINV service object from the (AIRINV)
272  // service context
273  AIRINV_Service& lAIRINV_Service =
274  lAIRINV_Master_ServiceContext.getAIRINV_Service();
275 
276  // Delegate the file parsing and BOM building to the dedicated service
277  lAIRINV_Service.parseAndLoad (iInventoryInputFilename);
278 
283  if (doesOwnStdairService == true) {
284 
285  //
287  }
288  }
289 
290  // ////////////////////////////////////////////////////////////////////
292 
293  // Retrieve the AirInv Master service context
294  if (_airinvMasterServiceContext == NULL) {
295  throw stdair::NonInitialisedServiceException ("The AirInvMaster service "
296  "has not been initialised");
297  }
298  assert (_airinvMasterServiceContext != NULL);
299 
300  // Retrieve the AirInv service context and whether it owns the Stdair
301  // service
302  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
303  *_airinvMasterServiceContext;
304  const bool doesOwnStdairService =
305  lAIRINV_Master_ServiceContext.getOwnStdairServiceFlag();
306 
307  // Retrieve the StdAir service object from the (AirInv) service context
308  stdair::STDAIR_Service& lSTDAIR_Service =
309  lAIRINV_Master_ServiceContext.getSTDAIR_Service();
310  stdair::BomRoot& lPersistentBomRoot =
311  lSTDAIR_Service.getPersistentBomRoot();
312 
317  if (doesOwnStdairService == true) {
318  //
319  lSTDAIR_Service.buildSampleBom();
320  }
321 
330  AIRINV_Service& lAIRINV_Service =
331  lAIRINV_Master_ServiceContext.getAIRINV_Service();
332  lAIRINV_Service.buildSampleBom();
333 
338  buildComplementaryLinks (lPersistentBomRoot);
339 
344  if (doesOwnStdairService == true) {
345 
346  //
348  }
349  }
350 
351  // ////////////////////////////////////////////////////////////////////
353  parseAndLoad (const stdair::ScheduleFilePath& iScheduleInputFilename,
354  const stdair::ODFilePath& iODInputFilename,
355  const stdair::FRAT5FilePath& iFRAT5InputFilename,
356  const stdair::FFDisutilityFilePath& iFFDisutilityInputFilename,
357  const AIRRAC::YieldFilePath& iYieldFilename) {
358 
359  // Retrieve the AirInv Master service context
360  if (_airinvMasterServiceContext == NULL) {
361  throw stdair::NonInitialisedServiceException ("The AirInvMaster service "
362  "has not been initialised");
363  }
364  assert (_airinvMasterServiceContext != NULL);
365 
366  // Retrieve the AirInv service context and whether it owns the Stdair
367  // service
368  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
369  *_airinvMasterServiceContext;
370  const bool doesOwnStdairService =
371  lAIRINV_Master_ServiceContext.getOwnStdairServiceFlag();
372 
373  // Retrieve the slave AirInv service object from the (AirInv)
374  // service context
375  AIRINV_Service& lAIRINV_Service =
376  lAIRINV_Master_ServiceContext.getAIRINV_Service();
377 
378  // Retrieve the StdAir service object from the (AirInv) service context
379  stdair::STDAIR_Service& lSTDAIR_Service =
380  lAIRINV_Master_ServiceContext.getSTDAIR_Service();
381  stdair::BomRoot& lPersistentBomRoot =
382  lSTDAIR_Service.getPersistentBomRoot();
383 
387  lAIRINV_Service.parseAndLoad (iScheduleInputFilename, iODInputFilename,
388  iFRAT5InputFilename,
389  iFFDisutilityInputFilename, iYieldFilename);
390 
401  buildComplementaryLinks (lPersistentBomRoot);
402 
407  if (doesOwnStdairService == true) {
408 
409  //
411  }
412  }
413 
414  // ////////////////////////////////////////////////////////////////////
416 
417  // Retrieve the AirInv Master service context
418  if (_airinvMasterServiceContext == NULL) {
419  throw stdair::NonInitialisedServiceException ("The AirInvMaster service "
420  "has not been initialised");
421  }
422  assert (_airinvMasterServiceContext != NULL);
423 
424  // Retrieve the AirInv service context and whether it owns the Stdair
425  // service
426  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
427  *_airinvMasterServiceContext;
428  const bool doesOwnStdairService =
429  lAIRINV_Master_ServiceContext.getOwnStdairServiceFlag();
430 
431  // Retrieve the slave AIRINV service object from the (AIRINV)
432  // service context
433  AIRINV_Service& lAIRINV_Service =
434  lAIRINV_Master_ServiceContext.getAIRINV_Service();
435 
436  // Retrieve the StdAir service object from the (AIRINV) service context
437  stdair::STDAIR_Service& lSTDAIR_Service =
438  lAIRINV_Master_ServiceContext.getSTDAIR_Service();
439 
444  if (doesOwnStdairService == true) {
445 
446  //
447  lSTDAIR_Service.clonePersistentBom ();
448  }
449 
454  lAIRINV_Service.clonePersistentBom ();
455 
460  stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
461  buildComplementaryLinks (lBomRoot);
462  }
463 
464  // ////////////////////////////////////////////////////////////////////
466  buildComplementaryLinks (stdair::BomRoot& ioBomRoot) {
467  // Currently, no more things to do by AIRINV_Master at that stage.
468  }
469 
470  // ////////////////////////////////////////////////////////////////////
471  std::string AIRINV_Master_Service::
472  jsonHandler (const stdair::JSONString& lJSONString) const {
473 
474  // Retrieve the AirInv Master service context
475  if (_airinvMasterServiceContext == NULL) {
476  throw stdair::NonInitialisedServiceException ("The AirInvMaster service "
477  "has not been initialised");
478  }
479  assert (_airinvMasterServiceContext != NULL);
480 
481  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
482  *_airinvMasterServiceContext;
483 
484  // Retrieve the slave AirInv (slave) service object from
485  // the (AirInv master) service context
486  AIRINV_Service& lAIRINV_Service =
487  lAIRINV_Master_ServiceContext.getAIRINV_Service();
488 
489  // Delegate the BOM dump to the dedicated service
490  return lAIRINV_Service.jsonHandler (lJSONString);
491 
492  }
493 
494  // ////////////////////////////////////////////////////////////////////
495  std::string AIRINV_Master_Service::
496  jsonExportFlightDateList (const stdair::AirlineCode_T& iAirlineCode,
497  const stdair::FlightNumber_T& iFlightNumber) const {
498 
499  // Retrieve the AirInv Master service context
500  if (_airinvMasterServiceContext == NULL) {
501  throw stdair::NonInitialisedServiceException ("The AirInvMaster service "
502  "has not been initialised");
503  }
504  assert (_airinvMasterServiceContext != NULL);
505 
506  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
507  *_airinvMasterServiceContext;
508 
509  // Retrieve the slave AirInv (slave) service object from
510  // the (AirInv master) service context
511  AIRINV_Service& lAIRINV_Service =
512  lAIRINV_Master_ServiceContext.getAIRINV_Service();
513 
514  // Delegate the JSON export to the dedicated service
515  return lAIRINV_Service.jsonExportFlightDateList (iAirlineCode,
516  iFlightNumber);
517  }
518 
519  // ////////////////////////////////////////////////////////////////////
520  std::string AIRINV_Master_Service::
521  jsonExportFlightDateObjects (const stdair::AirlineCode_T& iAirlineCode,
522  const stdair::FlightNumber_T& iFlightNumber,
523  const stdair::Date_T& iDepartureDate) const {
524 
525  // Retrieve the AirInv Master service context
526  if (_airinvMasterServiceContext == NULL) {
527  throw stdair::NonInitialisedServiceException ("The AirInvMaster service "
528  "has not been initialised");
529  }
530  assert (_airinvMasterServiceContext != NULL);
531 
532  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
533  *_airinvMasterServiceContext;
534 
535  // Retrieve the slave AirInv (slave) service object from
536  // the (AirInv master) service context
537  AIRINV_Service& lAIRINV_Service =
538  lAIRINV_Master_ServiceContext.getAIRINV_Service();
539 
540  // Delegate the BOM dump to the dedicated service
541  return lAIRINV_Service.jsonExportFlightDateObjects (iAirlineCode,
542  iFlightNumber,
543  iDepartureDate);
544  }
545 
546  // ////////////////////////////////////////////////////////////////////
547  std::string AIRINV_Master_Service::
548  list (const stdair::AirlineCode_T& iAirlineCode,
549  const stdair::FlightNumber_T& iFlightNumber) const {
550  std::ostringstream oFlightListStr;
551 
552  // Retrieve the AirInv Master service context
553  if (_airinvMasterServiceContext == NULL) {
554  throw stdair::NonInitialisedServiceException ("The AirInvMaster service "
555  "has not been initialised");
556  }
557  assert (_airinvMasterServiceContext != NULL);
558 
559  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
560  *_airinvMasterServiceContext;
561 
562  // Retrieve the slave AirInv (slave) service object from
563  // the (AirInv master) service context
564  AIRINV_Service& lAIRINV_Service =
565  lAIRINV_Master_ServiceContext.getAIRINV_Service();
566 
567  // Delegate the BOM display to the dedicated service
568  return lAIRINV_Service.list (iAirlineCode, iFlightNumber);
569  }
570 
571  // ////////////////////////////////////////////////////////////////////
573  check (const stdair::AirlineCode_T& iAirlineCode,
574  const stdair::FlightNumber_T& iFlightNumber,
575  const stdair::Date_T& iDepartureDate) const {
576  std::ostringstream oFlightListStr;
577 
578  // Retrieve the AirInv Master service context
579  if (_airinvMasterServiceContext == NULL) {
580  throw stdair::NonInitialisedServiceException ("The AirInvMaster service "
581  "has not been initialised");
582  }
583  assert (_airinvMasterServiceContext != NULL);
584 
585  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
586  *_airinvMasterServiceContext;
587 
588  // Retrieve the slave AirInv (slave) service object from
589  // the (AirInv master) service context
590  AIRINV_Service& lAIRINV_Service =
591  lAIRINV_Master_ServiceContext.getAIRINV_Service();
592 
593  // Delegate the BOM display to the dedicated service
594  return lAIRINV_Service.check (iAirlineCode, iFlightNumber, iDepartureDate);
595  }
596 
597  // ////////////////////////////////////////////////////////////////////
598  std::string AIRINV_Master_Service::csvDisplay() const {
599 
600  // Retrieve the AirInv Master service context
601  if (_airinvMasterServiceContext == NULL) {
602  throw stdair::NonInitialisedServiceException ("The AirInvMaster service "
603  "has not been initialised");
604  }
605  assert (_airinvMasterServiceContext != NULL);
606 
607  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
608  *_airinvMasterServiceContext;
609 
610  // Retrieve the slave AIRINV service object from
611  // the (AIRINV) service context
612  AIRINV_Service& lAIRINV_Service =
613  lAIRINV_Master_ServiceContext.getAIRINV_Service();
614 
615  // Delegate the BOM display to the dedicated service
616  return lAIRINV_Service.csvDisplay();
617  }
618 
619  // ////////////////////////////////////////////////////////////////////
620  std::string AIRINV_Master_Service::
621  csvDisplay (const stdair::AirlineCode_T& iAirlineCode,
622  const stdair::FlightNumber_T& iFlightNumber,
623  const stdair::Date_T& iDepartureDate) const {
624 
625  // Retrieve the AirInv Master service context
626  if (_airinvMasterServiceContext == NULL) {
627  throw stdair::NonInitialisedServiceException ("The AirInvMaster service "
628  "has not been initialised");
629  }
630  assert (_airinvMasterServiceContext != NULL);
631 
632  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
633  *_airinvMasterServiceContext;
634 
635  // Retrieve the slave AIRINV service object from
636  // the (AIRINV) service context
637  AIRINV_Service& lAIRINV_Service =
638  lAIRINV_Master_ServiceContext.getAIRINV_Service();
639 
640  // Delegate the BOM display to the dedicated service
641  return lAIRINV_Service.csvDisplay (iAirlineCode, iFlightNumber,
642  iDepartureDate);
643  }
644 
645  // ////////////////////////////////////////////////////////////////////
647  initSnapshotAndRMEvents (const stdair::Date_T& iStartDate,
648  const stdair::Date_T& iEndDate) {
649 
650  // Retrieve the AirInv Master service context
651  if (_airinvMasterServiceContext == NULL) {
652  throw stdair::NonInitialisedServiceException ("The AirInvMaster service "
653  "has not been initialised");
654  }
655  assert (_airinvMasterServiceContext != NULL);
656 
657  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
658  *_airinvMasterServiceContext;
659 
660  // Retrieve the pointer on the SEvMgr service context
661  SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
662  lAIRINV_Master_ServiceContext.getSEVMGR_ServicePtr();
663  assert (lSEVMGR_Service_ptr != NULL);
664 
665  // Initialise the snapshot events
666  InventoryManager::initSnapshotEvents (lSEVMGR_Service_ptr, iStartDate, iEndDate);
667 
668  // \todo Browse the list of inventories and itinialise the RM events of
669  // each inventory.
670 
671  // Retrieve the slave AIRINV service object from the (AIRINV)
672  // service context
673  AIRINV_Service& lAIRINV_Service =
674  lAIRINV_Master_ServiceContext.getAIRINV_Service();
675  lSEVMGR_Service_ptr->addStatus (stdair::EventType::RM, 0);
676  stdair::RMEventList_T lRMEventList =
677  lAIRINV_Service.initRMEvents (iStartDate, iEndDate);
678  assert (lRMEventList.empty() == false);
679  InventoryManager::addRMEventsToEventQueue (lSEVMGR_Service_ptr, lRMEventList);
680  }
681 
682  // ////////////////////////////////////////////////////////////////////
684  calculateAvailability (stdair::TravelSolutionStruct& ioTravelSolution) {
685 
686  // Retrieve the AirInv Master service context
687  if (_airinvMasterServiceContext == NULL) {
688  throw stdair::NonInitialisedServiceException ("The AirInvMaster service "
689  "has not been initialised");
690  }
691  assert (_airinvMasterServiceContext != NULL);
692 
693  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
694  *_airinvMasterServiceContext;
695 
696  // Retrieve the slave AIRINV service object from the (AIRINV)
697  // service context
698  AIRINV_Service& lAIRINV_Service =
699  lAIRINV_Master_ServiceContext.getAIRINV_Service();
700 
701  // Delegate the availability retrieval to the dedicated service
702  stdair::BasChronometer lAvlChronometer;
703  lAvlChronometer.start();
704 
705  lAIRINV_Service.calculateAvailability (ioTravelSolution);
706 
707  // DEBUG
708  // const double lAvlMeasure = lAvlChronometer.elapsed();
709  // STDAIR_LOG_DEBUG ("Availability retrieval: " << lAvlMeasure << " - "
710  // << lAIRINV_Master_ServiceContext.display());
711  }
712 
713  // ////////////////////////////////////////////////////////////////////
714  bool AIRINV_Master_Service::sell (const std::string& iSegmentDateKey,
715  const stdair::ClassCode_T& iClassCode,
716  const stdair::PartySize_T& iPartySize) {
717 
718  // Retrieve the AirInv Master service context
719  if (_airinvMasterServiceContext == NULL) {
720  throw stdair::NonInitialisedServiceException ("The AirInvMaster service "
721  "has not been initialised");
722  }
723  assert (_airinvMasterServiceContext != NULL);
724 
725  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
726  *_airinvMasterServiceContext;
727 
728  // Retrieve the corresponding inventory key
729  // const stdair::InventoryKey& lInventoryKey =
730  // stdair::BomKeyManager::extractInventoryKey (iSegmentDateKey);
731 
732  // Retrieve the slave AirInv service object from the (AirInv Master)
733  // service context
734  AIRINV_Service& lAIRINV_Service =
735  lAIRINV_Master_ServiceContext.getAIRINV_Service();
736 
737  // Delegate the booking to the dedicated command
738  stdair::BasChronometer lSellChronometer;
739  lSellChronometer.start();
740 
741  // Delegate the BOM building to the dedicated service
742  const bool hasBeenSaleSuccessful =
743  lAIRINV_Service.sell (iSegmentDateKey, iClassCode, iPartySize);
744 
745  // const double lSellMeasure = lSellChronometer.elapsed();
746 
747  // DEBUG
748  // STDAIR_LOG_DEBUG ("Booking sell: " << lSellMeasure << " - "
749  // << lAIRINV_Master_ServiceContext.display());
750 
751  //
752  return hasBeenSaleSuccessful;
753  }
754 
755  // ////////////////////////////////////////////////////////////////////
756  bool AIRINV_Master_Service::sell (const stdair::BookingClassID_T& iClassID,
757  const stdair::PartySize_T& iPartySize) {
758 
759  // Retrieve the AirInv Master service context
760  if (_airinvMasterServiceContext == NULL) {
761  throw stdair::NonInitialisedServiceException ("The AirInvMaster service "
762  "has not been initialised");
763  }
764  assert (_airinvMasterServiceContext != NULL);
765 
766  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
767  *_airinvMasterServiceContext;
768 
769  // Retrieve the corresponding inventory key
770  // const stdair::InventoryKey& lInventoryKey =
771  // stdair::BomKeyManager::extractInventoryKey (iSegmentDateKey);
772 
773  // Retrieve the slave AirInv service object from the (AirInv Master)
774  // service context
775  AIRINV_Service& lAIRINV_Service =
776  lAIRINV_Master_ServiceContext.getAIRINV_Service();
777 
778  // Delegate the booking to the dedicated command
779  stdair::BasChronometer lSellChronometer;
780  lSellChronometer.start();
781 
782  // Delegate the BOM building to the dedicated service
783  const bool hasBeenSaleSuccessful =
784  lAIRINV_Service.sell (iClassID, iPartySize);
785 
786  // const double lSellMeasure = lSellChronometer.elapsed();
787 
788  // DEBUG
789  // STDAIR_LOG_DEBUG ("Booking sell: " << lSellMeasure << " - "
790  // << lAIRINV_Master_ServiceContext.display());
791 
792  //
793  return hasBeenSaleSuccessful;
794  }
795 
796  // ////////////////////////////////////////////////////////////////////
797  bool AIRINV_Master_Service::cancel (const std::string& iSegmentDateKey,
798  const stdair::ClassCode_T& iClassCode,
799  const stdair::PartySize_T& iPartySize) {
800 
801  // Retrieve the AirInv Master service context
802  if (_airinvMasterServiceContext == NULL) {
803  throw stdair::NonInitialisedServiceException ("The AirInvMaster service "
804  "has not been initialised");
805  }
806  assert (_airinvMasterServiceContext != NULL);
807 
808  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
809  *_airinvMasterServiceContext;
810 
811  // Retrieve the corresponding inventory key
812  // const stdair::InventoryKey& lInventoryKey =
813  // stdair::BomKeyManager::extractInventoryKey (iSegmentDateKey);
814 
815  // Retrieve the slave AirInv service object from the (AirInv Master)
816  // service context
817  AIRINV_Service& lAIRINV_Service =
818  lAIRINV_Master_ServiceContext.getAIRINV_Service();
819 
820  // Delegate the booking to the dedicated command
821  stdair::BasChronometer lCancelChronometer;
822  lCancelChronometer.start();
823 
824  // Delegate the BOM building to the dedicated service
825  const bool hasBeenSaleSuccessful =
826  lAIRINV_Service.cancel (iSegmentDateKey, iClassCode, iPartySize);
827 
828  // const double lCancelMeasure = lCancelChronometer.elapsed();
829 
830  // DEBUG
831  // STDAIR_LOG_DEBUG ("Booking cancel: " << lCancelMeasure << " - "
832  // << lAIRINV_Master_ServiceContext.display());
833 
834  //
835  return hasBeenSaleSuccessful;
836  }
837 
838  // ////////////////////////////////////////////////////////////////////
839  bool AIRINV_Master_Service::cancel (const stdair::BookingClassID_T& iClassID,
840  const stdair::PartySize_T& iPartySize) {
841 
842  // Retrieve the AirInv Master service context
843  if (_airinvMasterServiceContext == NULL) {
844  throw stdair::NonInitialisedServiceException ("The AirInvMaster service "
845  "has not been initialised");
846  }
847  assert (_airinvMasterServiceContext != NULL);
848 
849  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
850  *_airinvMasterServiceContext;
851 
852  // Retrieve the corresponding inventory key
853  // const stdair::InventoryKey& lInventoryKey =
854  // stdair::BomKeyManager::extractInventoryKey (iSegmentDateKey);
855 
856  // Retrieve the slave AirInv service object from the (AirInv Master)
857  // service context
858  AIRINV_Service& lAIRINV_Service =
859  lAIRINV_Master_ServiceContext.getAIRINV_Service();
860 
861  // Delegate the booking to the dedicated command
862  stdair::BasChronometer lCancelChronometer;
863  lCancelChronometer.start();
864 
865  // Delegate the BOM building to the dedicated service
866  const bool hasBeenSaleSuccessful =
867  lAIRINV_Service.cancel (iClassID, iPartySize);
868 
869  // const double lCancelMeasure = lCancelChronometer.elapsed();
870 
871  // DEBUG
872  // STDAIR_LOG_DEBUG ("Booking cancel: " << lCancelMeasure << " - "
873  // << lAIRINV_Master_ServiceContext.display());
874 
875  //
876  return hasBeenSaleSuccessful;
877  }
878 
879  // ////////////////////////////////////////////////////////////////////
881  takeSnapshots (const stdair::SnapshotStruct& iSnapshot) {
882 
883  // Retrieve the AirInv Master service context
884  if (_airinvMasterServiceContext == NULL) {
885  throw stdair::NonInitialisedServiceException ("The AirInvMaster service "
886  "has not been initialised");
887  }
888  assert (_airinvMasterServiceContext != NULL);
889 
890  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
891  *_airinvMasterServiceContext;
892 
893  // Retrieve the slave AIRINV service object from the (AIRINV)
894  // service context
895  AIRINV_Service& lAIRINV_Service =
896  lAIRINV_Master_ServiceContext.getAIRINV_Service();
897 
898  // Retrieve the snapshot time and the airline code.
899  const stdair::DateTime_T& lSnapshotTime = iSnapshot.getSnapshotTime();
900  const stdair::AirlineCode_T& lAirlineCode = iSnapshot.getAirlineCode();
901 
902  lAIRINV_Service.takeSnapshots (lAirlineCode, lSnapshotTime);
903  }
904 
905  // ////////////////////////////////////////////////////////////////////
907  optimise (const stdair::RMEventStruct& iRMEvent) {
908 
909  // Retrieve the AirInv Master service context
910  if (_airinvMasterServiceContext == NULL) {
911  throw stdair::NonInitialisedServiceException ("The AirInvMaster service "
912  "has not been initialised");
913  }
914  assert (_airinvMasterServiceContext != NULL);
915 
916  AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
917  *_airinvMasterServiceContext;
918 
919  // Retrieve the slave AIRINV service object from the (AIRINV)
920  // service context
921  AIRINV_Service& lAIRINV_Service =
922  lAIRINV_Master_ServiceContext.getAIRINV_Service();
923 
924  // Retrieve the snapshot time and the airline code.
925  const stdair::DateTime_T& lRMEventTime = iRMEvent.getRMEventTime();
926  const stdair::AirlineCode_T& lAirlineCode = iRMEvent.getAirlineCode();
927  const stdair::KeyDescription_T& lFDDescription =
928  iRMEvent.getFlightDateDescription();
929 
930  lAIRINV_Service.optimise (lAirlineCode, lFDDescription, lRMEventTime);
931  }
932 }