Eris
1.3.19
|
00001 #ifndef ERIS_TIMED_EVENT_SERVICE_H 00002 #define ERIS_TIMED_EVENT_SERVICE_H 00003 00004 #include <wfmath/timestamp.h> 00005 00006 #include <sigc++/signal.h> 00007 00008 #include <set> 00009 00010 namespace Eris 00011 { 00012 00016 class TimedEvent 00017 { 00018 public: 00019 virtual ~TimedEvent() 00020 { 00021 } 00022 00029 virtual void expired() = 0; 00030 00034 virtual const WFMath::TimeStamp& due() const = 0; 00035 }; 00036 00037 class EventsByDueOrdering 00038 { 00039 public: 00040 bool operator()(const TimedEvent* a, const TimedEvent* b) const 00041 { 00042 return a->due() < b->due(); 00043 } 00044 }; 00045 00046 class TimedEventService 00047 { 00048 public: 00049 00050 static TimedEventService* instance(); 00051 00052 static void del(); 00053 00058 unsigned long tick(bool idle = false); 00059 00062 void registerEvent(TimedEvent* te); 00063 00066 void unregisterEvent(TimedEvent* te); 00067 00071 sigc::signal<void> Idle; 00072 private: 00073 TimedEventService(); 00074 00075 static TimedEventService* static_instance; 00076 00077 typedef std::set<TimedEvent*, EventsByDueOrdering> TimedEventsByDue; 00078 TimedEventsByDue m_events; 00079 }; 00080 00081 } // of namespace Eris 00082 00083 #endif // of ERIS_TIMED_EVENT_SERVICE_H