blip  0.1
TimerManager.hpp
Go to the documentation of this file.
1 #ifndef __blip_TimerManager_hpp
2 #define __blip_TimerManager_hpp
3 
4 #include <deque>
5 #include <vector>
6 
7 #include <commonc++/Mutex.h++>
8 #include <commonc++/OutOfBoundsException.h++>
9 #include <commonc++/Thread.h++>
10 
11 #include <blip/Blip.hpp>
13 #include <blip/TimerEvent.hpp>
14 
15 namespace blip {
16 
17 class NativeActivity;
18 class Timer;
19 
27 class TimerManager : private ccxx::Thread
28 {
29  friend class NativeActivity;
30 
31  public:
32 
34  ~TimerManager();
35 
46  TimerID addTimer(timespan_s_t interval, bool repeating = true);
47 
52  void cancelTimer(TimerID id);
53 
55  void cancelAllTimers();
56 
58  uint_t getFreeTimerCount() const;
59 
62  static const int MAX_TIMERS;
63 
64  protected:
65 
67  virtual void run();
70  private:
71 
72  TimerManager(int fd);
73  const TimerEvent& getEvent(TimerID id);
74 
75  int _fd;
76  Timer* _timers;
77  uint_t _freeCount;
78  TimerEvent** _events;
79  TimerID* _buf;
80  mutable ccxx::Mutex _mutex;
81 
82  CCXX_COPY_DECLS(TimerManager);
83 };
84 
85 } // namespace blip
86 
87 #endif // __blip_TimerManager_hpp
static const int MAX_TIMERS
The maximum number of timers that can be allocated by an application.
Definition: TimerManager.hpp:62
TimerID addTimer(timespan_s_t interval, bool repeating=true)
Add a new timer.
Definition: TimerManager.cpp:59
A class that manages Timers and schedules TimerEvents for delivery when Timers fire.
Definition: TimerManager.hpp:27
uint_t getFreeTimerCount() const
Get the number of available (inactive) timers.
Definition: TimerManager.cpp:128
WAV file format details at: https://ccrma.stanford.edu/courses/422/projects/WaveFormat/.
Definition: AccelerometerSensorEvent.cpp:3
int8_t TimerID
Definition: TimerEvent.hpp:9
An abstract base class for all "native" (C++) Android activities.
Definition: NativeActivity.hpp:71
~TimerManager()
Destructor.
Definition: TimerManager.cpp:47
A timer which fires a TimerEvent at a fixed interval.
Definition: Timer.hpp:15
A timer event.
Definition: TimerEvent.hpp:17
void cancelTimer(TimerID id)
Cancel the timer with the given ID.
Definition: TimerManager.cpp:93
void cancelAllTimers()
Cancel all active timers.
Definition: TimerManager.cpp:110