]> ToastFreeware Gitweb - gregoa/zavai.git/blobdiff - src/gsm.vala
Merge branch 'master' into gregoa
[gregoa/zavai.git] / src / gsm.vala
index 19a854da04554e5fb56391cd120b274619e19c41..de96ee389dd51c508680d0df58837fab083dcdfb 100644 (file)
@@ -128,15 +128,19 @@ 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;
 
     public string info_provider;
+    public string info_registration;
     public int info_signal_strength;
 
     public signal void status_changed(string message);
     public signal void info_changed();
+    public signal void new_call(int index);
+    public signal void end_call(int index);
+    public signal void new_sms();
 
     protected void dump_table(HashTable<string, Value?> vals)
     {
@@ -165,7 +169,16 @@ public class GSM: zavai.ScriptMonitorService
             if (info_provider != vprovider.get_string())
             {
                 info_provider = vprovider.get_string();
-stderr.printf("ACQUIRE PROV %s\n", info_provider);
+                changed = true;
+            }
+        }
+
+        var vregistration = status.lookup("registration");
+        if (vregistration != null)
+        {
+            if (info_registration != vregistration.get_string())
+            {
+                info_registration = vregistration.get_string();
                 changed = true;
             }
         }
@@ -230,6 +243,10 @@ stderr.printf("ACQUIRE SIG %d\n", info_signal_strength);
         };
 
         call.call_status += on_call_status;
+        sim.incoming_stored_message += (idx) => {
+            stderr.printf("INCOMING STORED MESSAGE %d\n", idx);
+            sms_log_and_delete(idx);
+        };
     }
 
     /// Request GPS resource
@@ -328,12 +345,15 @@ stderr.printf("ACQUIRE SIG %d\n", info_signal_strength);
 
     public void on_call_status(int index, string status, HashTable<string, Value?> properties)
     {
+        bool is_new = false;
+        bool is_done = false;
         stderr.printf("CALL STATUS %d %s\n", index, status);
         dump_table(properties);
 
         CallInfo? info = lookup_call(index);
         if (info == null)
         {
+            is_new = true;
             Value? v = properties.lookup("peer");
             string title;
             if (v != null)
@@ -343,7 +363,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);
         }
 
@@ -354,18 +374,19 @@ 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)
                 {
                     calls.delete_link(i);
                     break;
                 }
+            is_done = true;
         }
 
         /*
@@ -385,6 +406,36 @@ stderr.printf("ACQUIRE SIG %d\n", info_signal_strength);
             os.system("vibrator-stop")
             os.system("ledctrl --off gta02-aux:red");
         */
+
+        if (is_new && !is_done)
+            new_call(index);
+        if (is_done)
+            end_call(index);
+    }
+
+    public async void sms_log_and_delete(int idx)
+    {
+        // Retrieve message info
+        string state, sender, msg;
+        GLib.HashTable<string, GLib.Value?> info;
+        yield sim.retrieve_message(idx, out state, out sender, out msg, out info);
+
+        // Log message info
+        var sms_log = zavai.log.log.start("sms", msg);
+        string sms_info = "state: %s\nsender: %s\nmsg: %s\n".printf(state, sender, msg);
+        info.for_each((pk, pv) => {
+            string k = (string)pk;
+            Value? v = (Value?)pv;
+            sms_info = sms_info + "%s: %s\n".printf(k, v == null ? "(null)" : v.strdup_contents());
+        });
+        sms_log.add(sms_info);
+        zavai.log.log.end(sms_log);
+
+        // Delete message
+        yield sim.delete_message(idx);
+
+        // Notify reception of the sms
+        new_sms();
     }
 }