[Spice-devel] [PATCH 6/9] Implement shared CD device auto-removal on disconnect, in usb-device-widget

alexander at daynix.com alexander at daynix.com
Thu Dec 5 17:49:12 UTC 2019


From: Alexander Nezhinsky <anezhins at redhat.com>

Signed-off-by: Alexander Nezhinsky <anezhins at redhat.com>
---
 src/usb-device-widget.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/usb-device-widget.c b/src/usb-device-widget.c
index e077482..a772ae0 100644
--- a/src/usb-device-widget.c
+++ b/src/usb-device-widget.c
@@ -519,10 +519,27 @@ static void _disconnect_cb(GObject *gobject, GAsyncResult *res, gpointer user_da
 {
     SpiceUsbDeviceManager *manager = SPICE_USB_DEVICE_MANAGER(gobject);
     connect_cb_data *data = user_data;
+    SpiceUsbDevice *device = g_object_get_data(G_OBJECT(data->check), "usb-device");
     GError *err = NULL;
+    gboolean rc;
 
     spice_usb_device_manager_disconnect_device_finish(manager, res, &err);
-    if (err) {
+    if (!err) {
+        if (spice_usb_device_manager_is_device_shared_cd(manager, device)) {
+            rc = spice_usb_device_manager_remove_shared_cd_device(manager, device, &err);
+            if (!rc) {
+                if (err) {
+                    SPICE_DEBUG("Failed to remove %s, %s",
+                                gtk_button_get_label(GTK_BUTTON(data->check)),
+                                err->message);
+                    g_error_free(err);
+                } else {
+                    SPICE_DEBUG("Failed to remove %s",
+                                gtk_button_get_label(GTK_BUTTON(data->check)));
+                }
+            }
+        }
+    } else {
         SPICE_DEBUG("Device disconnection failed");
         g_error_free(err);
     }
-- 
2.20.1



More information about the Spice-devel mailing list