mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-05-09 09:28:10 +02:00
lib: Add internal helper for up_client_get_devices2()
Making sure to pass GCancellable and GError arguments.
This commit is contained in:
parent
8f893964a2
commit
74aefb0fd7
1 changed files with 45 additions and 33 deletions
|
|
@ -98,6 +98,44 @@ up_client_get_devices (UpClient *client)
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GPtrArray *
|
||||||
|
up_client_get_devices_full (UpClient *client,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
g_auto(GStrv) devices = NULL;
|
||||||
|
GPtrArray *array;
|
||||||
|
guint i;
|
||||||
|
|
||||||
|
g_return_val_if_fail (UP_IS_CLIENT (client), NULL);
|
||||||
|
|
||||||
|
if (up_exported_daemon_call_enumerate_devices_sync (client->priv->proxy,
|
||||||
|
&devices,
|
||||||
|
cancellable,
|
||||||
|
error) == FALSE) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
|
||||||
|
|
||||||
|
for (i = 0; devices[i] != NULL; i++) {
|
||||||
|
UpDevice *device;
|
||||||
|
const char *object_path = ((char **)devices)[i];
|
||||||
|
gboolean ret;
|
||||||
|
|
||||||
|
device = up_device_new ();
|
||||||
|
ret = up_device_set_object_path_sync (device, object_path, cancellable, NULL);
|
||||||
|
if (!ret) {
|
||||||
|
g_object_unref (device);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_ptr_array_add (array, device);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* up_client_get_devices2:
|
* up_client_get_devices2:
|
||||||
* @client: a #UpClient instance.
|
* @client: a #UpClient instance.
|
||||||
|
|
@ -111,43 +149,17 @@ up_client_get_devices (UpClient *client)
|
||||||
GPtrArray *
|
GPtrArray *
|
||||||
up_client_get_devices2 (UpClient *client)
|
up_client_get_devices2 (UpClient *client)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
char **devices;
|
GPtrArray *ret = NULL;
|
||||||
GPtrArray *array;
|
|
||||||
guint i;
|
|
||||||
|
|
||||||
g_return_val_if_fail (UP_IS_CLIENT (client), NULL);
|
ret = up_client_get_devices_full (client, NULL, &error);
|
||||||
|
if (!ret) {
|
||||||
if (up_exported_daemon_call_enumerate_devices_sync (client->priv->proxy,
|
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||||
&devices,
|
g_warning ("up_client_get_devices failed: %s", error->message);
|
||||||
NULL,
|
|
||||||
&error) == FALSE) {
|
|
||||||
g_warning ("up_client_get_devices failed: %s", error->message);
|
|
||||||
g_error_free (error);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
|
|
||||||
|
|
||||||
for (i = 0; devices[i] != NULL; i++) {
|
|
||||||
UpDevice *device;
|
|
||||||
const char *object_path = devices[i];
|
|
||||||
gboolean ret;
|
|
||||||
|
|
||||||
device = up_device_new ();
|
|
||||||
ret = up_device_set_object_path_sync (device, object_path, NULL, NULL);
|
|
||||||
if (!ret) {
|
|
||||||
g_object_unref (device);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_ptr_array_add (array, device);
|
|
||||||
}
|
|
||||||
g_strfreev (devices);
|
|
||||||
|
|
||||||
return array;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* up_client_get_display_device:
|
* up_client_get_display_device:
|
||||||
* @client: a #UpClient instance.
|
* @client: a #UpClient instance.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue