Reunified sources, as there seemed to be only disadvantages in compilation time
[gregoa/zavai.git] / test / test-gsm-receive.vala
index af6ce6f7e123b1d552a59c41c1fb8d53c0d8f9ea..79539627662e906a00d162c704a2e03a47920657 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 call;
 
@@ -31,16 +34,28 @@ public class GSMReceive: Object, zavai.Resource
     {
         //zavai.gsm.gsm.request("GSMReceive");
 
-        network = zavai.registry.sbus.get_object(
+        device = sbus.get_object(
+                   "org.freesmartphone.ogsmd",
+                   "/org/freesmartphone/GSM/Device",
+                   "org.freesmartphone.GSM.Device");
+
+        network = sbus.get_object(
             "org.freesmartphone.ogsmd", 
             "/org/freesmartphone/GSM/Device",
             "org.freesmartphone.GSM.Network");
 
-        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;
@@ -51,21 +66,32 @@ public class GSMReceive: Object, zavai.Resource
         //zavai.gsm.gsm.release("GSMReceive");
     }
 
-    public void on_network_SignalStrength(int strength)
+    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(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,14 +407,15 @@ 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();
@@ -400,7 +427,7 @@ static int main (string[] args) {
        Gtk.main();
 
        // zavai.info("Shutting down")
-       zavai.registry.shutdown();
+       // zavai.registry.shutdown();
 
        return 0;
 }