From: Enrico Zini Date: Sat, 27 Mar 2010 17:38:03 +0000 (+0000) Subject: Remove unneeded ID systems X-Git-Url: https://git.toastfreeware.priv.at/gregoa/zavai.git/commitdiff_plain/b74d0a482a598a8184af2a5a0a90554c849bd1d7 Remove unneeded ID systems --- diff --git a/src/app_alarm.vala b/src/app_alarm.vala index 8baa9d6..a92cb2e 100644 --- a/src/app_alarm.vala +++ b/src/app_alarm.vala @@ -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; diff --git a/src/clock.vala b/src/clock.vala index d08717b..fd5e6f0 100644 --- a/src/clock.vala +++ b/src/clock.vala @@ -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(); } - 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(); } diff --git a/src/gps.vala b/src/gps.vala index 950d76b..17e7642 100644 --- a/src/gps.vala +++ b/src/gps.vala @@ -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); } } diff --git a/src/gsm.vala b/src/gsm.vala index 841b995..e554503 100644 --- a/src/gsm.vala +++ b/src/gsm.vala @@ -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 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 i = calls; i != null; i = i.next) if (i.data.gsm_id == index) { diff --git a/src/log.vala b/src/log.vala index eb78363..1a5eba9 100644 --- a/src/log.vala +++ b/src/log.vala @@ -88,15 +88,13 @@ public class TrackEntry : Waypoint public class Log : Object { - public uint id; public string tag; public string title; public List entries; public List 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 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 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 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 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(); } }