summaryrefslogtreecommitdiff
path: root/libupower-glib
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2022-01-23 22:48:17 +0100
committerBastien Nocera <hadess@hadess.net>2022-01-23 23:26:33 +0100
commit1fdc0824b6f4470a97cc980b5d70144071dc3dba (patch)
treeb8e31e556dc203c4da62cab9887ff2e57384020a /libupower-glib
parent95618dfad441bab442049475fd6d53470ddada60 (diff)
downloadupower-1fdc0824b6f4470a97cc980b5d70144071dc3dba.tar.gz
lib: Implement up_client_get_devices_async()
Diffstat (limited to 'libupower-glib')
-rw-r--r--libupower-glib/up-client.c65
-rw-r--r--libupower-glib/up-client.h7
2 files changed, 72 insertions, 0 deletions
diff --git a/libupower-glib/up-client.c b/libupower-glib/up-client.c
index 8dc3a22..93d3507 100644
--- a/libupower-glib/up-client.c
+++ b/libupower-glib/up-client.c
@@ -160,6 +160,71 @@ up_client_get_devices2 (UpClient *client)
}
return ret;
}
+
+static void
+get_devices_async_thread (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable)
+{
+ GError *error = NULL;
+ GPtrArray *array;
+
+ array = up_client_get_devices_full (UP_CLIENT (source_object), cancellable, &error);
+ if (!array)
+ g_task_return_error (task, error);
+ else
+ g_task_return_pointer (task, array, (GDestroyNotify) g_ptr_array_unref);
+}
+
+/**
+ * up_client_get_devices_async:
+ * @client: a #UpClient instance.
+ * @cancellable: (nullable): a #GCancellable or %NULL
+ * @callback: a #GAsyncReadyCallback to call when the request is satisfied
+ * @user_data: the data to pass to @callback
+ *
+ * Asynchronously fetches the list of #UpDevice objects.
+ *
+ * Since: 0.99.14
+ **/
+void
+up_client_get_devices_async (UpClient *client,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GTask *task;
+
+ task = g_task_new (client, cancellable, callback, user_data);
+ g_task_set_source_tag (task, (gpointer) G_STRFUNC);
+
+ g_task_run_in_thread (task, get_devices_async_thread);
+}
+
+/**
+ * up_client_get_devices_finish:
+ * @client: a #UpClient instance.
+ * @res: a #GAsyncResult obtained from the #GAsyncReadyCallback passed
+ * to up_client_get_devices_async()
+ *
+ * Finishes an operation started with up_client_get_devices_async().
+ *
+ * Return value: (element-type UpDevice) (transfer full): an array of
+ * #UpDevice objects or %NULL on error.
+ **/
+GPtrArray *
+up_client_get_devices_finish (UpClient *client,
+ GAsyncResult *res,
+ GError **error)
+{
+ g_return_val_if_fail (UP_IS_CLIENT (client), NULL);
+ g_return_val_if_fail (g_task_is_valid (res, client), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ return g_task_propagate_pointer (G_TASK (res), error);
+}
+
/**
* up_client_get_display_device:
* @client: a #UpClient instance.
diff --git a/libupower-glib/up-client.h b/libupower-glib/up-client.h
index bd149cd..da6a5d4 100644
--- a/libupower-glib/up-client.h
+++ b/libupower-glib/up-client.h
@@ -86,6 +86,13 @@ char * up_client_get_critical_action (UpClient *client);
/* accessors */
GPtrArray *up_client_get_devices (UpClient *client) G_DEPRECATED_FOR(up_client_get_devices2);
GPtrArray *up_client_get_devices2 (UpClient *client);
+void up_client_get_devices_async (UpClient *client,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+GPtrArray *up_client_get_devices_finish (UpClient *client,
+ GAsyncResult *res,
+ GError **error);
const gchar *up_client_get_daemon_version (UpClient *client);
G_DEPRECATED
gboolean up_client_get_lid_is_closed (UpClient *client);