]> ToastFreeware Gitweb - gregoa/zavai.git/blobdiff - src/clock.vala
Notes about remotising devices
[gregoa/zavai.git] / src / clock.vala
index 68eb43c2e2be3f262419ff40cfc4840323ca4472..d08717bcd9ad82e9e5562c4d8e49ec38a4d6bd1a 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * 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
@@ -155,7 +155,6 @@ public class AlarmTriggerInfo
 public class AlarmTriggerQueue : zavai.Service
 {
     protected List<AlarmTriggerInfo> queue;
-    protected int seq;
 
     public signal void triggered(AlarmTriggerInfo info);
     public signal void acked(AlarmTriggerInfo info);
@@ -164,14 +163,12 @@ public class AlarmTriggerQueue : zavai.Service
     public AlarmTriggerQueue()
     {
         queue = new List<AlarmTriggerInfo>();
-        seq = 0;
     }
 
     public uint enqueue_trigger(AlarmTriggerInfo info)
     {
-        // Generate a new sequence number
-        if (++seq == 0) ++seq;
-        info.id = seq;
+        // Reuse IDs from the associated logger object
+        info.id = zavai.log.log.start("alarm", "Alarm " + info.label);
         queue.append(info);
         if (queue.data.id == info.id)
             triggered(queue.data);
@@ -193,6 +190,8 @@ public class AlarmTriggerQueue : zavai.Service
         {
             info.acked = true;
             acked(info);
+            zavai.log.log.add(info.id, "alarm acknowledged");
+            zavai.log.log.end(info.id);
         }
         done_with_first();
     }
@@ -204,6 +203,8 @@ public class AlarmTriggerQueue : zavai.Service
         {
             info.canceled = true;
             canceled(info);
+            zavai.log.log.add(info.id, "alarm canceled");
+            zavai.log.log.end(info.id);
         }
         done_with_first();
     }
@@ -214,7 +215,6 @@ 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;
@@ -228,7 +228,6 @@ public class Clock: zavai.Service
     // 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()
     {
@@ -241,11 +240,6 @@ public class Clock: zavai.Service
         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",
@@ -263,7 +257,8 @@ public class Clock: zavai.Service
     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());
     }
 
@@ -286,7 +281,7 @@ public class Clock: zavai.Service
         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)
         {
@@ -331,7 +326,7 @@ public class Clock: zavai.Service
         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();
 
@@ -343,7 +338,7 @@ public class Clock: zavai.Service
         if (!started) return;
 
         Source.remove(system_time_timeout);
-        gps_time.TimeChanged -= on_gps_time;
+        zavai.gps.gps.time_changed -= on_gps_time;
 
         base.stop();
     }