|
|
|
/*
|
|
|
|
* task.c: task management
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "task.h"
|
|
|
|
#include "grow.h"
|
|
|
|
#include "async.h"
|
|
|
|
|
|
|
|
static struct grow *tasks = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
bool task_add(struct task t) {
|
|
|
|
bool retval = true;
|
|
|
|
struct task *p_t = malloc(sizeof(struct task));
|
|
|
|
if(p_t == NULL) {
|
|
|
|
syslog(cfg_log_facility | LOG_ERR, "task: could not allocate space for task: %m");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*p_t = t;
|
|
|
|
if (tasks == NULL) {
|
|
|
|
tasks = grow_init(true);
|
|
|
|
if (tasks == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uint64_t id = tasks -> elems; // This relies on implementation detail of our growing array.
|
|
|
|
retval &= grow_push(p_t, tasks);
|
|
|
|
|
|
|
|
// Create a timer for the task
|
|
|
|
// store timerid in ((struct task *)(tasks -> arr[id])) -> timerid
|
|
|
|
}
|
|
|
|
|
|
|
|
bool task_disable(uint64_t id);
|
|
|
|
bool task_enable(uint64_t id);
|
|
|
|
bool task_delete(uint64_t id);
|
|
|
|
|
|
|
|
struct grow *task_list(void);
|
|
|
|
struct task task_details(uint64_t id);
|
|
|
|
void task_recalc(uint64_t id);
|
|
|
|
|
|
|
|
bool task_load(void);
|
|
|
|
bool task_save(void);
|
|
|
|
void task_flush(void);
|