X-Git-Url: https://git.distorted.org.uk/~mdw/disorder/blobdiff_plain/758aa6c3c5b1768f35e503a00f374d0c52a55a6a..440af55d72c65f5c149718dc52abd00f512ffb71:/server/schedule.c diff --git a/server/schedule.c b/server/schedule.c index 7776c3c..6092fb5 100644 --- a/server/schedule.c +++ b/server/schedule.c @@ -81,28 +81,7 @@ * * TODO: add disorder-dump support */ - -#include -#include "types.h" - -#include -#include -#include -#include - -#include "trackdb.h" -#include "trackdb-int.h" -#include "schedule.h" -#include "table.h" -#include "kvp.h" -#include "log.h" -#include "queue.h" -#include "server-queue.h" -#include "state.h" -#include "play.h" -#include "mem.h" -#include "random.h" -#include "vector.h" +#include "disorder-server.h" static int schedule_trigger(ev_source *ev, const struct timeval *now, @@ -208,6 +187,7 @@ static int schedule_init_tid(ev_source *ev, if(priority && !strcmp(priority, "junk")) { /* Junk actions that are in the past are discarded during startup */ /* TODO recurring events should be handled differently here */ + info("junk event %s is in the past, discarding", id); if(cdel(cursor)) goto deadlocked; /* Skip this time */ @@ -249,8 +229,6 @@ void schedule_init(ev_source *ev) { /** @brief Create a scheduled event * @param ev Event loop * @param actiondata Action data - * - * The caller should set the timeout themselves. */ static int schedule_add_tid(const char *id, struct kvp *actiondata, @@ -262,7 +240,8 @@ static int schedule_add_tid(const char *id, k.data = (void *)id; k.size = strlen(id); switch(err = trackdb_scheduledb->put(trackdb_scheduledb, tid, &k, - encode_data(&d, actiondata), 0)) { + encode_data(&d, actiondata), + DB_NOOVERWRITE)) { case 0: break; case DB_LOCK_DEADLOCK: @@ -285,10 +264,10 @@ static int schedule_add_tid(const char *id, * is not allowed to perform them or if they are scheduled for a time * in the past. */ -char *schedule_add(ev_source *ev, - struct kvp *actiondata) { +const char *schedule_add(ev_source *ev, + struct kvp *actiondata) { int e, n; - char *id; + const char *id; struct timeval when; /* TODO: handle recurring events */ @@ -314,7 +293,7 @@ char *schedule_add(ev_source *ev, id = random_id(); WITH_TRANSACTION(schedule_add_tid(id, actiondata, tid)); } while(e == DB_KEYEXIST); - ev_timeout(ev, 0/*handlep*/, &when, schedule_trigger, id); + ev_timeout(ev, 0/*handlep*/, &when, schedule_trigger, (void *)id); return id; } @@ -454,7 +433,7 @@ static int schedule_lookup(const char *id, int n; /* Look up the action */ - n = TABLE_FIND(schedule_actions, typeof(schedule_actions[0]), name, action); + n = TABLE_FIND(schedule_actions, name, action); if(n < 0) { error(0, "scheduled event %s: unrecognized action '%s'", id, action); return -1;