7 #include <stdair/stdair_exceptions.hpp>
8 #include <stdair/basic/BasConst_Event.hpp>
9 #include <stdair/bom/EventStruct.hpp>
10 #include <stdair/service/Logger.hpp>
18 EventQueue::EventQueue()
20 _progressStatus (stdair::DEFAULT_PROGRESS_STATUS,
21 stdair::DEFAULT_PROGRESS_STATUS) {
25 EventQueue::EventQueue (
const Key_T& iKey)
26 : _key (iKey), _parent (NULL),
27 _progressStatus (stdair::DEFAULT_PROGRESS_STATUS,
28 stdair::DEFAULT_PROGRESS_STATUS) {
34 _progressStatus (stdair::DEFAULT_PROGRESS_STATUS,
35 stdair::DEFAULT_PROGRESS_STATUS) {
46 std::ostringstream oStr;
56 std::ostringstream oStr;
65 std::ostringstream oStr;
70 for (stdair::EventList_T::const_iterator itEvent =
_eventList.begin();
72 const stdair::EventStruct& lEvent = itEvent->second;
74 oStr << lEvent.describe();
82 list (
const stdair::EventType::EN_EventType& iType)
const {
83 std::ostringstream oStr;
86 oStr <<
"List " << stdair::EventType::getLabel(iType)
87 <<
" events:" << std::endl;
90 for (stdair::EventList_T::const_iterator itEvent =
_eventList.begin();
92 const stdair::EventStruct& lEvent = itEvent->second;
94 if (lEvent.getEventType() == iType) {
95 oStr << lEvent.describe();
126 for (ProgressStatusMap_T::iterator itProgressStatus =
129 stdair::ProgressStatus& lProgressStatus = itProgressStatus->second;
130 lProgressStatus.reset();
142 ProgressStatusMap_T::const_iterator itProgressStatus =
146 STDAIR_LOG_DEBUG (
"No ProgressStatus structure can be retrieved in the "
147 <<
"EventQueue: " <<
display());
149 hasProgressStatus =
false;
161 ProgressStatusMap_T::const_iterator itProgressStatus =
165 STDAIR_LOG_ERROR (
"No ProgressStatus structure can be retrieved in the "
166 <<
"EventQueue: " <<
display());
170 const stdair::ProgressStatus& lProgressStatus = itProgressStatus->second;
171 return lProgressStatus.getCurrentNb();
180 ProgressStatusMap_T::const_iterator itProgressStatus =
183 std::ostringstream oStr;
184 oStr <<
"No ProgressStatus structure can be retrieved in the EventQueue '"
185 <<
display() <<
"'. The EventQueue should be initialised, e.g., by "
186 <<
"calling a buildSampleBom() method.";
188 STDAIR_LOG_ERROR (oStr.str());
192 const stdair::ProgressStatus& lProgressStatus = itProgressStatus->second;
193 return lProgressStatus.getExpectedNb();
202 ProgressStatusMap_T::const_iterator itProgressStatus =
206 STDAIR_LOG_ERROR (
"No ProgressStatus structure can be retrieved in the "
207 <<
"EventQueue: " <<
display());
211 const stdair::ProgressStatus& lProgressStatus = itProgressStatus->second;
212 return lProgressStatus.getActualNb();
217 const stdair::ProgressStatus& iProgressStatus) {
221 ProgressStatusMap_T::iterator itProgressStatus =
224 const bool hasInsertBeenSuccessful =
226 value_type (iType, iProgressStatus)).second;
228 if (hasInsertBeenSuccessful ==
false) {
229 STDAIR_LOG_ERROR (
"No progress_status can be inserted "
230 <<
"for the following event type: "
231 << stdair::EventType::getLabel(iType)
233 throw stdair::EventException (
"No progress_status can be inserted for the "
234 "following event type: "
235 + stdair::EventType::getLabel(iType)
242 stdair::ProgressStatus& lProgressStatus = itProgressStatus->second;
245 const stdair::Count_T& lCurrentNb = iProgressStatus.getCurrentNb();
246 lProgressStatus.setCurrentNb (lCurrentNb);
248 const stdair::Count_T& lExpectedNb = iProgressStatus.getExpectedNb();
249 lProgressStatus.setExpectedNb(lProgressStatus.getExpectedNb() + lExpectedNb);
251 const stdair::Count_T& lActualNb = iProgressStatus.getActualNb();
252 lProgressStatus.setActualNb (lProgressStatus.getActualNb() + lActualNb);
257 addStatus (
const stdair::EventType::EN_EventType& iType,
258 const stdair::NbOfEvents_T& iExpectedTotalNbOfEvents) {
261 const stdair::Count_T lExpectedTotalNbOfEventsInt =
262 static_cast<const stdair::Count_T
> (std::floor (iExpectedTotalNbOfEvents));
263 const stdair::ProgressStatus lProgressStatus (lExpectedTotalNbOfEventsInt);
269 const stdair::Count_T lExpectedNb =
271 + iExpectedTotalNbOfEvents);
274 const stdair::Count_T lActualNb =
276 + iExpectedTotalNbOfEvents);
283 const stdair::NbOfEvents_T& iActualNbOfEvents) {
286 stdair:: Count_T lActualNbOfEventsInt =
287 static_cast<const stdair::Count_T
> (std::floor (iActualNbOfEvents));
290 ProgressStatusMap_T::iterator itProgressStatus =
295 stdair::ProgressStatus& lProgressStatus = itProgressStatus->second;
298 const stdair::Count_T lActualEventTypeNb = lProgressStatus.getActualNb();
300 _progressStatus.setActualNb (lActualTotalNb + iActualNbOfEvents - lActualEventTypeNb);
303 lProgressStatus.setActualNb (lActualNbOfEventsInt);
309 const stdair::ProgressStatus& iProgressStatus) {
313 ProgressStatusMap_T::iterator itProgressStatus =
318 itProgressStatus->second = iProgressStatus;
324 getStatus (
const stdair::EventType::EN_EventType& iType)
const {
328 ProgressStatusMap_T::const_iterator itProgressStatus =
331 std::ostringstream oStr;
332 oStr <<
"No ProgressStatus structure can be retrieved in the EventQueue '"
333 <<
display() <<
"' for the following event type: "
334 << stdair::EventType::getLabel(iType) <<
".";
336 STDAIR_LOG_ERROR (oStr.str());
341 const stdair::ProgressStatus& oProgressStatus = itProgressStatus->second;
342 return oProgressStatus;
351 ProgressStatusMap_T::const_iterator itProgressStatus =
355 STDAIR_LOG_ERROR (
"No ProgressStatus structure can be retrieved in the "
356 <<
"EventQueue: " <<
display());
360 const stdair::ProgressStatus& lProgressStatus = itProgressStatus->second;
361 return lProgressStatus.progress();
368 std::ostringstream oStr;
369 oStr <<
"The event queue '" <<
describeKey() <<
"' is empty. "
370 <<
"No event can be popped.";
372 STDAIR_LOG_ERROR (oStr.str());
380 stdair::EventList_T::iterator itEvent =
_eventList.begin();
388 ioEventStruct = itEvent->second;
390 const stdair::EventType::EN_EventType& lEventType = ioEventStruct.getEventType();
391 stdair::ProgressStatusSet oProgressStatusSet (lEventType);
410 stdair::ProgressStatus lEventTypeProgressStatus =
getStatus (lEventType);
413 ++lEventTypeProgressStatus;
416 setStatus (lEventType, lEventTypeProgressStatus);
420 oProgressStatusSet.setTypeSpecificStatus (lEventTypeProgressStatus);
429 return oProgressStatusSet;
434 bool insertionSucceeded =
435 _eventList.insert (stdair::EventListElement_T (ioEventStruct.getEventTimeStamp(),
436 ioEventStruct)).second;
450 const unsigned int idx = 0;
451 while (insertionSucceeded ==
false && idx != 1e3) {
453 ioEventStruct.incrementEventTimeStamp();
457 _eventList.insert (stdair::EventListElement_T (ioEventStruct.getEventTimeStamp(),
458 ioEventStruct)).second;
462 return insertionSucceeded;
468 bool hasSearchEventBeenSucessful =
true;
475 const stdair::Duration_T lDuration =
476 iDateTime - stdair::DEFAULT_EVENT_OLDEST_DATETIME;
477 const stdair::LongDuration_T lDateTimeStamp =
478 lDuration.total_milliseconds();
481 stdair::EventList_T::iterator itEvent =
487 hasSearchEventBeenSucessful =
false;
490 return hasSearchEventBeenSucessful;