X-Git-Url: https://git.toastfreeware.priv.at/gregoa/zavai.git/blobdiff_plain/46a947217c02eb25f390b8d7a5d4bd829934732a..a7d1a285763bffe81b29c854b905d8ca83e9a2bd:/src/clock.vala?ds=sidebyside diff --git a/src/clock.vala b/src/clock.vala index d6b2d13..bcd25e7 100644 --- a/src/clock.vala +++ b/src/clock.vala @@ -29,20 +29,58 @@ public enum SourceType GPS } -public class Alarm : Object -{ - public signal void trigger(Alarm a); +/* +TODO: schedule alarms via at + +Uses the 'z' queue. + +atq -q z can be used to list the jobs (for example, at startup, or after a job has run) +at -c id can be used to query a job, parsing its contents (which can have + comments or variables being set) +zavai --notify ... can be used to notify the job (and start zavai if it's not running) - public time_t deadline; - public string label; +Alarm needs to be able to serialize itself to an at invocation and to +deserialize itself from the output of at -c - public Alarm(time_t deadline, string label) +Alarm needs to deserialize also a job with no special markers whatsoever: a +generic at job. + + + +refresh_alarms() +{ + oldtime = next_alarm ? next_alarm.time : 0 + next_alarm = the first alarm from atq + if (oldtime != next_alarm.time) { - this.deadline = deadline; - this.label = label; + remove existing triggers + (triggers can be skipped if we don't need to support non-zavai alarms) + schedule a trigger calling refresh_alarms() at next_alarm.time + 30 seconds + (triggers can be skipped if we don't need to support non-zavai alarms) } } +at clock constructor: refresh_alarms() +inotifywait -e close /usr/bin/at -> refresh_alarms() (shows when someone has just used at) + (can be skipped if we don't need to support non-zavai alarms) +at alarm triggered through zavai: refresh_alarms() + + +*/ + + +public class Alarm : Object +{ + // Notify of an alarm being triggered + //public static signal void trigger(string label); + + // Schedule with at + public static void schedule(time_t deadline, string label); + + // Get the label of the job with the given at ID + public static string getLabel(int atID); +} + private int alarm_compare(void* a, void* b) { return (int)(((Alarm*)a)->deadline - ((Alarm*)b)->deadline); @@ -77,7 +115,7 @@ public class Clock: zavai.Service public Clock() { - name = "clock"; + Object(name: "clock"); alarms = null; listener = new AlarmNotification(); last_minute = 0; @@ -137,10 +175,10 @@ public class Clock: zavai.Service zavai.log.error("Cannot reschedule alarms: " + e.message); } - string t = rtc.GetCurrentTime(); - stderr.printf("Current time: %d, RTC time: %s\n", (int)time_t(), t); + int t = rtc.GetCurrentTime(); + stderr.printf("Current time: %d, RTC time: %d\n", (int)time_t(), t); t = rtc.GetWakeupTime(); - stderr.printf("Scheduled alarm: %d, RTC wakeup time: %s\n", (int)alarms.data.deadline, t); + stderr.printf("Scheduled alarm: %d, RTC wakeup time: %d\n", (int)alarms.data.deadline, t); } else zavai.log.info("No alarms left to reschedule"); schedule_changed();