]> ToastFreeware Gitweb - gregoa/zavai.git/blob - src/wifi.vala
First version of a WiFi app.
[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                 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     public void power_cycle()
52     {
53         // "Have you tried turning it off and on again?"
54                 try {
55             usage.SetResourcePolicy("WiFi", "disabled");
56                 } catch (GLib.Error e) {
57                         zavai.log.error(e.message);
58                 }
59         Thread.usleep(500000);
60                 try {
61             usage.SetResourcePolicy("WiFi", "auto");
62                 } catch (GLib.Error e) {
63                         zavai.log.error(e.message);
64                 }
65     }
66
67         /// Request WiFi resource
68         public override void start()
69         {
70                 if (started) return;
71                 try {
72                         usage.RequestResource("WiFi");
73                         zavai.log.info("Acquired WiFi");
74                         base.start();
75                 } catch (GLib.Error e) {
76                         zavai.log.error(e.message);
77                 }
78                 base.start();
79         }
80
81         // Release usage of WiFi
82         public override void stop()
83         {
84                 if (!started) return;
85                 try {
86                         usage.ReleaseResource("WiFi");
87                         zavai.log.info("Released WiFi");
88                         base.stop();
89                 } catch (GLib.Error e) {
90                         zavai.log.error(e.message);
91                 }
92                 base.stop();
93         }
94 }
95
96
97 public zavai.wifi.WiFi wifi = null;
98
99 public void init()
100 {
101         wifi = new WiFi();
102         zavai.registry.register_service(wifi);
103 }
104
105 }
106 }