This repository was archived by the owner on Jan 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTimerContext.h
More file actions
86 lines (74 loc) · 1.9 KB
/
Copy pathTimerContext.h
File metadata and controls
86 lines (74 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* TimerContext.h
*
* Created on: 25.09.2013
* Author: niklausd
*/
#ifndef TIMERCONTEX_H_
#define TIMERCONTEX_H_
class Timer;
/**
* Timer Context.
*
* Features:
* - is like a very simple scheduler.
* - has to be kicked (by calling yield(), scheduleTimers() or TimerContext::handleTick()) as often as possible and/or on regular intervals,
* i.e. in the Arduino main loop() function:
*
* #include "Timer.h"
*
* void loop()
* {
* // Kick the timer(s)
* yield();
*
* // .. do something
* }
*
* - holds a single linked list of registered Timer objects,
* the Timers automatically attach themselves to this on their creation
* and automatically detach themselves on their destruction.
* - is a Singleton
*/
class TimerContext
{
friend class Timer;
public:
/**
* Create and/or return singleton instance of Timer Context.
* @return Pointer to singleton TimerContext object pointer.
*/
static TimerContext* instance();
/**
* Destructor.
*/
virtual ~TimerContext();
protected:
/**
* Add a Timer object to the single linked list.
* @param timer Timer object pointer.
*/
void attach(Timer* timer);
/**
* Remove specified Timer object from the single linked list.
* @param timer Timer object pointer.
*/
void detach(Timer* timer);
public:
/**
* Kick all attached Timer objects (calls the Timer::tick() method).
*/
void handleTick();
private:
/**
* Constructor.
*/
TimerContext();
private:
static TimerContext* s_instance; /// Timer Context singleton instance variable.
Timer* m_timer; /// Root node of single linked list containing the timers to be kicked.
private: // forbidden default functions
TimerContext& operator = (const TimerContext& src); // assignment operator
TimerContext(const TimerContext& src); // copy constructor
};
#endif /* TIMERCONTEX_H_ */