8 #include <boost/make_shared.hpp>
10 #include <stdair/basic/BasChronometer.hpp>
11 #include <stdair/basic/BasConst_General.hpp>
12 #include <stdair/basic/JSonCommand.hpp>
13 #include <stdair/bom/BomRoot.hpp>
14 #include <stdair/bom/BomDisplay.hpp>
15 #include <stdair/bom/EventStruct.hpp>
16 #include <stdair/bom/BookingRequestStruct.hpp>
17 #include <stdair/bom/BomJSONImport.hpp>
18 #include <stdair/service/Logger.hpp>
19 #include <stdair/STDAIR_Service.hpp>
32 SEVMGR_Service::SEVMGR_Service() : _sevmgrServiceContext (NULL) {
37 SEVMGR_Service::SEVMGR_Service (
const SEVMGR_Service& iService)
38 : _sevmgrServiceContext (NULL) {
43 SEVMGR_Service::SEVMGR_Service (
const stdair::BasLogParams& iLogParams,
44 const stdair::BasDBParams& iDBParams)
45 : _sevmgrServiceContext (NULL) {
48 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
49 initStdAirService (iLogParams, iDBParams);
56 const bool ownStdairService =
true;
57 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
64 SEVMGR_Service::SEVMGR_Service (
const stdair::BasLogParams& iLogParams)
65 : _sevmgrServiceContext (NULL) {
68 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
69 initStdAirService (iLogParams);
76 const bool ownStdairService =
true;
77 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
85 SEVMGR_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr)
86 : _sevmgrServiceContext (NULL) {
93 const bool doesNotOwnStdairService =
false;
94 addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
107 void SEVMGR_Service::finalise() {
108 assert (_sevmgrServiceContext != NULL);
110 _sevmgrServiceContext->reset();
114 void SEVMGR_Service::initServiceContext() {
116 SEVMGR_ServiceContext& lSEVMGR_ServiceContext =
118 _sevmgrServiceContext = &lSEVMGR_ServiceContext;
122 void SEVMGR_Service::
123 addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
124 const bool iOwnStdairService) {
126 assert (_sevmgrServiceContext != NULL);
127 SEVMGR_ServiceContext& lSEVMGR_ServiceContext =
128 *_sevmgrServiceContext;
131 lSEVMGR_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
136 stdair::STDAIR_ServicePtr_T SEVMGR_Service::
137 initStdAirService (
const stdair::BasLogParams& iLogParams,
138 const stdair::BasDBParams& iDBParams) {
145 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
146 boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
147 assert (lSTDAIR_Service_ptr != NULL);
149 return lSTDAIR_Service_ptr;
153 stdair::STDAIR_ServicePtr_T SEVMGR_Service::
154 initStdAirService (
const stdair::BasLogParams& iLogParams) {
161 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
162 boost::make_shared<stdair::STDAIR_Service> (iLogParams);
163 assert (lSTDAIR_Service_ptr != NULL);
165 return lSTDAIR_Service_ptr;
169 void SEVMGR_Service::initSevmgrService() {
178 if (_sevmgrServiceContext == NULL) {
179 throw stdair::NonInitialisedServiceException (
"The SEvMgr service has "
180 "not been initialised");
182 assert (_sevmgrServiceContext != NULL);
187 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
188 lSEVMGR_ServiceContext.getSTDAIR_ServicePtr();
191 EventQueue& lEventQueue = lSEVMGR_ServiceContext.getEventQueue();
203 if (_sevmgrServiceContext == NULL) {
204 throw stdair::NonInitialisedServiceException (
"The SEvMgr service has "
205 "not been initialised");
207 assert (_sevmgrServiceContext != NULL);
212 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
213 lSEVMGR_ServiceContext.getSTDAIR_ServicePtr();
216 stdair::BookingRequestStruct oBookingRequest =
220 return oBookingRequest;
227 if (_sevmgrServiceContext == NULL) {
228 throw stdair::NonInitialisedServiceException (
"The SEvMgr service has "
229 "not been initialised");
231 assert (_sevmgrServiceContext != NULL);
236 EventQueue& lEventQueue = lSEVMGR_ServiceContext.getEventQueue();
246 if (_sevmgrServiceContext == NULL) {
247 throw stdair::NonInitialisedServiceException (
"The SEvMgr service has "
248 "not been initialised");
250 assert (_sevmgrServiceContext != NULL);
255 EventQueue& lEventQueue = lSEVMGR_ServiceContext.getEventQueue ();
263 list (
const stdair::EventType::EN_EventType& iEventType)
const {
266 if (_sevmgrServiceContext == NULL) {
267 throw stdair::NonInitialisedServiceException (
"The SEvMgr service has "
268 "not been initialised");
270 assert (_sevmgrServiceContext != NULL);
275 EventQueue& lEventQueue = lSEVMGR_ServiceContext.getEventQueue ();
288 stdair::JSonCommand::EN_JSonCommand lEN_JSonCommand;
289 const bool hasCommandBeenRetrieved =
290 stdair::BomJSONImport::jsonImportCommand (iJSONString,
293 if (hasCommandBeenRetrieved ==
false) {
295 std::ostringstream oErrorStream;
296 oErrorStream <<
"{\"error\": \"Wrong JSON-ified string: "
297 <<
"the command is not understood.\"}";
298 return oErrorStream.str();
300 assert (hasCommandBeenRetrieved ==
true);
305 switch (lEN_JSonCommand) {
306 case stdair::JSonCommand::EVENT_LIST:{
311 stdair::EventType::EN_EventType lEN_EventType;
312 const bool hasEventTypeBeenRetrieved =
313 stdair::BomJSONImport::jsonImportEventType (iJSONString,
316 if (hasEventTypeBeenRetrieved ==
true) {
323 std::ostringstream lErrorCmdMessage;
324 const std::string& lCommandStr =
325 stdair::JSonCommand::getLabel(lEN_JSonCommand);
326 lErrorCmdMessage <<
"{\"error\": \"The command '" << lCommandStr
327 <<
"' is not handled by the DSim service.\"}";
328 return lErrorCmdMessage.str();
335 std::string lJSONDump (
"{\"error\": \"Wrong JSON-ified string\"}");
344 std::ostringstream oStr;
347 if (_sevmgrServiceContext == NULL) {
348 throw stdair::NonInitialisedServiceException (
"The SEvMgr service "
349 "has not been initialised");
351 assert (_sevmgrServiceContext != NULL);
356 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
357 lSEVMGR_ServiceContext.getSTDAIR_ServicePtr();
361 lSEVMGR_ServiceContext.getEventQueue();
365 lEventQueue, iEventType);
374 std::ostringstream oStr;
377 if (_sevmgrServiceContext == NULL) {
378 throw stdair::NonInitialisedServiceException (
"The SEvMgr service "
379 "has not been initialised");
381 assert (_sevmgrServiceContext != NULL);
386 stdair::STDAIR_Service& lSTDAIR_Service =
387 lSEVMGR_ServiceContext.getSTDAIR_Service();
390 oStr << lSTDAIR_Service.jsonExportEventObject (iEvent);
398 popEvent (stdair::EventStruct& iEventStruct)
const {
401 if (_sevmgrServiceContext == NULL) {
402 throw stdair::NonInitialisedServiceException (
"The SEvMgr service "
403 "has not been initialised");
405 assert (_sevmgrServiceContext != NULL);
409 EventQueue& lQueue = lSEVMGR_ServiceContext.getEventQueue();
417 run (stdair::EventStruct& iEventStruct)
const {
420 if (_sevmgrServiceContext == NULL) {
421 throw stdair::NonInitialisedServiceException (
"The SEvMgr service "
422 "has not been initialised");
424 assert (_sevmgrServiceContext != NULL);
428 EventQueue& lQueue = lSEVMGR_ServiceContext.getEventQueue();
437 select (stdair::EventStruct& iEventStruct,
438 const stdair::DateTime_T& iEventDateTime)
const {
441 if (_sevmgrServiceContext == NULL) {
442 throw stdair::NonInitialisedServiceException (
"The SEvMgr service "
443 "has not been initialised");
445 assert (_sevmgrServiceContext != NULL);
449 EventQueue& lQueue = lSEVMGR_ServiceContext.getEventQueue();
459 const stdair::Count_T& iEventCount)
const {
462 if (_sevmgrServiceContext == NULL) {
463 throw stdair::NonInitialisedServiceException (
"The SEvMgr service "
464 "has not been initialised");
466 assert (_sevmgrServiceContext != NULL);
470 EventQueue& lQueue = lSEVMGR_ServiceContext.getEventQueue();
478 addStatus (
const stdair::EventType::EN_EventType& iEventType,
479 const stdair::Count_T& iEventCount)
const {
482 if (_sevmgrServiceContext == NULL) {
483 throw stdair::NonInitialisedServiceException (
"The SEvMgr service "
484 "has not been initialised");
486 assert (_sevmgrServiceContext != NULL);
490 EventQueue& lQueue = lSEVMGR_ServiceContext.getEventQueue();
500 if (_sevmgrServiceContext == NULL) {
501 throw stdair::NonInitialisedServiceException (
"The SEvMgr service "
502 "has not been initialised");
504 assert (_sevmgrServiceContext != NULL);
506 *_sevmgrServiceContext;
509 const EventQueue& lQueue = lSEVMGR_ServiceContext.getEventQueue();
522 if (_sevmgrServiceContext == NULL) {
523 throw stdair::NonInitialisedServiceException (
"The SEvMgr service "
524 "has not been initialised");
526 assert (_sevmgrServiceContext != NULL);
528 *_sevmgrServiceContext;
531 const EventQueue& lQueue = lSEVMGR_ServiceContext.getEventQueue();
545 if (_sevmgrServiceContext == NULL) {
546 throw stdair::NonInitialisedServiceException (
"The SEvMgr service "
547 "has not been initialised");
549 assert (_sevmgrServiceContext != NULL);
551 *_sevmgrServiceContext;
554 const EventQueue& lQueue = lSEVMGR_ServiceContext.getEventQueue();
564 if (_sevmgrServiceContext == NULL) {
565 throw stdair::NonInitialisedServiceException (
"The SEvMgr service "
566 "has not been initialised");
568 assert (_sevmgrServiceContext != NULL);
570 *_sevmgrServiceContext;
573 EventQueue& lQueue = lSEVMGR_ServiceContext.getEventQueue();
583 if (_sevmgrServiceContext == NULL) {
584 throw stdair::NonInitialisedServiceException (
"The SEvMgr service "
585 "has not been initialised");
587 assert (_sevmgrServiceContext != NULL);
590 *_sevmgrServiceContext;
592 return lSEVMGR_ServiceContext.getEventQueue();
599 if (_sevmgrServiceContext == NULL) {
600 throw stdair::NonInitialisedServiceException (
"The SEvMgr service "
601 "has not been initialised");
603 assert (_sevmgrServiceContext != NULL);
605 *_sevmgrServiceContext;
608 EventQueue& lQueue = lSEVMGR_ServiceContext.getEventQueue();
619 if (_sevmgrServiceContext == NULL) {
620 throw stdair::NonInitialisedServiceException (
"The SEvMgr service "
621 "has not been initialised");
623 assert (_sevmgrServiceContext != NULL);
625 *_sevmgrServiceContext;
628 const EventQueue& lQueue = lSEVMGR_ServiceContext.getEventQueue();
639 if (_sevmgrServiceContext == NULL) {
640 throw stdair::NonInitialisedServiceException (
"The SEvMgr service "
641 "has not been initialised");
643 assert (_sevmgrServiceContext != NULL);
645 *_sevmgrServiceContext;
648 const EventQueue& lQueue = lSEVMGR_ServiceContext.getEventQueue();
660 if (_sevmgrServiceContext == NULL) {
661 throw stdair::NonInitialisedServiceException (
"The SEvMgr service "
662 "has not been initialised");
664 assert (_sevmgrServiceContext != NULL);
666 *_sevmgrServiceContext;
669 const EventQueue& lQueue = lSEVMGR_ServiceContext.getEventQueue();
681 if (_sevmgrServiceContext == NULL) {
682 throw stdair::NonInitialisedServiceException (
"The SEvMgr service "
683 "has not been initialised");
685 assert (_sevmgrServiceContext != NULL);
687 *_sevmgrServiceContext;
690 const EventQueue& lQueue = lSEVMGR_ServiceContext.getEventQueue();
699 const stdair::STDAIR_Service& SEVMGR_Service::getSTDAIR_Service()
const {
702 if (_sevmgrServiceContext == NULL) {
703 throw stdair::NonInitialisedServiceException (
"The SEvMgr service "
704 "has not been initialised");
706 assert (_sevmgrServiceContext != NULL);
707 const stdair::STDAIR_Service& lSTDAIR_Service =
708 _sevmgrServiceContext->getSTDAIR_Service();
711 return lSTDAIR_Service;
718 if (_sevmgrServiceContext == NULL) {
719 throw stdair::NonInitialisedServiceException (
"The SEvMgr service "
720 "has not been initialised");
722 assert (_sevmgrServiceContext != NULL);
724 *_sevmgrServiceContext;
727 EventQueue& lQueue = lSEVMGR_ServiceContext.getEventQueue();
736 getStatus(
const stdair::EventType::EN_EventType& iEventType)
const {
739 if (_sevmgrServiceContext == NULL) {
740 throw stdair::NonInitialisedServiceException (
"The SEvMgr service "
741 "has not been initialised");
743 assert (_sevmgrServiceContext != NULL);
745 *_sevmgrServiceContext;
748 EventQueue& lQueue = lSEVMGR_ServiceContext.getEventQueue();