$treeview $search $mathjax
00001 // ////////////////////////////////////////////////////////////////////// 00002 // Import section 00003 // ////////////////////////////////////////////////////////////////////// 00004 // STL 00005 #include <cassert> 00006 // Boost 00007 #include <boost/make_shared.hpp> 00008 // StdAir 00009 #include <stdair/basic/ProgressStatusSet.hpp> 00010 #include <stdair/basic/EventType.hpp> 00011 #include <stdair/basic/BasConst_Event.hpp> 00012 #include <stdair/bom/BomManager.hpp> 00013 #include <stdair/bom/EventStruct.hpp> 00014 #include <stdair/bom/BookingRequestStruct.hpp> 00015 #include <stdair/bom/BreakPointStruct.hpp> 00016 #include <stdair/service/Logger.hpp> 00017 #include <stdair/STDAIR_Service.hpp> 00018 // SEvMgr 00019 #include <sevmgr/bom/EventQueue.hpp> 00020 #include <sevmgr/command/EventQueueManager.hpp> 00021 00022 namespace SEVMGR { 00023 00024 // ////////////////////////////////////////////////////////////////////// 00025 void EventQueueManager:: 00026 buildSampleQueue (stdair::STDAIR_ServicePtr_T lSTDAIR_ServicePtr, 00027 EventQueue& ioEventQueue) { 00028 00029 // Total number of booking requests into the queue 00030 stdair::Count_T lNbOfBookingRequests (2); 00031 addStatus(ioEventQueue, stdair::EventType::BKG_REQ, lNbOfBookingRequests); 00032 00033 // Create a shared pointer on a first booking request 00034 // Date of the request (15-MAY-2011) 00035 const stdair::BookingRequestStruct& lBookingRequest = 00036 buildSampleBookingRequest (lSTDAIR_ServicePtr); 00037 const stdair::BookingRequestPtr_T lBookingRequest_ptr = 00038 boost::make_shared<stdair::BookingRequestStruct> (lBookingRequest); 00039 00040 // Create an event structure 00041 stdair::EventStruct lEventStruct (stdair::EventType::BKG_REQ, 00042 lBookingRequest_ptr); 00043 00044 // Add the event into the queue 00045 addEvent(ioEventQueue, lEventStruct); 00046 00047 // Create a second shared pointer on a second booking request 00048 // Date of the request (22-JAN-2010) 00049 const bool isForCRS = true; 00050 const stdair::BookingRequestStruct& lBookingRequestForCRS = 00051 buildSampleBookingRequest (lSTDAIR_ServicePtr, isForCRS); 00052 const stdair::BookingRequestPtr_T lBookingRequestForCRS_ptr = 00053 boost::make_shared<stdair::BookingRequestStruct> (lBookingRequestForCRS); 00054 00055 // Create an event structure 00056 stdair::EventStruct lEventStructForCRS (stdair::EventType::BKG_REQ, 00057 lBookingRequestForCRS_ptr); 00058 00059 // Add the event into the queue 00060 addEvent(ioEventQueue, lEventStructForCRS); 00061 00062 // Total number of break points into the queue 00063 stdair::Count_T lNbOfBreakPoints (2); 00064 addStatus(ioEventQueue, stdair::EventType::BRK_PT, lNbOfBreakPoints); 00065 00066 // Create a shared pointer on a second break point 00067 // Date of the break point (21-JAN-2010) 00068 const stdair::Date_T lBP1Date (2010, boost::gregorian::Jan, 21); 00069 // Time of the break point (00:00) 00070 const stdair::Duration_T lBP1Time (0, 0, 0); 00071 // Date-time of the break point (made of the date and time above) 00072 const stdair::DateTime_T lBP1DateTime (lBP1Date, lBP1Time); 00073 const stdair::BreakPointPtr_T lBreakPoint1_ptr = 00074 boost::make_shared<stdair::BreakPointStruct> (lBP1DateTime); 00075 00076 // Create an event structure 00077 stdair::EventStruct lEventBreakPoint1 (stdair::EventType::BRK_PT, 00078 lBreakPoint1_ptr); 00079 00080 // Add the event into the queue 00081 addEvent(ioEventQueue, lEventBreakPoint1); 00082 00083 // Create a shared pointer on a second break point 00084 // Date of the break point (14-MAY-2011) 00085 const stdair::Date_T lBP2Date (2011, boost::gregorian::May, 14); 00086 // Time of the break point (00:00) 00087 const stdair::Duration_T lBP2Time (0, 0, 0); 00088 // Date-time of the break point (made of the date and time above) 00089 const stdair::DateTime_T lBP2DateTime (lBP2Date, lBP2Time); 00090 00091 // TODO: understand why the form above does not work. 00092 const stdair::BreakPointPtr_T lBreakPoint2_ptr = 00093 boost::make_shared<stdair::BreakPointStruct> (lBP2DateTime); 00094 00095 // Create an event structure 00096 stdair::EventStruct lEventBreakPoint2 (stdair::EventType::BRK_PT, 00097 lBreakPoint2_ptr); 00098 00099 // Add the event into the queue 00100 addEvent(ioEventQueue, lEventBreakPoint2); 00101 00102 } 00103 00104 // ////////////////////////////////////////////////////////////////////// 00105 stdair::BookingRequestStruct EventQueueManager:: 00106 buildSampleBookingRequest(stdair::STDAIR_ServicePtr_T lSTDAIR_ServicePtr, 00107 const bool isForCRS) { 00108 00109 // Delegate the booking request building to the dedicated service 00110 stdair::BookingRequestStruct oBookingRequest = 00111 lSTDAIR_ServicePtr->buildSampleBookingRequest (isForCRS); 00112 00113 return oBookingRequest; 00114 } 00115 00116 00117 // //////////////////////////////////////////////////////////////////// 00118 void EventQueueManager::reset (EventQueue& ioEventQueue) { 00119 00123 ioEventQueue.reset(); 00124 } 00125 00126 // //////////////////////////////////////////////////////////////////// 00127 bool EventQueueManager:: 00128 hasProgressStatus (const EventQueue& iEventQueue, 00129 const stdair::EventType::EN_EventType& iEventType) { 00130 00134 const bool hasProgressStatus = iEventQueue.hasProgressStatus(iEventType); 00135 00136 // 00137 return hasProgressStatus; 00138 } 00139 00140 // //////////////////////////////////////////////////////////////////// 00141 void EventQueueManager::addEvent (EventQueue& ioEventQueue, 00142 stdair::EventStruct& iEventStruct) { 00143 00147 ioEventQueue.addEvent(iEventStruct); 00148 } 00149 00150 // ////////////////////////////////////////////////////////////////////// 00151 const std::string EventQueueManager:: 00152 list (const EventQueue& iEventQueue) { 00153 00157 const std::string& lEventListStr = iEventQueue.list(); 00158 00159 // 00160 return lEventListStr; 00161 } 00162 00163 // ////////////////////////////////////////////////////////////////////// 00164 const std::string EventQueueManager:: 00165 list (const EventQueue& iEventQueue, 00166 const stdair::EventType::EN_EventType& iEventType) { 00167 00171 const std::string& lEventListStr = 00172 iEventQueue.list(iEventType); 00173 00174 // 00175 return lEventListStr; 00176 } 00177 00178 // ////////////////////////////////////////////////////////////////////// 00179 const std::string EventQueueManager:: 00180 describeKey (const EventQueue& iEventQueue) { 00181 00185 const std::string& lEventQueueKeyStr = iEventQueue.describeKey(); 00186 00187 // 00188 return lEventQueueKeyStr; 00189 } 00190 00191 // //////////////////////////////////////////////////////////////////// 00192 stdair::ProgressStatusSet EventQueueManager:: 00193 popEvent (EventQueue& ioEventQueue, 00194 stdair::EventStruct& iEventStruct) { 00195 00196 try { 00200 const stdair::ProgressStatusSet& lProgressStatusSet 00201 = ioEventQueue.popEvent (iEventStruct); 00202 00203 // DEBUG 00204 std::ostringstream oEventStr; 00205 oEventStr << "Poped event: '" 00206 << iEventStruct.describe() << "'."; 00207 STDAIR_LOG_DEBUG (oEventStr.str()); 00208 00209 // 00210 return lProgressStatusSet; 00211 00212 } catch (EventQueueException& lEventQueueException) { 00213 // DEBUG 00214 std::ostringstream oErrorMessage; 00215 oErrorMessage << "The event queue is empty: no event can be popped out."; 00216 std::cerr << oErrorMessage.str() << std::endl; 00217 STDAIR_LOG_DEBUG(oErrorMessage.str()); 00218 00219 } 00220 00221 // 00222 return stdair::ProgressStatusSet(stdair::EventType::BKG_REQ); 00223 } 00224 00225 // //////////////////////////////////////////////////////////////////// 00226 void EventQueueManager::run (EventQueue& ioEventQueue, 00227 stdair::EventStruct& iEventStruct) { 00228 00229 // Default event type 00230 stdair::EventType::EN_EventType lEventType = stdair::EventType::BKG_REQ; 00231 00232 // While no break point has been encountered, keep on extracting events 00233 while (ioEventQueue.isQueueDone() == false 00234 && lEventType != stdair::EventType::BRK_PT) { 00238 ioEventQueue.popEvent (iEventStruct); 00239 lEventType = iEventStruct.getEventType(); 00240 00241 } 00242 00243 } 00244 00245 // //////////////////////////////////////////////////////////////////// 00246 bool EventQueueManager::select (EventQueue& ioEventQueue, 00247 stdair::EventStruct& iEventStruct, 00248 const stdair::DateTime_T& iDateTime) { 00249 00250 // Search if an event has the given key 00251 const bool hasResearchBeenSuccessful = 00252 ioEventQueue.hasEventDateTime (iDateTime); 00253 00254 // If no event has the given hey, return 00255 if (hasResearchBeenSuccessful == false) { 00256 return hasResearchBeenSuccessful; 00257 } 00258 assert (hasResearchBeenSuccessful == true); 00259 00260 // Default date time 00261 stdair::DateTime_T lDateTime = stdair::DEFAULT_EVENT_OLDEST_DATETIME; 00262 00263 // While the event with the given key has not been retrieved, keep on 00264 // extracting events 00265 while (ioEventQueue.isQueueDone() == false 00266 && lDateTime != iDateTime) { 00267 ioEventQueue.popEvent (iEventStruct); 00268 lDateTime = iEventStruct.getEventTime (); 00269 00270 } 00271 00272 assert (lDateTime == iDateTime); 00273 return hasResearchBeenSuccessful; 00274 00275 } 00276 00277 // //////////////////////////////////////////////////////////////////// 00278 void EventQueueManager:: 00279 updateStatus (EventQueue& ioEventQueue, 00280 const stdair::EventType::EN_EventType& iEventType, 00281 const stdair::Count_T& iEventCount) { 00282 00286 ioEventQueue.updateStatus (iEventType, iEventCount); 00287 } 00288 00289 // //////////////////////////////////////////////////////////////////// 00290 void EventQueueManager:: 00291 addStatus (EventQueue& ioEventQueue, 00292 const stdair::EventType::EN_EventType& iEventType, 00293 const stdair::Count_T& iEventCount) { 00294 00299 ioEventQueue.addStatus (iEventType, iEventCount); 00300 } 00301 00302 // //////////////////////////////////////////////////////////////////// 00303 bool EventQueueManager:: 00304 isQueueDone (const EventQueue& iEventQueue) { 00305 00309 const bool isQueueDone = iEventQueue.isQueueDone(); 00310 00311 // 00312 return isQueueDone; 00313 } 00314 00315 // //////////////////////////////////////////////////////////////////// 00316 const stdair::Count_T& EventQueueManager:: 00317 getQueueSize (const EventQueue& iEventQueue) { 00318 00322 const stdair::Count_T& lQueueSize = iEventQueue.getQueueSize(); 00323 00324 // 00325 return lQueueSize; 00326 } 00327 00328 // //////////////////////////////////////////////////////////////////// 00329 const stdair::Count_T& EventQueueManager:: 00330 getExpectedTotalNumberOfEventsToBeGenerated (const EventQueue& ioEventQueue) { 00331 00335 const stdair::Count_T& lExpectedTotalNumberOfEvents = 00336 ioEventQueue.getExpectedTotalNbOfEvents (); 00337 00338 // 00339 return lExpectedTotalNumberOfEvents; 00340 } 00341 00342 // //////////////////////////////////////////////////////////////////// 00343 const stdair::Count_T& EventQueueManager:: 00344 getExpectedTotalNumberOfEventsToBeGenerated (const EventQueue& ioEventQueue, 00345 const stdair::EventType::EN_EventType& iEventType) { 00346 00350 const stdair::Count_T& lExpectedTotalNumberOfEvents = 00351 ioEventQueue.getExpectedTotalNbOfEvents (iEventType); 00352 00353 // 00354 return lExpectedTotalNumberOfEvents; 00355 } 00356 00357 // //////////////////////////////////////////////////////////////////// 00358 const stdair::Count_T& EventQueueManager:: 00359 getActualTotalNumberOfEventsToBeGenerated (const EventQueue& ioEventQueue) { 00360 00364 const stdair::Count_T& lActualTotalNumberOfEvents = 00365 ioEventQueue.getActualTotalNbOfEvents (); 00366 00367 // 00368 return lActualTotalNumberOfEvents; 00369 00370 } 00371 00372 // //////////////////////////////////////////////////////////////////// 00373 const stdair::Count_T& EventQueueManager:: 00374 getActualTotalNumberOfEventsToBeGenerated (const EventQueue& ioEventQueue, 00375 const stdair::EventType::EN_EventType& iEventType) { 00376 00380 const stdair::Count_T& lActualTotalNumberOfEvents = 00381 ioEventQueue.getActualTotalNbOfEvents (iEventType); 00382 00383 // 00384 return lActualTotalNumberOfEvents; 00385 00386 } 00387 00389 const stdair::ProgressStatus& EventQueueManager:: 00390 getStatus (const EventQueue& iEventQueue, 00391 const stdair::EventType::EN_EventType& iEventType) { 00392 00396 return iEventQueue.getStatus(iEventType); 00397 00398 } 00399 00401 const stdair::ProgressStatus& EventQueueManager:: 00402 getStatus (const EventQueue& iEventQueue) { 00403 00407 return iEventQueue.getStatus(); 00408 00409 } 00410 00411 }