Commit d8233bd9 authored by Christian Kellner's avatar Christian Kellner

client: find a device by uid or name

Will obtain a list of all available devices and then return the
first one that this matching either the uid or the name of the
device.
parent 4de69c79
......@@ -550,6 +550,31 @@ bolt_client_get_device (BoltClient *client,
return dev;
}
BoltDevice *
bolt_client_find_device (BoltClient *client,
const char *name,
GError **error)
{
g_autoptr(GPtrArray) devices = NULL;
devices = bolt_client_list_devices (client, NULL, error);
if (devices == NULL)
return NULL;
for (guint i = 0; i < devices->len; i++)
{
BoltDevice *dev = g_ptr_array_index (devices, i);
if (bolt_streq (name, bolt_device_get_uid (dev)) ||
bolt_streq (name, bolt_device_get_name (dev)))
return g_object_ref (dev);
}
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
"could not find device matching '%s'", name);
return NULL;
}
BoltDevice *
bolt_client_enroll_device (BoltClient *client,
const char *uid,
......
......@@ -61,6 +61,10 @@ BoltDevice * bolt_client_get_device (BoltClient *client,
GCancellable *cancellable,
GError **error);
BoltDevice * bolt_client_find_device (BoltClient *client,
const char *name,
GError **error);
BoltDevice * bolt_client_enroll_device (BoltClient *client,
const char *uid,
BoltPolicy policy,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment