diff options
author | Richard Hughes <richard@hughsie.com> | 2015-01-05 20:23:48 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2015-01-05 20:24:52 +0000 |
commit | 229c9b0322a88245cad966aa527458e291bae8d2 (patch) | |
tree | 0a1b8ab385a8cb286486686302760e4b5641b9a5 | |
parent | aad3c3c60ca93f313198c8ee41ebe488dcf23179 (diff) | |
download | gusb-229c9b0322a88245cad966aa527458e291bae8d2.tar.gz |
Add g_usb_device_get_children()
This is slow, but it's not expected to be called 1000's of times.
-rw-r--r-- | gusb/gusb-device.c | 29 | ||||
-rw-r--r-- | gusb/gusb-device.h | 1 |
2 files changed, 30 insertions, 0 deletions
diff --git a/gusb/gusb-device.c b/gusb/gusb-device.c index aa1fd36..5ddf687 100644 --- a/gusb/gusb-device.c +++ b/gusb/gusb-device.c @@ -33,6 +33,7 @@ #include <libusb-1.0/libusb.h> +#include "gusb-cleanup.h" #include "gusb-context.h" #include "gusb-context-private.h" #include "gusb-util.h" @@ -93,6 +94,34 @@ g_usb_device_get_parent (GUsbDevice *device) } /** + * g_usb_device_get_children: + * @device: a #GUsbDevice instance + * + * Gets the device children if any exist. + * + * Return value: (transfer full): an array of #GUsbDevice + **/ +GPtrArray * +g_usb_device_get_children (GUsbDevice *device) +{ + GPtrArray *children; + GUsbDevice *device_tmp; + GUsbDevicePrivate *priv = device->priv; + guint i; + _cleanup_ptrarray_unref_ GPtrArray *devices = NULL; + + /* find any devices that have @device as a parent */ + children = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); + devices = g_usb_context_get_devices (priv->context); + for (i = 0; i < devices->len; i++) { + device_tmp = g_ptr_array_index (devices, i); + if (priv->device == libusb_get_parent (device_tmp->priv->device)) + g_ptr_array_add (children, g_object_ref (device_tmp)); + } + return children; +} + +/** * g_usb_device_error_quark: * * Return value: Our personal error quark. diff --git a/gusb/gusb-device.h b/gusb/gusb-device.h index 7ac3377..dc1c368 100644 --- a/gusb/gusb-device.h +++ b/gusb/gusb-device.h @@ -122,6 +122,7 @@ GQuark g_usb_device_error_quark (void); const gchar *g_usb_device_get_platform_id (GUsbDevice *device); GUsbDevice *g_usb_device_get_parent (GUsbDevice *device); +GPtrArray *g_usb_device_get_children (GUsbDevice *device); guint8 g_usb_device_get_bus (GUsbDevice *device); guint8 g_usb_device_get_address (GUsbDevice *device); |