[Spice-devel] [spice-gtk Win32 v4 08/17] win-usb-driver-install: add capability to remove (uninstall) a win usb driver
Uri Lublin
uril at redhat.com
Thu Jul 5 13:44:00 PDT 2012
---
gtk/usb-device-manager.c | 17 +++++++---
gtk/win-usb-driver-install.c | 69 +++++++++++++++++++++++++++++-------------
gtk/win-usb-driver-install.h | 6 ++++
3 files changed, 66 insertions(+), 26 deletions(-)
diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index c320fb8..224b7e8 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -752,8 +752,8 @@ static void spice_usb_device_manager_drv_install_cb(GObject *gobject,
UsbInstallCbInfo *cbinfo;
GCancellable *cancellable;
GAsyncReadyCallback callback;
-
- SPICE_DEBUG("Win USB driver Installation finished");
+ gboolean is_install;
+ const gchar *opstr;
g_return_if_fail(user_data != NULL);
@@ -771,20 +771,27 @@ 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);
+
status = spice_win_usb_driver_install_finish(installer, res, &err);
g_object_unref(installer);
if (err) {
- g_warning("win usb driver installation failed -- %s",
- err->message);
+ g_warning("win usb driver %s failed -- %s", opstr, err->message);
g_error_free(err);
spice_usb_device_unref(device);
return;
}
if (!status) {
- g_warning("failed to install win usb driver (status=0)");
+ g_warning("failed to %s win usb driver (status=0)", opstr);
+ spice_usb_device_unref(device);
+ return;
+ }
+
+ if (! is_install) {
spice_usb_device_unref(device);
return;
}
diff --git a/gtk/win-usb-driver-install.c b/gtk/win-usb-driver-install.c
index 0ca981b..76ff2c2 100644
--- a/gtk/win-usb-driver-install.c
+++ b/gtk/win-usb-driver-install.c
@@ -101,7 +101,7 @@ static void win_usb_driver_async_result_set_cancelled(GSimpleAsyncResult *result
{
g_simple_async_result_set_error(result,
G_IO_ERROR, G_IO_ERROR_CANCELLED,
- "Win USB driver installation cancelled");
+ "Win USB driver un/installation cancelled");
}
static void win_usb_driver_cancelled_cb(GCancellable *cancellable, gpointer user_data)
@@ -273,36 +273,26 @@ SpiceWinUsbDriver *spice_win_usb_driver_new(void)
return SPICE_WIN_USB_DRIVER(obj);
}
-/**
- * spice_win_usb_driver_install:
- * Start libusb driver installation for @device
- *
- * A new NamedPipe is created for each request.
- *
- * Returns: TRUE if a request was sent to usbclerk
- * FALSE upon failure to send a request.
- */
-G_GNUC_INTERNAL
-void spice_win_usb_driver_install(SpiceWinUsbDriver *self,
- SpiceUsbDevice *device,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+static
+void spice_win_usb_driver_op(SpiceWinUsbDriver *self,
+ SpiceUsbDevice *device,
+ guint16 op_type,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
guint16 vid, pid;
GError *err = NULL;
GSimpleAsyncResult *result;
SpiceWinUsbDriverPrivate *priv;
- SPICE_DEBUG("Win usb driver installation started");
-
g_return_if_fail(SPICE_IS_WIN_USB_DRIVER(self));
g_return_if_fail(device != NULL);
priv = self->priv;
result = g_simple_async_result_new(G_OBJECT(self), callback, user_data,
- spice_win_usb_driver_install);
+ spice_win_usb_driver_op);
vid = spice_usb_device_get_vid(device);
pid = spice_usb_device_get_pid(device);
@@ -325,7 +315,7 @@ void spice_win_usb_driver_install(SpiceWinUsbDriver *self,
goto failed_request;
}
- if (!spice_win_usb_driver_send_request(self, USB_CLERK_DRIVER_INSTALL,
+ if (!spice_win_usb_driver_send_request(self, op_type,
vid, pid, &err)) {
g_warning("failed to send a request to usbclerk %s", err->message);
g_simple_async_result_take_error(result, err);
@@ -353,6 +343,43 @@ void spice_win_usb_driver_install(SpiceWinUsbDriver *self,
}
+
+/**
+ * spice_win_usb_driver_install:
+ * Start libusb driver installation for @device
+ *
+ * A new NamedPipe is created for each request.
+ *
+ * Returns: TRUE if a request was sent to usbclerk
+ * FALSE upon failure to send a request.
+ */
+G_GNUC_INTERNAL
+void spice_win_usb_driver_install(SpiceWinUsbDriver *self,
+ SpiceUsbDevice *device,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ SPICE_DEBUG("Win usb driver installation started");
+
+ spice_win_usb_driver_op(self, device, USB_CLERK_DRIVER_INSTALL, cancellable,
+ callback, user_data);
+}
+
+G_GNUC_INTERNAL
+void spice_win_usb_driver_uninstall(SpiceWinUsbDriver *self,
+ SpiceUsbDevice *device,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ SPICE_DEBUG("Win usb driver uninstall operation started");
+
+ spice_win_usb_driver_op(self, device, USB_CLERK_DRIVER_REMOVE, cancellable,
+ callback, user_data);
+}
+
+
/**
* Returns: currently returns 0 (failure) and 1 (success)
* possibly later we'll add error-codes
@@ -365,7 +392,7 @@ gint spice_win_usb_driver_install_finish(SpiceWinUsbDriver *self,
g_return_val_if_fail(SPICE_IS_WIN_USB_DRIVER(self), 0);
g_return_val_if_fail(g_simple_async_result_is_valid(res, G_OBJECT(self),
- spice_win_usb_driver_install),
+ spice_win_usb_driver_op),
FALSE);
if (g_simple_async_result_propagate_error(result, err))
return 0;
diff --git a/gtk/win-usb-driver-install.h b/gtk/win-usb-driver-install.h
index b0ccf33..034abf9 100644
--- a/gtk/win-usb-driver-install.h
+++ b/gtk/win-usb-driver-install.h
@@ -70,6 +70,12 @@ void spice_win_usb_driver_install(SpiceWinUsbDriver *self,
GAsyncReadyCallback callback,
gpointer user_data);
+void spice_win_usb_driver_uninstall(SpiceWinUsbDriver *self,
+ SpiceUsbDevice *device,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
gint spice_win_usb_driver_install_finish(SpiceWinUsbDriver *self,
GAsyncResult *res, GError **err);
--
1.7.7.6
More information about the Spice-devel
mailing list