Add a fu_udev_device_get_children_with_subsystem function

This works like fu_udev_device_get_siblings_with_subsystem but returns child
devices of self rather than siblings.
This commit is contained in:
Peter Marheine 2021-04-19 15:32:22 +10:00 committed by Richard Hughes
parent 6ff0ae2bc4
commit 6281467a6b
3 changed files with 45 additions and 0 deletions

View File

@ -1781,6 +1781,48 @@ fu_udev_device_get_siblings_with_subsystem (FuUdevDevice *self,
return g_steal_pointer(&out);
}
/**
* fu_udev_device_get_children_with_subsystem
* @self: a #FuUdevDevice
* @subsystem: the name of a udev subsystem
*
* Get a list of devices that are children of self and have the
* provided subsystem.
*
* Returns (element-type FuUdevDevice) (transfer full): devices
*
* Since: 1.6.2
*/
GPtrArray *
fu_udev_device_get_children_with_subsystem (FuUdevDevice *self,
const gchar *const subsystem)
{
g_autoptr(GPtrArray) out = g_ptr_array_new_with_free_func (g_object_unref);
#ifdef HAVE_GUDEV
const gchar *self_path = fu_udev_device_get_sysfs_path (self);
g_autoptr(GUdevClient) udev_client = g_udev_client_new (NULL);
g_autoptr(GList) enumerated = g_udev_client_query_by_subsystem (udev_client, subsystem);
for (GList *element = enumerated; element != NULL; element = element->next) {
g_autoptr(GUdevDevice) enumerated_device = element->data;
g_autoptr(GUdevDevice) enumerated_parent =
g_udev_device_get_parent (enumerated_device);
const gchar *enumerated_parent_path =
g_udev_device_get_sysfs_path (enumerated_parent);
/* enumerated device is a child of self if its parent is the
* same as self */
if (g_strcmp0 (self_path, enumerated_parent_path) == 0) {
g_ptr_array_add (out,
fu_udev_device_new (g_steal_pointer (&enumerated_device)));
}
}
#endif
return g_steal_pointer (&out);
}
static void
fu_udev_device_get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)

View File

@ -122,3 +122,5 @@ gboolean fu_udev_device_write_sysfs (FuUdevDevice *self,
const gchar *fu_udev_device_get_devtype (FuUdevDevice *self);
GPtrArray *fu_udev_device_get_siblings_with_subsystem (FuUdevDevice *self,
const gchar *subsystem);
GPtrArray *fu_udev_device_get_children_with_subsystem (FuUdevDevice *self,
const gchar *subsystem);

View File

@ -831,6 +831,7 @@ LIBFWUPDPLUGIN_1.6.2 {
fu_i2c_device_read_full;
fu_i2c_device_set_bus_number;
fu_i2c_device_write_full;
fu_udev_device_get_children_with_subsystem;
fu_udev_device_set_dev;
local: *;
} LIBFWUPDPLUGIN_1.6.1;