From 623a6bfc57c3d3ea52d671079947a10cb3150999 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 31 Aug 2017 15:58:59 +0200 Subject: [PATCH] linux: Move function to prepare for new use Move up_device_supply_get_sibling_with_subsystem() so we can use it in up_device_supply_refresh_device() https://bugs.freedesktop.org/show_bug.cgi?id=102493 --- src/linux/up-device-supply.c | 90 ++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/src/linux/up-device-supply.c b/src/linux/up-device-supply.c index 15987b8..1e2bfb6 100644 --- a/src/linux/up-device-supply.c +++ b/src/linux/up-device-supply.c @@ -848,6 +848,51 @@ out: return ret; } +static GUdevDevice * +up_device_supply_get_sibling_with_subsystem (GUdevDevice *device, + const char *subsystem) +{ + GUdevDevice *parent; + GUdevClient *client; + GUdevDevice *sibling; + const char * class[] = { NULL, NULL }; + const char *parent_path; + GList *devices, *l; + + g_return_val_if_fail (device != NULL, NULL); + g_return_val_if_fail (subsystem != NULL, NULL); + + parent = g_udev_device_get_parent (device); + if (!parent) + return NULL; + parent_path = g_udev_device_get_sysfs_path (parent); + + sibling = NULL; + class[0] = subsystem; + client = g_udev_client_new (class); + devices = g_udev_client_query_by_subsystem (client, subsystem); + for (l = devices; l != NULL && sibling == NULL; l = l->next) { + GUdevDevice *d = l->data; + GUdevDevice *p; + const char *p_path; + + p = g_udev_device_get_parent (d); + if (!p) + continue; + p_path = g_udev_device_get_sysfs_path (p); + if (g_strcmp0 (p_path, parent_path) == 0) + sibling = g_object_ref (d); + + g_object_unref (p); + } + + g_list_free_full (devices, (GDestroyNotify) g_object_unref); + g_object_unref (client); + g_object_unref (parent); + + return sibling; +} + /** * up_device_supply_refresh_device: * @@ -948,51 +993,6 @@ up_device_supply_poll_unknown_battery (UpDevice *device) return FALSE; } -static GUdevDevice * -up_device_supply_get_sibling_with_subsystem (GUdevDevice *device, - const char *subsystem) -{ - GUdevDevice *parent; - GUdevClient *client; - GUdevDevice *sibling; - const char * class[] = { NULL, NULL }; - const char *parent_path; - GList *devices, *l; - - g_return_val_if_fail (device != NULL, NULL); - g_return_val_if_fail (subsystem != NULL, NULL); - - parent = g_udev_device_get_parent (device); - if (!parent) - return NULL; - parent_path = g_udev_device_get_sysfs_path (parent); - - sibling = NULL; - class[0] = subsystem; - client = g_udev_client_new (class); - devices = g_udev_client_query_by_subsystem (client, subsystem); - for (l = devices; l != NULL && sibling == NULL; l = l->next) { - GUdevDevice *d = l->data; - GUdevDevice *p; - const char *p_path; - - p = g_udev_device_get_parent (d); - if (!p) - continue; - p_path = g_udev_device_get_sysfs_path (p); - if (g_strcmp0 (p_path, parent_path) == 0) - sibling = g_object_ref (d); - - g_object_unref (p); - } - - g_list_free_full (devices, (GDestroyNotify) g_object_unref); - g_object_unref (client); - g_object_unref (parent); - - return sibling; -} - static UpDeviceKind up_device_supply_guess_type (GUdevDevice *native, const char *native_path) -- 2.14.1