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;
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;
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()
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();
}
public class GPX : Service
{
protected uint wpt_seq = 0;
- protected uint log_id = 0;
+ protected zavai.log.Log log = null;
public GPX()
{
{
if (!started)
{
- log_id = log.log.start("track", "GPS track");
+ log = zavai.log.log.start("track", "GPS track");
base.start();
}
}
{
if (started)
{
- log.log.end(log_id);
- log_id = 0;
+ zavai.log.log.end(log);
+ log = null;
base.stop();
}
}
// Mark a waypoint
public void waypoint(string? name = null)
{
- if (log_id == 0) return;
+ if (log == null) return;
string wptname;
if (name == null)
wptname = name;
}
- log.log.add(log_id, wptname);
+ log.add(wptname);
}
}
protected class CallInfo
{
public int gsm_id;
- public uint log_id;
+ public zavai.log.Log log;
}
protected List<CallInfo> calls;
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);
}
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)
{
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;
public class Logger : Resource, Object
{
protected List<Log> logs;
- protected uint seq;
public Logger()
{
logs = null;
- seq = 0;
-
zavai.registry.register(this);
}
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();
}
}