1 |
torben |
26 |
|
2 |
|
|
#include "TaskManager.h" |
3 |
|
|
|
4 |
|
|
#include "common.h" |
5 |
|
|
|
6 |
torben |
82 |
#include <time.h> |
7 |
torben |
26 |
|
8 |
|
|
TaskManager::TaskManager() |
9 |
torben |
82 |
: _lastExecuted(0) |
10 |
torben |
26 |
{ |
11 |
|
|
} |
12 |
|
|
|
13 |
|
|
TaskManager::~TaskManager() |
14 |
|
|
{ |
15 |
|
|
} |
16 |
|
|
|
17 |
|
|
|
18 |
|
|
void TaskManager::LoadTasks() |
19 |
|
|
{ |
20 |
|
|
|
21 |
|
|
} |
22 |
|
|
|
23 |
torben |
82 |
|
24 |
|
|
void TaskManager::ExecuteTasks() |
25 |
|
|
{ |
26 |
|
|
int now = time(0); |
27 |
|
|
|
28 |
|
|
if (now > _lastExecuted) // only execute the tasks once every second |
29 |
|
|
{ |
30 |
|
|
_lastExecuted = now; |
31 |
|
|
|
32 |
|
|
std::map<std::string, Task*>::iterator it; |
33 |
|
|
|
34 |
|
|
for (it = _tasks.begin(); it != _tasks.end(); ++it) |
35 |
|
|
{ |
36 |
|
|
Task* tsk = (*it).second; |
37 |
|
|
tsk->ExecuteTask(); |
38 |
|
|
} |
39 |
|
|
} |
40 |
|
|
} |
41 |
|
|
|
42 |
|
|
|
43 |
torben |
26 |
Task* TaskManager::GetTask(const std::string& taskname) |
44 |
|
|
{ |
45 |
|
|
return _tasks[ taskname ]; |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
|
49 |
|
|
std::vector<Task*> TaskManager::GetTaskList() |
50 |
|
|
{ |
51 |
|
|
typedef std::map<std::string, Task*>::iterator MapIterator; |
52 |
|
|
std::vector<Task*> task_list; |
53 |
|
|
|
54 |
torben |
82 |
for (MapIterator it = _tasks.begin(); it != _tasks.end(); ++it) |
55 |
torben |
26 |
{ |
56 |
|
|
Task* pl = (*it).second; |
57 |
|
|
task_list.push_back(pl); |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
|
61 |
|
|
return task_list; |
62 |
|
|
} |