Log incoming SMSes
authorEnrico Zini <enrico@enricozini.org>
Sun, 28 Mar 2010 11:20:10 +0000 (12:20 +0100)
committerEnrico Zini <enrico@enricozini.org>
Sun, 28 Mar 2010 11:20:10 +0000 (12:20 +0100)
src/gsm.vala

index e5545038cbcd197cafea0fb6eed035b4ea44fa19..ed9c60b9c9835466b5ca34e15ed999474e59f047 100644 (file)
@@ -240,6 +240,10 @@ stderr.printf("ACQUIRE SIG %d\n", info_signal_strength);
         };
 
         call.call_status += on_call_status;
         };
 
         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
     }
 
     /// Request GPS resource
@@ -396,6 +400,28 @@ stderr.printf("ACQUIRE SIG %d\n", info_signal_strength);
             os.system("ledctrl --off gta02-aux:red");
         */
     }
             os.system("ledctrl --off gta02-aux:red");
         */
     }
+
+    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);
+    }
 }
 
 public class GPRS: zavai.Service
 }
 
 public class GPRS: zavai.Service