From 88fb24c6896b60f9976de7e1b19f299c31468b44 Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Fri, 26 Mar 2010 19:47:48 +0000 Subject: [PATCH] Try to log calls --- zavai/gsm.vala | 90 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 2 deletions(-) diff --git a/zavai/gsm.vala b/zavai/gsm.vala index a73e9f8..bf9abc0 100644 --- a/zavai/gsm.vala +++ b/zavai/gsm.vala @@ -101,13 +101,36 @@ public interface FSO_GSM_Network : GLib.Object { public abstract async void get_country_code(out string param0, out string param1) throws DBus.Error; } +[DBus (name = "org.freesmartphone.GSM.Call")] +public interface FSO_GSM_Call : GLib.Object { + public abstract async void activate(int index) throws DBus.Error; + public abstract async void emergency(string number) throws DBus.Error; + public abstract async void hold_active() throws DBus.Error; + public abstract async void release_held() throws DBus.Error; + public abstract async void send_dtmf(string tones) throws DBus.Error; + public abstract async void release_all() throws DBus.Error; + public abstract async int initiate(string number, string type_) throws DBus.Error; + // public abstract async CallParam0Struct[] list_calls() throws DBus.Error; + public abstract async void transfer(string number) throws DBus.Error; + public abstract async void release(int index) throws DBus.Error; + public signal void call_status(int index, string status, GLib.HashTable properties); + public abstract async void activate_conference(int index) throws DBus.Error; +} + public class GSM: zavai.ScriptMonitorService { protected dynamic DBus.Object dbus; public FSO_GSM_Device device; public FSO_GSM_Network network; public FSO_GSM_SIM sim; - public dynamic DBus.Object call; + public FSO_GSM_Call call; + + protected class CallInfo + { + public int gsm_id; + public uint log_id; + } + protected List calls; public string info_provider; public int info_signal_strength; @@ -163,6 +186,8 @@ public class GSM: zavai.ScriptMonitorService { Object(name: "gsm"); + calls = new List(); + device = (FSO_GSM_Device)zavai.registry.sbus.get_object( "org.freesmartphone.ogsmd", "/org/freesmartphone/GSM/Device", @@ -175,7 +200,7 @@ public class GSM: zavai.ScriptMonitorService "org.freesmartphone.ogsmd", "/org/freesmartphone/GSM/Device", "org.freesmartphone.GSM.SIM"); - call = zavai.registry.sbus.get_object( + call = (FSO_GSM_Call)zavai.registry.sbus.get_object( "org.freesmartphone.ogsmd", "/org/freesmartphone/GSM/Device", "org.freesmartphone.GSM.Call"); @@ -198,6 +223,8 @@ public class GSM: zavai.ScriptMonitorService stderr.printf("SIGNAL STRENGTH %d\n", strength); acquire_new_signal_strength(strength); }; + + call.call_status += on_call_status; } /// Request GPS resource @@ -285,6 +312,65 @@ public class GSM: zavai.ScriptMonitorService acquire_new_status(yield network.get_status()); acquire_new_signal_strength(yield network.get_signal_strength()); } + + protected CallInfo? lookup_call(int gsm_id) + { + for (weak List i = calls; i != null; i = i.next) + if (i.data.gsm_id == gsm_id) + return i.data; + return null; + } + + public void on_call_status(int index, string status, HashTable properties) + { + stderr.printf("CALL STATUS %d %s\n", index, status); + dump_table(properties); + + CallInfo? info = lookup_call(index); + if (info == null) + { + Value? v = properties.lookup("peer"); + string title; + if (v != null) + title = "%s call from %s".printf(status, v.get_string()); + else + title = "%s call".printf(status); + + info = new CallInfo(); + info.gsm_id = index; + info.log_id = zavai.log.log.start("call", title); + calls.append(info); + } + + // Log a summary of all info + string call_info = "status: %s\n".printf(status); + properties.for_each((pk, pv) => { + string k = (string)pk; + 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); + + // TODO: remove entry when it's the last possible status + + /* + dbg("cbCallStatus %d, %s, %s" % (id, status, formatDict(properties))) + self.status = status + if status == "incoming": + if "peer" in properties and properties["peer"] == "+358942832031": + self.gsm_call_iface.ReleaseAll() + os.system("kapula-debug-call-handler &") + else: + os.system("alsactl restore -f /etc/alsa-scenarios/stereoout-maxvolume.state") + os.system("vibrator-start") + os.system("ringtone-start") + os.system("ledctrl --on-time 400 --off-time 200 gta02-aux:red"); + if status == "release": + os.system("ringtone-stop") + os.system("vibrator-stop") + os.system("ledctrl --off gta02-aux:red"); + */ + } } public class GPRS: zavai.Service -- 2.39.5