libgps19 -> 20
[gregoa/zavai.git] / test / test-gsm-receive.vala
index b1110f86d075efe88d5aebb52955de6db0f710c4..a9d360475bbe0e934cf615c0ae8fe1ca33c8789e 100644 (file)
 
 using GLib;
 
+public DBus.Connection sbus;
+
 //string VERSION = "0.1";
 
-public class GSMReceive: Object, zavai.Resource
+public class GSMReceive: Object //, zavai.Resource
 {
+    public dynamic DBus.Object device;
     public dynamic DBus.Object network;
+    public dynamic DBus.Object sim;
     public dynamic DBus.Object call;
 
     public GSMReceive()
     {
-        zavai.gsm.gsm.request("GSMReceive");
+        //zavai.gsm.gsm.request("GSMReceive");
+
+        device = sbus.get_object(
+                   "org.freesmartphone.ogsmd",
+                   "/org/freesmartphone/GSM/Device",
+                   "org.freesmartphone.GSM.Device");
 
-        network = zavai.registry.sbus.get_object(
+        network = sbus.get_object(
             "org.freesmartphone.ogsmd", 
             "/org/freesmartphone/GSM/Device",
             "org.freesmartphone.GSM.Network");
+        sim = sbus.get_object(
+            "org.freesmartphone.ogsmd", 
+            "/org/freesmartphone/GSM/Device",
+            "org.freesmartphone.GSM.SIM");
 
-        call = zavai.registry.sbus.get_object(
+        call = sbus.get_object(
                 "org.freesmartphone.ogsmd",
                 "/org/freesmartphone/GSM/Device",
                 "org.freesmartphone.GSM.Call");
 
+       stderr.printf("Antenna is %s\n", device.GetAntennaPower() ? "on" : "off");
+       stderr.printf("Signal strength: %d\n", network.GetSignalStrength());
+       stderr.printf("Calling identification: %s\n", network.GetCallingIdentification());
+       GLib.HashTable<string, GLib.Value?> status = network.GetStatus();
+       stderr.printf("Network status:\n");
+       dump_table(status);
+
         network.Status += on_network_Status;
         network.SignalStrength += on_network_SignalStrength;
         call.CallStatus += on_call_Status;
+       sim.IncomingStoredMessage += on_sim_IncomingStoredMessage;
     }
 
     public void shutdown()
     {
-        zavai.gsm.gsm.release("GSMReceive");
+        //zavai.gsm.gsm.release("GSMReceive");
+    }
+
+    protected void dump_table(HashTable<string, Value?> vals)
+    {
+       vals.for_each((pk, pv) => {
+               string k = (string)pk;
+               Value? v = (Value?)pv;
+               stderr.printf("K: %s V: %s\n", k, v == null ? "(null)" : v.strdup_contents());
+       });
     }
 
-    public void on_network_SignalStrength(int strength)
+    public void on_sim_IncomingStoredMessage(DBus.Object sender, int index)
+    {
+       stderr.printf("INCOMING STORED MESSAGE %d\n", index);
+       dump_message(index);
+    }
+
+    public void dump_message(int index)
+    {
+       string state, sender, msg;
+       GLib.HashTable<string, GLib.Value?> info;
+       sim.RetrieveMessage(index, out state, out sender, out msg, out info);
+       stderr.printf("state: %s\n", state);
+       stderr.printf("sender: %s\n", sender);
+       stderr.printf("msg: %s\n", msg);
+       dump_table(info);
+    }
+
+    public void on_network_SignalStrength(DBus.Object sender, int strength)
     {
         stderr.printf("SIGNAL STRENGTH %d\n", strength);
     }
 
-    public void on_network_Status(GLib.HashTable<string, GLib.Value?> status)
+    public void on_network_Status(DBus.Object sender, HashTable<string, Value?> status)
     {
         stderr.printf("NETWORK STATUS\n");
+       dump_table(status);
 
         // dbg("cbNetworkStatus %s" % formatDict(status))
     }
 
-    public void on_call_Status(int index, string status, GLib.HashTable<string, GLib.Value?> properties)
+    public void on_call_Status(DBus.Object sender, int index, string status, HashTable<string, Value?> properties)
     {
         stderr.printf("CALL STATUS %d %s\n", index, status);
+       dump_table(properties);
         /*
         dbg("cbCallStatus %d, %s, %s" % (id, status, formatDict(properties)))
         self.status = status
@@ -381,25 +430,30 @@ public class GSMReceive: Object, zavai.Resource
 
 static int main (string[] args) {
        Gtk.init (ref args);
-    Gst.init (ref args);
+    // Gst.init (ref args);
 
        // Set up zavai
+       sbus = DBus.Bus.get(DBus.BusType.SYSTEM);
 
     // Core infrastructure
-       zavai.config = new zavai.Config();
-       zavai.config.argv0 = args[0];
-       zavai.registry = new zavai.Registry();
+//     zavai.config = new zavai.Config();
+//     zavai.config.argv0 = args[0];
+//     zavai.registry = new zavai.Registry();
 
     // Additional infrastructure
-       zavai.gsm.init();
-       zavai.log.init();
+       //zavai.gsm.init();
+       //zavai.log.init();
 
     // PLAY here
+    var gr = new GSMReceive();
+
+       if (args.length > 1)
+               gr.dump_message(args[1].to_int());
 
        Gtk.main();
 
        // zavai.info("Shutting down")
-       zavai.registry.shutdown();
+       // zavai.registry.shutdown();
 
        return 0;
 }