diff options
-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); |