]> ToastFreeware Gitweb - gregoa/zavai.git/blobdiff - src/clock.vala
Merge branch 'master' into gregoa
[gregoa/zavai.git] / src / clock.vala
index f01da084c9baf571881e7a8a8d39013bdf62d5e0..b55d3b250c36589a60839ac5bd619d2124f21172 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
@@ -138,14 +138,13 @@ public class ZavaiClock : Object {
 
 public class AlarmTriggerInfo
 {
-    public uint id;
+    public zavai.log.Log log;
     public string label;
     public bool acked;
     public bool canceled;
 
     public AlarmTriggerInfo(string label)
     {
-        id = 0;
         this.label = label;
         acked = false;
         canceled = false;
@@ -155,7 +154,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,18 +162,15 @@ public class AlarmTriggerQueue : zavai.Service
     public AlarmTriggerQueue()
     {
         queue = new List<AlarmTriggerInfo>();
-        seq = 0;
     }
 
-    public uint enqueue_trigger(AlarmTriggerInfo info)
+    public void enqueue_trigger(AlarmTriggerInfo info)
     {
-        // Generate a new sequence number
-        if (++seq == 0) ++seq;
-        info.id = seq;
+        // Reuse IDs from the associated logger object
+        info.log = zavai.log.log.start("alarm", "Alarm " + info.label);
         queue.append(info);
-        if (queue.data.id == info.id)
+        if (queue.data == info)
             triggered(queue.data);
-        return info.id;
     }
 
     protected void done_with_first()
@@ -188,22 +183,27 @@ public class AlarmTriggerQueue : zavai.Service
 
     public void ack(AlarmTriggerInfo info)
     {
-        if (queue == null || info.id != queue.data.id) return;
+        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.id != queue.data.id) return;
+        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();
     }
@@ -214,7 +214,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;
@@ -240,11 +239,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",
@@ -286,7 +280,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 +325,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 +337,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();
     }