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
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2014-07-21 05:50:24 +0000
+++ src/CMakeLists.txt 2014-09-08 21:18:20 +0000
@@ -16,10 +16,6 @@
16# generated sources16# generated sources
17include(GdbusCodegen)17include(GdbusCodegen)
18set(SERVICE_GENERATED_SOURCES)18set(SERVICE_GENERATED_SOURCES)
19add_gdbus_codegen_with_namespace(SERVICE_GENERATED_SOURCES dbus-upower
20 org.freedesktop
21 Dbus
22 ${CMAKE_CURRENT_SOURCE_DIR}/org.freedesktop.UPower.xml)
23add_gdbus_codegen_with_namespace(SERVICE_GENERATED_SOURCES dbus-battery19add_gdbus_codegen_with_namespace(SERVICE_GENERATED_SOURCES dbus-battery
24 com.canonical.indicator.power20 com.canonical.indicator.power
25 Dbus21 Dbus
@@ -31,6 +27,7 @@
31# add warnings/coverage info on handwritten files27# add warnings/coverage info on handwritten files
32# but not the autogenerated ones...28# but not the autogenerated ones...
33set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-bad-function-cast") # g_clear_object()29set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-bad-function-cast") # g_clear_object()
30set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-used-but-marked-unused") # G_ADD_PRIVATE
34set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-disabled-macro-expansion") # G_DEFINE_TYPE31set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-disabled-macro-expansion") # G_DEFINE_TYPE
35set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-assign-enum") # GParamFlags32set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-assign-enum") # GParamFlags
36set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-switch-enum")33set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-switch-enum")
3734
=== modified file 'src/device-provider-upower.c'
--- src/device-provider-upower.c 2014-07-14 04:33:16 +0000
+++ src/device-provider-upower.c 2014-09-08 21:18:20 +0000
@@ -17,34 +17,45 @@
17 * with this program. If not, see <http://www.gnu.org/licenses/>.17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */18 */
1919
20#include "dbus-upower.h"
21#include "device.h"20#include "device.h"
22#include "device-provider.h"21#include "device-provider.h"
23#include "device-provider-upower.h"22#include "device-provider-upower.h"
2423
25#define BUS_NAME "org.freedesktop.UPower"24#define BUS_NAME "org.freedesktop.UPower"
26#define BUS_PATH "/org/freedesktop/UPower"25
26#define MGR_IFACE "org.freedesktop.UPower"
27#define MGR_PATH "/org/freedesktop/UPower"
28
29#define DISPLAY_DEVICE_PATH "/org/freedesktop/UPower/devices/DisplayDevice"
2730
28/***31/***
29**** private struct32**** private struct
30***/33***/
3134
32struct _IndicatorPowerDeviceProviderUPowerPriv35typedef struct
33{36{
34 GDBusConnection * bus;37 GDBusConnection * bus;
35
36 DbusUPower * upower_proxy;
37 GHashTable * devices; /* dbus object path --> IndicatorPowerDevice */
38 GCancellable * cancellable;38 GCancellable * cancellable;
3939
40 /* dbus object path --> IndicatorPowerDevice */
41 GHashTable * devices;
42
40 /* a hashset of paths whose devices need to be refreshed */43 /* a hashset of paths whose devices need to be refreshed */
41 GHashTable * queued_paths;44 GHashTable * queued_paths;
4245
43 /* when this timer fires, the queued_paths will be refreshed */46 /* when this timer fires, the queued_paths will be refreshed */
44 guint queued_paths_timer;47 guint queued_paths_timer;
45};48
4649 GSList* subscriptions;
47typedef IndicatorPowerDeviceProviderUPowerPriv priv_t;50
51 guint name_tag;
52}
53IndicatorPowerDeviceProviderUPowerPrivate;
54
55typedef IndicatorPowerDeviceProviderUPowerPrivate priv_t;
56
57#define get_priv(o) ((priv_t*)indicator_power_device_provider_upower_get_instance_private(o))
58
4859
49/***60/***
50**** GObject boilerplate61**** GObject boilerplate
@@ -57,6 +68,7 @@
57 IndicatorPowerDeviceProviderUPower,68 IndicatorPowerDeviceProviderUPower,
58 indicator_power_device_provider_upower,69 indicator_power_device_provider_upower,
59 G_TYPE_OBJECT,70 G_TYPE_OBJECT,
71 G_ADD_PRIVATE(IndicatorPowerDeviceProviderUPower)
60 G_IMPLEMENT_INTERFACE (INDICATOR_TYPE_POWER_DEVICE_PROVIDER,72 G_IMPLEMENT_INTERFACE (INDICATOR_TYPE_POWER_DEVICE_PROVIDER,
61 indicator_power_device_provider_interface_init))73 indicator_power_device_provider_interface_init))
6274
@@ -77,11 +89,11 @@
77}89}
7890
79static void91static void
80on_device_properties_ready (GObject * o, GAsyncResult * res, gpointer gdata)92on_get_all_response (GObject * o, GAsyncResult * res, gpointer gdata)
81{93{
94 struct device_get_all_data * data = gdata;
82 GError * error;95 GError * error;
83 GVariant * response;96 GVariant * response;
84 struct device_get_all_data * data = gdata;
8597
86 error = NULL;98 error = NULL;
87 response = g_dbus_connection_call_finish (G_DBUS_CONNECTION(o), res, &error);99 response = g_dbus_connection_call_finish (G_DBUS_CONNECTION(o), res, &error);
@@ -102,7 +114,7 @@
102 gint64 time_to_full = 0;114 gint64 time_to_full = 0;
103 gint64 time;115 gint64 time;
104 IndicatorPowerDevice * device;116 IndicatorPowerDevice * device;
105 IndicatorPowerDeviceProviderUPowerPriv * p = data->self->priv;117 priv_t * p = get_priv(data->self);
106 GVariant * dict = g_variant_get_child_value (response, 0);118 GVariant * dict = g_variant_get_child_value (response, 0);
107119
108 g_variant_lookup (dict, "Type", "u", &kind);120 g_variant_lookup (dict, "Type", "u", &kind);
@@ -149,55 +161,55 @@
149update_device_from_object_path (IndicatorPowerDeviceProviderUPower * self,161update_device_from_object_path (IndicatorPowerDeviceProviderUPower * self,
150 const char * path)162 const char * path)
151{163{
152 priv_t * p = self->priv;164 priv_t * p = get_priv(self);
153 struct device_get_all_data * data;165 struct device_get_all_data * data;
154166
167 /* Symbolic composite item. Nice idea! But its composite rules
168 differ from Design's so (for now) don't use it.
169 https://wiki.ubuntu.com/Power#Handling_multiple_batteries */
170 if (!g_strcmp0(path, DISPLAY_DEVICE_PATH))
171 return;
172
155 data = g_slice_new (struct device_get_all_data);173 data = g_slice_new (struct device_get_all_data);
156 data->path = g_strdup (path);174 data->path = g_strdup (path);
157 data->self = self;175 data->self = self;
158176
159 g_dbus_connection_call (p->bus,177 g_dbus_connection_call(p->bus,
160 BUS_NAME,178 BUS_NAME,
161 path,179 path,
162 "org.freedesktop.DBus.Properties",180 "org.freedesktop.DBus.Properties",
163 "GetAll",181 "GetAll",
164 g_variant_new ("(s)", "org.freedesktop.UPower.Device"),182 g_variant_new ("(s)", "org.freedesktop.UPower.Device"),
165 G_VARIANT_TYPE("(a{sv})"),183 G_VARIANT_TYPE("(a{sv})"),
166 G_DBUS_CALL_FLAGS_NO_AUTO_START,184 G_DBUS_CALL_FLAGS_NO_AUTO_START,
167 -1, /* default timeout */185 -1, /* default timeout */
168 p->cancellable,186 p->cancellable,
169 on_device_properties_ready,187 on_get_all_response,
170 data);188 data);
171}189}
172190
173/*191/*
174 * UPower doesn't seem to be sending PropertyChanged signals.192 * UPower 0.99 added proper PropertyChanged signals, but before that
175 *193 * it MGR_IFACE emitted a DeviceChanged signal which didn't tell which
176 * Instead, it's got a DIY mechanism for notification: a DeviceChanged signal194 * property changed, so all properties had to get refreshed w/GetAll().
177 * that doesn't tell us which property changed, so to refresh we need to195 *
178 * rebuild all the properties with a GetAll() call.196 * Changes often come in bursts, so this timer tries to fold them together
179 *197 * by waiting a small bit before making calling GetAll().
180 * To make things worse, these DeviceChanged signals come fast and furious
181 * in common situations like disconnecting a power cable.
182 *
183 * This code tries to reduce bus traffic by adding a timer to wait a small bit
184 * before rebuilding our proxy's properties. This helps to fold multiple
185 * DeviceChanged events into a single rebuild.
186 */198 */
187199
188/* rebuild all the proxies listed in our queued_paths hashset */200/* rebuild all the devices listed in our queued_paths hashset */
189static gboolean201static gboolean
190on_queued_paths_timer (gpointer gself)202on_queued_paths_timer(gpointer gself)
191{203{
204 IndicatorPowerDeviceProviderUPower * self;
205 priv_t * p;
206 GHashTableIter iter;
192 gpointer path;207 gpointer path;
193 GHashTableIter iter;
194 IndicatorPowerDeviceProviderUPower * self;
195 priv_t * p;
196208
197 self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER (gself);209 self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER (gself);
198 p = self->priv;210 p = get_priv(self);
199211
200 /* create new proxies for all the queued paths */212 /* create new devices for all the queued paths */
201 g_hash_table_iter_init (&iter, p->queued_paths);213 g_hash_table_iter_init (&iter, p->queued_paths);
202 while (g_hash_table_iter_next (&iter, &path, NULL))214 while (g_hash_table_iter_next (&iter, &path, NULL))
203 update_device_from_object_path (self, path);215 update_device_from_object_path (self, path);
@@ -213,7 +225,7 @@
213refresh_device_soon (IndicatorPowerDeviceProviderUPower * self,225refresh_device_soon (IndicatorPowerDeviceProviderUPower * self,
214 const char * object_path)226 const char * object_path)
215{227{
216 priv_t * p = self->priv;228 priv_t * p = get_priv(self);
217229
218 g_hash_table_add (p->queued_paths, g_strdup (object_path));230 g_hash_table_add (p->queued_paths, g_strdup (object_path));
219231
@@ -226,155 +238,261 @@
226***/238***/
227239
228static void240static void
229on_upower_device_enumerations_ready (GObject * proxy,241on_enumerate_devices_response(GObject * bus,
230 GAsyncResult * res,242 GAsyncResult * res,
231 gpointer gself)243 gpointer gself)
232{244{
233 GError * err;245 GError* error;
234 char ** object_paths;246 GVariant* v;
235247
236 err = NULL;248 error = NULL;
237 dbus_upower_call_enumerate_devices_finish (DBUS_UPOWER(proxy),249 v = g_dbus_connection_call_finish(G_DBUS_CONNECTION(bus), res, &error);
238 &object_paths,250 if (v == NULL)
239 res,251 {
240 &err);252 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
241253 g_warning ("Unable to enumerate UPower devices: %s", error->message);
242 if (err != NULL)254 g_error_free (error);
243 {255 }
244 g_warning ("Unable to get UPower devices: %s", err->message);256 else if (g_variant_is_of_type(v, G_VARIANT_TYPE("(ao)")))
245 g_error_free (err);257 {
246 }258 GVariant * ao;
247 else259 GVariantIter iter;
248 {260 const gchar * path;
249 guint i;261
250262 ao = g_variant_get_child_value(v, 0);
251 for (i=0; object_paths && object_paths[i]; i++)263 g_variant_iter_init(&iter, ao);
252 refresh_device_soon (gself, object_paths[i]);264 path = NULL;
253265 while(g_variant_iter_loop(&iter, "o", &path))
254 g_strfreev (object_paths);266 refresh_device_soon (gself, path);
255 }267
256}268 g_variant_unref(ao);
257269 }
258static void270
259on_upower_device_changed (DbusUPower * unused G_GNUC_UNUSED,271 g_clear_pointer(&v, g_variant_unref);
260 const char * object_path,272}
261 gpointer gself)273
262{274static void
263 refresh_device_soon (gself, object_path);275on_device_properties_changed(GDBusConnection * connection G_GNUC_UNUSED,
264}276 const gchar * sender_name G_GNUC_UNUSED,
265277 const gchar * object_path,
266static void278 const gchar * interface_name G_GNUC_UNUSED,
267on_upower_device_added (DbusUPower * unused G_GNUC_UNUSED,279 const gchar * signal_name G_GNUC_UNUSED,
268 const char * object_path,280 GVariant * parameters,
269 gpointer gself)281 gpointer gself)
270{282{
271 refresh_device_soon (gself, object_path);283 IndicatorPowerDeviceProviderUPower* self;
272}284 priv_t* p;
273285 IndicatorPowerDevice* device;
274static void286
275on_upower_device_removed (DbusUPower * unused G_GNUC_UNUSED,287 self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(gself);
276 const char * object_path,288 p = get_priv(self);
277 gpointer gself)289
278{290 device = g_hash_table_lookup(p->devices, object_path);
279 IndicatorPowerDeviceProviderUPower * self;291 if (device == NULL) /* unlikely, but let's handle it */
280292 {
281 self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER (gself);293 refresh_device_soon (self, object_path);
282 g_hash_table_remove (self->priv->devices, object_path);294 }
283 g_hash_table_remove (self->priv->queued_paths, object_path);295 else if ((parameters != NULL) && g_variant_n_children(parameters)>=2)
284296 {
297 gboolean changed = FALSE;
298 GVariant* dict;
299 GVariantIter iter;
300 gchar* key;
301 GVariant* value;
302
303 dict = g_variant_get_child_value(parameters, 1);
304 g_variant_iter_init(&iter, dict);
305 while (g_variant_iter_next(&iter, "{sv}", &key, &value))
306 {
307 if (!g_strcmp0(key, "TimeToFull") || !g_strcmp0(key, "TimeToEmpty"))
308 {
309 const gint64 i = g_variant_get_int64(value);
310 if (i != 0)
311 {
312 g_object_set(device,
313 INDICATOR_POWER_DEVICE_TIME, (guint64)i,
314 NULL);
315 changed = TRUE;
316 }
317 }
318 else if (!g_strcmp0(key, "Percentage"))
319 {
320 const gdouble d = g_variant_get_double(value);
321 g_object_set(device,
322 INDICATOR_POWER_DEVICE_PERCENTAGE, d,
323 NULL);
324 changed = TRUE;
325 }
326 else if (!g_strcmp0(key, "Type"))
327 {
328 const guint32 u = g_variant_get_uint32(value);
329 g_object_set(device,
330 INDICATOR_POWER_DEVICE_KIND, (gint)u,
331 NULL);
332 changed = TRUE;
333 }
334 else if (!g_strcmp0(key, "State"))
335 {
336 const guint32 u = g_variant_get_uint32(value);
337 g_object_set(device,
338 INDICATOR_POWER_DEVICE_STATE, (gint)u,
339 NULL);
340 changed = TRUE;
341 }
342 }
343 g_variant_unref(dict);
344
345 if (changed)
346 emit_devices_changed(self);
347 }
348}
349
350static const gchar*
351get_path_from_nth_child(GVariant* parameters, gsize i)
352{
353 const gchar* path = NULL;
354
355 if ((parameters != NULL) && g_variant_n_children(parameters)>i)
356 {
357 GVariant* v = g_variant_get_child_value(parameters, i);
358 if (g_variant_is_of_type(v, G_VARIANT_TYPE_STRING) || /* UPower < 0.99 */
359 g_variant_is_of_type(v, G_VARIANT_TYPE_OBJECT_PATH)) /* and >= 0.99 */
360 {
361 path = g_variant_get_string(v, NULL);
362 }
363 g_variant_unref(v);
364 }
365
366 return path;
367}
368
369static void
370on_upower_signal(GDBusConnection * connection G_GNUC_UNUSED,
371 const gchar * sender_name G_GNUC_UNUSED,
372 const gchar * object_path G_GNUC_UNUSED,
373 const gchar * interface_name G_GNUC_UNUSED,
374 const gchar * signal_name,
375 GVariant * parameters,
376 gpointer gself)
377{
378 IndicatorPowerDeviceProviderUPower * self;
379 priv_t * p;
380
381 self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(gself);
382 p = get_priv(self);
383
384 if (!g_strcmp0(signal_name, "DeviceAdded"))
385 {
386 refresh_device_soon (self, get_path_from_nth_child(parameters, 0));
387 }
388 else if (!g_strcmp0(signal_name, "DeviceRemoved"))
389 {
390 const char* device_path = get_path_from_nth_child(parameters, 0);
391 g_hash_table_remove(p->devices, device_path);
392 g_hash_table_remove(p->queued_paths, device_path);
393 emit_devices_changed(self);
394 }
395 else if (!g_strcmp0(signal_name, "DeviceChanged")) /* UPower < 0.99 */
396 {
397 refresh_device_soon (self, get_path_from_nth_child(parameters, 0));
398 }
399 else if (!g_strcmp0(signal_name, "Resuming")) /* UPower < 0.99 */
400 {
401 GHashTableIter iter;
402 gpointer device_path = NULL;
403 g_debug("Resumed from hibernate/sleep; queueing all devices for a refresh");
404 g_hash_table_iter_init (&iter, p->devices);
405 while (g_hash_table_iter_next (&iter, &device_path, NULL))
406 refresh_device_soon (self, device_path);
407 }
408}
409
410/* start listening for UPower events on the bus */
411static void
412on_bus_name_appeared(GDBusConnection * bus,
413 const gchar * name G_GNUC_UNUSED,
414 const gchar * name_owner,
415 gpointer gself)
416{
417 IndicatorPowerDeviceProviderUPower * self;
418 priv_t * p;
419 guint tag;
420
421 self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(gself);
422 p = get_priv(self);
423 p->bus = G_DBUS_CONNECTION(g_object_ref(bus));
424
425 /* listen for signals from the boss */
426 tag = g_dbus_connection_signal_subscribe(p->bus,
427 name_owner,
428 MGR_IFACE,
429 NULL /*signal_name*/,
430 MGR_PATH,
431 NULL /*arg0*/,
432 G_DBUS_SIGNAL_FLAGS_NONE,
433 on_upower_signal,
434 self,
435 NULL);
436 p->subscriptions = g_slist_prepend(p->subscriptions, GUINT_TO_POINTER(tag));
437
438 /* listen for change events from the devices */
439 tag = g_dbus_connection_signal_subscribe(p->bus,
440 name_owner,
441 "org.freedesktop.DBus.Properties",
442 "PropertiesChanged",
443 NULL /*object_path*/,
444 "org.freedesktop.UPower.Device", /*arg0*/
445 G_DBUS_SIGNAL_FLAGS_MATCH_ARG0_NAMESPACE,
446 on_device_properties_changed,
447 self,
448 NULL);
449 p->subscriptions = g_slist_prepend(p->subscriptions, GUINT_TO_POINTER(tag));
450
451 /* rebuild our devices list */
452 g_dbus_connection_call(p->bus,
453 BUS_NAME,
454 MGR_PATH,
455 MGR_IFACE,
456 "EnumerateDevices",
457 NULL,
458 G_VARIANT_TYPE("(ao)"),
459 G_DBUS_CALL_FLAGS_NO_AUTO_START,
460 -1, /* default timeout */
461 p->cancellable,
462 on_enumerate_devices_response,
463 self);
464}
465
466static void
467on_bus_name_vanished(GDBusConnection * connection G_GNUC_UNUSED,
468 const gchar * name G_GNUC_UNUSED,
469 gpointer gself)
470{
471 IndicatorPowerDeviceProviderUPower * self;
472 priv_t * p;
473 GSList * l;
474
475 self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(gself);
476 p = get_priv(self);
477
478 /* clear the devices */
479 g_hash_table_remove_all(p->devices);
480 g_hash_table_remove_all(p->queued_paths);
481 if (p->queued_paths_timer != 0)
482 {
483 g_source_remove(p->queued_paths_timer);
484 p->queued_paths_timer = 0;
485 }
285 emit_devices_changed (self);486 emit_devices_changed (self);
286}487
287488 /* clear the bus subscriptions */
288static void489 for (l=p->subscriptions; l!=NULL; l=l->next)
289on_upower_resuming (DbusUPower * unused G_GNUC_UNUSED,490 g_dbus_connection_signal_unsubscribe(p->bus, GPOINTER_TO_UINT(l->data));
290 gpointer gself)491 g_slist_free(p->subscriptions);
291{492 p->subscriptions = NULL;
292 IndicatorPowerDeviceProviderUPower * self;493
293 GHashTableIter iter;494 /* clear the bus */
294 gpointer object_path;495 g_clear_object(&p->bus);
295
296 self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER (gself);
297
298 g_debug ("Resumed from hibernate/sleep; queueing all devices for a refresh");
299 g_hash_table_iter_init (&iter, self->priv->devices);
300 while (g_hash_table_iter_next (&iter, &object_path, NULL))
301 refresh_device_soon (self, object_path);
302}
303
304static void
305on_upower_proxy_ready (GObject * source G_GNUC_UNUSED,
306 GAsyncResult * res,
307 gpointer gself)
308{
309 GError * err;
310 DbusUPower * proxy;
311
312 err = NULL;
313 proxy = dbus_upower_proxy_new_finish (res, &err);
314 if (err != NULL)
315 {
316 g_warning ("Unable to get UPower proxy: %s", err->message);
317 g_error_free (err);
318 }
319 else
320 {
321 IndicatorPowerDeviceProviderUPower * self;
322 priv_t * p;
323
324 self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER (gself);
325 p = self->priv;
326
327 p->upower_proxy = proxy;
328 g_signal_connect (proxy, "resuming",
329 G_CALLBACK (on_upower_resuming), self);
330 g_signal_connect (proxy, "device-changed",
331 G_CALLBACK (on_upower_device_changed), self);
332 g_signal_connect (proxy, "device-added",
333 G_CALLBACK (on_upower_device_added), self);
334 g_signal_connect (proxy, "device-removed",
335 G_CALLBACK (on_upower_device_removed), self);
336
337 dbus_upower_call_enumerate_devices (p->upower_proxy,
338 p->cancellable,
339 on_upower_device_enumerations_ready,
340 self);
341 }
342}
343
344static void
345on_bus_ready (GObject * source_object G_GNUC_UNUSED,
346 GAsyncResult * res,
347 gpointer gself)
348{
349 GError * error;
350 GDBusConnection * tmp;
351
352 error = NULL;
353 tmp = g_bus_get_finish (res, &error);
354 if (error != NULL)
355 {
356 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
357 g_warning ("Error acquiring bus: %s", error->message);
358 g_error_free (error);
359 }
360 else
361 {
362 IndicatorPowerDeviceProviderUPower * self;
363 priv_t * p;
364
365 self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER (gself);
366 p = self->priv;
367
368 p->bus = tmp;
369
370 dbus_upower_proxy_new (p->bus,
371 G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
372 BUS_NAME,
373 BUS_PATH,
374 p->cancellable,
375 on_upower_proxy_ready,
376 self);
377 }
378}496}
379497
380/***498/***
@@ -382,14 +500,16 @@
382***/500***/
383501
384static GList *502static GList *
385my_get_devices (IndicatorPowerDeviceProvider * provider)503my_get_devices(IndicatorPowerDeviceProvider * provider)
386{504{
505 IndicatorPowerDeviceProviderUPower * self;
506 priv_t * p;
387 GList * devices;507 GList * devices;
388 IndicatorPowerDeviceProviderUPower * self;
389508
390 self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(provider);509 self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(provider);
510 p = get_priv(self);
391511
392 devices = g_hash_table_get_values (self->priv->devices);512 devices = g_hash_table_get_values (p->devices);
393 g_list_foreach (devices, (GFunc)g_object_ref, NULL);513 g_list_foreach (devices, (GFunc)g_object_ref, NULL);
394 return devices;514 return devices;
395}515}
@@ -405,7 +525,7 @@
405 priv_t * p;525 priv_t * p;
406526
407 self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(o);527 self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(o);
408 p = self->priv;528 p = get_priv(self);
409529
410 if (p->cancellable != NULL)530 if (p->cancellable != NULL)
411 {531 {
@@ -421,18 +541,15 @@
421 p->queued_paths_timer = 0;541 p->queued_paths_timer = 0;
422 }542 }
423543
424 if (p->upower_proxy != NULL)544 if (p->name_tag != 0)
425 {545 {
426 g_signal_handlers_disconnect_by_data (p->upower_proxy, self);546 g_bus_unwatch_name(p->name_tag);
547 on_bus_name_vanished(NULL, NULL, self);
427548
428 g_clear_object (&p->upower_proxy);549 p->name_tag = 0;
429 }550 }
430551
431 g_hash_table_remove_all (p->devices);552 G_OBJECT_CLASS (indicator_power_device_provider_upower_parent_class)->dispose(o);
432
433 g_clear_object (&p->bus);
434
435 G_OBJECT_CLASS (indicator_power_device_provider_upower_parent_class)->dispose (o);
436}553}
437554
438static void555static void
@@ -442,12 +559,12 @@
442 priv_t * p;559 priv_t * p;
443560
444 self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(o);561 self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(o);
445 p = self->priv;562 p = get_priv(self);
446563
447 g_hash_table_destroy (p->devices);564 g_hash_table_destroy (p->devices);
448 g_hash_table_destroy (p->queued_paths);565 g_hash_table_destroy (p->queued_paths);
449566
450 G_OBJECT_CLASS (indicator_power_device_provider_upower_parent_class)->dispose (o);567 G_OBJECT_CLASS (indicator_power_device_provider_upower_parent_class)->finalize (o);
451}568}
452569
453/***570/***
@@ -461,9 +578,6 @@
461578
462 object_class->dispose = my_dispose;579 object_class->dispose = my_dispose;
463 object_class->finalize = my_finalize;580 object_class->finalize = my_finalize;
464
465 g_type_class_add_private (klass,
466 sizeof (IndicatorPowerDeviceProviderUPowerPriv));
467}581}
468582
469static void583static void
@@ -475,30 +589,27 @@
475static void589static void
476indicator_power_device_provider_upower_init (IndicatorPowerDeviceProviderUPower * self)590indicator_power_device_provider_upower_init (IndicatorPowerDeviceProviderUPower * self)
477{591{
478 IndicatorPowerDeviceProviderUPowerPriv * p;592 priv_t * p = get_priv(self);
479593
480 p = G_TYPE_INSTANCE_GET_PRIVATE (self,594 p->cancellable = g_cancellable_new();
481 INDICATOR_TYPE_POWER_DEVICE_PROVIDER_UPOWER,595
482 IndicatorPowerDeviceProviderUPowerPriv);596 p->devices = g_hash_table_new_full(g_str_hash,
483597 g_str_equal,
484 self->priv = p;598 g_free,
485599 g_object_unref);
486 p->cancellable = g_cancellable_new ();600
487601 p->queued_paths = g_hash_table_new_full(g_str_hash,
488 p->devices = g_hash_table_new_full (g_str_hash,602 g_str_equal,
489 g_str_equal,603 g_free,
490 g_free,604 NULL);
491 g_object_unref);605
492606 p->name_tag = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
493 p->queued_paths = g_hash_table_new_full (g_str_hash,607 BUS_NAME,
494 g_str_equal,608 G_BUS_NAME_WATCHER_FLAGS_NONE,
495 g_free,609 on_bus_name_appeared,
496 NULL);610 on_bus_name_vanished,
497611 self,
498 g_bus_get (G_BUS_TYPE_SYSTEM,612 NULL);
499 p->cancellable,
500 on_bus_ready,
501 self);
502}613}
503614
504/***615/***
@@ -506,7 +617,7 @@
506***/617***/
507618
508IndicatorPowerDeviceProvider *619IndicatorPowerDeviceProvider *
509indicator_power_device_provider_upower_new (void)620indicator_power_device_provider_upower_new(void)
510{621{
511 gpointer o = g_object_new (INDICATOR_TYPE_POWER_DEVICE_PROVIDER_UPOWER, NULL);622 gpointer o = g_object_new (INDICATOR_TYPE_POWER_DEVICE_PROVIDER_UPOWER, NULL);
512623
513624
=== modified file 'src/device-provider-upower.h'
--- src/device-provider-upower.h 2014-07-14 04:43:41 +0000
+++ src/device-provider-upower.h 2014-09-08 21:18:20 +0000
@@ -45,8 +45,6 @@
4545
46typedef struct _IndicatorPowerDeviceProviderUPower46typedef struct _IndicatorPowerDeviceProviderUPower
47 IndicatorPowerDeviceProviderUPower;47 IndicatorPowerDeviceProviderUPower;
48typedef struct _IndicatorPowerDeviceProviderUPowerPriv
49 IndicatorPowerDeviceProviderUPowerPriv;
50typedef struct _IndicatorPowerDeviceProviderUPowerClass48typedef struct _IndicatorPowerDeviceProviderUPowerClass
51 IndicatorPowerDeviceProviderUPowerClass;49 IndicatorPowerDeviceProviderUPowerClass;
5250
@@ -56,8 +54,6 @@
56struct _IndicatorPowerDeviceProviderUPower54struct _IndicatorPowerDeviceProviderUPower
57{55{
58 GObject parent_instance;56 GObject parent_instance;
59
60 IndicatorPowerDeviceProviderUPowerPriv * priv;
61};57};
6258
63struct _IndicatorPowerDeviceProviderUPowerClass59struct _IndicatorPowerDeviceProviderUPowerClass
6460
=== removed file 'src/org.freedesktop.UPower.xml'
--- src/org.freedesktop.UPower.xml 2013-06-17 04:03:23 +0000
+++ src/org.freedesktop.UPower.xml 1970-01-01 00:00:00 +0000
@@ -1,43 +0,0 @@
1<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
2 "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
3<node>
4 <interface name="org.freedesktop.UPower">
5 <method name="HibernateAllowed">
6 <arg name="allowed" type="b" direction="out"/>
7 </method>
8 <method name="Hibernate">
9 </method>
10 <method name="SuspendAllowed">
11 <arg name="allowed" type="b" direction="out"/>
12 </method>
13 <method name="Suspend">
14 </method>
15 <method name="AboutToSleep">
16 </method>
17 <method name="EnumerateDevices">
18 <arg name="devices" type="ao" direction="out"/>
19 </method>
20 <signal name="Resuming">
21 </signal>
22 <signal name="Sleeping">
23 </signal>
24 <signal name="Changed">
25 </signal>
26 <signal name="DeviceChanged">
27 <arg type="s"/>
28 </signal>
29 <signal name="DeviceRemoved">
30 <arg type="s"/>
31 </signal>
32 <signal name="DeviceAdded">
33 <arg type="s"/>
34 </signal>
35 <property name="LidIsPresent" type="b" access="read"/>
36 <property name="LidIsClosed" type="b" access="read"/>
37 <property name="OnLowBattery" type="b" access="read"/>
38 <property name="OnBattery" type="b" access="read"/>
39 <property name="CanHibernate" type="b" access="read"/>
40 <property name="CanSuspend" type="b" access="read"/>
41 <property name="DaemonVersion" type="s" access="read"/>
42 </interface>
43</node>
44\ No newline at end of file0\ No newline at end of file
451
=== modified file 'tests/glib-fixture.h'
--- tests/glib-fixture.h 2014-07-24 21:25:32 +0000
+++ tests/glib-fixture.h 2014-09-08 21:18:20 +0000
@@ -64,7 +64,7 @@
64 const gchar * message,64 const gchar * message,
65 gpointer self)65 gpointer self)
66 {66 {
67 auto tmp = g_strdup_printf ("%s:%d \"%s\"", log_domain, (int)log_level, message);67 auto tmp = g_strdup_printf ("%s:%d \"%s\"", log_domain, int(log_level), message);
68 static_cast<GlibFixture*>(self)->log[log_level].push_back(tmp);68 static_cast<GlibFixture*>(self)->log[log_level].push_back(tmp);
69 g_free(tmp);69 g_free(tmp);
70 }70 }
@@ -101,7 +101,7 @@
101 static gboolean101 static gboolean
102 wait_for_signal__timeout(gpointer name)102 wait_for_signal__timeout(gpointer name)
103 {103 {
104 g_error("%s: timed out waiting for signal '%s'", G_STRLOC, (char*)name);104 g_error("%s: timed out waiting for signal '%s'", G_STRLOC, static_cast<char*>(name));
105 return G_SOURCE_REMOVE;105 return G_SOURCE_REMOVE;
106 }106 }
107107
108108
=== modified file 'tests/indicator-power-service-cmdline-battery.cc'
--- tests/indicator-power-service-cmdline-battery.cc 2014-07-22 14:58:29 +0000
+++ tests/indicator-power-service-cmdline-battery.cc 2014-09-08 21:18:20 +0000
@@ -37,7 +37,7 @@
37on_name_lost (gpointer instance G_GNUC_UNUSED, gpointer loop)37on_name_lost (gpointer instance G_GNUC_UNUSED, gpointer loop)
38{38{
39 g_message ("exiting: service couldn't acquire or lost ownership of busname");39 g_message ("exiting: service couldn't acquire or lost ownership of busname");
40 g_main_loop_quit ((GMainLoop*)loop);40 g_main_loop_quit (static_cast<GMainLoop*>(loop));
41}41}
4242
43static IndicatorPowerDevice * battery = nullptr;43static IndicatorPowerDevice * battery = nullptr;
4444
=== modified file 'tests/test-device.cc'
--- tests/test-device.cc 2014-07-29 15:05:20 +0000
+++ tests/test-device.cc 2014-09-08 21:18:20 +0000
@@ -172,11 +172,11 @@
172 key = INDICATOR_POWER_DEVICE_PERCENTAGE;172 key = INDICATOR_POWER_DEVICE_PERCENTAGE;
173 g_object_set (o, key, 50.0, NULL);173 g_object_set (o, key, 50.0, NULL);
174 g_object_get (o, key, &d, NULL);174 g_object_get (o, key, &d, NULL);
175 ASSERT_EQ((int)d, 50);175 ASSERT_EQ(int(d), 50);
176176
177 // TIME177 // TIME
178 key = INDICATOR_POWER_DEVICE_TIME;178 key = INDICATOR_POWER_DEVICE_TIME;
179 g_object_set (o, key, (guint64)30, NULL);179 g_object_set (o, key, guint64(30), NULL);
180 g_object_get (o, key, &u64, NULL);180 g_object_get (o, key, &u64, NULL);
181 ASSERT_EQ(u64, 30);181 ASSERT_EQ(u64, 30);
182182
@@ -193,11 +193,11 @@
193 30);193 30);
194 ASSERT_TRUE (device != NULL);194 ASSERT_TRUE (device != NULL);
195 ASSERT_TRUE (INDICATOR_IS_POWER_DEVICE(device));195 ASSERT_TRUE (INDICATOR_IS_POWER_DEVICE(device));
196 ASSERT_EQ (indicator_power_device_get_kind(device), UP_DEVICE_KIND_BATTERY);196 ASSERT_EQ (UP_DEVICE_KIND_BATTERY, indicator_power_device_get_kind(device));
197 ASSERT_EQ (indicator_power_device_get_state(device), UP_DEVICE_STATE_CHARGING);197 ASSERT_EQ (UP_DEVICE_STATE_CHARGING, indicator_power_device_get_state(device));
198 ASSERT_STREQ (indicator_power_device_get_object_path(device), "/object/path");198 ASSERT_STREQ ("/object/path", indicator_power_device_get_object_path(device));
199 ASSERT_EQ ((int)indicator_power_device_get_percentage(device), 50);199 ASSERT_EQ (50, int(indicator_power_device_get_percentage(device)));
200 ASSERT_EQ (indicator_power_device_get_time(device), 30);200 ASSERT_EQ (30, indicator_power_device_get_time(device));
201201
202 // cleanup202 // cleanup
203 g_object_unref (device);203 g_object_unref (device);
@@ -205,22 +205,22 @@
205205
206TEST_F(DeviceTest, NewFromVariant)206TEST_F(DeviceTest, NewFromVariant)
207{207{
208 GVariant * variant = g_variant_new ("(susdut)",208 auto variant = g_variant_new("(susdut)",
209 "/object/path",209 "/object/path",
210 (guint32) UP_DEVICE_KIND_BATTERY,210 guint32(UP_DEVICE_KIND_BATTERY),
211 "icon",211 "icon",
212 (gdouble) 50.0,212 50.0,
213 (guint32) UP_DEVICE_STATE_CHARGING,213 guint32(UP_DEVICE_STATE_CHARGING),
214 (guint64) 30);214 guint64(30));
215 IndicatorPowerDevice * device = indicator_power_device_new_from_variant (variant);215 IndicatorPowerDevice * device = indicator_power_device_new_from_variant (variant);
216 ASSERT_TRUE (variant != NULL);216 ASSERT_TRUE (variant != NULL);
217 ASSERT_TRUE (device != NULL);217 ASSERT_TRUE (device != NULL);
218 ASSERT_TRUE (INDICATOR_IS_POWER_DEVICE(device));218 ASSERT_TRUE (INDICATOR_IS_POWER_DEVICE(device));
219 ASSERT_EQ (indicator_power_device_get_kind(device), UP_DEVICE_KIND_BATTERY);219 ASSERT_EQ (UP_DEVICE_KIND_BATTERY, indicator_power_device_get_kind(device));
220 ASSERT_EQ (indicator_power_device_get_state(device), UP_DEVICE_STATE_CHARGING);220 ASSERT_EQ (UP_DEVICE_STATE_CHARGING, indicator_power_device_get_state(device));
221 ASSERT_STREQ (indicator_power_device_get_object_path(device), "/object/path");221 ASSERT_STREQ ("/object/path", indicator_power_device_get_object_path(device));
222 ASSERT_EQ ((int)indicator_power_device_get_percentage(device), 50);222 ASSERT_EQ (50, int(indicator_power_device_get_percentage(device)));
223 ASSERT_EQ (indicator_power_device_get_time(device), 30);223 ASSERT_EQ (30, indicator_power_device_get_time(device));
224224
225 // cleanup225 // cleanup
226 g_object_unref (device);226 g_object_unref (device);
@@ -407,7 +407,7 @@
407 g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind,407 g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind,
408 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING,408 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING,
409 INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0,409 INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0,
410 INDICATOR_POWER_DEVICE_TIME, (guint64)(60*60),410 INDICATOR_POWER_DEVICE_TIME, guint64(60*60),
411 NULL);411 NULL);
412 g_string_append_printf (expected, "%s-060;", kind_str);412 g_string_append_printf (expected, "%s-060;", kind_str);
413 g_string_append_printf (expected, "gpm-%s-060;", kind_str);413 g_string_append_printf (expected, "gpm-%s-060;", kind_str);
@@ -420,7 +420,7 @@
420 g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind,420 g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind,
421 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING,421 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING,
422 INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0,422 INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0,
423 INDICATOR_POWER_DEVICE_TIME, (guint64)(60*60),423 INDICATOR_POWER_DEVICE_TIME, guint64(60*60),
424 NULL);424 NULL);
425 g_string_append_printf (expected, "%s-020;", kind_str);425 g_string_append_printf (expected, "%s-020;", kind_str);
426 g_string_append_printf (expected, "gpm-%s-020;", kind_str);426 g_string_append_printf (expected, "gpm-%s-020;", kind_str);
@@ -433,7 +433,7 @@
433 g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind,433 g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind,
434 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING,434 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING,
435 INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0,435 INDICATOR_POWER_DEVICE_PERCENTAGE, 25.0,
436 INDICATOR_POWER_DEVICE_TIME, (guint64)(60*15),436 INDICATOR_POWER_DEVICE_TIME, guint64(60*15),
437 NULL);437 NULL);
438 g_string_append_printf (expected, "%s-020;", kind_str);438 g_string_append_printf (expected, "%s-020;", kind_str);
439 g_string_append_printf (expected, "gpm-%s-020;", kind_str);439 g_string_append_printf (expected, "gpm-%s-020;", kind_str);
@@ -446,7 +446,7 @@
446 g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind,446 g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind,
447 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING,447 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING,
448 INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0,448 INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0,
449 INDICATOR_POWER_DEVICE_TIME, (guint64)(60*60),449 INDICATOR_POWER_DEVICE_TIME, guint64(60*60),
450 NULL);450 NULL);
451 g_string_append_printf (expected, "%s-000;", kind_str);451 g_string_append_printf (expected, "%s-000;", kind_str);
452 g_string_append_printf (expected, "gpm-%s-000;", kind_str);452 g_string_append_printf (expected, "gpm-%s-000;", kind_str);
@@ -459,7 +459,7 @@
459 g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind,459 g_object_set (o, INDICATOR_POWER_DEVICE_KIND, kind,
460 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING,460 INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING,
461 INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0,461 INDICATOR_POWER_DEVICE_PERCENTAGE, 5.0,
462 INDICATOR_POWER_DEVICE_TIME, (guint64)(60*15),462 INDICATOR_POWER_DEVICE_TIME, guint64(60*15),
463 NULL);463 NULL);
464 g_string_append_printf (expected, "%s-000;", kind_str);464 g_string_append_printf (expected, "%s-000;", kind_str);
465 g_string_append_printf (expected, "gpm-%s-000;", kind_str);465 g_string_append_printf (expected, "gpm-%s-000;", kind_str);
@@ -495,12 +495,12 @@
495 log_count_ipower_expected++;495 log_count_ipower_expected++;
496 check_label (NULL, NULL);496 check_label (NULL, NULL);
497 log_count_ipower_expected += 5;497 log_count_ipower_expected += 5;
498 check_header (NULL, NULL, NULL, NULL, NULL);498 check_header (nullptr, nullptr, nullptr, nullptr, nullptr);
499499
500 // bad args: a GObject that isn't a device500 // bad args: a GObject that isn't a device
501 GObject * o = G_OBJECT(g_cancellable_new());501 GObject * o = G_OBJECT(g_cancellable_new());
502 log_count_ipower_expected++;502 log_count_ipower_expected++;
503 check_label ((IndicatorPowerDevice*)o, NULL);503 check_label (INDICATOR_POWER_DEVICE(o), nullptr);
504 log_count_ipower_expected += 5;504 log_count_ipower_expected += 5;
505 check_header (NULL, NULL, NULL, NULL, NULL);505 check_header (NULL, NULL, NULL, NULL, NULL);
506 g_object_unref (o);506 g_object_unref (o);
@@ -710,7 +710,7 @@
710710
711 std::vector<IndicatorPowerDevice*> devices;711 std::vector<IndicatorPowerDevice*> devices;
712 for(const auto& desc : descriptions)712 for(const auto& desc : descriptions)
713 devices.push_back(indicator_power_device_new(desc.path, desc.kind, desc.percentage, desc.state, (time_t)desc.time));713 devices.push_back(indicator_power_device_new(desc.path, desc.kind, desc.percentage, desc.state, time_t(desc.time)));
714714
715 const struct {715 const struct {
716 std::vector<unsigned int> device_indices;716 std::vector<unsigned int> device_indices;
@@ -756,7 +756,7 @@
756 EXPECT_EQ(x.kind, indicator_power_device_get_kind(primary));756 EXPECT_EQ(x.kind, indicator_power_device_get_kind(primary));
757 EXPECT_EQ(x.state, indicator_power_device_get_state(primary));757 EXPECT_EQ(x.state, indicator_power_device_get_state(primary));
758 EXPECT_EQ(x.time, indicator_power_device_get_time(primary));758 EXPECT_EQ(x.time, indicator_power_device_get_time(primary));
759 EXPECT_EQ((int)ceil(x.percentage), (int)ceil(indicator_power_device_get_percentage(primary)));759 EXPECT_EQ(int(ceil(x.percentage)), int(ceil(indicator_power_device_get_percentage(primary))));
760 g_object_unref(primary);760 g_object_unref(primary);
761761
762 // reverse the list and repeat the test762 // reverse the list and repeat the test
@@ -767,7 +767,7 @@
767 EXPECT_EQ(x.kind, indicator_power_device_get_kind(primary));767 EXPECT_EQ(x.kind, indicator_power_device_get_kind(primary));
768 EXPECT_EQ(x.state, indicator_power_device_get_state(primary));768 EXPECT_EQ(x.state, indicator_power_device_get_state(primary));
769 EXPECT_EQ(x.time, indicator_power_device_get_time(primary));769 EXPECT_EQ(x.time, indicator_power_device_get_time(primary));
770 EXPECT_EQ((int)ceil(x.percentage), (int)ceil(indicator_power_device_get_percentage(primary)));770 EXPECT_EQ(int(ceil(x.percentage)), int(ceil(indicator_power_device_get_percentage(primary))));
771 g_object_unref(primary);771 g_object_unref(primary);
772772
773 // cleanup773 // cleanup
774774
=== modified file 'tests/test-notify.cc'
--- tests/test-notify.cc 2014-07-25 04:31:11 +0000
+++ tests/test-notify.cc 2014-09-08 21:18:20 +0000
@@ -131,7 +131,7 @@
131131
132 bus = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr);132 bus = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr);
133 g_dbus_connection_set_exit_on_close(bus, FALSE);133 g_dbus_connection_set_exit_on_close(bus, FALSE);
134 g_object_add_weak_pointer(G_OBJECT(bus), (gpointer *)&bus);134 g_object_add_weak_pointer(G_OBJECT(bus), reinterpret_cast<gpointer*>(&bus));
135135
136 notify_init(APP_NAME);136 notify_init(APP_NAME);
137 }137 }

Subscribers

People subscribed via source and target branches