[Spice-devel] [spice-gtk Win32 v3 11/12] Win32/mingw: usb-device-manager: uninstall win usb driver upon device disconnect

Uri Lublin uril at redhat.com
Wed Jun 27 18:46:40 PDT 2012


---
 gtk/usb-device-manager.c |   37 ++++++++++++++++++++++++++++++++++---
 1 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index d4740cf..e4a098c 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -697,6 +697,7 @@ typedef struct _UsbInstallCbInfo {
     GCancellable          *cancellable;
     GAsyncReadyCallback   callback;
     gpointer              user_data;
+    gboolean              is_install;
 } UsbInstallCbInfo;

 /**
@@ -722,8 +723,9 @@ static void spice_usb_device_manager_drv_install_cb(GObject *gobject,
     UsbInstallCbInfo *cbinfo;
     GCancellable *cancellable;
     GAsyncReadyCallback callback;
+    gboolean is_install;

-    SPICE_DEBUG("Win USB driver Installation finished");
+    SPICE_DEBUG("Win USB driver Un/Installation finished");

     g_return_if_fail(user_data != NULL);

@@ -734,6 +736,7 @@ static void spice_usb_device_manager_drv_install_cb(GObject *gobject,
     cancellable = cbinfo->cancellable;
     callback    = cbinfo->callback;
     user_data   = cbinfo->user_data;
+    is_install  = cbinfo->is_install;

     g_free(cbinfo);

@@ -746,7 +749,7 @@ static void spice_usb_device_manager_drv_install_cb(GObject *gobject,
     g_object_unref(installer);

     if (err) {
-        g_warning("win usb driver installation failed -- %s",
+        g_warning("win usb driver un/installation failed -- %s",
                   err->message);
         g_error_free(err);
         g_object_unref(device);
@@ -754,7 +757,12 @@ static void spice_usb_device_manager_drv_install_cb(GObject *gobject,
     }

     if (!status) {
-        g_warning("failed to install win usb driver (status=0)");
+        g_warning("failed to un/install win usb driver (status=0)");
+        g_object_unref(device);
+        return;
+    }
+
+    if (! is_install) {
         g_object_unref(device);
         return;
     }
@@ -1016,6 +1024,7 @@ void spice_usb_device_manager_connect_device_async(SpiceUsbDeviceManager *self,
     cbinfo->cancellable = cancellable;
     cbinfo->callback    = callback;
     cbinfo->user_data   = user_data;
+    cbinfo->is_install  = TRUE;
     spice_win_usb_driver_install(installer, device, NULL,
                                  spice_usb_device_manager_drv_install_cb,
                                  cbinfo);
@@ -1064,6 +1073,28 @@ void spice_usb_device_manager_disconnect_device(SpiceUsbDeviceManager *self,
     channel = spice_usb_device_manager_get_channel_for_dev(self, device);
     if (channel)
         spice_usbredir_channel_disconnect_device(channel);
+
+#ifdef G_OS_WIN32
+    SpiceWinUsbDriver *installer;
+    UsbInstallCbInfo *cbinfo;
+
+    g_warn_if_fail(SPICE_IS_USB_DEVICE(device));
+
+    installer = spice_win_usb_driver_new();
+    cbinfo = g_new0(UsbInstallCbInfo, 1);
+    cbinfo->manager     = self;
+    cbinfo->device      = g_object_ref(device);
+    cbinfo->installer   = installer;
+    cbinfo->cancellable = NULL;
+    cbinfo->callback    = NULL;
+    cbinfo->user_data   = NULL;
+    cbinfo->is_install  = FALSE;
+
+    spice_win_usb_driver_uninstall(installer, device, NULL,
+                                   spice_usb_device_manager_drv_install_cb,
+                                   cbinfo);
+#endif
+
 #endif
 }

-- 
1.7.7.6



More information about the Spice-devel mailing list