This source file includes following definitions.
- dc_task_init
- dc_task_destroy
- dc_task_add
- dc_task_get_current
#include "task.h"
void dc_task_init(TaskList *list)
{
list->tasks = gf_list_new();
list->size = 0;
}
void dc_task_destroy(TaskList *list)
{
gf_list_del(list->tasks);
}
void dc_task_add(TaskList *list, int source_number, char *id_name, time_t start, time_t end)
{
Task *task = (Task*)gf_malloc(sizeof(Task));
task->source_number = source_number;
strncpy(task->id, id_name, MAX_ID_SIZE-1);
task->start_time_t = start;
task->end_time_t = end;
gf_list_add(list->tasks, task);
list->size++;
}
int dc_task_get_current(TaskList *list, Task *task)
{
u32 i;
time_t now_time = time(NULL);
for (i = 0; i<list->size; i++) {
Task *cur_task = (Task*)gf_list_get(list->tasks, i);
if (now_time > cur_task->start_time_t && now_time < cur_task->end_time_t) {
task->source_number = cur_task->source_number;
return 0;
}
}
task->source_number = 0;
return -1;
}