]> ToastFreeware Gitweb - gregoa/zavai.git/blob - src/wifi.vala
Merge branch 'master' into gregoa
[gregoa/zavai.git] / src / wifi.vala
1 /*
2  * wifi - wifi resource for zavai
3  * copied from gps.vala
4  *
5  * Copyright (C) 2009  Enrico Zini <enrico@enricozini.org>
6  * Copyright (C) 2009  gregor herrmann <gregor.herrmann@comodo.priv.at>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 using GLib;
24
25 namespace zavai {
26 namespace wifi {
27
28 // For a list of dbus services, look in /etc/dbus-1/system.d/
29 public class WiFi: zavai.Service
30 {
31         public dynamic DBus.Object usage;
32         public dynamic DBus.Object device;
33         protected bool s = false;
34
35         public WiFi()
36         {
37                 Object(name: "wifi.wifi");
38
39                 // see mdbus -s org.freesmartphone.ousaged /org/freesmartphone/Usage
40                 usage = zavai.registry.sbus.get_object(
41                         "org.freesmartphone.ousaged",
42                         "/org/freesmartphone/Usage",
43                         "org.freesmartphone.Usage");
44
45                 device = zavai.registry.sbus.get_object(
46                         "org.freesmartphone.odeviced", 
47                         "/org/freesmartphone/Device/PowerControl/WiFi",
48                         "org.freesmartphone.Device.PowerControl");
49         }
50
51         /// Request WiFi resource
52         public override void start()
53         {
54                 if (started) return;
55                 try {
56                         usage.RequestResource("WiFi");
57                         zavai.log.info("Acquired WiFi");
58                         base.start();
59                 } catch (GLib.Error e) {
60                         zavai.log.error(e.message);
61                 }
62                 base.start();
63         }
64
65         // Release usage of WiFi
66         public override void stop()
67         {
68                 if (!started) return;
69                 try {
70                         usage.ReleaseResource("WiFi");
71                         zavai.log.info("Released WiFi");
72                         base.stop();
73                 } catch (GLib.Error e) {
74                         zavai.log.error(e.message);
75                 }
76                 base.stop();
77         }
78 }
79
80
81 public zavai.wifi.WiFi wifi = null;
82
83 public void init()
84 {
85         wifi = new WiFi();
86 }
87
88 }
89 }