-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask.cxx
246 lines (207 loc) · 4.29 KB
/
Task.cxx
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#include <iostream>
#include "Task.hxx"
int Task::taskIdGen = 1;
/**
* Default Constructor
*/
Task::Task() : deadline_(), timeRemaining_(), priority_(), spawnTime_(),
timeStarted_(), timeFinished_(), finished_(false), firstRun_(false), blockPeriod_(), lengthBlock_(0), taskID(taskIdGen++) {}
/**
* Alternative ctor
*/
Task::Task(int length, int timeSpawned, int deadline, int priority, int blockPeriod, int blockLength) :
deadline_(deadline), timeRemaining_(length), priority_(priority),
spawnTime_(timeSpawned), timeStarted_(), timeFinished_(), finished_(false), firstRun_(false),
blockPeriod_(blockPeriod), lengthBlock_(blockLength),blockRemaining_(0), timeLastRun_(0), taskID(taskIdGen++) {}
/**
* Destructor
*/
Task::~Task() {}
/**
* Updates task based on current time
* checks if task is blocked, if not advanced a step
* @return whether the task is blocked post advance
*/
bool Task::updateTask(int curTime) {
if(getBlockRemaining() > 0) {
setBlockRemaining(getBlockRemaining() - 1);
}else {
setTimeLastRun(curTime);
if(!getFirstRun()){
setFirstRun();
setTimeStarted(curTime);
}
setTimeRemaining(getTimeRemaining() - 1);
//Checks finished
if(getTimeRemaining() == 0) {
setTimeFinished(curTime + 1);
setFinished(true);
}
//Checks if time for block post update to avoid infinitely blocking
if(getBlockPeriod() != 0) {
if(!(getTimeRemaining() % getBlockPeriod())){
setBlockRemaining(getBlockLength()); //block length set arbitrarily at 10
}
}
}
// //Priority update, probably call to strategy
return getBlockRemaining() > 0; //will return true until updated post block
}
//Getters
/**
* Returns ID
*/
int Task::getID() {
return taskID;
}
/**
* Returns task deadline
*/
int Task::getDeadline(){
return deadline_;
}
/**
* Returns time remaining for task
*/
int Task::getTimeRemaining(){
return timeRemaining_;
}
/**
* Returns priority of task
*/
int Task::getPriority(){
return priority_;
}
/**
* Returns time task spawned
*/
int Task::getSpawnTime(){
return spawnTime_;
}
/**
* Returns time task started
*/
int Task::getTimeStarted(){
return timeStarted_;
}
/**
* Returns time task finished
*/
int Task::getTimeFinished(){
return timeFinished_;
}
/**
* Returns if task is finished
*/
bool Task::getFinished() {
return finished_;
}
/**
* Returns if task has run for first time
*/
bool Task::getFirstRun() {
return firstRun_;
}
/**
* Returns block period
*/
int Task::getBlockPeriod() {
return blockPeriod_;
}
/**
* Returns block length
*/
int Task::getBlockLength() {
return lengthBlock_;
}
/**
* Returns time blocked remaining
*/
int Task::getBlockRemaining() {
return blockRemaining_;
}
/**
* Returns Last Run time
*/
int Task::getTimeLastRun() {
return timeLastRun_;
}
//Setters
/**
* Sets task ID
*/
void Task::setID(int ID) {
taskID = ID;
}
/**
* Sets task deadline
*/
void Task::setDeadline(int deadline) {
deadline_ = deadline;
}
/**
* Sets task time remaining
*/
void Task::setTimeRemaining(int time) {
timeRemaining_ = time;
}
/**
* Sets task priority
*/
void Task::setPriority(int priority) {
priority_ = priority;
}
/**
* Sets task time spawned
*/
void Task::setTimeSpawned(int time) {
spawnTime_ = time;
}
/**
* Sets task time started
*/
void Task::setTimeStarted(int time) {
timeStarted_ = time;
}
/**
* Sets task time finished
*/
void Task::setTimeFinished(int time) {
timeFinished_ = time;
}
/**
* Sets task finished
*/
void Task::setFinished(bool finished) {
finished_ = finished;
}
/**
* Sets task first run
*/
void Task::setFirstRun() {
firstRun_ = true;
}
/**
* Sets task block period
*/
void Task::setBlockPeriod(int period) {
blockPeriod_ = period;
}
/**
* Sets task block length
*/
void Task::setBlockLength(int length) {
lengthBlock_ = length;
}
/**
* Sets task block time remaining
*/
void Task::setBlockRemaining(int time) {
blockRemaining_ = time;
}
/**
* Sets task time last run
*/
void Task::setTimeLastRun(int time) {
timeLastRun_ = time;
}