[Spice-devel,spice-gtk,Win32,v4,09/17] Win32/mingw: usb-device-manager: uninstall win usb driver upon device disconnect

Submitted by Uri Lublin on July 5, 2012, 8:44 p.m.

Details

Message ID 1341521049-4562-10-git-send-email-uril@redhat.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Uri Lublin July 5, 2012, 8:44 p.m.
---
 gtk/usb-device-manager.c |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

Patch hide | download patch | download mbox

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

 /**
@@ -764,6 +765,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);

@@ -1064,6 +1066,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);
@@ -1113,6 +1116,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(device != NULL);
+
+    installer = spice_win_usb_driver_new();
+    cbinfo = g_new0(UsbInstallCbInfo, 1);
+    cbinfo->manager     = self;
+    cbinfo->device      = spice_usb_device_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
 }