[PATCH spice-gtk v4 03/29] usb-redir: move implementation of device description to USB backend

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Yuri Benditovich <yuri.benditovich@xxxxxxxxxx>

For local USB device the USB backend returns the same device
description as spice-usb-manager did, for emulated devices it
uses the description provided by device's implementation.

Signed-off-by: Yuri Benditovich <yuri.benditovich@xxxxxxxxxx>
Acked-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---
 src/usb-backend.c        | 41 ++++++++++++++++++++++++++++++++++++++++
 src/usb-backend.h        |  1 +
 src/usb-device-manager.c | 29 +---------------------------
 3 files changed, 43 insertions(+), 28 deletions(-)

diff --git a/src/usb-backend.c b/src/usb-backend.c
index 7f9fcc17..aa11c791 100644
--- a/src/usb-backend.c
+++ b/src/usb-backend.c
@@ -42,6 +42,7 @@
 #include "usb-emulation.h"
 #include "channel-usbredir-priv.h"
 #include "spice-channel-priv.h"
+#include "usbutil.h"
 
 #define LOUD_DEBUG(x, ...)
 
@@ -844,6 +845,46 @@ spice_usb_backend_channel_get_guest_filter(SpiceUsbBackendChannel *ch,
     }
 }
 
+gchar * spice_usb_backend_device_get_description(SpiceUsbBackendDevice *dev,
+                                                 const gchar *format)
+{
+    guint16 bus, address, vid, pid;
+    gchar *description, *descriptor, *manufacturer = NULL, *product = NULL;
+
+    g_return_val_if_fail(dev != NULL, NULL);
+
+    bus     = dev->device_info.bus;
+    address = dev->device_info.address;
+    vid     = dev->device_info.vid;
+    pid     = dev->device_info.pid;
+
+    if ((vid > 0) && (pid > 0)) {
+        descriptor = g_strdup_printf("[%04x:%04x]", vid, pid);
+    } else {
+        descriptor = g_strdup("");
+    }
+
+    if (dev->libusb_device) {
+        spice_usb_util_get_device_strings(bus, address, vid, pid,
+                                          &manufacturer, &product);
+    } else {
+        product = device_ops(dev->edev)->get_product_description(dev->edev);
+    }
+
+    if (!format) {
+        format = _("%s %s %s at %d-%d");
+    }
+
+    description = g_strdup_printf(format, manufacturer ? manufacturer : "",
+                                  product, descriptor, bus, address);
+
+    g_free(manufacturer);
+    g_free(descriptor);
+    g_free(product);
+
+    return description;
+}
+
 void spice_usb_backend_device_report_change(SpiceUsbBackend *be,
                                             SpiceUsbBackendDevice *dev)
 {
diff --git a/src/usb-backend.h b/src/usb-backend.h
index cd3ff097..c694dbb2 100644
--- a/src/usb-backend.h
+++ b/src/usb-backend.h
@@ -90,5 +90,6 @@ void spice_usb_backend_channel_get_guest_filter(SpiceUsbBackendChannel *ch,
                                                 const struct usbredirfilter_rule  **rules,
                                                 int *count);
 void spice_usb_backend_return_write_data(SpiceUsbBackendChannel *ch, void *data);
+gchar *spice_usb_backend_device_get_description(SpiceUsbBackendDevice *dev, const gchar *format);
 
 G_END_DECLS
diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
index b3db5de6..5834e032 100644
--- a/src/usb-device-manager.c
+++ b/src/usb-device-manager.c
@@ -32,7 +32,6 @@
 #endif
 
 #include "channel-usbredir-priv.h"
-#include "usbutil.h"
 #endif
 
 #include "spice-session-priv.h"
@@ -1439,35 +1438,9 @@ spice_usb_device_manager_can_redirect_device(SpiceUsbDeviceManager  *self,
 gchar *spice_usb_device_get_description(SpiceUsbDevice *device, const gchar *format)
 {
 #ifdef USE_USBREDIR
-    guint16 bus, address, vid, pid;
-    gchar *description, *descriptor, *manufacturer = NULL, *product = NULL;
-
     g_return_val_if_fail(device != NULL, NULL);
 
-    bus     = spice_usb_device_get_busnum(device);
-    address = spice_usb_device_get_devaddr(device);
-    vid     = spice_usb_device_get_vid(device);
-    pid     = spice_usb_device_get_pid(device);
-
-    if ((vid > 0) && (pid > 0)) {
-        descriptor = g_strdup_printf("[%04x:%04x]", vid, pid);
-    } else {
-        descriptor = g_strdup("");
-    }
-
-    spice_usb_util_get_device_strings(bus, address, vid, pid,
-                                      &manufacturer, &product);
-
-    if (!format)
-        format = _("%s %s %s at %d-%d");
-
-    description = g_strdup_printf(format, manufacturer, product, descriptor, bus, address);
-
-    g_free(manufacturer);
-    g_free(descriptor);
-    g_free(product);
-
-    return description;
+    return spice_usb_backend_device_get_description(device->bdev, format);
 #else
     return NULL;
 #endif
-- 
2.20.1

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]