Draft GSM resource
[gregoa/zavai.git] / src / gsm.vala
1 /*
2  * gsm - gsm resource for zavai
3  *
4  * Copyright (C) 2009  Enrico Zini <enrico@enricozini.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 using GLib;
22
23 namespace zavai {
24 namespace gsm {
25
26 public class GSM: zavai.Service
27 {
28         public dynamic DBus.Object device;
29
30         public GSM()
31         {
32                 name = "gsm.gsm";
33
34                 device = zavai.registry.sbus.get_object(
35                         "org.freesmartphone.ogpsd", 
36                         "/org/freesmartphone/GSM/Device",
37                         "org.freesmartphone.Resource");
38         }
39
40         /// Request GPS resource
41         public override void start()
42         {
43                 if (started) return;
44                 try {
45                         device.Enable();
46                         zavai.log.info("Started GSM");
47                         base.start();
48                 } catch (GLib.Error e) {
49                         zavai.log.error(e.message);
50                 }
51                 base.start();
52         }
53
54         // Release usage of GPS
55         public override void stop()
56         {
57                 if (!started) return;
58                 try {
59                         device.Disable();
60                         zavai.log.info("Stopped GSM");
61                         base.stop();
62                 } catch (GLib.Error e) {
63                         zavai.log.error(e.message);
64                 }
65                 base.stop();
66         }
67 }
68
69 public class GPRS: zavai.Service
70 {
71         public dynamic DBus.Object device;
72
73         public GPRS()
74         {
75                 name = "gsm.gprs";
76
77                 device = zavai.registry.sbus.get_object(
78                         "org.freesmartphone.ogpsd", 
79                         "/org/freesmartphone/GSM/Device",
80                         "org.freesmartphone.GSM.PDP");
81         }
82
83         /// Request GPS resource
84         public override void start()
85         {
86                 if (started) return;
87                 try {
88                         //gsm.request(name);
89                         device.ActivateContext(
90                                 zavai.config.gprs_apn,
91                                 zavai.config.gprs_user,
92                                 zavai.config.gprs_pass);
93                         zavai.log.info("Started GPRS");
94                         base.start();
95                 } catch (GLib.Error e) {
96                         zavai.log.error(e.message);
97                 }
98                 base.start();
99         }
100
101         // Release usage of GPS
102         public override void stop()
103         {
104                 if (!started) return;
105                 try {
106                         //gsm.release(name);
107                         device.DeactivateContext();
108                         zavai.log.info("Stopped GPRS");
109                         base.stop();
110                 } catch (GLib.Error e) {
111                         zavai.log.error(e.message);
112                 }
113                 base.stop();
114         }
115 }
116
117 public zavai.gsm.GSM gsm = null;
118 public zavai.gsm.GPRS gprs = null;
119
120 public void init()
121 {
122         gsm = new GSM();
123         gprs = new GPRS();
124
125         zavai.registry.register_service(gsm);
126         zavai.registry.register_service(gprs);
127 }
128
129 }
130 }