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
This commit is contained in:
Bastien Nocera 2017-08-31 15:58:59 +02:00
parent 320cc87811
commit 623a6bfc57

View file

@ -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)