[Spice-devel] [PATCH] [spice-gtk v2] usb-device: Expose libusb device

Fabiano FidĂȘncio fidencio at redhat.com
Wed Nov 12 17:32:24 PST 2014


As we only can filter USB devices by their Classes and sometimes it is
not enough (eg: I do not want to have Keyboard and Mouse, but I want to
have Joysticks, being all of them part of HID Class), let's expose the
libusb device associated to the SpiceUsbDevice, so the applications can
have access to whatever information they need, directly from the libusb
device, to refine their filters.
---
Changes since v1:
- The approach is completely different. In the first version of the patch
  I've added a new API to get, specifically, class, subclass and protocol
  of a libusb device. Discussing this approach with Marc-André and taking
  into consideration that, from Boxes, we could refine the filter once we
  have access to the libusb device I've decided to keep it simple in the
  spice-gtk and give more freedom to the applications access whatever
  they need from their side.
---
 gtk/map-file             |  1 +
 gtk/spice-glib-sym-file  |  1 +
 gtk/usb-device-manager.c | 25 +++++++++++++++++++++++++
 gtk/usb-device-manager.h |  1 +
 4 files changed, 28 insertions(+)

diff --git a/gtk/map-file b/gtk/map-file
index 9f8d04e..3e9624f 100644
--- a/gtk/map-file
+++ b/gtk/map-file
@@ -114,6 +114,7 @@ spice_uri_set_scheme;
 spice_uri_set_user;
 spice_uri_to_string;
 spice_usb_device_get_description;
+spice_usb_device_get_libusb_device;
 spice_usb_device_get_type;
 spice_usb_device_manager_can_redirect_device;
 spice_usb_device_manager_connect_device_async;
diff --git a/gtk/spice-glib-sym-file b/gtk/spice-glib-sym-file
index 2189fa5..6ea8aeb 100644
--- a/gtk/spice-glib-sym-file
+++ b/gtk/spice-glib-sym-file
@@ -91,6 +91,7 @@ spice_uri_set_scheme
 spice_uri_set_user
 spice_uri_to_string
 spice_usb_device_get_description
+spice_usb_device_get_libusb_device
 spice_usb_device_get_type
 spice_usb_device_manager_can_redirect_device
 spice_usb_device_manager_connect_device_async
diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index 5013b6c..824264c 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -706,6 +706,31 @@ static gboolean spice_usb_device_manager_get_device_descriptor(
     return TRUE;
 }
 
+
+/**
+ * spice_usb_device_get_libusb_device:
+ * @device: #SpiceUsbDevice to get the descriptor information of
+ *
+ * Returns: (transfer none): the %libusb_device associated to %SpiceUsbDevice.
+ *
+ * Since: 0.27
+ **/
+gconstpointer
+spice_usb_device_get_libusb_device(const SpiceUsbDevice *device G_GNUC_UNUSED)
+{
+#ifdef USE_USBREDIR
+#ifndef G_OS_WIN32
+    const SpiceUsbDeviceInfo *info = (const SpiceUsbDeviceInfo *)device;
+
+    g_return_val_if_fail(info != NULL, FALSE);
+
+    return info->libdev;
+#endif
+#else
+    return NULL;
+#endif
+}
+
 static gboolean spice_usb_device_manager_get_libdev_vid_pid(
     libusb_device *libdev, int *vid, int *pid)
 {
diff --git a/gtk/usb-device-manager.h b/gtk/usb-device-manager.h
index a7e3515..5b4cfbe 100644
--- a/gtk/usb-device-manager.h
+++ b/gtk/usb-device-manager.h
@@ -89,6 +89,7 @@ GType spice_usb_device_get_type(void);
 GType spice_usb_device_manager_get_type(void);
 
 gchar *spice_usb_device_get_description(SpiceUsbDevice *device, const gchar *format);
+gconstpointer spice_usb_device_get_libusb_device(const SpiceUsbDevice *device);
 
 SpiceUsbDeviceManager *spice_usb_device_manager_get(SpiceSession *session,
                                                     GError **err);
-- 
2.1.0



More information about the Spice-devel mailing list