7 #include <boost/make_shared.hpp>
9 #include <stdair/basic/ProgressStatusSet.hpp>
10 #include <stdair/basic/EventType.hpp>
11 #include <stdair/basic/BasConst_Event.hpp>
12 #include <stdair/bom/BomManager.hpp>
13 #include <stdair/bom/EventStruct.hpp>
14 #include <stdair/bom/BookingRequestStruct.hpp>
15 #include <stdair/bom/BreakPointStruct.hpp>
16 #include <stdair/service/Logger.hpp>
17 #include <stdair/STDAIR_Service.hpp>
25 void EventQueueManager::
26 buildSampleQueue (stdair::STDAIR_ServicePtr_T lSTDAIR_ServicePtr,
27 EventQueue& ioEventQueue) {
30 stdair::Count_T lNbOfBookingRequests (2);
31 addStatus(ioEventQueue, stdair::EventType::BKG_REQ, lNbOfBookingRequests);
35 const stdair::BookingRequestStruct& lBookingRequest =
36 buildSampleBookingRequest (lSTDAIR_ServicePtr);
37 const stdair::BookingRequestPtr_T lBookingRequest_ptr =
38 boost::make_shared<stdair::BookingRequestStruct> (lBookingRequest);
41 stdair::EventStruct lEventStruct (stdair::EventType::BKG_REQ,
45 addEvent(ioEventQueue, lEventStruct);
49 const bool isForCRS =
true;
50 const stdair::BookingRequestStruct& lBookingRequestForCRS =
51 buildSampleBookingRequest (lSTDAIR_ServicePtr, isForCRS);
52 const stdair::BookingRequestPtr_T lBookingRequestForCRS_ptr =
53 boost::make_shared<stdair::BookingRequestStruct> (lBookingRequestForCRS);
56 stdair::EventStruct lEventStructForCRS (stdair::EventType::BKG_REQ,
57 lBookingRequestForCRS_ptr);
60 addEvent(ioEventQueue, lEventStructForCRS);
63 stdair::Count_T lNbOfBreakPoints (2);
64 addStatus(ioEventQueue, stdair::EventType::BRK_PT, lNbOfBreakPoints);
68 const stdair::Date_T lBP1Date (2010, boost::gregorian::Jan, 21);
70 const stdair::Duration_T lBP1Time (0, 0, 0);
72 const stdair::DateTime_T lBP1DateTime (lBP1Date, lBP1Time);
73 const stdair::BreakPointPtr_T lBreakPoint1_ptr =
74 boost::make_shared<stdair::BreakPointStruct> (lBP1DateTime);
77 stdair::EventStruct lEventBreakPoint1 (stdair::EventType::BRK_PT,
81 addEvent(ioEventQueue, lEventBreakPoint1);
85 const stdair::Date_T lBP2Date (2011, boost::gregorian::May, 14);
87 const stdair::Duration_T lBP2Time (0, 0, 0);
89 const stdair::DateTime_T lBP2DateTime (lBP2Date, lBP2Time);
92 const stdair::BreakPointPtr_T lBreakPoint2_ptr =
93 boost::make_shared<stdair::BreakPointStruct> (lBP2DateTime);
96 stdair::EventStruct lEventBreakPoint2 (stdair::EventType::BRK_PT,
100 addEvent(ioEventQueue, lEventBreakPoint2);
105 stdair::BookingRequestStruct EventQueueManager::
106 buildSampleBookingRequest(stdair::STDAIR_ServicePtr_T lSTDAIR_ServicePtr,
107 const bool isForCRS) {
110 stdair::BookingRequestStruct oBookingRequest =
111 lSTDAIR_ServicePtr->buildSampleBookingRequest (isForCRS);
113 return oBookingRequest;
118 void EventQueueManager::reset (EventQueue& ioEventQueue) {
123 ioEventQueue.reset();
127 bool EventQueueManager::
128 hasProgressStatus (
const EventQueue& iEventQueue,
129 const stdair::EventType::EN_EventType& iEventType) {
134 const bool hasProgressStatus = iEventQueue.hasProgressStatus(iEventType);
137 return hasProgressStatus;
141 void EventQueueManager::addEvent (EventQueue& ioEventQueue,
142 stdair::EventStruct& iEventStruct) {
147 ioEventQueue.addEvent(iEventStruct);
151 const std::string EventQueueManager::
152 list (
const EventQueue& iEventQueue) {
157 const std::string& lEventListStr = iEventQueue.list();
160 return lEventListStr;
164 const std::string EventQueueManager::
165 list (
const EventQueue& iEventQueue,
166 const stdair::EventType::EN_EventType& iEventType) {
171 const std::string& lEventListStr =
172 iEventQueue.list(iEventType);
175 return lEventListStr;
179 const std::string EventQueueManager::
180 describeKey (
const EventQueue& iEventQueue) {
185 const std::string& lEventQueueKeyStr = iEventQueue.describeKey();
188 return lEventQueueKeyStr;
192 stdair::ProgressStatusSet EventQueueManager::
193 popEvent (EventQueue& ioEventQueue,
194 stdair::EventStruct& iEventStruct) {
200 const stdair::ProgressStatusSet& lProgressStatusSet
201 = ioEventQueue.popEvent (iEventStruct);
204 std::ostringstream oEventStr;
205 oEventStr <<
"Poped event: '"
206 << iEventStruct.describe() <<
"'.";
207 STDAIR_LOG_DEBUG (oEventStr.str());
210 return lProgressStatusSet;
212 }
catch (EventQueueException& lEventQueueException) {
214 std::ostringstream oErrorMessage;
215 oErrorMessage <<
"The event queue is empty: no event can be popped out.";
216 std::cerr << oErrorMessage.str() << std::endl;
217 STDAIR_LOG_DEBUG(oErrorMessage.str());
222 return stdair::ProgressStatusSet(stdair::EventType::BKG_REQ);
226 void EventQueueManager::run (EventQueue& ioEventQueue,
227 stdair::EventStruct& iEventStruct) {
230 stdair::EventType::EN_EventType lEventType = stdair::EventType::BKG_REQ;
233 while (ioEventQueue.isQueueDone() ==
false
234 && lEventType != stdair::EventType::BRK_PT) {
238 ioEventQueue.popEvent (iEventStruct);
239 lEventType = iEventStruct.getEventType();
246 bool EventQueueManager::select (EventQueue& ioEventQueue,
247 stdair::EventStruct& iEventStruct,
248 const stdair::DateTime_T& iDateTime) {
251 const bool hasResearchBeenSuccessful =
252 ioEventQueue.hasEventDateTime (iDateTime);
255 if (hasResearchBeenSuccessful ==
false) {
256 return hasResearchBeenSuccessful;
258 assert (hasResearchBeenSuccessful ==
true);
261 stdair::DateTime_T lDateTime = stdair::DEFAULT_EVENT_OLDEST_DATETIME;
265 while (ioEventQueue.isQueueDone() ==
false
266 && lDateTime != iDateTime) {
267 ioEventQueue.popEvent (iEventStruct);
268 lDateTime = iEventStruct.getEventTime ();
272 assert (lDateTime == iDateTime);
273 return hasResearchBeenSuccessful;
278 void EventQueueManager::
279 updateStatus (EventQueue& ioEventQueue,
280 const stdair::EventType::EN_EventType& iEventType,
281 const stdair::Count_T& iEventCount) {
286 ioEventQueue.updateStatus (iEventType, iEventCount);
290 void EventQueueManager::
291 addStatus (EventQueue& ioEventQueue,
292 const stdair::EventType::EN_EventType& iEventType,
293 const stdair::Count_T& iEventCount) {
299 ioEventQueue.addStatus (iEventType, iEventCount);
303 bool EventQueueManager::
304 isQueueDone (
const EventQueue& iEventQueue) {
309 const bool isQueueDone = iEventQueue.isQueueDone();
316 const stdair::Count_T& EventQueueManager::
317 getQueueSize (
const EventQueue& iEventQueue) {
322 const stdair::Count_T& lQueueSize = iEventQueue.getQueueSize();
329 const stdair::Count_T& EventQueueManager::
330 getExpectedTotalNumberOfEventsToBeGenerated (
const EventQueue& ioEventQueue) {
335 const stdair::Count_T& lExpectedTotalNumberOfEvents =
336 ioEventQueue.getExpectedTotalNbOfEvents ();
339 return lExpectedTotalNumberOfEvents;
343 const stdair::Count_T& EventQueueManager::
344 getExpectedTotalNumberOfEventsToBeGenerated (
const EventQueue& ioEventQueue,
345 const stdair::EventType::EN_EventType& iEventType) {
350 const stdair::Count_T& lExpectedTotalNumberOfEvents =
351 ioEventQueue.getExpectedTotalNbOfEvents (iEventType);
354 return lExpectedTotalNumberOfEvents;
358 const stdair::Count_T& EventQueueManager::
359 getActualTotalNumberOfEventsToBeGenerated (
const EventQueue& ioEventQueue) {
364 const stdair::Count_T& lActualTotalNumberOfEvents =
365 ioEventQueue.getActualTotalNbOfEvents ();
368 return lActualTotalNumberOfEvents;
373 const stdair::Count_T& EventQueueManager::
374 getActualTotalNumberOfEventsToBeGenerated (
const EventQueue& ioEventQueue,
375 const stdair::EventType::EN_EventType& iEventType) {
380 const stdair::Count_T& lActualTotalNumberOfEvents =
381 ioEventQueue.getActualTotalNbOfEvents (iEventType);
384 return lActualTotalNumberOfEvents;
389 const stdair::ProgressStatus& EventQueueManager::
390 getStatus (
const EventQueue& iEventQueue,
391 const stdair::EventType::EN_EventType& iEventType) {
396 return iEventQueue.getStatus(iEventType);
401 const stdair::ProgressStatus& EventQueueManager::
402 getStatus (
const EventQueue& iEventQueue) {
407 return iEventQueue.getStatus();