[Spice-devel] [PATCH spice-gtk 12/44] usb-redir: device error signal without device object

Frediano Ziglio fziglio at redhat.com
Tue Jul 30 12:03:01 UTC 2019


From: Yuri Benditovich <yuri.benditovich at daynix.com>

Add ability to indicate error to external modules via
'device error' signal when real SpiceUsbDevice is not passed.
This is needed to indicate error during creation of emulated
device, when the device is not created yet. For that we
allocate temporary SpiceUsbDevice structure with backend
device fields set to NULL and use it for indication. Device
description for such device will be 'USB Redirection'.
Unreferencing of such device will be 'no operation'.

Signed-off-by: Yuri Benditovich <yuri.benditovich at daynix.com>
---
 src/usb-backend.c        |  3 +++
 src/usb-device-manager.c | 14 ++++++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/usb-backend.c b/src/usb-backend.c
index a6c7b199..9adfd125 100644
--- a/src/usb-backend.c
+++ b/src/usb-backend.c
@@ -538,6 +538,9 @@ SpiceUsbBackendDevice *spice_usb_backend_device_ref(SpiceUsbBackendDevice *dev)
 
 void spice_usb_backend_device_unref(SpiceUsbBackendDevice *dev)
 {
+    if (!dev) {
+        return;
+    }
     LOUD_DEBUG("%s >> %p(%d)", __FUNCTION__, dev, dev->ref_count);
     if (g_atomic_int_dec_and_test(&dev->ref_count)) {
         if (dev->libusb_device) {
diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
index 743db9b7..86733466 100644
--- a/src/usb-device-manager.c
+++ b/src/usb-device-manager.c
@@ -934,10 +934,16 @@ static void spice_usb_device_manager_check_redir_on_connect(
 void spice_usb_device_manager_device_error(
     SpiceUsbDeviceManager *self, SpiceUsbDevice *device, GError *err)
 {
+    SpiceUsbDevice *dev = device;
     g_return_if_fail(SPICE_IS_USB_DEVICE_MANAGER(self));
-    g_return_if_fail(device != NULL);
-
+    if (device == NULL) {
+        dev = g_new0(SpiceUsbDevice, 1);
+        dev->ref = 1;
+    }
     g_signal_emit(self, signals[DEVICE_ERROR], 0, device, err);
+    if (device == NULL) {
+        spice_usb_device_unref(dev);
+    }
 }
 #endif
 
@@ -1436,6 +1442,10 @@ gchar *spice_usb_device_get_description(SpiceUsbDevice *device, const gchar *for
 #ifdef USE_USBREDIR
     g_return_val_if_fail(device != NULL, NULL);
 
+    if (!device->bdev) {
+        return g_strdup(_("USB redirection"));
+    }
+
     return spice_usb_backend_device_get_description(device->bdev, format);
 #else
     return NULL;
-- 
2.20.1



More information about the Spice-devel mailing list