3 |
|
|
4 |
#include "common.h" |
#include "common.h" |
5 |
|
|
6 |
|
#include <time.h> |
7 |
|
|
8 |
TaskManager::TaskManager() |
TaskManager::TaskManager() |
9 |
|
: _lastExecuted(0) |
10 |
{ |
{ |
11 |
} |
} |
12 |
|
|
20 |
|
|
21 |
} |
} |
22 |
|
|
23 |
|
|
24 |
|
void TaskManager::ExecuteTasks(IGsmModem& modem) |
25 |
|
{ |
26 |
|
const int SLEEP_TIME = 10; //wait at least 10 seconds between executions |
27 |
|
int now = time(0); |
28 |
|
|
29 |
|
if (now > (_lastExecuted + SLEEP_TIME) ) |
30 |
|
{ |
31 |
|
_lastExecuted = now; |
32 |
|
|
33 |
|
std::map<std::string, Task*>::iterator it; |
34 |
|
|
35 |
|
for (it = _tasks.begin(); it != _tasks.end(); ++it) |
36 |
|
{ |
37 |
|
Task* tsk = (*it).second; |
38 |
|
tsk->ExecuteTask(modem); |
39 |
|
} |
40 |
|
} |
41 |
|
} |
42 |
|
|
43 |
|
|
44 |
Task* TaskManager::GetTask(const std::string& taskname) |
Task* TaskManager::GetTask(const std::string& taskname) |
45 |
{ |
{ |
46 |
return _tasks[ taskname ]; |
return _tasks[ taskname ]; |
52 |
typedef std::map<std::string, Task*>::iterator MapIterator; |
typedef std::map<std::string, Task*>::iterator MapIterator; |
53 |
std::vector<Task*> task_list; |
std::vector<Task*> task_list; |
54 |
|
|
55 |
for (MapIterator it = _tasks.begin(); it != _tasks.end(); it++) |
for (MapIterator it = _tasks.begin(); it != _tasks.end(); ++it) |
56 |
{ |
{ |
57 |
Task* pl = (*it).second; |
Task* pl = (*it).second; |
58 |
task_list.push_back(pl); |
task_list.push_back(pl); |