Eris 1.3.16

TimedEventService.h

00001 #ifndef ERIS_TIMED_EVENT_SERVICE_H
00002 #define ERIS_TIMED_EVENT_SERVICE_H
00003 
00004 #include <wfmath/timestamp.h>
00005 
00006 #include <set>
00007 
00008 namespace Eris
00009 {
00010 
00014 class TimedEvent
00015 {
00016 public:
00017     virtual ~TimedEvent()
00018     {
00019     }
00020     
00027     virtual void expired() = 0;
00028     
00032     virtual const WFMath::TimeStamp& due() const = 0;
00033 };
00034 
00035 class EventsByDueOrdering
00036 {
00037 public:
00038     bool operator()(const TimedEvent* a, const TimedEvent* b) const
00039     {
00040         return a->due() < b->due();
00041     }
00042 };
00043 
00044 class TimedEventService
00045 {
00046 public:
00047 
00048     static TimedEventService* instance();
00049 
00054     unsigned long tick();
00055 
00058     void registerEvent(TimedEvent* te);
00059 
00062     void unregisterEvent(TimedEvent* te);
00063 private:
00064     TimedEventService();
00065     
00066     static TimedEventService* static_instance;
00067     
00068     typedef std::set<TimedEvent*, EventsByDueOrdering> TimedEventsByDue;
00069     TimedEventsByDue m_events;
00070 };
00071 
00072 } // of namespace Eris
00073 
00074 #endif // of ERIS_TIMED_EVENT_SERVICE_H