Initial commit - move development to a public repo
[libautomation/elektra-notification.git] / lib / task.c
blobae4d756485447ee402faba0926c4a65334373604
1 #include "libautomation.h"
3 void atm_call_in(ev_tstamp seconds, void *f) {
4 ev_once(EV_A_ -1, 0, seconds, f, NULL);
7 void atm_task_cb(EV_P_ ev_timer *w, int revents) {
8 struct ATM_TASK *task = (struct ATM_TASK *) w;
9 ev_tstamp delay;
10 int ret;
12 atm_time = atm_timestamp();
14 ret = task->dsgrp.policy(&task->dsgrp);
15 if (ret > 0) {
16 ev_timer_stop(EV_A_ w);
17 ev_timer_set(w, ret * ATM_TIMER_RES, w->repeat);
18 ev_timer_start(EV_A_ w);
20 return;
23 task->task();
26 void atm_task_init(struct ATM_TASK *task, ev_tstamp interval) {
27 ev_timer_init(&task->watcher, atm_task_cb, 0.1, interval);
28 atm_dsgrp_init(&task->dsgrp);
29 task->task = atm_do_nothing;