diff options
author | Bastien Nocera <hadess@hadess.net> | 2019-10-23 17:18:56 +0200 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2019-10-23 17:18:56 +0200 |
commit | 90d45301427e3318e05bfa69f387aeeee819b1fb (patch) | |
tree | 20a00ac9d1b4c515ff23248395e6456a0deda430 | |
parent | 78426641dfb867ec243b1ae5c0100dca02478021 (diff) | |
download | upower-wip/hadess/upower-session.tar.gz |
lib: Split out connecting to a UPower daemonwip/hadess/upower-session
-rw-r--r-- | libupower-glib/up-client.c | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/libupower-glib/up-client.c b/libupower-glib/up-client.c index 9547634..19a121e 100644 --- a/libupower-glib/up-client.c +++ b/libupower-glib/up-client.c @@ -524,6 +524,35 @@ up_client_class_init (UpClientClass *klass) G_TYPE_NONE, 1, G_TYPE_STRING); } +static void +connect_to_one_daemon (GBusType bus_type, + const char *name, + const char *object_path, + GCancellable *cancellable, + GError **error) +{ + GDBusProxy *proxy; + + proxy = up_exported_daemon_proxy_new_for_bus_sync (bus_type, + G_DBUS_PROXY_FLAGS_NONE, + name, + object_path, + cancellable, + error); + if (proxy == NULL) + return NULL; + + /* all callbacks */ + g_signal_connect (proxy, "device-added", + G_CALLBACK (up_device_added_cb), client); + g_signal_connect (proxy, "device-removed", + G_CALLBACK (up_device_removed_cb), client); + g_signal_connect (proxy, "notify", + G_CALLBACK (up_client_notify_cb), client); + + return proxy; +} + static gboolean up_client_initable_init (GInitable *initable, GCancellable *cancellable, GError **error) { @@ -536,23 +565,14 @@ up_client_initable_init (GInitable *initable, GCancellable *cancellable, GError } /* connect to main interface */ - client->priv->proxy = up_exported_daemon_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - "org.freedesktop.UPower", - "/org/freedesktop/UPower", - cancellable, - error); - if (client->priv->proxy == NULL) + client->priv->proxy = connect_to_one_daemon (G_BUS_TYPE_SYSTEM, + "org.freedesktop.UPower", + "/org/freedesktop/UPower", + cancellable, + error); + if (!client->priv->proxy) return FALSE; - /* all callbacks */ - g_signal_connect (client->priv->proxy, "device-added", - G_CALLBACK (up_device_added_cb), client); - g_signal_connect (client->priv->proxy, "device-removed", - G_CALLBACK (up_device_removed_cb), client); - g_signal_connect (client->priv->proxy, "notify", - G_CALLBACK (up_client_notify_cb), client); - return TRUE; } |