Remove unneeded ID systems
authorEnrico Zini <enrico@enricozini.org>
Sat, 27 Mar 2010 17:38:03 +0000 (17:38 +0000)
committerEnrico Zini <enrico@enricozini.org>
Sat, 27 Mar 2010 17:38:03 +0000 (17:38 +0000)
src/app_alarm.vala
src/clock.vala
src/gps.vala
src/gsm.vala
src/log.vala

index 8baa9d6f5c86300876c0c047dc996e3f1550d028..a92cb2eb32e8c6d1df98b591e3f56efb77622f11 100644 (file)
@@ -128,7 +128,7 @@ public class AlarmNotifier : zavai.Resource, Gtk.Window
 
     public void on_done(clock.AlarmTriggerInfo info)
     {
-        if (current == null || current.id != info.id) return;
+        if (current == null || current != info) return;
         visible = false;
         abort_timeout();
         current = null;
index d08717bcd9ad82e9e5562c4d8e49ec38a4d6bd1a..fd5e6f0926673c69eca3a50cc7eba828e59131be 100644 (file)
@@ -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;
@@ -165,14 +164,13 @@ public class AlarmTriggerQueue : zavai.Service
         queue = new List<AlarmTriggerInfo>();
     }
 
-    public uint enqueue_trigger(AlarmTriggerInfo info)
+    public void enqueue_trigger(AlarmTriggerInfo info)
     {
         // Reuse IDs from the associated logger object
-        info.id = zavai.log.log.start("alarm", "Alarm " + info.label);
+        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()
@@ -185,26 +183,26 @@ 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);
-            zavai.log.log.add(info.id, "alarm acknowledged");
-            zavai.log.log.end(info.id);
+            info.log.add("alarm acknowledged");
+            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);
-            zavai.log.log.add(info.id, "alarm canceled");
-            zavai.log.log.end(info.id);
+            info.log.add("alarm canceled");
+            zavai.log.log.end(info.log);
         }
         done_with_first();
     }
index 950d76b3091ae7c7b918a26e3f182ea91ee96f85..17e76421e00f577d970a76830d3f234365e120c8 100644 (file)
@@ -189,7 +189,7 @@ public class GPS: zavai.ScriptService
 public class GPX : Service
 {
     protected uint wpt_seq = 0;
-    protected uint log_id = 0;
+    protected zavai.log.Log log = null;
 
     public GPX()
     {
@@ -200,7 +200,7 @@ public class GPX : Service
     {
         if (!started)
         {
-            log_id = log.log.start("track", "GPS track");
+            log = zavai.log.log.start("track", "GPS track");
             base.start();
         }
     }
@@ -209,8 +209,8 @@ public class GPX : Service
     {
         if (started)
         {
-            log.log.end(log_id);
-            log_id = 0;
+            zavai.log.log.end(log);
+            log = null;
             base.stop();
         }
     }
@@ -218,7 +218,7 @@ public class GPX : Service
     // Mark a waypoint
     public void waypoint(string? name = null)
     {
-        if (log_id == 0) return;
+        if (log == null) return;
 
         string wptname;
         if (name == null)
@@ -229,7 +229,7 @@ public class GPX : Service
             wptname = name;
         }
 
-        log.log.add(log_id, wptname);
+        log.add(wptname);
     }
 }
 
index 841b995e042a02d4f5bbdc906c9cb6a6a83bc721..e5545038cbcd197cafea0fb6eed035b4ea44fa19 100644 (file)
@@ -128,7 +128,7 @@ public class GSM: zavai.ScriptMonitorService
     protected class CallInfo
     {
         public int gsm_id;
-        public uint log_id;
+        public zavai.log.Log log;
     }
     protected List<CallInfo> calls;
 
@@ -353,7 +353,7 @@ stderr.printf("ACQUIRE SIG %d\n", info_signal_strength);
 
             info = new CallInfo();
             info.gsm_id = index;
-            info.log_id = zavai.log.log.start("call", title);
+            info.log = zavai.log.log.start("call", title);
             calls.append(info);
         }
 
@@ -364,12 +364,12 @@ stderr.printf("ACQUIRE SIG %d\n", info_signal_strength);
             Value? v = (Value?)pv;
             call_info = call_info + "%s: %s\n".printf(k, v == null ? "(null)" : v.strdup_contents());
         });
-        zavai.log.log.add(info.log_id, call_info);
+        info.log.add(call_info);
 
         // Remove entry when it's the last possible status
         if (status == "release")
         {
-            zavai.log.log.end(info.log_id);
+            zavai.log.log.end(info.log);
             for (weak List<CallInfo> i = calls; i != null; i = i.next)
                 if (i.data.gsm_id == index)
                 {
index eb78363990ba2f2e26a2df82b115c9f355abd83d..1a5eba946d0f7111607349fe157f42315292c2e3 100644 (file)
@@ -88,15 +88,13 @@ public class TrackEntry : Waypoint
 
 public class Log : Object
 {
-    public uint id;
     public string tag;
     public string title;
     public List<LogEntry> entries;
     public List<TrackEntry> track;
 
-    public Log(uint id, string tag, string title)
+    public Log(string tag, string title)
     {
-        this.id = id;
         this.tag = tag;
         this.title = title;
         entries = null;
@@ -183,13 +181,10 @@ public class Log : Object
 public class Logger : Resource, Object
 {
     protected List<Log> logs;
-    protected uint seq;
 
     public Logger()
     {
         logs = null;
-        seq = 0;
-
         zavai.registry.register(this);
     }
 
@@ -209,83 +204,45 @@ public class Logger : Resource, Object
             i.data.add_trackpoint();
     }
 
-    protected uint gen_seq()
-    {
-        // Increase avoiding 0 on rollover
-        while (true)
-        {
-            if (++seq == 0) ++seq;
-            bool found = false;
-            for (weak List<Log> i = logs; i != null; i = i.next)
-            {
-                if (i.data.id == seq)
-                {
-                    found = true;
-                    break;
-                }
-            }
-            if (!found) break;
-        }
-        return seq;
-    }
-
-    protected weak Log? find(uint id)
-    {
-        for (weak List<Log> i = logs; i != null; i = i.next)
-            if (i.data.id == id)
-                return i.data;
-        return null;
-    }
-
-    protected Log? pop(uint id)
+    protected void pop(Log log)
     {
         for (weak List<Log> i = logs; i != null; i = i.next)
-            if (i.data.id == id)
-            {
-                Log res = i.data;
+            if (i.data == log)
                 logs.delete_link(i);
-                return res;
-            }
-        return null;
     }
 
-    public uint start(string tag, string title)
+    public Log start(string tag, string title)
     {
         bool was_empty = (logs == null);
-        uint id = gen_seq();
-        logs.append(new Log(id, tag, title));
+        Log res = new Log(tag, title);
+        logs.append(res);
         if (was_empty) start_trace();
-        return id;
-    }
-
-    public void add(uint id, string msg)
-    {
-        Log log = find(id);
-        if (log == null) return;
-        log.add(msg);
+        return res;
     }
 
-    public void end(uint id)
+    public void end(Log log)
     {
-        Log log = pop(id);
+        pop(log);
         log.save();
-        if (log == null) end_trace();
+        if (logs == null) end_trace();
     }
 
     public void instant(string tag, string msg)
     {
-        var log = new Log(0, tag, msg);
+        var log = new Log(tag, msg);
         log.add(msg);
         log.save();
     }
 
     public void shutdown()
     {
+        bool had_logs = (logs != null);
         while (logs != null)
         {
-            var log = pop(logs.data.id);
-            log.save();
+            logs.data.save();
+            logs.delete_link(logs);
         }
+        if (had_logs) end_trace();
     }
 }