diff options
author | Richard Hughes <richard@hughsie.com> | 2017-07-22 21:11:27 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2017-07-23 21:05:55 +0100 |
commit | 0951efa755708cc5903ed626a182bc1d698a1635 (patch) | |
tree | 692399b9fedf041428ed282f84b6f21c0dcb3aa5 /tools | |
parent | 8b223ea0cb16112b0820e4db5708a2cb6a2a00ed (diff) | |
download | gusb-0951efa755708cc5903ed626a182bc1d698a1635.tar.gz |
Add g_usb_context_set_flags()
This allows us to auto-open devices as they are hotplugged.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/gusb-main.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tools/gusb-main.c b/tools/gusb-main.c index 234115c..7626719 100644 --- a/tools/gusb-main.c +++ b/tools/gusb-main.c @@ -158,6 +158,32 @@ gusb_cmd_get_descriptions (GPtrArray *array) return g_string_free (string, FALSE); } +static void +gusb_main_device_open (GUsbDevice *device) +{ + GError *error = NULL; + guint8 idx; + + /* open */ + if (!g_usb_device_open (device, &error)) { + g_print ("failed to open: %s\n", error->message); + g_error_free (error); + return; + } + + /* print info we can only get whilst open */ + idx = g_usb_device_get_product_index (device); + if (idx != 0x00) { + gchar *product = g_usb_device_get_string_descriptor (device, idx, &error); + if (product == NULL) { + g_print ("failed to get string desc: %s\n", error->message); + g_error_free (error); + return; + } + g_print ("product: %s\n", product); + } +} + /** * gusb_device_list_added_cb: **/ @@ -170,6 +196,7 @@ gusb_device_list_added_cb (GUsbContext *context, g_usb_device_get_platform_id (device), g_usb_device_get_bus (device), g_usb_device_get_address (device)); + gusb_main_device_open (device); } /** @@ -339,6 +366,7 @@ gusb_cmd_watch (GUsbCmdPrivate *priv, gchar **values, GError **error) g_usb_device_get_platform_id (device), g_usb_device_get_bus (device), g_usb_device_get_address (device)); + gusb_main_device_open (device); } loop = g_main_loop_new (NULL, FALSE); @@ -478,6 +506,7 @@ main (int argc, char *argv[]) /* GUsbContext */ priv->usb_ctx = g_usb_context_new (NULL); + g_usb_context_set_flags (priv->usb_ctx, G_USB_CONTEXT_FLAGS_AUTO_OPEN_DEVICES); /* add commands */ priv->cmd_array = g_ptr_array_new_with_free_func ((GDestroyNotify) gusb_cmd_item_free); |