Phasor  01.00.10.059
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Timers.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <list>
5 #include "Types.h"
6 
7 class Timers;
8 
9 class TimerEvent
10 {
11 private:
12  DWORD dwExpiryTime, dwDelay;
13  void SetExpiry(DWORD dwDelay);
14 
15 protected:
16  TimerEvent(DWORD dwDelay);
17 
18 public:
19  virtual ~TimerEvent();
20 
21  // Get a timer's id
22  DWORD GetID() const;
23 
24  // used to check if the timer is ready
25  bool ready(DWORD dwCurTicks) const;
26 
27  // Reset the timer
28  void Reset();
29 
30  // return true to reset the timer
31  virtual bool OnExpiration(Timers& timers) = 0;
32 };
33 
34 typedef std::unique_ptr<TimerEvent> timer_ptr;
35 
36 class Timers
37 {
38 private:
39  typedef std::list<timer_ptr> timerlist_t;
40  timerlist_t timerlist;
41  DWORD currentId;
42 
43 public:
44  Timers();
45  virtual ~Timers();
46 
47  // Should be called periodically to process complete timers
48  void Process();
49 
50  // Adds a new timer
52 
53  // Removes a timer
54  bool RemoveTimer(DWORD id);
55  void RemoveAllTimers();
56 };