Draft GSM resource
authorEnrico Zini <enrico@enricozini.org>
Fri, 9 Oct 2009 21:01:02 +0000 (22:01 +0100)
committerEnrico Zini <enrico@enricozini.org>
Fri, 9 Oct 2009 21:01:02 +0000 (22:01 +0100)
src/gsm.vala

index 25ed65d091a9f035cc9eb9bdc497812f5f5340aa..31e6bb700b3b118652c84efa6c22a9c6a08cd619 100644 (file)
@@ -23,7 +23,49 @@ using GLib;
 namespace zavai {
 namespace gsm {
 
-// For a list of dbus services, look in /etc/dbus-1/system.d/
+public class GSM: zavai.Service
+{
+       public dynamic DBus.Object device;
+
+       public GSM()
+       {
+               name = "gsm.gsm";
+
+               device = zavai.registry.sbus.get_object(
+                       "org.freesmartphone.ogpsd", 
+                       "/org/freesmartphone/GSM/Device",
+                       "org.freesmartphone.Resource");
+       }
+
+       /// Request GPS resource
+       public override void start()
+       {
+               if (started) return;
+               try {
+                       device.Enable();
+                       zavai.log.info("Started GSM");
+                       base.start();
+               } catch (GLib.Error e) {
+                       zavai.log.error(e.message);
+               }
+               base.start();
+       }
+
+       // Release usage of GPS
+       public override void stop()
+       {
+               if (!started) return;
+               try {
+                       device.Disable();
+                       zavai.log.info("Stopped GSM");
+                       base.stop();
+               } catch (GLib.Error e) {
+                       zavai.log.error(e.message);
+               }
+               base.stop();
+       }
+}
+
 public class GPRS: zavai.Service
 {
        public dynamic DBus.Object device;
@@ -43,6 +85,7 @@ public class GPRS: zavai.Service
        {
                if (started) return;
                try {
+                       //gsm.request(name);
                        device.ActivateContext(
                                zavai.config.gprs_apn,
                                zavai.config.gprs_user,
@@ -60,6 +103,7 @@ public class GPRS: zavai.Service
        {
                if (!started) return;
                try {
+                       //gsm.release(name);
                        device.DeactivateContext();
                        zavai.log.info("Stopped GPRS");
                        base.stop();
@@ -70,12 +114,15 @@ public class GPRS: zavai.Service
        }
 }
 
+public zavai.gsm.GSM gsm = null;
 public zavai.gsm.GPRS gprs = null;
 
 public void init()
 {
+       gsm = new GSM();
        gprs = new GPRS();
 
+       zavai.registry.register_service(gsm);
        zavai.registry.register_service(gprs);
 }