TravelCCM Logo  0.5.3
C++ Travel Customer Choice Model Library
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
TRAVELCCM_Service.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 // Boost
7 #include <boost/make_shared.hpp>
8 // StdAir
9 #include <stdair/basic/BasChronometer.hpp>
10 #include <stdair/basic/BasFileMgr.hpp>
11 #include <stdair/bom/BomManager.hpp>
12 #include <stdair/bom/BookingRequestStruct.hpp>
13 #include <stdair/factory/FacBomManager.hpp>
14 #include <stdair/service/Logger.hpp>
15 #include <stdair/STDAIR_Service.hpp>
16 // TravelCCM
21 
22 namespace TRAVELCCM {
23 
24  // ////////////////////////////////////////////////////////////////////
25  TRAVELCCM_Service::TRAVELCCM_Service() : _travelccmServiceContext (NULL) {
26  assert (false);
27  }
28 
29  // ////////////////////////////////////////////////////////////////////
30  TRAVELCCM_Service::TRAVELCCM_Service (const TRAVELCCM_Service& iService)
31  : _travelccmServiceContext (NULL) {
32  assert (false);
33  }
34 
35  // ////////////////////////////////////////////////////////////////////
36  TRAVELCCM_Service::TRAVELCCM_Service (const stdair::BasLogParams& iLogParams,
37  const stdair::BasDBParams& iDBParams)
38  : _travelccmServiceContext (NULL) {
39 
40  // Initialise the STDAIR service handler
41  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
42  initStdAirService (iLogParams, iDBParams);
43 
44  // Initialise the service context
45  initServiceContext();
46 
47  // Add the StdAir service context to the AIRINV service context
48  // \note AIRINV owns the STDAIR service resources here.
49  const bool ownStdairService = true;
50  addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
51 
52  // Initialise the (remaining of the) context
53  initTravelCCMService();
54  }
55 
56  // ////////////////////////////////////////////////////////////////////
57  TRAVELCCM_Service::TRAVELCCM_Service (const stdair::BasLogParams& iLogParams)
58  : _travelccmServiceContext (NULL) {
59 
60  // Initialise the STDAIR service handler
61  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
62  initStdAirService (iLogParams);
63 
64  // Initialise the service context
65  initServiceContext();
66 
67  // Add the StdAir service context to the AIRINV service context
68  // \note AIRINV owns the STDAIR service resources here.
69  const bool ownStdairService = true;
70  addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
71 
72  // Initialise the (remaining of the) context
73  initTravelCCMService();
74  }
75 
76  // ////////////////////////////////////////////////////////////////////
77  TRAVELCCM_Service::
78  TRAVELCCM_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr)
79  : _travelccmServiceContext (NULL) {
80 
81  // Initialise the service context
82  initServiceContext();
83 
84  // Store the STDAIR service object within the (AIRINV) service context
85  // \note AirInv does not own the STDAIR service resources here.
86  const bool doesNotOwnStdairService = false;
87  addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
88 
89  // Initialise the (remaining of the) context
90  initTravelCCMService();
91  }
92 
93  // ////////////////////////////////////////////////////////////////////
95  // Delete/Clean all the objects from memory
96  finalise();
97  }
98 
99  // ////////////////////////////////////////////////////////////////////
100  void TRAVELCCM_Service::finalise() {
101  assert (_travelccmServiceContext != NULL);
102  // Reset the (Boost.)Smart pointer pointing on the STDAIR_Service object.
103  _travelccmServiceContext->reset();
104  }
105 
106  // ////////////////////////////////////////////////////////////////////
107  void TRAVELCCM_Service::initServiceContext() {
108  // Initialise the context
109  TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
111  _travelccmServiceContext = &lTRAVELCCM_ServiceContext;
112  }
113 
114  // ////////////////////////////////////////////////////////////////////
115  void TRAVELCCM_Service::
116  addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
117  const bool iOwnStdairService) {
118  // Retrieve the Travelccm service context
119  assert (_travelccmServiceContext != NULL);
120  TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
121  *_travelccmServiceContext;
122 
123  // Store the STDAIR service object within the (TRAVELCCM) service context
124  lTRAVELCCM_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
125  iOwnStdairService);
126  }
127 
128  // ////////////////////////////////////////////////////////////////////
129  stdair::STDAIR_ServicePtr_T TRAVELCCM_Service::
130  initStdAirService (const stdair::BasLogParams& iLogParams,
131  const stdair::BasDBParams& iDBParams) {
132 
139  stdair::STDAIR_ServicePtr_T oSTDAIR_Service_ptr =
140  boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
141  assert (oSTDAIR_Service_ptr != NULL);
142 
143  return oSTDAIR_Service_ptr;
144  }
145 
146  // ////////////////////////////////////////////////////////////////////
147  stdair::STDAIR_ServicePtr_T TRAVELCCM_Service::
148  initStdAirService (const stdair::BasLogParams& iLogParams) {
149 
156  stdair::STDAIR_ServicePtr_T oSTDAIR_Service_ptr =
157  boost::make_shared<stdair::STDAIR_Service> (iLogParams);
158  assert (oSTDAIR_Service_ptr != NULL);
159 
160  return oSTDAIR_Service_ptr;
161  }
162 
163  // ////////////////////////////////////////////////////////////////////
164  void TRAVELCCM_Service::initTravelCCMService() {
165  // Do nothing at this stage. A sample BOM tree may be built by
166  // calling the buildSampleBom() method
167  }
168 
169  // //////////////////////////////////////////////////////////////////////
171 
172  // Retrieve the TravelCCM service context
173  if (_travelccmServiceContext == NULL) {
174  throw stdair::NonInitialisedServiceException ("The TravelCCM service has "
175  "not been initialised");
176  }
177  assert (_travelccmServiceContext != NULL);
178 
179  // Retrieve the TravelCCM service context and whether it owns the Stdair
180  // service
181  TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
182  *_travelccmServiceContext;
183  const bool doesOwnStdairService =
184  lTRAVELCCM_ServiceContext.getOwnStdairServiceFlag();
185 
186  // Retrieve the StdAir service object from the (TravelCCM) service context
187  stdair::STDAIR_Service& lSTDAIR_Service =
188  lTRAVELCCM_ServiceContext.getSTDAIR_Service();
189 
194  if (doesOwnStdairService == true) {
195  //
196  lSTDAIR_Service.buildSampleBom();
197  }
198 
213  }
214 
215  // //////////////////////////////////////////////////////////////////////
217  buildSampleTravelSolutions (stdair::TravelSolutionList_T& ioTSList) {
218 
219  // Retrieve the TRAVELCCM service context
220  if (_travelccmServiceContext == NULL) {
221  throw stdair::NonInitialisedServiceException ("The Travelccm service has "
222  "not been initialised");
223  }
224  assert (_travelccmServiceContext != NULL);
225 
226  TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
227  *_travelccmServiceContext;
228 
229  // Retrieve the STDAIR service object from the (TRAVELCCM) service context
230  stdair::STDAIR_Service& lSTDAIR_Service =
231  lTRAVELCCM_ServiceContext.getSTDAIR_Service();
232 
233  // Delegate the BOM building to the dedicated service
234  lSTDAIR_Service.buildSampleTravelSolutions (ioTSList);
235  }
236 
237  // //////////////////////////////////////////////////////////////////////
238  stdair::BookingRequestStruct TRAVELCCM_Service::
239  buildSampleBookingRequest (const bool isForCRS) {
240 
241  // Retrieve the TRAVELCCM service context
242  if (_travelccmServiceContext == NULL) {
243  throw stdair::NonInitialisedServiceException ("The Travelccm service has "
244  "not been initialised");
245  }
246  assert (_travelccmServiceContext != NULL);
247 
248  TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
249  *_travelccmServiceContext;
250 
251  // Retrieve the STDAIR service object from the (TRAVELCCM) service context
252  stdair::STDAIR_Service& lSTDAIR_Service =
253  lTRAVELCCM_ServiceContext.getSTDAIR_Service();
254 
255  // Delegate the BOM building to the dedicated service
256  return lSTDAIR_Service.buildSampleBookingRequest (isForCRS);
257  }
258 
259  // //////////////////////////////////////////////////////////////////////
260  std::string TRAVELCCM_Service::csvDisplay() const {
261 
262  // Retrieve the TRAVELCCM service context
263  if (_travelccmServiceContext == NULL) {
264  throw stdair::NonInitialisedServiceException ("The TravelccmMaster service"
265  " has not been initialised");
266  }
267  assert (_travelccmServiceContext != NULL);
268 
269  TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
270  *_travelccmServiceContext;
271 
272  // Retrieve the STDAIR service object from the (TRAVELCCM) service context
273  stdair::STDAIR_Service& lSTDAIR_Service =
274  lTRAVELCCM_ServiceContext.getSTDAIR_Service();
275 
276  // Delegate the BOM building to the dedicated service
277  return lSTDAIR_Service.csvDisplay();
278  }
279 
280  // //////////////////////////////////////////////////////////////////////
281  std::string TRAVELCCM_Service::
282  csvDisplay (const stdair::TravelSolutionList_T& iTravelSolutionList) const {
283  // Retrieve the TRAVELCCM service context
284  if (_travelccmServiceContext == NULL) {
285  throw stdair::NonInitialisedServiceException ("The TravelccmMaster service"
286  " has not been initialised");
287  }
288  assert (_travelccmServiceContext != NULL);
289 
290  TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
291  *_travelccmServiceContext;
292 
293  // Retrieve the STDAIR service object from the (TRAVELCCM) service context
294  stdair::STDAIR_Service& lSTDAIR_Service =
295  lTRAVELCCM_ServiceContext.getSTDAIR_Service();
296 
297  // Delegate the BOM building to the dedicated service
298  return lSTDAIR_Service.csvDisplay (iTravelSolutionList);
299  }
300 
301  // ////////////////////////////////////////////////////////////////////
302  const stdair::TravelSolutionStruct* TRAVELCCM_Service::
303  chooseTravelSolution (stdair::TravelSolutionList_T& ioTravelSolutionList,
304  const stdair::BookingRequestStruct& iBookingRequest) {
305 
306  const stdair::TravelSolutionStruct* oTravelSolution_ptr =
307  ChoiceManager::chooseTravelSolution (ioTravelSolutionList,
308  iBookingRequest);
309  return oTravelSolution_ptr;
310  }
311 
312 }