Added functions to start/stop GPRS
[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 // For a list of dbus services, look in /etc/dbus-1/system.d/
27 public class GPRS: zavai.Service
28 {
29         public dynamic DBus.Object device;
30
31         public GPRS()
32         {
33                 name = "gsm.gprs";
34
35                 device = zavai.registry.sbus.get_object(
36                         "org.freesmartphone.ogpsd", 
37                         "/org/freesmartphone/GSM/Device",
38                         "org.freesmartphone.GSM.PDP");
39         }
40
41         /// Request GPS resource
42         public override void start()
43         {
44                 if (started) return;
45                 try {
46                         device.ActivateContext(
47                                 zavai.config.gprs_apn,
48                                 zavai.config.gprs_user,
49                                 zavai.config.gprs_pass);
50                         zavai.log.info("Started GPRS");
51                         base.start();
52                 } catch (GLib.Error e) {
53                         zavai.log.error(e.message);
54                 }
55                 base.start();
56         }
57
58         // Release usage of GPS
59         public override void stop()
60         {
61                 if (!started) return;
62                 try {
63                         device.DeactivateContext();
64                         zavai.log.info("Stopped GPRS");
65                         base.stop();
66                 } catch (GLib.Error e) {
67                         zavai.log.error(e.message);
68                 }
69                 base.stop();
70         }
71 }
72
73 public zavai.gsm.GPRS gprs = null;
74
75 public void init()
76 {
77         gprs = new GPRS();
78
79         zavai.registry.register_service(gprs);
80 }
81
82 }
83 }