blip  0.1
Timer.hpp
Go to the documentation of this file.
1 #ifndef __blip_Timer_hpp
2 #define __blip_Timer_hpp
3 
4 #include <blip/Blip.hpp>
5 
6 namespace blip {
7 
8 class TimerManager;
9 
15 class Timer
16 {
17  friend class TimerManager;
18 
19  public:
20 
22  ~Timer();
23 
25  inline timespan_s_t getInterval() const
26  { return(_interval); }
27 
29  inline void setInterval(timespan_s_t interval)
30  {
31  _interval = interval;
32  _intervalMS = _interval * 1000;
33  }
34 
36  inline bool isRepeating() const
37  { return(_repeating); }
38 
40  inline void setRepeating(bool repeating)
41  { _repeating = repeating; }
42 
44  inline time_ms_t getLastFiredTime() const
45  { return(_lastFiredTime); }
46 
47  private: // called by TimerManager
48 
49  Timer();
50 
51  void setLastFiredTime(time_ms_t lastFiredTime)
52  { _lastFiredTime = lastFiredTime; }
53 
54  bool isActive() const
55  { return(_active); }
56 
57  void setActive(bool active)
58  { _active = active; }
59 
60  bool shouldFire(const time_ms_t& now) const;
61 
62  private:
63 
64  timespan_s_t _interval;
65  timespan_ms_t _intervalMS;
66  bool _repeating;
67  bool _active;
68  mutable time_ms_t _lastFiredTime;
69 };
70 
71 } // namespace blip
72 
73 #endif // __blip_Timer_hpp
bool isRepeating() const
Test if this is a repeating timer.
Definition: Timer.hpp:36
A class that manages Timers and schedules TimerEvents for delivery when Timers fire.
Definition: TimerManager.hpp:27
~Timer()
Destructor.
Definition: Timer.cpp:19
void setRepeating(bool repeating)
Specify whether this is a repeating or one-shot timer.
Definition: Timer.hpp:40
void setInterval(timespan_s_t interval)
Set the interval at which this timer fires.
Definition: Timer.hpp:29
time_ms_t getLastFiredTime() const
Get the time at which this timer last fired.
Definition: Timer.hpp:44
WAV file format details at: https://ccrma.stanford.edu/courses/422/projects/WaveFormat/.
Definition: AccelerometerSensorEvent.cpp:3
A timer which fires a TimerEvent at a fixed interval.
Definition: Timer.hpp:15
timespan_s_t getInterval() const
Get the interval at which this timer fires.
Definition: Timer.hpp:25