diff options
author | Martin Pitt <martin.pitt@ubuntu.com> | 2016-05-18 09:22:43 +0200 |
---|---|---|
committer | Martin Pitt <martin.pitt@ubuntu.com> | 2016-05-18 14:58:28 +0200 |
commit | 932a6a39e35754be571e1274aec4730fd42dba13 (patch) | |
tree | 90484519ac9ef6fce5ca437c24cd19a8b62eccb3 /libupower-glib/up-client.h | |
parent | 28cee8e2845b094488c337c4ecfa84ada0b6be60 (diff) | |
download | upower-932a6a39e35754be571e1274aec4730fd42dba13.tar.gz |
lib: Add proper error and cancellable handling to UpClient constructor
A GObject's _init() should never fail or block, but this is currently the case
as up_client_init() connects to upowerd on D-Bus. Convert this to the GInitable
interface and provide a new constructor up_client_new_full() which accepts a
GCancellable and GError, so that clients can do proper error handling
and reporting.
This changes up_client_new() to return NULL when connecting to upowerd fails.
This provides a more well-defined behaviour in this case as clients can check
for this and our methods stop segfaulting as they have checks like
g_return_val_if_fail (UP_IS_CLIENT (client), ...)
Previously we returned a valid object, but trying to call any method on it
segfaulted due to the NULL D-Bus proxy, so client code had no chance to check
whether the UpClient object was really valid.
https://bugs.freedesktop.org/show_bug.cgi?id=95350
Diffstat (limited to 'libupower-glib/up-client.h')
-rw-r--r-- | libupower-glib/up-client.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/libupower-glib/up-client.h b/libupower-glib/up-client.h index 79c2d9e..5b9af3c 100644 --- a/libupower-glib/up-client.h +++ b/libupower-glib/up-client.h @@ -72,6 +72,7 @@ typedef struct /* general */ GType up_client_get_type (void); UpClient *up_client_new (void); +UpClient *up_client_new_full (GCancellable *cancellable, GError **error); /* sync versions */ UpDevice * up_client_get_display_device (UpClient *client); |