Merge lp:~charlesk/indicator-power/lp-1330037-add-upower-099-support into lp:indicator-power/14.10

Proposed by Charles Kerr
Status: Merged
Approved by: Ted Gould
Approved revision: 263
Merged at revision: 259
Proposed branch: lp:~charlesk/indicator-power/lp-1330037-add-upower-099-support
Merge into: lp:indicator-power/14.10
Diff against target: 1034 lines (+380/-319)
8 files modified
src/CMakeLists.txt (+1/-4)
src/device-provider-upower.c (+346/-235)
src/device-provider-upower.h (+0/-4)
src/org.freedesktop.UPower.xml (+0/-43)
tests/glib-fixture.h (+2/-2)
tests/indicator-power-service-cmdline-battery.cc (+1/-1)
tests/test-device.cc (+29/-29)
tests/test-notify.cc (+1/-1)
To merge this branch: bzr merge lp:~charlesk/indicator-power/lp-1330037-add-upower-099-support
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+233734@code.launchpad.net

Commit message

Add support for UPower 0.99.

Description of the change

== Description of Change

For indicator-datetime's code, the main change is that the org.freedesktop.UPower interface's DeviceChanged(o) signal has been replaced with proper org.freedesktop.DBus.Properties interface's PropertiesChanged(o,a{sv},as) signals from the devices themselves.

This branch listens for both signals, and so works under both the old and new UPower code.

1. Watch for the unique bus name org.freedesktop.UPower to be owned

2. When an owner appears, ask it for a list of all devices and subscribe to its signals: (1) org.freedesktop.UPower signals (handle DeviceAdded, DeviceRemoved, and, in <0.99, DeviceChanged) (2) PropertiesChanged signals on org.freedesktop.UPower.Device properties

3. When a DeviceChanged signal shows up, handle it just as we did before this MP

4. When a PropertiesChanged signal shows up, update our Device struct and emit a devices_changed() signal.

== MP Checklist

> Are there any related MPs required for this MP to build/function as expected? Please list.

This MP should work correctly both on older versions of UPower and on UPower 0.99, which can be found at https://launchpad.net/~noskcaj/+archive/ubuntu/upower/+packages

This command can be used to confirm which version of UPower is running:

dbus-send --system --print-reply --dest=org.freedesktop.UPower \
 "/org/freedesktop/UPower" "org.freedesktop.DBus.Properties.Get" \
 string:"org.freedesktop.UPower" string:"DaemonVersion"

> Is your branch in sync with latest trunk? (e.g. bzr pull lp:trunk -> no changes)

Yes

> Did the code build without warnings?

Yes

> Did the tests run successfully?

Yes

> Did you perform an exploratory manual test run of your code change and any related functionality?

Yes

> If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?

N/A

> Did your component test plan pass? If on a device, what image number?

Mako + rtm r29

> Please list which manual tests are germane for the reviewer in this MR.

indicator-power/detect-charging-or-discharging will be enough because it will exercise change events on both >=0.99 and on <0.99

> Did you provide a link to this page https://wiki.ubuntu.com/Process/Merges/Checklists/indicator-power

Yes

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Interesting, DeviceTest.NewFromVariant failed. I didn't change anything in that code and the tests are passing here, so that may be a one-off.

I'll inspect that test and resubmit to Jenkins.

Revision history for this message
Charles Kerr (charlesk) wrote :

Apparently it's not a one-off. Fixing. :/

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
263. By Charles Kerr

fix typo introduced while trying to fix clang -Weverything warnings

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ted Gould (ted) wrote :

A lot of code, but I can't find anything wrong with it :-)

review: Approve
264. By Charles Kerr

drop our gcc -Weverything fixes in notifier.c so that they don't step on the changes in lp-1296431-low-power-snap-decisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CMakeLists.txt'
2--- src/CMakeLists.txt 2014-07-21 05:50:24 +0000
3+++ src/CMakeLists.txt 2014-09-08 21:18:20 +0000
4@@ -16,10 +16,6 @@
5 # generated sources
6 include(GdbusCodegen)
7 set(SERVICE_GENERATED_SOURCES)
8-add_gdbus_codegen_with_namespace(SERVICE_GENERATED_SOURCES dbus-upower
9- org.freedesktop
10- Dbus
11- ${CMAKE_CURRENT_SOURCE_DIR}/org.freedesktop.UPower.xml)
12 add_gdbus_codegen_with_namespace(SERVICE_GENERATED_SOURCES dbus-battery
13 com.canonical.indicator.power
14 Dbus
15@@ -31,6 +27,7 @@
16 # add warnings/coverage info on handwritten files
17 # but not the autogenerated ones...
18 set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-bad-function-cast") # g_clear_object()
19+set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-used-but-marked-unused") # G_ADD_PRIVATE
20 set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-disabled-macro-expansion") # G_DEFINE_TYPE
21 set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-assign-enum") # GParamFlags
22 set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-switch-enum")
23
24=== modified file 'src/device-provider-upower.c'
25--- src/device-provider-upower.c 2014-07-14 04:33:16 +0000
26+++ src/device-provider-upower.c 2014-09-08 21:18:20 +0000
27@@ -17,34 +17,45 @@
28 * with this program. If not, see <http://www.gnu.org/licenses/>.
29 */
30
31-#include "dbus-upower.h"
32 #include "device.h"
33 #include "device-provider.h"
34 #include "device-provider-upower.h"
35
36 #define BUS_NAME "org.freedesktop.UPower"
37-#define BUS_PATH "/org/freedesktop/UPower"
38+
39+#define MGR_IFACE "org.freedesktop.UPower"
40+#define MGR_PATH "/org/freedesktop/UPower"
41+
42+#define DISPLAY_DEVICE_PATH "/org/freedesktop/UPower/devices/DisplayDevice"
43
44 /***
45 **** private struct
46 ***/
47
48-struct _IndicatorPowerDeviceProviderUPowerPriv
49+typedef struct
50 {
51 GDBusConnection * bus;
52-
53- DbusUPower * upower_proxy;
54- GHashTable * devices; /* dbus object path --> IndicatorPowerDevice */
55 GCancellable * cancellable;
56
57+ /* dbus object path --> IndicatorPowerDevice */
58+ GHashTable * devices;
59+
60 /* a hashset of paths whose devices need to be refreshed */
61 GHashTable * queued_paths;
62
63 /* when this timer fires, the queued_paths will be refreshed */
64 guint queued_paths_timer;
65-};
66-
67-typedef IndicatorPowerDeviceProviderUPowerPriv priv_t;
68+
69+ GSList* subscriptions;
70+
71+ guint name_tag;
72+}
73+IndicatorPowerDeviceProviderUPowerPrivate;
74+
75+typedef IndicatorPowerDeviceProviderUPowerPrivate priv_t;
76+
77+#define get_priv(o) ((priv_t*)indicator_power_device_provider_upower_get_instance_private(o))
78+
79
80 /***
81 **** GObject boilerplate
82@@ -57,6 +68,7 @@
83 IndicatorPowerDeviceProviderUPower,
84 indicator_power_device_provider_upower,
85 G_TYPE_OBJECT,
86+ G_ADD_PRIVATE(IndicatorPowerDeviceProviderUPower)
87 G_IMPLEMENT_INTERFACE (INDICATOR_TYPE_POWER_DEVICE_PROVIDER,
88 indicator_power_device_provider_interface_init))
89
90@@ -77,11 +89,11 @@
91 }
92
93 static void
94-on_device_properties_ready (GObject * o, GAsyncResult * res, gpointer gdata)
95+on_get_all_response (GObject * o, GAsyncResult * res, gpointer gdata)
96 {
97+ struct device_get_all_data * data = gdata;
98 GError * error;
99 GVariant * response;
100- struct device_get_all_data * data = gdata;
101
102 error = NULL;
103 response = g_dbus_connection_call_finish (G_DBUS_CONNECTION(o), res, &error);
104@@ -102,7 +114,7 @@
105 gint64 time_to_full = 0;
106 gint64 time;
107 IndicatorPowerDevice * device;
108- IndicatorPowerDeviceProviderUPowerPriv * p = data->self->priv;
109+ priv_t * p = get_priv(data->self);
110 GVariant * dict = g_variant_get_child_value (response, 0);
111
112 g_variant_lookup (dict, "Type", "u", &kind);
113@@ -149,55 +161,55 @@
114 update_device_from_object_path (IndicatorPowerDeviceProviderUPower * self,
115 const char * path)
116 {
117- priv_t * p = self->priv;
118+ priv_t * p = get_priv(self);
119 struct device_get_all_data * data;
120
121+ /* Symbolic composite item. Nice idea! But its composite rules
122+ differ from Design's so (for now) don't use it.
123+ https://wiki.ubuntu.com/Power#Handling_multiple_batteries */
124+ if (!g_strcmp0(path, DISPLAY_DEVICE_PATH))
125+ return;
126+
127 data = g_slice_new (struct device_get_all_data);
128 data->path = g_strdup (path);
129 data->self = self;
130
131- g_dbus_connection_call (p->bus,
132- BUS_NAME,
133- path,
134- "org.freedesktop.DBus.Properties",
135- "GetAll",
136- g_variant_new ("(s)", "org.freedesktop.UPower.Device"),
137- G_VARIANT_TYPE("(a{sv})"),
138- G_DBUS_CALL_FLAGS_NO_AUTO_START,
139- -1, /* default timeout */
140- p->cancellable,
141- on_device_properties_ready,
142- data);
143+ g_dbus_connection_call(p->bus,
144+ BUS_NAME,
145+ path,
146+ "org.freedesktop.DBus.Properties",
147+ "GetAll",
148+ g_variant_new ("(s)", "org.freedesktop.UPower.Device"),
149+ G_VARIANT_TYPE("(a{sv})"),
150+ G_DBUS_CALL_FLAGS_NO_AUTO_START,
151+ -1, /* default timeout */
152+ p->cancellable,
153+ on_get_all_response,
154+ data);
155 }
156
157 /*
158- * UPower doesn't seem to be sending PropertyChanged signals.
159- *
160- * Instead, it's got a DIY mechanism for notification: a DeviceChanged signal
161- * that doesn't tell us which property changed, so to refresh we need to
162- * rebuild all the properties with a GetAll() call.
163- *
164- * To make things worse, these DeviceChanged signals come fast and furious
165- * in common situations like disconnecting a power cable.
166- *
167- * This code tries to reduce bus traffic by adding a timer to wait a small bit
168- * before rebuilding our proxy's properties. This helps to fold multiple
169- * DeviceChanged events into a single rebuild.
170+ * UPower 0.99 added proper PropertyChanged signals, but before that
171+ * it MGR_IFACE emitted a DeviceChanged signal which didn't tell which
172+ * property changed, so all properties had to get refreshed w/GetAll().
173+ *
174+ * Changes often come in bursts, so this timer tries to fold them together
175+ * by waiting a small bit before making calling GetAll().
176 */
177
178-/* rebuild all the proxies listed in our queued_paths hashset */
179+/* rebuild all the devices listed in our queued_paths hashset */
180 static gboolean
181-on_queued_paths_timer (gpointer gself)
182+on_queued_paths_timer(gpointer gself)
183 {
184+ IndicatorPowerDeviceProviderUPower * self;
185+ priv_t * p;
186+ GHashTableIter iter;
187 gpointer path;
188- GHashTableIter iter;
189- IndicatorPowerDeviceProviderUPower * self;
190- priv_t * p;
191
192 self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER (gself);
193- p = self->priv;
194+ p = get_priv(self);
195
196- /* create new proxies for all the queued paths */
197+ /* create new devices for all the queued paths */
198 g_hash_table_iter_init (&iter, p->queued_paths);
199 while (g_hash_table_iter_next (&iter, &path, NULL))
200 update_device_from_object_path (self, path);
201@@ -213,7 +225,7 @@
202 refresh_device_soon (IndicatorPowerDeviceProviderUPower * self,
203 const char * object_path)
204 {
205- priv_t * p = self->priv;
206+ priv_t * p = get_priv(self);
207
208 g_hash_table_add (p->queued_paths, g_strdup (object_path));
209
210@@ -226,155 +238,261 @@
211 ***/
212
213 static void
214-on_upower_device_enumerations_ready (GObject * proxy,
215- GAsyncResult * res,
216- gpointer gself)
217-{
218- GError * err;
219- char ** object_paths;
220-
221- err = NULL;
222- dbus_upower_call_enumerate_devices_finish (DBUS_UPOWER(proxy),
223- &object_paths,
224- res,
225- &err);
226-
227- if (err != NULL)
228- {
229- g_warning ("Unable to get UPower devices: %s", err->message);
230- g_error_free (err);
231- }
232- else
233- {
234- guint i;
235-
236- for (i=0; object_paths && object_paths[i]; i++)
237- refresh_device_soon (gself, object_paths[i]);
238-
239- g_strfreev (object_paths);
240- }
241-}
242-
243-static void
244-on_upower_device_changed (DbusUPower * unused G_GNUC_UNUSED,
245- const char * object_path,
246- gpointer gself)
247-{
248- refresh_device_soon (gself, object_path);
249-}
250-
251-static void
252-on_upower_device_added (DbusUPower * unused G_GNUC_UNUSED,
253- const char * object_path,
254- gpointer gself)
255-{
256- refresh_device_soon (gself, object_path);
257-}
258-
259-static void
260-on_upower_device_removed (DbusUPower * unused G_GNUC_UNUSED,
261- const char * object_path,
262- gpointer gself)
263-{
264- IndicatorPowerDeviceProviderUPower * self;
265-
266- self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER (gself);
267- g_hash_table_remove (self->priv->devices, object_path);
268- g_hash_table_remove (self->priv->queued_paths, object_path);
269-
270+on_enumerate_devices_response(GObject * bus,
271+ GAsyncResult * res,
272+ gpointer gself)
273+{
274+ GError* error;
275+ GVariant* v;
276+
277+ error = NULL;
278+ v = g_dbus_connection_call_finish(G_DBUS_CONNECTION(bus), res, &error);
279+ if (v == NULL)
280+ {
281+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
282+ g_warning ("Unable to enumerate UPower devices: %s", error->message);
283+ g_error_free (error);
284+ }
285+ else if (g_variant_is_of_type(v, G_VARIANT_TYPE("(ao)")))
286+ {
287+ GVariant * ao;
288+ GVariantIter iter;
289+ const gchar * path;
290+
291+ ao = g_variant_get_child_value(v, 0);
292+ g_variant_iter_init(&iter, ao);
293+ path = NULL;
294+ while(g_variant_iter_loop(&iter, "o", &path))
295+ refresh_device_soon (gself, path);
296+
297+ g_variant_unref(ao);
298+ }
299+
300+ g_clear_pointer(&v, g_variant_unref);
301+}
302+
303+static void
304+on_device_properties_changed(GDBusConnection * connection G_GNUC_UNUSED,
305+ const gchar * sender_name G_GNUC_UNUSED,
306+ const gchar * object_path,
307+ const gchar * interface_name G_GNUC_UNUSED,
308+ const gchar * signal_name G_GNUC_UNUSED,
309+ GVariant * parameters,
310+ gpointer gself)
311+{
312+ IndicatorPowerDeviceProviderUPower* self;
313+ priv_t* p;
314+ IndicatorPowerDevice* device;
315+
316+ self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(gself);
317+ p = get_priv(self);
318+
319+ device = g_hash_table_lookup(p->devices, object_path);
320+ if (device == NULL) /* unlikely, but let's handle it */
321+ {
322+ refresh_device_soon (self, object_path);
323+ }
324+ else if ((parameters != NULL) && g_variant_n_children(parameters)>=2)
325+ {
326+ gboolean changed = FALSE;
327+ GVariant* dict;
328+ GVariantIter iter;
329+ gchar* key;
330+ GVariant* value;
331+
332+ dict = g_variant_get_child_value(parameters, 1);
333+ g_variant_iter_init(&iter, dict);
334+ while (g_variant_iter_next(&iter, "{sv}", &key, &value))
335+ {
336+ if (!g_strcmp0(key, "TimeToFull") || !g_strcmp0(key, "TimeToEmpty"))
337+ {
338+ const gint64 i = g_variant_get_int64(value);
339+ if (i != 0)
340+ {
341+ g_object_set(device,
342+ INDICATOR_POWER_DEVICE_TIME, (guint64)i,
343+ NULL);
344+ changed = TRUE;
345+ }
346+ }
347+ else if (!g_strcmp0(key, "Percentage"))
348+ {
349+ const gdouble d = g_variant_get_double(value);
350+ g_object_set(device,
351+ INDICATOR_POWER_DEVICE_PERCENTAGE, d,
352+ NULL);
353+ changed = TRUE;
354+ }
355+ else if (!g_strcmp0(key, "Type"))
356+ {
357+ const guint32 u = g_variant_get_uint32(value);
358+ g_object_set(device,
359+ INDICATOR_POWER_DEVICE_KIND, (gint)u,
360+ NULL);
361+ changed = TRUE;
362+ }
363+ else if (!g_strcmp0(key, "State"))
364+ {
365+ const guint32 u = g_variant_get_uint32(value);
366+ g_object_set(device,
367+ INDICATOR_POWER_DEVICE_STATE, (gint)u,
368+ NULL);
369+ changed = TRUE;
370+ }
371+ }
372+ g_variant_unref(dict);
373+
374+ if (changed)
375+ emit_devices_changed(self);
376+ }
377+}
378+
379+static const gchar*
380+get_path_from_nth_child(GVariant* parameters, gsize i)
381+{
382+ const gchar* path = NULL;
383+
384+ if ((parameters != NULL) && g_variant_n_children(parameters)>i)
385+ {
386+ GVariant* v = g_variant_get_child_value(parameters, i);
387+ if (g_variant_is_of_type(v, G_VARIANT_TYPE_STRING) || /* UPower < 0.99 */
388+ g_variant_is_of_type(v, G_VARIANT_TYPE_OBJECT_PATH)) /* and >= 0.99 */
389+ {
390+ path = g_variant_get_string(v, NULL);
391+ }
392+ g_variant_unref(v);
393+ }
394+
395+ return path;
396+}
397+
398+static void
399+on_upower_signal(GDBusConnection * connection G_GNUC_UNUSED,
400+ const gchar * sender_name G_GNUC_UNUSED,
401+ const gchar * object_path G_GNUC_UNUSED,
402+ const gchar * interface_name G_GNUC_UNUSED,
403+ const gchar * signal_name,
404+ GVariant * parameters,
405+ gpointer gself)
406+{
407+ IndicatorPowerDeviceProviderUPower * self;
408+ priv_t * p;
409+
410+ self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(gself);
411+ p = get_priv(self);
412+
413+ if (!g_strcmp0(signal_name, "DeviceAdded"))
414+ {
415+ refresh_device_soon (self, get_path_from_nth_child(parameters, 0));
416+ }
417+ else if (!g_strcmp0(signal_name, "DeviceRemoved"))
418+ {
419+ const char* device_path = get_path_from_nth_child(parameters, 0);
420+ g_hash_table_remove(p->devices, device_path);
421+ g_hash_table_remove(p->queued_paths, device_path);
422+ emit_devices_changed(self);
423+ }
424+ else if (!g_strcmp0(signal_name, "DeviceChanged")) /* UPower < 0.99 */
425+ {
426+ refresh_device_soon (self, get_path_from_nth_child(parameters, 0));
427+ }
428+ else if (!g_strcmp0(signal_name, "Resuming")) /* UPower < 0.99 */
429+ {
430+ GHashTableIter iter;
431+ gpointer device_path = NULL;
432+ g_debug("Resumed from hibernate/sleep; queueing all devices for a refresh");
433+ g_hash_table_iter_init (&iter, p->devices);
434+ while (g_hash_table_iter_next (&iter, &device_path, NULL))
435+ refresh_device_soon (self, device_path);
436+ }
437+}
438+
439+/* start listening for UPower events on the bus */
440+static void
441+on_bus_name_appeared(GDBusConnection * bus,
442+ const gchar * name G_GNUC_UNUSED,
443+ const gchar * name_owner,
444+ gpointer gself)
445+{
446+ IndicatorPowerDeviceProviderUPower * self;
447+ priv_t * p;
448+ guint tag;
449+
450+ self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(gself);
451+ p = get_priv(self);
452+ p->bus = G_DBUS_CONNECTION(g_object_ref(bus));
453+
454+ /* listen for signals from the boss */
455+ tag = g_dbus_connection_signal_subscribe(p->bus,
456+ name_owner,
457+ MGR_IFACE,
458+ NULL /*signal_name*/,
459+ MGR_PATH,
460+ NULL /*arg0*/,
461+ G_DBUS_SIGNAL_FLAGS_NONE,
462+ on_upower_signal,
463+ self,
464+ NULL);
465+ p->subscriptions = g_slist_prepend(p->subscriptions, GUINT_TO_POINTER(tag));
466+
467+ /* listen for change events from the devices */
468+ tag = g_dbus_connection_signal_subscribe(p->bus,
469+ name_owner,
470+ "org.freedesktop.DBus.Properties",
471+ "PropertiesChanged",
472+ NULL /*object_path*/,
473+ "org.freedesktop.UPower.Device", /*arg0*/
474+ G_DBUS_SIGNAL_FLAGS_MATCH_ARG0_NAMESPACE,
475+ on_device_properties_changed,
476+ self,
477+ NULL);
478+ p->subscriptions = g_slist_prepend(p->subscriptions, GUINT_TO_POINTER(tag));
479+
480+ /* rebuild our devices list */
481+ g_dbus_connection_call(p->bus,
482+ BUS_NAME,
483+ MGR_PATH,
484+ MGR_IFACE,
485+ "EnumerateDevices",
486+ NULL,
487+ G_VARIANT_TYPE("(ao)"),
488+ G_DBUS_CALL_FLAGS_NO_AUTO_START,
489+ -1, /* default timeout */
490+ p->cancellable,
491+ on_enumerate_devices_response,
492+ self);
493+}
494+
495+static void
496+on_bus_name_vanished(GDBusConnection * connection G_GNUC_UNUSED,
497+ const gchar * name G_GNUC_UNUSED,
498+ gpointer gself)
499+{
500+ IndicatorPowerDeviceProviderUPower * self;
501+ priv_t * p;
502+ GSList * l;
503+
504+ self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(gself);
505+ p = get_priv(self);
506+
507+ /* clear the devices */
508+ g_hash_table_remove_all(p->devices);
509+ g_hash_table_remove_all(p->queued_paths);
510+ if (p->queued_paths_timer != 0)
511+ {
512+ g_source_remove(p->queued_paths_timer);
513+ p->queued_paths_timer = 0;
514+ }
515 emit_devices_changed (self);
516-}
517-
518-static void
519-on_upower_resuming (DbusUPower * unused G_GNUC_UNUSED,
520- gpointer gself)
521-{
522- IndicatorPowerDeviceProviderUPower * self;
523- GHashTableIter iter;
524- gpointer object_path;
525-
526- self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER (gself);
527-
528- g_debug ("Resumed from hibernate/sleep; queueing all devices for a refresh");
529- g_hash_table_iter_init (&iter, self->priv->devices);
530- while (g_hash_table_iter_next (&iter, &object_path, NULL))
531- refresh_device_soon (self, object_path);
532-}
533-
534-static void
535-on_upower_proxy_ready (GObject * source G_GNUC_UNUSED,
536- GAsyncResult * res,
537- gpointer gself)
538-{
539- GError * err;
540- DbusUPower * proxy;
541-
542- err = NULL;
543- proxy = dbus_upower_proxy_new_finish (res, &err);
544- if (err != NULL)
545- {
546- g_warning ("Unable to get UPower proxy: %s", err->message);
547- g_error_free (err);
548- }
549- else
550- {
551- IndicatorPowerDeviceProviderUPower * self;
552- priv_t * p;
553-
554- self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER (gself);
555- p = self->priv;
556-
557- p->upower_proxy = proxy;
558- g_signal_connect (proxy, "resuming",
559- G_CALLBACK (on_upower_resuming), self);
560- g_signal_connect (proxy, "device-changed",
561- G_CALLBACK (on_upower_device_changed), self);
562- g_signal_connect (proxy, "device-added",
563- G_CALLBACK (on_upower_device_added), self);
564- g_signal_connect (proxy, "device-removed",
565- G_CALLBACK (on_upower_device_removed), self);
566-
567- dbus_upower_call_enumerate_devices (p->upower_proxy,
568- p->cancellable,
569- on_upower_device_enumerations_ready,
570- self);
571- }
572-}
573-
574-static void
575-on_bus_ready (GObject * source_object G_GNUC_UNUSED,
576- GAsyncResult * res,
577- gpointer gself)
578-{
579- GError * error;
580- GDBusConnection * tmp;
581-
582- error = NULL;
583- tmp = g_bus_get_finish (res, &error);
584- if (error != NULL)
585- {
586- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
587- g_warning ("Error acquiring bus: %s", error->message);
588- g_error_free (error);
589- }
590- else
591- {
592- IndicatorPowerDeviceProviderUPower * self;
593- priv_t * p;
594-
595- self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER (gself);
596- p = self->priv;
597-
598- p->bus = tmp;
599-
600- dbus_upower_proxy_new (p->bus,
601- G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
602- BUS_NAME,
603- BUS_PATH,
604- p->cancellable,
605- on_upower_proxy_ready,
606- self);
607- }
608+
609+ /* clear the bus subscriptions */
610+ for (l=p->subscriptions; l!=NULL; l=l->next)
611+ g_dbus_connection_signal_unsubscribe(p->bus, GPOINTER_TO_UINT(l->data));
612+ g_slist_free(p->subscriptions);
613+ p->subscriptions = NULL;
614+
615+ /* clear the bus */
616+ g_clear_object(&p->bus);
617 }
618
619 /***
620@@ -382,14 +500,16 @@
621 ***/
622
623 static GList *
624-my_get_devices (IndicatorPowerDeviceProvider * provider)
625+my_get_devices(IndicatorPowerDeviceProvider * provider)
626 {
627+ IndicatorPowerDeviceProviderUPower * self;
628+ priv_t * p;
629 GList * devices;
630- IndicatorPowerDeviceProviderUPower * self;
631
632 self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(provider);
633+ p = get_priv(self);
634
635- devices = g_hash_table_get_values (self->priv->devices);
636+ devices = g_hash_table_get_values (p->devices);
637 g_list_foreach (devices, (GFunc)g_object_ref, NULL);
638 return devices;
639 }
640@@ -405,7 +525,7 @@
641 priv_t * p;
642
643 self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(o);
644- p = self->priv;
645+ p = get_priv(self);
646
647 if (p->cancellable != NULL)
648 {
649@@ -421,18 +541,15 @@
650 p->queued_paths_timer = 0;
651 }
652
653- if (p->upower_proxy != NULL)
654+ if (p->name_tag != 0)
655 {
656- g_signal_handlers_disconnect_by_data (p->upower_proxy, self);
657+ g_bus_unwatch_name(p->name_tag);
658+ on_bus_name_vanished(NULL, NULL, self);
659
660- g_clear_object (&p->upower_proxy);
661+ p->name_tag = 0;
662 }
663
664- g_hash_table_remove_all (p->devices);
665-
666- g_clear_object (&p->bus);
667-
668- G_OBJECT_CLASS (indicator_power_device_provider_upower_parent_class)->dispose (o);
669+ G_OBJECT_CLASS (indicator_power_device_provider_upower_parent_class)->dispose(o);
670 }
671
672 static void
673@@ -442,12 +559,12 @@
674 priv_t * p;
675
676 self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(o);
677- p = self->priv;
678+ p = get_priv(self);
679
680 g_hash_table_destroy (p->devices);
681 g_hash_table_destroy (p->queued_paths);
682
683- G_OBJECT_CLASS (indicator_power_device_provider_upower_parent_class)->dispose (o);
684+ G_OBJECT_CLASS (indicator_power_device_provider_upower_parent_class)->finalize (o);
685 }
686
687 /***
688@@ -461,9 +578,6 @@
689
690 object_class->dispose = my_dispose;
691 object_class->finalize = my_finalize;
692-
693- g_type_class_add_private (klass,
694- sizeof (IndicatorPowerDeviceProviderUPowerPriv));
695 }
696
697 static void
698@@ -475,30 +589,27 @@
699 static void
700 indicator_power_device_provider_upower_init (IndicatorPowerDeviceProviderUPower * self)
701 {
702- IndicatorPowerDeviceProviderUPowerPriv * p;
703-
704- p = G_TYPE_INSTANCE_GET_PRIVATE (self,
705- INDICATOR_TYPE_POWER_DEVICE_PROVIDER_UPOWER,
706- IndicatorPowerDeviceProviderUPowerPriv);
707-
708- self->priv = p;
709-
710- p->cancellable = g_cancellable_new ();
711-
712- p->devices = g_hash_table_new_full (g_str_hash,
713- g_str_equal,
714- g_free,
715- g_object_unref);
716-
717- p->queued_paths = g_hash_table_new_full (g_str_hash,
718- g_str_equal,
719- g_free,
720- NULL);
721-
722- g_bus_get (G_BUS_TYPE_SYSTEM,
723- p->cancellable,
724- on_bus_ready,
725- self);
726+ priv_t * p = get_priv(self);
727+
728+ p->cancellable = g_cancellable_new();
729+
730+ p->devices = g_hash_table_new_full(g_str_hash,
731+ g_str_equal,
732+ g_free,
733+ g_object_unref);
734+
735+ p->queued_paths = g_hash_table_new_full(g_str_hash,
736+ g_str_equal,
737+ g_free,
738+ NULL);
739+
740+ p->name_tag = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
741+ BUS_NAME,
742+ G_BUS_NAME_WATCHER_FLAGS_NONE,
743+ on_bus_name_appeared,
744+ on_bus_name_vanished,
745+ self,
746+ NULL);
747 }
748
749 /***
750@@ -506,7 +617,7 @@
751 ***/
752
753 IndicatorPowerDeviceProvider *
754-indicator_power_device_provider_upower_new (void)
755+indicator_power_device_provider_upower_new(void)
756 {
757 gpointer o = g_object_new (INDICATOR_TYPE_POWER_DEVICE_PROVIDER_UPOWER, NULL);
758
759
760=== modified file 'src/device-provider-upower.h'
761--- src/device-provider-upower.h 2014-07-14 04:43:41 +0000
762+++ src/device-provider-upower.h 2014-09-08 21:18:20 +0000
763@@ -45,8 +45,6 @@
764
765 typedef struct _IndicatorPowerDeviceProviderUPower
766 IndicatorPowerDeviceProviderUPower;
767-typedef struct _IndicatorPowerDeviceProviderUPowerPriv
768- IndicatorPowerDeviceProviderUPowerPriv;
769 typedef struct _IndicatorPowerDeviceProviderUPowerClass
770 IndicatorPowerDeviceProviderUPowerClass;
771
772@@ -56,8 +54,6 @@
773 struct _IndicatorPowerDeviceProviderUPower
774 {
775 GObject parent_instance;
776-
777- IndicatorPowerDeviceProviderUPowerPriv * priv;
778 };
779
780 struct _IndicatorPowerDeviceProviderUPowerClass
781
782=== removed file 'src/org.freedesktop.UPower.xml'
783--- src/org.freedesktop.UPower.xml 2013-06-17 04:03:23 +0000
784+++ src/org.freedesktop.UPower.xml 1970-01-01 00:00:00 +0000
785@@ -1,43 +0,0 @@
786-<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
787- "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
788-<node>
789- <interface name="org.freedesktop.UPower">
790- <method name="HibernateAllowed">
791- <arg name="allowed" type="b" direction="out"/>
792- </method>
793- <method name="Hibernate">
794- </method>
795- <method name="SuspendAllowed">
796- <arg name="allowed" type="b" direction="out"/>
797- </method>
798- <method name="Suspend">
799- </method>
800- <method name="AboutToSleep">
801- </method>
802- <method name="EnumerateDevices">
803- <arg name="devices" type="ao" direction="out"/>
804- </method>
805- <signal name="Resuming">
806- </signal>
807- <signal name="Sleeping">
808- </signal>
809- <signal name="Changed">
810- </signal>
811- <signal name="DeviceChanged">
812- <arg type="s"/>
813- </signal>
814- <signal name="DeviceRemoved">
815- <arg type="s"/>
816- </signal>
817- <signal name="DeviceAdded">
818- <arg type="s"/>
819- </signal>
820- <property name="LidIsPresent" type="b" access="read"/>
821- <property name="LidIsClosed" type="b" access="read"/>
822- <property name="OnLowBattery" type="b" access="read"/>
823- <property name="OnBattery" type="b" access="read"/>
824- <property name="CanHibernate" type="b" access="read"/>
825- <property name="CanSuspend" type="b" access="read"/>
826- <property name="DaemonVersion" type="s" access="read"/>
827- </interface>
828-</node>
829\ No newline at end of file
830
831=== modified file 'tests/glib-fixture.h'
832--- tests/glib-fixture.h 2014-07-24 21:25:32 +0000
833+++ tests/glib-fixture.h 2014-09-08 21:18:20 +0000
834@@ -64,7 +64,7 @@
835 const gchar * message,
836 gpointer self)
837 {
838- auto tmp = g_strdup_printf ("%s:%d \"%s\"", log_domain, (int)log_level, message);
839+ auto tmp = g_strdup_printf ("%s:%d \"%s\"", log_domain, int(log_level), message);
840 static_cast<GlibFixture*>(self)->log[log_level].push_back(tmp);
841 g_free(tmp);
842 }
843@@ -101,7 +101,7 @@
844 static gboolean
845 wait_for_signal__timeout(gpointer name)
846 {
847- g_error("%s: timed out waiting for signal '%s'", G_STRLOC, (char*)name);
848+ g_error("%s: timed out waiting for signal '%s'", G_STRLOC, static_cast<char*>(name));
849 return G_SOURCE_REMOVE;
850 }
851
852
853=== modified file 'tests/indicator-power-service-cmdline-battery.cc'
854--- tests/indicator-power-service-cmdline-battery.cc 2014-07-22 14:58:29 +0000
855+++ tests/indicator-power-service-cmdline-battery.cc 2014-09-08 21:18:20 +0000
856@@ -37,7 +37,7 @@
857 on_name_lost (gpointer instance G_GNUC_UNUSED, gpointer loop)
858 {
859 g_message ("exiting: service couldn't acquire or lost ownership of busname");
860- g_main_loop_quit ((GMainLoop*)loop);
861+ g_main_loop_quit (static_cast<GMainLoop*>(loop));
862 }
863
864 static IndicatorPowerDevice * battery = nullptr;
865
866=== modified file 'tests/test-device.cc'
867--- tests/test-device.cc 2014-07-29 15:05:20 +0000
868+++ tests/test-device.cc 2014-09-08 21:18:20 +0000
869@@ -172,11 +172,11 @@
870 key = INDICATOR_POWER_DEVICE_PERCENTAGE;
871 g_object_set (o, key, 50.0, NULL);
872 g_object_get (o, key, &d, NULL);
873- ASSERT_EQ((int)d, 50);
874+ ASSERT_EQ(int(d), 50);
875
876 // TIME
877 key = INDICATOR_POWER_DEVICE_TIME;
878- g_object_set (o, key, (guint64)30, NULL);
879+ g_object_set (o, key, guint64(30), NULL);
880 g_object_get (o, key, &u64, NULL);
881 ASSERT_EQ(u64, 30);
882
883@@ -193,11 +193,11 @@
884 30);
885 ASSERT_TRUE (device != NULL);
886 ASSERT_TRUE (INDICATOR_IS_POWER_DEVICE(device));
887- ASSERT_EQ (indicator_power_device_get_kind(device), UP_DEVICE_KIND_BATTERY);
888- ASSERT_EQ (indicator_power_device_get_state(device), UP_DEVICE_STATE_CHARGING);
889- ASSERT_STREQ (indicator_power_device_get_object_path(device), "/object/path");
890- ASSERT_EQ ((int)indicator_power_device_get_percentage(device), 50);
891- ASSERT_EQ (indicator_power_device_get_time(device), 30);
892+ ASSERT_EQ (UP_DEVICE_KIND_BATTERY, indicator_power_device_get_kind(device));
893+ ASSERT_EQ (UP_DEVICE_STATE_CHARGING, indicator_power_device_get_state(device));
894+ ASSERT_STREQ ("/object/path", indicator_power_device_get_object_path(device));
895+ ASSERT_EQ (50, int(indicator_power_device_get_percentage(device)));
896+ ASSERT_EQ (30, indicator_power_device_get_time(device));
897
898 // cleanup
899 g_object_unref (device);
900@@ -205,22 +205,22 @@
901
902 TEST_F(DeviceTest, NewFromVariant)
903 {
904- GVariant * variant = g_variant_new ("(susdut)",
905- "/object/path",
906- (guint32) UP_DEVICE_KIND_BATTERY,
907- "icon",
908- (gdouble) 50.0,
909- (guint32) UP_DEVICE_STATE_CHARGING,
910- (guint64) 30);
911+ auto variant = g_variant_new("(susdut)",
912+ "/object/path",
913+ guint32(UP_DEVICE_KIND_BATTERY),
914+ "icon",
915+ 50.0,
916+ guint32(UP_DEVICE_STATE_CHARGING),
917+ guint64(30));
918 IndicatorPowerDevice * device = indicator_power_device_new_from_variant (variant);
919 ASSERT_TRUE (variant != NULL);
920 ASSERT_TRUE (device != NULL);
921 ASSERT_TRUE (INDICATOR_IS_POWER_DEVICE(device));
922- ASSERT_EQ (indicator_power_device_get_kind(device), UP_DEVICE_KIND_BATTERY);
923- ASSERT_EQ (indicator_power_device_get_state(device), UP_DEVICE_STATE_CHARGING);
924- ASSERT_STREQ (indicator_power_device_get_object_path(device), "/object/path");
925- ASSERT_EQ ((int)indicator_power_device_get_percentage(device), 50);
926- ASSERT_EQ (indicator_power_device_get_time(device), 30);
927+ ASSERT_EQ (UP_DEVICE_KIND_BATTERY, indicator_power_device_get_kind(device));
928+ ASSERT_EQ (UP_DEVICE_STATE_CHARGING, indicator_power_device_get_state(device));
929+ ASSERT_STREQ ("/object/path", indicator_power_device_get_object_path(device));
930+ ASSERT_EQ (50, int(indicator_power_device_get_percentage(device)));
931+ ASSERT_EQ (30, indicator_power_device_get_time(device));
932
933 // cleanup
934 g_object_unref (device);
935@@ -407,7 +407,7 @@
936 g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind,
937 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING,
938 INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0,
939- INDICATOR_POWER_DEVICE_TIME, (guint64)(60*60),
940+ INDICATOR_POWER_DEVICE_TIME, guint64(60*60),
941 NULL);
942 g_string_append_printf (expected, "%s-060;", kind_str);
943 g_string_append_printf (expected, "gpm-%s-060;", kind_str);
944@@ -420,7 +420,7 @@
945 g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind,
946 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING,
947 INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0,
948- INDICATOR_POWER_DEVICE_TIME, (guint64)(60*60),
949+ INDICATOR_POWER_DEVICE_TIME, guint64(60*60),
950 NULL);
951 g_string_append_printf (expected, "%s-020;", kind_str);
952 g_string_append_printf (expected, "gpm-%s-020;", kind_str);
953@@ -433,7 +433,7 @@
954 g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind,
955 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING,
956 INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0,
957- INDICATOR_POWER_DEVICE_TIME, (guint64)(60*15),
958+ INDICATOR_POWER_DEVICE_TIME, guint64(60*15),
959 NULL);
960 g_string_append_printf (expected, "%s-020;", kind_str);
961 g_string_append_printf (expected, "gpm-%s-020;", kind_str);
962@@ -446,7 +446,7 @@
963 g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind,
964 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING,
965 INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0,
966- INDICATOR_POWER_DEVICE_TIME, (guint64)(60*60),
967+ INDICATOR_POWER_DEVICE_TIME, guint64(60*60),
968 NULL);
969 g_string_append_printf (expected, "%s-000;", kind_str);
970 g_string_append_printf (expected, "gpm-%s-000;", kind_str);
971@@ -459,7 +459,7 @@
972 g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind,
973 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING,
974 INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0,
975- INDICATOR_POWER_DEVICE_TIME, (guint64)(60*15),
976+ INDICATOR_POWER_DEVICE_TIME, guint64(60*15),
977 NULL);
978 g_string_append_printf (expected, "%s-000;", kind_str);
979 g_string_append_printf (expected, "gpm-%s-000;", kind_str);
980@@ -495,12 +495,12 @@
981 log_count_ipower_expected++;
982 check_label (NULL, NULL);
983 log_count_ipower_expected += 5;
984- check_header (NULL, NULL, NULL, NULL, NULL);
985+ check_header (nullptr, nullptr, nullptr, nullptr, nullptr);
986
987 // bad args: a GObject that isn't a device
988 GObject * o = G_OBJECT(g_cancellable_new());
989 log_count_ipower_expected++;
990- check_label ((IndicatorPowerDevice*)o, NULL);
991+ check_label (INDICATOR_POWER_DEVICE(o), nullptr);
992 log_count_ipower_expected += 5;
993 check_header (NULL, NULL, NULL, NULL, NULL);
994 g_object_unref (o);
995@@ -710,7 +710,7 @@
996
997 std::vector<IndicatorPowerDevice*> devices;
998 for(const auto& desc : descriptions)
999- devices.push_back(indicator_power_device_new(desc.path, desc.kind, desc.percentage, desc.state, (time_t)desc.time));
1000+ devices.push_back(indicator_power_device_new(desc.path, desc.kind, desc.percentage, desc.state, time_t(desc.time)));
1001
1002 const struct {
1003 std::vector<unsigned int> device_indices;
1004@@ -756,7 +756,7 @@
1005 EXPECT_EQ(x.kind, indicator_power_device_get_kind(primary));
1006 EXPECT_EQ(x.state, indicator_power_device_get_state(primary));
1007 EXPECT_EQ(x.time, indicator_power_device_get_time(primary));
1008- EXPECT_EQ((int)ceil(x.percentage), (int)ceil(indicator_power_device_get_percentage(primary)));
1009+ EXPECT_EQ(int(ceil(x.percentage)), int(ceil(indicator_power_device_get_percentage(primary))));
1010 g_object_unref(primary);
1011
1012 // reverse the list and repeat the test
1013@@ -767,7 +767,7 @@
1014 EXPECT_EQ(x.kind, indicator_power_device_get_kind(primary));
1015 EXPECT_EQ(x.state, indicator_power_device_get_state(primary));
1016 EXPECT_EQ(x.time, indicator_power_device_get_time(primary));
1017- EXPECT_EQ((int)ceil(x.percentage), (int)ceil(indicator_power_device_get_percentage(primary)));
1018+ EXPECT_EQ(int(ceil(x.percentage)), int(ceil(indicator_power_device_get_percentage(primary))));
1019 g_object_unref(primary);
1020
1021 // cleanup
1022
1023=== modified file 'tests/test-notify.cc'
1024--- tests/test-notify.cc 2014-07-25 04:31:11 +0000
1025+++ tests/test-notify.cc 2014-09-08 21:18:20 +0000
1026@@ -131,7 +131,7 @@
1027
1028 bus = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr);
1029 g_dbus_connection_set_exit_on_close(bus, FALSE);
1030- g_object_add_weak_pointer(G_OBJECT(bus), (gpointer *)&bus);
1031+ g_object_add_weak_pointer(G_OBJECT(bus), reinterpret_cast<gpointer*>(&bus));
1032
1033 notify_init(APP_NAME);
1034 }

Subscribers

People subscribed via source and target branches