StdAir Logo  0.44.0
C++ Standard Airline IT Object Library
EventQueue.hpp
Go to the documentation of this file.
00001 #ifndef __STDAIR_BOM_EVENTQUEUE_HPP
00002 #define __STDAIR_BOM_EVENTQUEUE_HPP
00003 
00004 // //////////////////////////////////////////////////////////////////////
00005 // Import section
00006 // //////////////////////////////////////////////////////////////////////
00007 // STL
00008 #include <iosfwd>
00009 #include <string>
00010 // StdAir
00011 #include <stdair/stdair_basic_types.hpp>
00012 #include <stdair/basic/ProgressStatusSet.hpp>
00013 #include <stdair/basic/EventType.hpp>
00014 #include <stdair/bom/BomAbstract.hpp>
00015 #include <stdair/bom/EventQueueKey.hpp>
00016 #include <stdair/bom/EventQueueTypes.hpp>
00017 #include <stdair/bom/EventTypes.hpp>
00018 
00019 namespace stdair {
00020 
00059   class EventQueue : public BomAbstract {
00060     template <typename BOM> friend class FacBom;
00061     friend class FacBomManager;
00062 
00063   public:
00064     // ////////// Type definitions ////////////
00068     typedef EventQueueKey Key_T;
00069 
00075     typedef std::map<EventType::EN_EventType,
00076                      ProgressStatus> ProgressStatusMap_T;
00077     
00078 
00079   public:
00080     // /////////// Getters ///////////////
00082     const Key_T& getKey() const {
00083       return _key;
00084     }
00085 
00087     BomAbstract* const getParent() const {
00088       return _parent;
00089     }
00090     
00092     const HolderMap_T& getHolderMap() const {
00093       return _holderMap;
00094     }
00095     
00097     const ProgressStatus& getStatus() const {
00098       return _progressStatus;
00099     }
00101     const Count_T& getCurrentNbOfEvents() const {
00102       return _progressStatus.getCurrentNb();
00103     }
00105     const Count_T& getExpectedTotalNbOfEvents() const {
00106       return _progressStatus.getExpectedNb();
00107     }
00109     const Count_T& getActualTotalNbOfEvents() const {
00110       return _progressStatus.getActualNb();
00111     }
00112 
00117     ProgressStatus getStatus (const EventType::EN_EventType&) const;
00118 
00120     const Count_T& getCurrentNbOfEvents (const EventType::EN_EventType&) const;
00121 
00123     const Count_T& getExpectedTotalNbOfEvents (const EventType::EN_EventType&) const;
00124 
00126     const Count_T& getActualTotalNbOfEvents (const EventType::EN_EventType&) const;
00127 
00128   public:
00129     // /////////// Setters ///////////////
00131     void setStatus (const ProgressStatus& iProgressStatus) {
00132       _progressStatus = iProgressStatus;
00133     }
00135     void setStatus (const Count_T& iCurrentNbOfEvents,
00136                     const Count_T& iExpectedTotalNbOfEvents,
00137                     const Count_T& iActualTotalNbOfEvents) {
00138       _progressStatus.setCurrentNb (iCurrentNbOfEvents);
00139       _progressStatus.setExpectedNb (iExpectedTotalNbOfEvents);
00140       _progressStatus.setActualNb (iActualTotalNbOfEvents);
00141     }
00143     void setStatus (const Count_T& iCurrentNbOfEvents,
00144                     const Count_T& iActualTotalNbOfEvents) {
00145       _progressStatus.setCurrentNb (iCurrentNbOfEvents);
00146       _progressStatus.setActualNb (iActualTotalNbOfEvents);
00147     }
00149     void setCurrentNbOfEvents (const Count_T& iCurrentNbOfEvents) {
00150       _progressStatus.setCurrentNb (iCurrentNbOfEvents);
00151     }
00153     void setExpectedTotalNbOfEvents (const Count_T& iExpectedTotalNbOfEvents) {
00154       _progressStatus.setExpectedNb (iExpectedTotalNbOfEvents);
00155     }
00157     void setActualTotalNbOfEvents (const Count_T& iActualTotalNbOfEvents) {
00158       _progressStatus.setActualNb (iActualTotalNbOfEvents);
00159     }
00160 
00165     void setStatus (const EventType::EN_EventType& iType,
00166                     const ProgressStatus& iProgressStatus);
00167 
00168 
00169   public:
00170     // /////////// Display support methods /////////
00176     void toStream (std::ostream& ioOut) const {
00177       ioOut << toString();
00178     }
00179 
00185     void fromStream (std::istream& ioIn) {
00186     }
00187 
00191     std::string toString() const;
00192     
00196     const std::string describeKey() const {
00197       return _key.toString();
00198     }
00199     
00200     /*
00201      * Display the full content of the event queue, with all its
00202      * demand streams.
00203      *
00204      * That method can be very consuming (in time, CPU and memory)
00205      * when there are a lot of demand streams (e.g., several hundreds
00206      * of thousands). Call it only for debug purposes.
00207     */
00208     std::string display() const;
00209     
00210     
00211   public:
00212     // ////////// Business methods /////////
00217     void reset();
00218     
00232      ProgressStatusSet popEvent (EventStruct&);
00233 
00254     bool addEvent (EventStruct&);
00255 
00261     bool isQueueDone() const;
00262 
00276     void addStatus (const EventType::EN_EventType&,
00277                     const NbOfRequests_T& iExpectedTotalNbOfEvents);
00278 
00287     void updateStatus (const EventType::EN_EventType&,
00288                        const ProgressStatus& iProgressStatus);
00289 
00303     void updateStatus (const EventType::EN_EventType&,
00304                        const NbOfEvents_T& iActualTotalNbOfEvents);
00305 
00316     ProgressPercentage_T calculateProgress() const {
00317       return _progressStatus.progress();
00318     }
00319 
00330     ProgressPercentage_T calculateProgress(const EventType::EN_EventType&)const;
00331 
00332 
00333   public:
00334     // ////////// Debug methods /////////
00336     Count_T getQueueSize() const;
00337 
00339     bool isQueueEmpty() const;
00340 
00341     
00342   protected:
00343     // ////////// Constructors and destructors /////////
00345     EventQueue (const Key_T&);
00347     EventQueue (const EventQueue&);
00349     ~EventQueue();
00350   private:
00352     EventQueue();
00353     
00354 
00355   protected:
00356     // ////////// Attributes /////////
00360     Key_T _key;
00361 
00365     BomAbstract* _parent;
00366 
00372     HolderMap_T _holderMap;
00373 
00377     EventList_T _eventList;
00378     
00382     ProgressStatus _progressStatus;
00383 
00389     ProgressStatusMap_T _progressStatusMap;
00390   };
00391 
00392 }
00393 #endif // __STDAIR_BOM_EVENTQUEUE_HPP