Eris  1.3.21
TimedEventService.h
1 #ifndef ERIS_TIMED_EVENT_SERVICE_H
2 #define ERIS_TIMED_EVENT_SERVICE_H
3 
4 #include <wfmath/timestamp.h>
5 
6 #include <sigc++/signal.h>
7 
8 #include <set>
9 
10 namespace Eris
11 {
12 
17 {
18 public:
19  virtual ~TimedEvent()
20  {
21  }
22 
29  virtual void expired() = 0;
30 
34  virtual const WFMath::TimeStamp& due() const = 0;
35 };
36 
38 {
39 public:
40  bool operator()(const TimedEvent* a, const TimedEvent* b) const
41  {
42  return a->due() < b->due();
43  }
44 };
45 
47 {
48 public:
49 
50  static TimedEventService* instance();
51 
52  static void del();
53 
58  unsigned long tick(bool idle = false);
59 
62  void registerEvent(TimedEvent* te);
63 
66  void unregisterEvent(TimedEvent* te);
67 
71  sigc::signal<void> Idle;
72 private:
74 
75  static TimedEventService* static_instance;
76 
77  typedef std::set<TimedEvent*, EventsByDueOrdering> TimedEventsByDue;
78  TimedEventsByDue m_events;
79 };
80 
81 } // of namespace Eris
82 
83 #endif // of ERIS_TIMED_EVENT_SERVICE_H
Abstract interface for things which occur after a period of time.
Definition: TimedEventService.h:16
Definition: TimedEventService.h:37
virtual void expired()=0
Implement the expiry behaviour of this object.
virtual const WFMath::TimeStamp & due() const =0
The time value when this event is due.
sigc::signal< void > Idle
Signal emitted when tick is idle.
Definition: TimedEventService.h:71
unsigned long tick(bool idle=false)
Tick all the timed events registered with the service instance.
Definition: TimedEventService.cpp:39
Definition: TimedEventService.h:46