[Spice-devel] [spice-gtk Win32 v3 10/12] win-usb-driver-install: add capability to remove (uninstall) a win usb driver

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


---
 gtk/win-usb-driver-install.c |   69 +++++++++++++++++++++++++++++-------------
 gtk/win-usb-driver-install.h |    6 ++++
 2 files changed, 54 insertions(+), 21 deletions(-)

diff --git a/gtk/win-usb-driver-install.c b/gtk/win-usb-driver-install.c
index 9f4fdfc..7388923 100644
--- a/gtk/win-usb-driver-install.c
+++ b/gtk/win-usb-driver-install.c
@@ -113,7 +113,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)
@@ -271,21 +271,13 @@ 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;
     SpiceNamedPipe *np;
@@ -294,15 +286,13 @@ void spice_win_usb_driver_install(SpiceWinUsbDriver *self,
     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(SPICE_IS_USB_DEVICE(device));

     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);
@@ -318,7 +308,7 @@ void spice_win_usb_driver_install(SpiceWinUsbDriver *self,
     npc = g_object_new(SPICE_TYPE_NAMED_PIPE_CONNECTION, "namedpipe", np, NULL);
     priv->gios = G_IO_STREAM(npc);

-    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);
@@ -345,6 +335,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
@@ -357,7 +384,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 eb04707..e49be2f 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