Repository navigation
Expand file tree
/
Copy pathTaskControlBlock.h
More file actions
196 lines (166 loc) · 5.61 KB
/
Copy pathTaskControlBlock.h
File metadata and controls
196 lines (166 loc) · 5.61 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#ifndef TASKCONTROLBLOCK_H
#define TASKCONTROLBLOCK_H
#include <Task.h>
/**
* @brief The Task struct holds all necessary information for a tast to schedule, the task pointer, the timer
* @brief and the information whether it is a single shot or not.
* @author Marc Vester (XaserLE)
*/
class TaskControlBlock
{
public:
/**
* @brief Constructor, initializes the task.
*/
TaskControlBlock(void);
/**
* @brief Destructor, deletes the task.
*/
~TaskControlBlock();
/**
* @brief Inserts a new task if this one is not in use.
* @param task_ The new task.
* @param timer_ Time till next execution.
* @param reshot_ Indicates whether this is a periodically task or not.
* @param isTaskHelper_ If true, this task was generated by the scheduler, so we will take ownership.
* @param isTaskHelperWithData_ Same as above, but this task helper has data to forward to his function pointer.
* @return True if task was added successfully, false otherwise.
*/
bool set(Task * task_, unsigned long timer_, bool reshot_, bool isTaskHelper_, bool isTaskHelperWithData_);
/**
* @brief Will call the update function of the task.
*/
void run(void);
/**
* @brief Access method.
* @return True if this is a TaskHelper, false otherwise.
*/
bool isTaskHelper(void) const;
/**
* @brief Access method.
* @return True if this is a TaskHelperWithData, false otherwise.
*/
bool isTaskHelperWithData(void) const;
/**
* @brief Reinitializes this TaskControlBlock and deletes the the task pointer if it is a TaskHelper(WithData).
*/
void remove(void);
/**
* @brief Compares the task in this block with the given one.
* @param task_ Pointer to the task for comparison.
* @return True if the task in this block matches task_, false otherwise.
*/
bool compare(Task * task_) const;
/**
* @brief Compares the task in this block with the given one.
* @param task_ Pointer to the function of the task for comparison.
* @return True if the task in this block matches task_, false otherwise.
*/
bool compare(void (* func_)(void)) const;
/**
* @brief Compares the task in this block with the given one.
* @param task_ Pointer to the function of the task for comparison.
* @return True if the task in this block matches task_, false otherwise.
*/
bool compare(void (* func_)(void *)) const;
/**
* @brief Access method.
* @return Pointer to the task in this block.
*/
Task const * task(void) const;
/**
* @brief Access method.
* @return The timer of this task.
*/
unsigned long timer(void) const;
/**
* @brief Access method.
* @return Time of last execution.
*/
unsigned long timestamp(void) const;
/**
* @brief Access method.
* @return True if there is no task in this block, false otherwise.
*/
bool isFree(void) const;
/**
* @brief Access method.
* @return True if there is a task in this block, false otherwise.
*/
bool isUsed(void) const;
/**
* @brief Access method.
* @return True if this is a periodically task, false otherwise.
*/
bool reshot(void) const;
/**
* @brief Indicates whether this task is ready or not.
* @return If true, execution time of this task has expired, so it is ready to run.
*/
bool ready(void) const;
private:
/**
* @brief Reinitializes this TaskControlBlock.
*/
void reset(void);
/**
* @brief Access method.
* @return Pointer to the task in this block.
*/
Task * task(void);
/**
* @brief Access method.
* @param task_ The new task to set.
*/
void setTask(Task * task_);
/**
* @brief Access method.
* @param timer_ The new timer to set.
*/
void setTimer(unsigned long timer_);
/**
* @brief Access method.
* @param timestamp_ The new timestamp to set.
*/
void setTimestamp(unsigned long timestamp_);
/**
* @brief Access method.
* @param Sets the timestamp to the actual time.
*/
void setActualTimestamp(void);
/**
* @brief Access method.
* @param reshot_ If true, this is a periodically task.
*/
void setReshot(bool reshot_);
/**
* @brief Access method.
* @param isTaskHelper_ If true, this task was generated by the scheduler. Therefore this block will take ownership of it.
*/
void setIsTaskHelper(bool isTaskHelper_);
/**
* @brief Access method.
* @param isTaskHelperWithData_ If true, this task was generated by the scheduler. Therefore this block will take ownership of it. Also this task has data to forward for its function.
*/
void setIsTaskHelperWithData(bool isTaskHelperWithData_);
/**
* @brief Access method.
* @param isFreeValue_ If true, this block is empty, so a task can be added.
*/
void setIsFree(bool isFreeValue_);
// Will be executed after timer milliseconds. NULL indicates this slot is free.
Task * _task;
// Time in milliseconds after task will be called.
unsigned long _timer;
// Time when task was added. Needed for calculation.
unsigned long _timestamp;
// If true, task will be executed after every timer milliseconds, otherwise it will be deleted after one call.
bool _reshot;
// If true, the task was instanciated by the scheduler, cause the was added only as function pointer.
bool _isTaskHelper;
// The same as _isTaskHelper, but this one has data to forward to it's function pointer.
bool _isTaskHelperWithData;
// If true, there is no task in this control block.
bool _isFree;
};
#endif // TASKCONTROLBLOCK_H