--- gtk/usb-device-manager.c | 57 +++++++++++++++++++++++++++----------------- gtk/win-usb-driver-install.c | 7 ++++++ gtk/win-usb-driver-install.h | 4 ++++ 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c index 8582d5d..147026c 100644 --- a/gtk/usb-device-manager.c +++ b/gtk/usb-device-manager.c @@ -1043,7 +1043,6 @@ typedef struct _UsbInstallCbInfo { GCancellable *cancellable; GAsyncReadyCallback callback; gpointer user_data; - gboolean is_install; } UsbInstallCbInfo; /** @@ -1072,8 +1071,6 @@ static void spice_usb_device_manager_drv_install_cb(GObject *gobject, UsbInstallCbInfo *cbinfo; GCancellable *cancellable; GAsyncReadyCallback callback; - gboolean is_install; - const gchar *opstr; g_return_if_fail(user_data != NULL); @@ -1084,7 +1081,6 @@ 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); @@ -1092,31 +1088,21 @@ static void spice_usb_device_manager_drv_install_cb(GObject *gobject, g_return_if_fail(SPICE_IS_WIN_USB_DRIVER(installer)); g_return_if_fail(device!= NULL); - opstr = is_install ? "install" : "uninstall"; - SPICE_DEBUG("Win USB driver %s finished", opstr); + SPICE_DEBUG("Win USB driver install finished"); status = spice_win_usb_driver_install_finish(installer, res, &err); - spice_usb_device_unref(device); - - if (is_install) { - spice_usb_device_set_state(device, SPICE_USB_DEVICE_STATE_INSTALLED); - } else { - spice_usb_device_set_state(device, SPICE_USB_DEVICE_STATE_NONE); - } - if (err) { - g_warning("win usb driver %s failed -- %s", opstr, err->message); + g_warning("win usb driver install failed -- %s", err->message); g_error_free(err); } if (!status) { - g_warning("failed to %s win usb driver (status=0)", opstr); + g_warning("failed to install win usb driver (status=0)"); } - if (! is_install) { - return; - } + spice_usb_device_unref(device); + spice_usb_device_set_state(device, SPICE_USB_DEVICE_STATE_INSTALLED); /* device is already ref'ed */ _spice_usb_device_manager_connect_device_async(self, @@ -1126,6 +1112,35 @@ static void spice_usb_device_manager_drv_install_cb(GObject *gobject, user_data); } + +static void spice_usb_device_manager_drv_uninstall_cb(GObject *gobject, + GAsyncResult *res, + gpointer user_data) +{ + UsbInstallCbInfo *cbinfo = user_data; + SpiceUsbDeviceManager *self = cbinfo->manager; + GError *err = NULL; + gint status; + + SPICE_DEBUG("Win USB driver uninstall finished"); + g_return_if_fail(SPICE_IS_USB_DEVICE_MANAGER(self)); + + status = spice_win_usb_driver_uninstall_finish(cbinfo->installer, res, &err); + if (err) { + g_warning("win usb driver uninstall failed -- %s", err->message); + g_clear_error(&err); + } + + if (!status) { + g_warning("failed to uninstall win usb driver (status=0)"); + } + + spice_usb_device_unref(cbinfo->device); + spice_usb_device_set_state(cbinfo->device, SPICE_USB_DEVICE_STATE_NONE); + + g_free(cbinfo); +} + #endif /* ------------------------------------------------------------------ */ @@ -1493,7 +1508,6 @@ 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_async(installer, device, cancellable, spice_usb_device_manager_drv_install_cb, @@ -1570,10 +1584,9 @@ void spice_usb_device_manager_disconnect_device(SpiceUsbDeviceManager *self, cbinfo->cancellable = NULL; cbinfo->callback = NULL; cbinfo->user_data = NULL; - cbinfo->is_install = FALSE; spice_win_usb_driver_uninstall_async(installer, device, NULL, - spice_usb_device_manager_drv_install_cb, + spice_usb_device_manager_drv_uninstall_cb, cbinfo); #endif diff --git a/gtk/win-usb-driver-install.c b/gtk/win-usb-driver-install.c index bdc2372..c3a7ace 100644 --- a/gtk/win-usb-driver-install.c +++ b/gtk/win-usb-driver-install.c @@ -388,6 +388,13 @@ gint spice_win_usb_driver_install_finish(SpiceWinUsbDriver *self, } G_GNUC_INTERNAL +gint spice_win_usb_driver_uninstall_finish(SpiceWinUsbDriver *self, + GAsyncResult *res, GError **err) +{ + return spice_win_usb_driver_op_finish(self, res, err); +} + +G_GNUC_INTERNAL SpiceUsbDevice *spice_win_usb_driver_get_device(SpiceWinUsbDriver *self) { g_return_val_if_fail(SPICE_IS_WIN_USB_DRIVER(self), 0); diff --git a/gtk/win-usb-driver-install.h b/gtk/win-usb-driver-install.h index b3ca4bf..bac41f1 100644 --- a/gtk/win-usb-driver-install.h +++ b/gtk/win-usb-driver-install.h @@ -77,6 +77,10 @@ void spice_win_usb_driver_uninstall_async(SpiceWinUsbDriver *self, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); +gint spice_win_usb_driver_uninstall_finish(SpiceWinUsbDriver *self, + GAsyncResult *res, GError **err); + + SpiceUsbDevice *spice_win_usb_driver_get_device(SpiceWinUsbDriver *self); -- 1.8.5.3 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/spice-devel