Merge lp:~cando/zeitgeist/storage-monitor into lp:~zeitgeist/zeitgeist/bluebird

Proposed by Stefano Candori
Status: Merged
Merged at revision: 339
Proposed branch: lp:~cando/zeitgeist/storage-monitor
Merge into: lp:~zeitgeist/zeitgeist/bluebird
Diff against target: 234 lines (+167/-4)
2 files modified
extensions/storage-monitor.vala (+150/-4)
src/remote.vala (+17/-0)
To merge this branch: bzr merge lp:~cando/zeitgeist/storage-monitor
Reviewer Review Type Date Requested Status
Siegfried Gevatter Needs Fixing
Review via email: mp+84299@code.launchpad.net

Description of the change

In this branch i've ported the support for "net-storages" in the storage-monitor.

To post a comment you must log in.
Revision history for this message
Siegfried Gevatter (rainct) wrote :

Hey,

Good job, thanks for working on this.

Some comments:

> (this.network != null) { ... }
What's this supposed to do? You've already unwatched everything in the "else { ... }", so you can just return.

> this.network.setup ();
I'm not too happy about this. Hm. Let's leave it like this, but at least add a comment to the abstract setup() document that it will call on_network_up/on_network_up with the initial state of the network.

> public interface NetworkMonitor: Object
Shouldn't this be private? It's not supposed to be used anywhere outside the extension.

> Write connectivity to the DB.
Not sure what this comment is supposed to mean.

> private void name_appeared_handler(DBusConnection connection, string name, string name_owner)
You're missing a space between "handler (".

> Checks whether there is a funtioning
Typo (funtioning -> functioning). I'd reword it to something like "Monitor the availability of working network connections using Network Manager (0.8 or later)".

> // ^^ There is a bug in some Connman versions causing it to not emit the
This comment is about the proxy.state_changed.connect, but the position where it's places make it look like it's proxy.get_state.

review: Needs Fixing
lp:~cando/zeitgeist/storage-monitor updated
341. By Stefano Candori

Fixes basing on RainCT's review.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'extensions/storage-monitor.vala'
2--- extensions/storage-monitor.vala 2011-09-30 09:35:12 +0000
3+++ extensions/storage-monitor.vala 2011-12-03 14:26:26 +0000
4@@ -2,6 +2,7 @@
5 *
6 * Copyright © 2011 Collabora Ltd.
7 * By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com>
8+ * Copyright © 2011 Stefano Candori <stefano.candori@gmail.com>
9 *
10 * Based upon a Python implementation:
11 * Copyright © 2009 Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com>
12@@ -36,6 +37,16 @@
13 [DBus (signature = "a{sv}")] Variant storage_description);
14 public signal void storage_unavailable (string storage_id);
15 }
16+
17+ private interface NetworkMonitor: Object
18+ {
19+ // This method emits the on_network_up/on_network_up signals
20+ // basing on the initial state of the network.
21+ public abstract void setup ();
22+
23+ public signal void on_network_up ();
24+ public signal void on_network_down ();
25+ }
26
27 namespace StorageMedia
28 {
29@@ -97,6 +108,10 @@
30 private Sqlite.Statement store_storage_medium_stmt;
31 private Sqlite.Statement insert_unavailable_medium_stmt;
32 private Sqlite.Statement update_medium_state_stmt;
33+
34+ private NetworkMonitor network;
35+ private uint watch_connman;
36+ private uint watch_nm;
37
38 StorageMonitor ()
39 {
40@@ -136,9 +151,41 @@
41 volume.get_icon ().to_string (), volume.get_name ());
42 }
43
44- // FIXME: ConnMan / NetworkManager D-Bus stuff...
45- }
46+ // Dynamically decide whether to use Connman or NetworkManager
47+ watch_connman = Bus.watch_name (BusType.SYSTEM,
48+ "net.connman",
49+ BusNameWatcherFlags.NONE,
50+ name_appeared_handler,
51+ null);
52+ watch_nm = Bus.watch_name (BusType.SYSTEM,
53+ "org.freedesktop.NetworkManager",
54+ BusNameWatcherFlags.NONE,
55+ name_appeared_handler,
56+ null);
57
58+ }
59+
60+ private void name_appeared_handler (DBusConnection connection, string name, string name_owner)
61+ {
62+ if (this.network != null)
63+ return;
64+
65+ if (name == "net.connman")
66+ this.network = new ConnmanNetworkMonitor ();
67+ else if (name == "org.freedesktop.NetworkManager")
68+ this.network = new NMNetworkMonitor ();
69+
70+ this.network.on_network_up.connect (() =>
71+ this.add_storage_medium ("net", "stock_internet", "Internet"));
72+ this.network.on_network_down.connect (() =>
73+ this.remove_storage_medium ("net"));
74+
75+ this.network.setup ();
76+
77+ Bus.unwatch_name (watch_connman);
78+ Bus.unwatch_name (watch_nm);
79+ }
80+
81 public override void unload ()
82 {
83 // FIXME: move all this D-Bus stuff to some shared
84@@ -228,7 +275,7 @@
85 return "unknown";
86 }
87
88- private void on_volume_added (VolumeMonitor monitor, Volume volume)
89+ private void on_volume_added (Volume volume)
90 {
91 debug ("volume added");
92 Icon icon = volume.get_icon ();
93@@ -240,7 +287,7 @@
94 volume.get_name ());
95 }
96
97- private void on_volume_removed (VolumeMonitor monitor, Volume volume)
98+ private void on_volume_removed (Volume volume)
99 {
100 debug ("Volume removed");
101 remove_storage_medium (get_volume_id (volume));
102@@ -329,6 +376,105 @@
103
104 }
105
106+ /*
107+ * Monitor the availability of working network connections using Network Manager
108+ * (requires 0.8 or later).
109+ * See http://projects.gnome.org/NetworkManager/developers/spec-08.html
110+ */
111+ class NMNetworkMonitor : Object, NetworkMonitor
112+ {
113+ private const string NM_BUS_NAME = "org.freedesktop.NetworkManager";
114+ private const string NM_IFACE = "org.freedesktop.NetworkManager";
115+ private const string NM_OBJECT_PATH = "/org/freedesktop/NetworkManager";
116+
117+ //NM 0.9 broke API so we have to check for two possible values for the state
118+ private const int NM_STATE_CONNECTED_PRE_09 = 3;
119+ private const int NM_STATE_CONNECTED_POST_09 = 70;
120+
121+ private NetworkManagerDBus proxy;
122+
123+ public NMNetworkMonitor ()
124+ {
125+ Object ();
126+ }
127+
128+ public void setup ()
129+ {
130+ debug ("Creating NetworkManager network monitor");
131+ try
132+ {
133+ proxy = Bus.get_proxy_sync<NetworkManagerDBus> (BusType.SYSTEM,
134+ NM_BUS_NAME,
135+ NM_OBJECT_PATH);
136+ proxy.state_changed.connect (this.on_state_changed);
137+
138+ uint32 state = proxy.state ();
139+ this.on_state_changed (state);
140+ }
141+ catch (IOError e )
142+ {
143+ warning ("%s", e.message);
144+ }
145+ }
146+
147+ private void on_state_changed(uint32 state)
148+ {
149+ debug ("NetworkManager network state: %u", state);
150+ if (state == NMNetworkMonitor.NM_STATE_CONNECTED_PRE_09 ||
151+ state == NMNetworkMonitor.NM_STATE_CONNECTED_POST_09)
152+ on_network_up ();
153+ else
154+ on_network_down ();
155+ }
156+ }
157+
158+ class ConnmanNetworkMonitor : Object, NetworkMonitor
159+ {
160+ private const string CM_BUS_NAME = "net.connman";
161+ private const string CM_IFACE = "net.connman.Manager";
162+ private const string CM_OBJECT_PATH = "/";
163+
164+ private ConnmanManagerDBus proxy;
165+
166+ public ConnmanNetworkMonitor ()
167+ {
168+ Object ();
169+ }
170+
171+ public void setup ()
172+ {
173+ debug ("Creating ConnmanNetworkManager network monitor");
174+
175+ try
176+ {
177+ proxy = Bus.get_proxy_sync<ConnmanManagerDBus> (BusType.SYSTEM,
178+ CM_BUS_NAME,
179+ CM_OBJECT_PATH);
180+
181+ // There is a bug in some Connman versions causing it to not emit the
182+ // net.connman.Manager.StateChanged signal. We take our chances this
183+ // instance is working properly :-)
184+ proxy.state_changed.connect (this.on_state_changed);
185+
186+ string state = proxy.get_state ();
187+ this.on_state_changed (state);
188+ }
189+ catch (IOError e )
190+ {
191+ warning ("%s", e.message);
192+ }
193+ }
194+
195+ private void on_state_changed(string state)
196+ {
197+ debug ("ConnmanNetworkMonitor network state: %s", state);
198+ if (state == "online")
199+ on_network_up ();
200+ else
201+ on_network_down ();
202+ }
203+ }
204+
205 [ModuleInit]
206 #if BUILTIN_EXTENSIONS
207 public static Type storage_monitor_init (TypeModule module)
208
209=== modified file 'src/remote.vala'
210--- src/remote.vala 2011-10-12 21:13:12 +0000
211+++ src/remote.vala 2011-12-03 14:26:26 +0000
212@@ -121,6 +121,23 @@
213 [DBus (signature = "a(asaasay)")] Variant filter_templates,
214 uint offset, uint count, uint result_type) throws Error;
215 }
216+
217+ /* FIXME: Remove this! Only here because of a bug in Vala (see ext-fts) */
218+ [DBus (name = "org.freedesktop.NetworkManager")]
219+ public interface NetworkManagerDBus : Object
220+ {
221+ [DBus (name = "state")]
222+ public abstract uint32 state () throws IOError;
223+ public signal void state_changed (uint32 state);
224+ }
225+
226+ /* FIXME: Remove this! Only here because of a bug in Vala (see ext-fts) */
227+ [DBus (name = "net.connman.Manager")]
228+ public interface ConnmanManagerDBus : Object
229+ {
230+ public abstract string get_state () throws IOError;
231+ public signal void state_changed (string state);
232+ }
233
234 }
235

Subscribers

People subscribed via source and target branches