/*
* clock - clock resource for zavai
*
- * Copyright (C) 2009 Enrico Zini <enrico@enricozini.org>
+ * Copyright (C) 2009--2010 Enrico Zini <enrico@enricozini.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
}
}
+public class AlarmTriggerInfo
+{
+ public zavai.log.Log log;
+ public string label;
+ public bool acked;
+ public bool canceled;
+
+ public AlarmTriggerInfo(string label)
+ {
+ this.label = label;
+ acked = false;
+ canceled = false;
+ }
+}
+
+public class AlarmTriggerQueue : zavai.Service
+{
+ protected List<AlarmTriggerInfo> queue;
+
+ public signal void triggered(AlarmTriggerInfo info);
+ public signal void acked(AlarmTriggerInfo info);
+ public signal void canceled(AlarmTriggerInfo info);
+
+ public AlarmTriggerQueue()
+ {
+ queue = new List<AlarmTriggerInfo>();
+ }
+
+ public void enqueue_trigger(AlarmTriggerInfo info)
+ {
+ // Reuse IDs from the associated logger object
+ info.log = zavai.log.log.start("alarm", "Alarm " + info.label);
+ queue.append(info);
+ if (queue.data == info)
+ triggered(queue.data);
+ }
+
+ protected void done_with_first()
+ {
+ var first = queue.data;
+ queue.remove_link(queue);
+ if (queue != null)
+ triggered(queue.data);
+ }
+
+ public void ack(AlarmTriggerInfo info)
+ {
+ if (queue == null || info != queue.data) return;
+ if (!info.acked && !info.canceled)
+ {
+ info.acked = true;
+ acked(info);
+ info.log.add("alarm acknowledged");
+ info.log.acked = true;
+ zavai.log.log.end(info.log);
+ }
+ done_with_first();
+ }
+
+ public void cancel(AlarmTriggerInfo info)
+ {
+ if (queue == null || info != queue.data) return;
+ if (!info.acked && !info.canceled)
+ {
+ info.canceled = true;
+ canceled(info);
+ info.log.add("alarm canceled");
+ zavai.log.log.end(info.log);
+ }
+ done_with_first();
+ }
+}
+
public class Clock: zavai.Service
{
protected time_t last_gps_time;
protected time_t last_gps_time_system_time;
protected time_t last_system_time;
- protected dynamic DBus.Object gps_time;
protected uint system_time_timeout;
protected time_t last_minute;
protected time_t chosen_time;
// Ticks once a minute
public signal void minute_changed(long time, SourceType source);
public signal void schedule_changed(Alarm? next);
- public signal void alarm_triggered(string label);
public Clock()
{
last_system_time = time_t();
chosen_time = last_system_time;
- gps_time = zavai.registry.sbus.get_object(
- "org.freesmartphone.ogpsd",
- "/org/freedesktop/Gypsy",
- "org.freedesktop.Gypsy.Time");
-
// FSO alarm system
otimed_alarm = zavai.registry.sbus.get_object(
"org.freesmartphone.otimed",
public void notify_alarm(string label)
{
stderr.printf("Notifying %s\n", label);
- alarm_triggered(label);
+ AlarmTriggerInfo info = new AlarmTriggerInfo(label);
+ alarm_trigger_queue.enqueue_trigger(info);
schedule_changed(next_alarm());
}
schedule_changed(next_alarm());
}
- private void on_gps_time(dynamic DBus.Object pos, int t)
+ private void on_gps_time(uint t)
{
if (t == 0)
{
if (started) return;
system_time_timeout = Timeout.add(5000, on_system_time);
- gps_time.TimeChanged += on_gps_time;
+ zavai.gps.gps.time_changed += on_gps_time;
last_system_time = time_t();
update_time();
if (!started) return;
Source.remove(system_time_timeout);
- gps_time.TimeChanged -= on_gps_time;
+ zavai.gps.gps.time_changed -= on_gps_time;
base.stop();
}
}
public Clock clock = null;
+public AlarmTriggerQueue alarm_trigger_queue = null;
public void init()
{
clock = new Clock();
+ alarm_trigger_queue = new AlarmTriggerQueue();
}
}