[Spice-devel] [PATCH spice-gtk 1/3] usb-device-manager: Add a spice_usb_device_get_description() method
Hans de Goede
hdegoede at redhat.com
Thu Sep 1 03:23:49 PDT 2011
This is just a place holder for now. A better implementation requires
gusb changes, and I hope there will be an official gusb release by the
time I get around to fixing this up.
Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
doc/reference/spice-gtk-sections.txt | 1 +
gtk/map-file | 1 +
gtk/usb-device-manager.c | 33 ++++++++++++++++++++++++++++-----
gtk/usb-device-manager.h | 2 ++
4 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/doc/reference/spice-gtk-sections.txt b/doc/reference/spice-gtk-sections.txt
index 4ac8576..d789d5a 100644
--- a/doc/reference/spice-gtk-sections.txt
+++ b/doc/reference/spice-gtk-sections.txt
@@ -271,6 +271,7 @@ spice_usb_device_manager_get_devices
spice_usb_device_manager_is_device_connected
spice_usb_device_manager_connect_device
spice_usb_device_manager_disconnect_device
+spice_usb_device_get_description
SpiceUsbDevice
<SUBSECTION Standard>
SPICE_USB_DEVICE_MANAGER
diff --git a/gtk/map-file b/gtk/map-file
index d9765c0..b383edf 100644
--- a/gtk/map-file
+++ b/gtk/map-file
@@ -77,6 +77,7 @@ spice_smartcard_reader_get_type;
spice_smartcard_reader_is_software;
spice_usbredir_channel_get_type;
spice_usb_device_get_type;
+spice_usb_device_get_description;
spice_usb_device_manager_get_type;
spice_usb_device_manager_get;
spice_usb_device_manager_register_channel;
diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index 7449ba0..251153c 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -322,22 +322,22 @@ static gboolean spice_usb_device_manager_source_callback(gpointer user_data)
}
static void spice_usb_device_manager_dev_added(GUsbDeviceList *devlist,
- GUsbDevice *device,
+ GUsbDevice *_device,
GUdevDevice *udev,
gpointer user_data)
{
SpiceUsbDeviceManager *manager = user_data;
SpiceUsbDeviceManagerPrivate *priv = manager->priv;
+ SpiceUsbDevice *device = (SpiceUsbDevice *)_device;
g_ptr_array_add(priv->devices, g_object_ref(device));
if (priv->auto_connect) {
GError *err = NULL;
- spice_usb_device_manager_connect_device(manager,
- (SpiceUsbDevice *)device,
- &err);
+ spice_usb_device_manager_connect_device(manager, device, &err);
if (err) {
- g_warning("Could not auto-redirect USB device: %s", err->message);
+ g_warning("Could not auto-redirect %s: %s",
+ spice_usb_device_get_description(device), err->message);
g_error_free(err);
}
}
@@ -589,3 +589,26 @@ void spice_usb_device_manager_disconnect_device(SpiceUsbDeviceManager *self,
spice_usbredir_channel_disconnect(channel);
#endif
}
+
+/**
+ * spice_usb_device_get_description:
+ * @device: #SpiceUsbDevice to get the description of
+ *
+ * Get a string describing the device which is suitable as a description of
+ * the device for the end user. The returned string should be freed with
+ * g_free() when no longer needed.
+ *
+ * Returns: a newly-allocated string holding the description
+ */
+gchar *spice_usb_device_get_description(SpiceUsbDevice *device)
+{
+ /* FIXME, extend gusb to get vid:pid + usb descriptor strings, use those */
+ int bus, address;
+
+ g_return_val_if_fail(device != NULL, "Unknown");
+
+ bus = g_usb_device_get_bus((GUsbDevice *)device);
+ address = g_usb_device_get_address((GUsbDevice *)device);
+
+ return g_strdup_printf("USB device at %d-%d", bus, address);
+}
diff --git a/gtk/usb-device-manager.h b/gtk/usb-device-manager.h
index 03048f4..674e2ff 100644
--- a/gtk/usb-device-manager.h
+++ b/gtk/usb-device-manager.h
@@ -83,6 +83,8 @@ struct _SpiceUsbDeviceManagerClass
GType spice_usb_device_get_type(void);
GType spice_usb_device_manager_get_type(void);
+gchar *spice_usb_device_get_description(SpiceUsbDevice *device);
+
SpiceUsbDeviceManager *spice_usb_device_manager_get(GMainContext *main_context,
GError **err);
--
1.7.6.1
More information about the Spice-devel
mailing list