-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSpinTimerContext.h
86 lines (74 loc) · 2.02 KB
/
SpinTimerContext.h
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
/*
* SpinTimerContext.h
*
* Created on: 25.09.2013
* Author: niklausd
*/
#ifndef SPINTIMERCONTEX_H_
#define SPINTIMERCONTEX_H_
class SpinTimer;
/**
* Spin Timer Context.
*
* Features:
* - is like a very simple scheduler.
* - has to be kicked (by calling scheduleTimers() or SpinTimerContext::handleTick()) as often as possible and/or on regular intervals,
* i.e. in the Arduino main loop() function:
*
* #include "SpinTimer.h"
*
* void loop()
* {
* // Kick the timer(s)
* scheduleTimers();
*
* // .. do something
* }
*
* - holds a single linked list of registered SpinTimer objects,
* the SpinTimers automatically attach themselves to this on their creation
* and automatically detach themselves on their destruction.
* - is a Singleton
*/
class SpinTimerContext
{
friend class SpinTimer;
public:
/**
* Create and/or return singleton instance of SpinTimerContext.
* @return Pointer to singleton SpinTimerContext object pointer.
*/
static SpinTimerContext* instance();
/**
* Destructor.
*/
virtual ~SpinTimerContext();
protected:
/**
* Add a SpinTimer object to the single linked list.
* @param timer SpinTimer object pointer.
*/
void attach(SpinTimer* timer);
/**
* Remove specified SpinTimer object from the single linked list.
* @param timer SpinTimer object pointer.
*/
void detach(SpinTimer* timer);
public:
/**
* Kick all attached SpinTimer objects (calls the SpinTimer::tick() method).
*/
void handleTick();
private:
/**
* Constructor.
*/
SpinTimerContext();
private:
static SpinTimerContext* s_instance; /// SpinTimerContext singleton instance variable.
SpinTimer* m_timer; /// Root node of single linked list containing the timers to be kicked.
private: // forbidden default functions
SpinTimerContext& operator = (const SpinTimerContext& src); // assignment operator
SpinTimerContext(const SpinTimerContext& src); // copy constructor
};
#endif /* SPINTIMERCONTEX_H_ */