[Spice-devel] [spice-gtk v1] win-usb: remove usbclerk
Victor Toso
victortoso at redhat.com
Mon Dec 19 17:48:03 UTC 2016
Hi,
On Thu, Dec 15, 2016 at 03:20:36PM +0100, Pavel Grunt wrote:
> Hi,
>
> On Fri, 2016-12-09 at 18:22 +0100, Victor Toso wrote:
> > From: Victor Toso <me at victortoso.com>
> >
> > As we have UsbDk integration now which is well maintained upstream.
>
> yes, it makes a sense
>
> >
> > Signed-off-by: Victor Toso <victortoso at redhat.com>
> > ---
> > doc/reference/Makefile.am | 2 -
> > src/Makefile.am | 3 -
> > src/usb-device-manager.c | 304 +++----------------------------
> > src/win-usb-clerk.h | 36 ----
> > src/win-usb-driver-install.c | 421 --------------------------------
> > -----------
> > src/win-usb-driver-install.h | 106 -----------
> > 6 files changed, 22 insertions(+), 850 deletions(-)
> > delete mode 100644 src/win-usb-clerk.h
> > delete mode 100644 src/win-usb-driver-install.c
> > delete mode 100644 src/win-usb-driver-install.h
> >
> > diff --git a/doc/reference/Makefile.am b/doc/reference/Makefile.am
> > index eaaf98c..999c1dc 100644
> > --- a/doc/reference/Makefile.am
> > +++ b/doc/reference/Makefile.am
> > @@ -58,9 +58,7 @@ IGNORE_HFILES=
> > \
> > usbutil.h \
> > vmcstream.h \
> > vncdisplaykeymap.h \
> > - win-usb-clerk.h \
> > win-usb-dev.h \
> > - win-usb-driver-install.h \
> > wocky-http-proxy.h \
> > $(NULL)
> >
> > diff --git a/src/Makefile.am b/src/Makefile.am
> > index 78b215f..e43cee0 100644
> > --- a/src/Makefile.am
> > +++ b/src/Makefile.am
> > @@ -371,9 +371,6 @@ endif
> > WIN_USB_FILES= \
> > win-usb-dev.h \
> > win-usb-dev.c \
> > - win-usb-clerk.h \
> > - win-usb-driver-install.h \
> > - win-usb-driver-install.c \
> > usbdk_api.h \
> > usbdk_api.c \
> > $(NULL)
> > diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
> > index 6d10daa..0ac3aae 100644
> > --- a/src/usb-device-manager.c
> > +++ b/src/usb-device-manager.c
> > @@ -35,7 +35,6 @@
> > #include <gudev/gudev.h>
> > #elif defined(G_OS_WIN32)
> > #include "win-usb-dev.h"
> > -#include "win-usb-driver-install.h"
> > #define USE_GUDEV /* win-usb-dev.h provides a fake gudev interface
> > */
> > #elif !defined USE_LIBUSB_HOTPLUG
> > #error "Expecting one of USE_GUDEV or USE_LIBUSB_HOTPLUG to be
> > defined"
> > @@ -127,9 +126,7 @@ struct _SpiceUsbDeviceManagerPrivate {
> > #ifdef G_OS_WIN32
> > usbdk_api_wrapper *usbdk_api;
> > HANDLE usbdk_hider_handle;
> > - SpiceWinUsbDriver *installer;
> > #endif
> > - gboolean use_usbclerk;
> > #endif
> > GPtrArray *devices;
> > GPtrArray *channels;
> > @@ -188,9 +185,6 @@ static SpiceUsbDevice
> > *spice_usb_device_ref(SpiceUsbDevice *device);
> > static void spice_usb_device_unref(SpiceUsbDevice *device);
> >
> > #ifdef G_OS_WIN32
> > -static guint8 spice_usb_device_get_state(SpiceUsbDevice *device);
> > -static void spice_usb_device_set_state(SpiceUsbDevice *device,
> > guint8 s);
> > -
> > static void _usbdk_hider_update(SpiceUsbDeviceManager *manager);
> > static void _usbdk_hider_clear(SpiceUsbDeviceManager *manager);
> > #endif
> > @@ -274,8 +268,11 @@ static void
> > spice_usb_device_manager_init(SpiceUsbDeviceManager *self)
> > self->priv = priv;
> >
> > #if defined(G_OS_WIN32) && defined(USE_USBREDIR)
> > - priv->use_usbclerk = !usbdk_is_driver_installed() ||
> > - !(priv->usbdk_api = usbdk_api_load());
> > + if (usbdk_is_driver_installed()) {
> > + priv->usbdk_api = usbdk_api_load();
> > + } else {
> > + spice_debug("UsbDk driver is not installed");
> > + }
> > #endif
> > priv->channels = g_ptr_array_new();
> > #ifdef USE_USBREDIR
> > @@ -298,16 +295,6 @@ static gboolean
> > spice_usb_device_manager_initable_init(GInitable *initable,
> > const gchar *const subsystems[] = {"usb", NULL};
> > #endif
> >
> > -#ifdef G_OS_WIN32
> > - if (priv->use_usbclerk) {
> > - priv->installer = spice_win_usb_driver_new(err);
> > - if (!priv->installer) {
> > - SPICE_DEBUG("failed to initialize winusb driver");
> > - return FALSE;
> > - }
> > - }
> > -#endif
> > -
> > /* Initialize libusb */
> > rc = libusb_init(&priv->context);
> > if (rc < 0) {
> > @@ -425,11 +412,7 @@ static void
> > spice_usb_device_manager_finalize(GObject *gobject)
> > free(priv->auto_conn_filter_rules);
> > free(priv->redirect_on_connect_rules);
> > #ifdef G_OS_WIN32
> > - if (priv->installer) {
> > - g_warn_if_fail(priv->use_usbclerk);
> > - g_object_unref(priv->installer);
> > - }
> > - if (!priv->use_usbclerk) {
> > + if (priv->usbdk_api != NULL) {
>
> this block can be removed - at the worst case there will be a runtime
> warning - which is imho fine (an user wants to use usbredir but usbdk
> is not installed)
>
> > _usbdk_hider_clear(self);
> > usbdk_api_unload(priv->usbdk_api);
> > }
> > @@ -505,9 +488,7 @@ static void
> > spice_usb_device_manager_set_property(GObject *gobject,
> > case PROP_AUTO_CONNECT:
> > priv->auto_connect = g_value_get_boolean(value);
> > #if defined(G_OS_WIN32) && defined(USE_USBREDIR)
> > - if (!priv->use_usbclerk) {
> > - _usbdk_hider_update(self);
> > - }
> > + _usbdk_hider_update(self);
>
> like you did here
>
> > #endif
> > break;
> > case PROP_AUTO_CONNECT_FILTER: {
> > @@ -533,9 +514,7 @@ static void
> > spice_usb_device_manager_set_property(GObject *gobject,
> > priv->auto_connect_filter = g_strdup(filter);
> >
> > #if defined(G_OS_WIN32) && defined(USE_USBREDIR)
> > - if (!priv->use_usbclerk) {
> > - _usbdk_hider_update(self);
> > - }
> > + _usbdk_hider_update(self);
> and here
Double checked. Indeed, seems no harm is done on removing that check.
Sending v2 shortly
> > #endif
> > break;
> > }
> > @@ -769,15 +748,10 @@ static gboolean
> > spice_usb_device_manager_get_udev_bus_n_address(
> >
> > *bus = *address = 0;
> >
> > - if (manager->priv->use_usbclerk) {
> > - /* Windows WinUsb/UsbClerk -- request vid:pid instead */
> > - bus_str = g_udev_device_get_property(udev, "VID");
> > - address_str = g_udev_device_get_property(udev, "PID");
> > - } else {
> > - /* Linux or UsbDk backend on Windows*/
> > - bus_str = g_udev_device_get_property(udev, "BUSNUM");
> > - address_str = g_udev_device_get_property(udev, "DEVNUM");
> > - }
> > + /* Linux or UsbDk backend on Windows*/
> > + bus_str = g_udev_device_get_property(udev, "BUSNUM");
> > + address_str = g_udev_device_get_property(udev, "DEVNUM");
> > +
> > if (bus_str)
> > *bus = atoi(bus_str);
> > if (address_str)
> > @@ -920,13 +894,8 @@ static gboolean
> > spice_usb_device_manager_device_match(SpiceUsbDeviceManager *self,
> > SpiceUsbDevice *device,
> > const int bus, const int
> > address)
> > {
> > - if (self->priv->use_usbclerk) {
> > - return (spice_usb_device_get_vid(device) == bus &&
> > - spice_usb_device_get_pid(device) == address);
> > - } else {
> > - return (spice_usb_device_get_busnum(device) == bus &&
> > - spice_usb_device_get_devaddr(device) == address);
> > - }
> > + return (spice_usb_device_get_busnum(device) == bus &&
> > + spice_usb_device_get_devaddr(device) == address);
> > }
> >
> > #ifdef USE_GUDEV
> > @@ -934,19 +903,9 @@ static gboolean
> > spice_usb_device_manager_libdev_match(SpiceUsbDeviceManager *self,
> > libusb_device *libdev,
> > const int bus, const int
> > address)
> > {
> > - if (self->priv->use_usbclerk) {
> > - /* WinUSB -- match functions for Windows -- match by
> > vid:pid */
> > - int vid, pid;
> > -
> > - if (!spice_usb_device_manager_get_libdev_vid_pid(libdev,
> > &vid, &pid)) {
> > - return FALSE;
> > - }
> > - return (bus == vid && address == pid);
> > - } else {
> > - /* match functions for Linux/UsbDk -- match by bus.addr */
> > - return (libusb_get_bus_number(libdev) == bus &&
> > - libusb_get_device_address(libdev) == address);
> > - }
> > + /* match functions for Linux/UsbDk -- match by bus.addr */
> > + return (libusb_get_bus_number(libdev) == bus &&
> > + libusb_get_device_address(libdev) == address);
> > }
> > #endif
> >
> > @@ -1026,18 +985,6 @@ static void
> > spice_usb_device_manager_remove_dev(SpiceUsbDeviceManager *self,
> > return;
> > }
> >
> > -#ifdef G_OS_WIN32
> > - if (priv->use_usbclerk) {
> > - const guint8 state = spice_usb_device_get_state(device);
> > - if ((state == SPICE_USB_DEVICE_STATE_INSTALLING) ||
> > - (state == SPICE_USB_DEVICE_STATE_UNINSTALLING)) {
> > - SPICE_DEBUG("skipping " DEV_ID_FMT ". It is
> > un/installing its driver",
> > - bus, address);
> > - return;
> > - }
> > - }
> > -#endif
> > -
> > spice_usb_device_manager_disconnect_device(self, device);
> >
> > SPICE_DEBUG("device removed %04x:%04x (%p)",
> > @@ -1186,106 +1133,6 @@ static void
> > spice_usb_device_manager_channel_connect_cb(
> > g_object_unref(task);
> > }
> >
> > -#ifdef G_OS_WIN32
> > -
> > -typedef struct _UsbInstallCbInfo {
> > - SpiceUsbDeviceManager *manager;
> > - SpiceUsbDevice *device;
> > - SpiceWinUsbDriver *installer;
> > - GCancellable *cancellable;
> > - GAsyncReadyCallback callback;
> > - gpointer user_data;
> > -} UsbInstallCbInfo;
> > -
> > -/**
> > - * spice_usb_device_manager_drv_install_cb:
> > - * @gobject: #SpiceWinUsbDriver in charge of installing the driver
> > - * @res: #GAsyncResult of async win usb driver installation
> > - * @user_data: #SpiceUsbDeviceManager requested the installation
> > - *
> > - * Called when an Windows libusb driver installation completed.
> > - *
> > - * If the driver installation was successful, continue with USB
> > - * device redirection
> > - *
> > - * Always call _spice_usb_device_manager_connect_device_async.
> > - * When installation fails, libusb_open fails too, but cleanup
> > would be better.
> > - */
> > -static void spice_usb_device_manager_drv_install_cb(GObject
> > *gobject,
> > - GAsyncResult
> > *res,
> > - gpointer
> > user_data)
> > -{
> > - SpiceUsbDeviceManager *self;
> > - SpiceWinUsbDriver *installer;
> > - GError *err = NULL;
> > - SpiceUsbDevice *device;
> > - UsbInstallCbInfo *cbinfo;
> > - GCancellable *cancellable;
> > - gpointer data;
> > -
> > - g_return_if_fail(user_data != NULL);
> > -
> > - cbinfo = user_data;
> > - self = cbinfo->manager;
> > - device = cbinfo->device;
> > - installer = cbinfo->installer;
> > - cancellable = cbinfo->cancellable;
> > - data = cbinfo->user_data;
> > -
> > - g_free(cbinfo);
> > -
> > - g_return_if_fail(SPICE_IS_USB_DEVICE_MANAGER(self));
> > - g_return_if_fail(self->priv->use_usbclerk);
> > - g_return_if_fail(SPICE_IS_WIN_USB_DRIVER(installer));
> > - g_return_if_fail(device!= NULL);
> > -
> > - SPICE_DEBUG("Win USB driver install finished");
> > -
> > - if (!spice_win_usb_driver_install_finish(installer, res, &err))
> > {
> > - g_warning("win usb driver install failed -- %s", err-
> > >message);
> > - g_error_free(err);
> > - }
> > -
> > - spice_usb_device_set_state(device,
> > SPICE_USB_DEVICE_STATE_INSTALLED);
> > -
> > - /* device is already ref'ed */
> > - _spice_usb_device_manager_connect_device_async(self,
> > - device,
> > - cancellable,
> > - _connect_device_
> > async_cb,
> > - data);
> > -
> > - spice_usb_device_unref(device);
> > -}
> > -
> > -static void spice_usb_device_manager_drv_uninstall_cb(GObject
> > *gobject,
> > - GAsyncResult
> > *res,
> > - gpointer
> > user_data)
> > -{
> > - GError *err = NULL;
> > -
> > - UsbInstallCbInfo *cbinfo = user_data;
> > - SpiceUsbDeviceManager *self = cbinfo->manager;
> > - SpiceUsbDevice *device = cbinfo->device;
> > - SpiceWinUsbDriver *installer = cbinfo->installer;
> > -
> > - g_free(cbinfo);
> > -
> > - SPICE_DEBUG("Win USB driver uninstall finished");
> > - g_return_if_fail(SPICE_IS_USB_DEVICE_MANAGER(self));
> > - g_return_if_fail(self->priv->use_usbclerk);
> > -
> > - if (!spice_win_usb_driver_uninstall_finish(installer, res,
> > &err)) {
> > - g_warning("win usb driver uninstall failed -- %s", err-
> > >message);
> > - g_clear_error(&err);
> > - }
> > -
> > - spice_usb_device_set_state(device,
> > SPICE_USB_DEVICE_STATE_NONE);
> > - spice_usb_device_unref(device);
> > -}
> > -
> > -#endif
> > -
> > /* ----------------------------------------------------------------
> > -- */
> > /* private
> > api */
> >
> > @@ -1518,68 +1365,6 @@ gboolean
> > spice_usb_device_manager_is_device_connected(SpiceUsbDeviceManager
> > *sel
> > return !!spice_usb_device_manager_get_channel_for_dev(self,
> > device);
> > }
> >
> > -#if defined(USE_USBREDIR) && defined(G_OS_WIN32)
> > -
> > -static void
> > -_spice_usb_device_manager_install_driver_async(SpiceUsbDeviceManage
> > r *self,
> > - SpiceUsbDevice
> > *device,
> > - GCancellable
> > *cancellable,
> > - GAsyncReadyCallback
> > callback,
> > - gpointer user_data)
> > -{
> > - SpiceWinUsbDriver *installer;
> > - UsbInstallCbInfo *cbinfo;
> > -
> > - g_return_if_fail(self->priv->installer);
> > -
> > - spice_usb_device_set_state(device,
> > SPICE_USB_DEVICE_STATE_INSTALLING);
> > -
> > - installer = self->priv->installer;
> > - cbinfo = g_new0(UsbInstallCbInfo, 1);
> > - cbinfo->manager = self;
> > - cbinfo->device = spice_usb_device_ref(device);
> > - cbinfo->installer = installer;
> > - cbinfo->cancellable = cancellable;
> > - cbinfo->callback = callback;
> > - cbinfo->user_data = user_data;
> > -
> > - spice_win_usb_driver_install_async(installer, device,
> > cancellable,
> > - spice_usb_device_manager_drv
> > _install_cb,
> > - cbinfo);
> > -}
> > -
> > -static void
> > -_spice_usb_device_manager_uninstall_driver_async(SpiceUsbDeviceMana
> > ger *self,
> > - SpiceUsbDevice
> > *device)
> > -{
> > - SpiceWinUsbDriver *installer;
> > - UsbInstallCbInfo *cbinfo;
> > - guint8 state;
> > -
> > - g_warn_if_fail(device != NULL);
> > - g_return_if_fail(self->priv->installer);
> > -
> > - state = spice_usb_device_get_state(device);
> > - if ((state != SPICE_USB_DEVICE_STATE_INSTALLED) &&
> > - (state != SPICE_USB_DEVICE_STATE_CONNECTED)) {
> > - return;
> > - }
> > -
> > - spice_usb_device_set_state(device,
> > SPICE_USB_DEVICE_STATE_UNINSTALLING);
> > -
> > - installer = self->priv->installer;
> > - cbinfo = g_new0(UsbInstallCbInfo, 1);
> > - cbinfo->manager = self;
> > - cbinfo->device = spice_usb_device_ref(device);
> > - cbinfo->installer = installer;
> > -
> > - spice_win_usb_driver_uninstall_async(installer, device, NULL,
> > - spice_usb_device_manager_d
> > rv_uninstall_cb,
> > - cbinfo);
> > -}
> > -
> > -#endif
> > -
> > #ifdef USE_USBREDIR
> >
> > static gboolean
> > @@ -1691,21 +1476,11 @@ void
> > spice_usb_device_manager_connect_device_async(SpiceUsbDeviceManager
> > *self,
> > g_task_new(G_OBJECT(self), cancellable, callback,
> > user_data);
> >
> > _set_redirecting(self, TRUE);
> > -
> > -#ifdef G_OS_WIN32
> > - if (self->priv->use_usbclerk) {
> > - _spice_usb_device_manager_install_driver_async(self,
> > device, cancellable,
> > - callback,
> > task);
> > - return;
> > - }
> > -#endif
> > -
> > _spice_usb_device_manager_connect_device_async(self,
> > device,
> > cancellable,
> > _connect_device_
> > async_cb,
> > task);
> > -
> > #endif
> > }
> >
> > @@ -1791,11 +1566,6 @@ void
> > spice_usb_device_manager_disconnect_device(SpiceUsbDeviceManager
> > *self,
> > if (channel)
> > spice_usbredir_channel_disconnect_device(channel);
> >
> > -#ifdef G_OS_WIN32
> > - if(self->priv->use_usbclerk)
> > - _spice_usb_device_manager_uninstall_driver_async(self,
> > device);
> > -#endif
> > -
> > #endif
> > }
> >
> > @@ -1817,12 +1587,6 @@ void _disconnect_device_async_cb(GObject
> > *gobject,
> > disconnect_cb_data *data = g_task_get_task_data(task);
> > SpiceUsbDeviceManager *self = SPICE_USB_DEVICE_MANAGER(data-
> > >self);
> >
> > -#ifdef G_OS_WIN32
> > - if (self->priv->use_usbclerk) {
> > - _spice_usb_device_manager_uninstall_driver_async(self,
> > data->device);
> > - }
> > -#endif
> > -
> > _set_redirecting(self, FALSE);
> >
> > spice_usbredir_channel_disconnect_device_finish(channel,
> > channel_res, &err);
> > @@ -2128,30 +1892,12 @@ gboolean
> > spice_usb_device_is_isochronous(const SpiceUsbDevice *device)
> > }
> >
> > #ifdef G_OS_WIN32
> > -void spice_usb_device_set_state(SpiceUsbDevice *device, guint8
> > state)
> > -{
> > - SpiceUsbDeviceInfo *info = (SpiceUsbDeviceInfo *)device;
> > -
> > - g_return_if_fail(info != NULL);
> > -
> > - info->state = state;
> > -}
> > -
> > -guint8 spice_usb_device_get_state(SpiceUsbDevice *device)
> > -{
> > - SpiceUsbDeviceInfo *info = (SpiceUsbDeviceInfo *)device;
> > -
> > - g_return_val_if_fail(info != NULL, 0);
> > -
> > - return info->state;
> > -}
> > -
> > static
> > gboolean _usbdk_hider_prepare(SpiceUsbDeviceManager *manager)
> > {
> > SpiceUsbDeviceManagerPrivate *priv = manager->priv;
> >
> > - g_return_val_if_fail(!priv->use_usbclerk, FALSE);
> > + g_return_val_if_fail(priv->usbdk_api != NULL, FALSE);
> >
> > if (priv->usbdk_hider_handle == NULL) {
> > priv->usbdk_hider_handle = usbdk_create_hider_handle(priv-
> > >usbdk_api);
> > @@ -2169,7 +1915,7 @@ void _usbdk_hider_clear(SpiceUsbDeviceManager
> > *manager)
> > {
> > SpiceUsbDeviceManagerPrivate *priv = manager->priv;
> >
> > - g_return_if_fail(!priv->use_usbclerk);
> > + g_return_if_fail(priv->usbdk_api != NULL);
> >
> > if (priv->usbdk_hider_handle != NULL) {
> > usbdk_clear_hide_rules(priv->usbdk_api, priv-
> > >usbdk_hider_handle);
> > @@ -2183,7 +1929,7 @@ void _usbdk_hider_update(SpiceUsbDeviceManager
> > *manager)
> > {
> > SpiceUsbDeviceManagerPrivate *priv = manager->priv;
> >
> > - g_return_if_fail(!priv->use_usbclerk);
> > + g_return_if_fail(priv->usbdk_api != NULL);
> >
> > if (priv->auto_connect_filter == NULL) {
> > SPICE_DEBUG("No autoredirect rules, no hider setup
> > needed");
> > @@ -2256,14 +2002,8 @@
> > spice_usb_manager_device_equal_libdev(SpiceUsbDeviceManager
> > *manager,
> > if ((device == NULL) || (libdev == NULL))
> > return FALSE;
> >
> > - if (manager->priv->use_usbclerk) {
> > - busnum = spice_usb_device_get_vid(device);
> > - devaddr = spice_usb_device_get_pid(device);
> > - } else {
> > - busnum = spice_usb_device_get_busnum(device);
> > - devaddr = spice_usb_device_get_devaddr(device);
> > - }
> > -
> > + busnum = spice_usb_device_get_busnum(device);
> > + devaddr = spice_usb_device_get_devaddr(device);
> > return spice_usb_device_manager_libdev_match(manager, libdev,
> > busnum, devaddr);
> > }
> > diff --git a/src/win-usb-clerk.h b/src/win-usb-clerk.h
> > deleted file mode 100644
> > index a17980d..0000000
> > --- a/src/win-usb-clerk.h
> > +++ /dev/null
> > @@ -1,36 +0,0 @@
> > -#ifndef _H_USBCLERK
> > -#define _H_USBCLERK
> > -
> > -#include <windows.h>
> > -
> > -#define USB_CLERK_PIPE_NAME TEXT("\\\\.\\pipe\\usbclerkpipe")
> > -#define USB_CLERK_MAGIC 0xDADAu
> > -#define USB_CLERK_VERSION 0x0003u
> > -
> > -typedef struct USBClerkHeader {
> > - UINT16 magic;
> > - UINT16 version;
> > - UINT16 type;
> > - UINT16 size;
> > -} USBClerkHeader;
> > -
> > -enum {
> > - USB_CLERK_DRIVER_INSTALL = 1,
> > - USB_CLERK_DRIVER_REMOVE,
> > - USB_CLERK_REPLY,
> > - USB_CLERK_DRIVER_SESSION_INSTALL,
> > - USB_CLERK_END_MESSAGE,
> > -};
> > -
> > -typedef struct USBClerkDriverOp {
> > - USBClerkHeader hdr;
> > - UINT16 vid;
> > - UINT16 pid;
> > -} USBClerkDriverOp;
> > -
> > -typedef struct USBClerkReply {
> > - USBClerkHeader hdr;
> > - UINT32 status;
> > -} USBClerkReply;
> > -
> > -#endif
> > diff --git a/src/win-usb-driver-install.c b/src/win-usb-driver-
> > install.c
> > deleted file mode 100644
> > index a72fcb8..0000000
> > --- a/src/win-usb-driver-install.c
> > +++ /dev/null
> > @@ -1,421 +0,0 @@
> > -/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
> > -/*
> > - Copyright (C) 2011 Red Hat, Inc.
> > -
> > - Red Hat Authors:
> > - Uri Lublin <uril at redhat.com>
> > -
> > - This library is free software; you can redistribute it and/or
> > - modify it under the terms of the GNU Lesser General Public
> > - License as published by the Free Software Foundation; either
> > - version 2.1 of the License, or (at your option) any later
> > version.
> > -
> > - This library is distributed in the hope that it will be useful,
> > - but WITHOUT ANY WARRANTY; without even the implied warranty of
> > - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > GNU
> > - Lesser General Public License for more details.
> > -
> > - You should have received a copy of the GNU Lesser General Public
> > - License along with this library; if not, see <http://www.gnu.org
> > /licenses/>.
> > -*/
> > -
> > -/*
> > - * Some notes:
> > - * Each installer (instance) opens a named-pipe to talk with win-
> > usb-clerk.
> > - * Each installer (instance) requests driver installation for a
> > single device.
> > - */
> > -
> > -#include "config.h"
> > -
> > -#include <windows.h>
> > -#include <gio/gio.h>
> > -#include <gio/gwin32inputstream.h>
> > -#include <gio/gwin32outputstream.h>
> > -#include "spice-util.h"
> > -#include "win-usb-clerk.h"
> > -#include "win-usb-driver-install.h"
> > -#include "usb-device-manager-priv.h"
> > -
> > -/* ----------------------------------------------------------------
> > -- */
> > -/* gobject
> > glue */
> > -
> > -#define SPICE_WIN_USB_DRIVER_GET_PRIVATE(obj) \
> > - (G_TYPE_INSTANCE_GET_PRIVATE ((obj), SPICE_TYPE_WIN_USB_DRIVER,
> > SpiceWinUsbDriverPrivate))
> > -
> > -struct _SpiceWinUsbDriverPrivate {
> > - USBClerkReply reply;
> > - GTask *task;
> > - HANDLE handle;
> > - SpiceUsbDevice *device;
> > -};
> > -
> > -
> > -static void spice_win_usb_driver_initable_iface_init(GInitableIface
> > *iface);
> > -
> > -G_DEFINE_TYPE_WITH_CODE(SpiceWinUsbDriver, spice_win_usb_driver,
> > G_TYPE_OBJECT,
> > - G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
> > spice_win_usb_driver_initable_iface_init));
> > -
> > -static void spice_win_usb_driver_init(SpiceWinUsbDriver *self)
> > -{
> > - self->priv = SPICE_WIN_USB_DRIVER_GET_PRIVATE(self);
> > -}
> > -
> > -static gboolean
> > spice_win_usb_driver_initable_init(GInitable *initable,
> > - GCancellable *c
> > ancellable,
> > - GError **
> > err)
> > -{
> > - SpiceWinUsbDriver *self = SPICE_WIN_USB_DRIVER(initable);
> > - SpiceWinUsbDriverPrivate *priv = self->priv;
> > -
> > - SPICE_DEBUG("win-usb-driver-install: connecting to usbclerk
> > named pipe");
> > - priv->handle = CreateFile(USB_CLERK_PIPE_NAME,
> > - GENERIC_READ | GENERIC_WRITE,
> > - 0, NULL,
> > - OPEN_EXISTING,
> > - FILE_ATTRIBUTE_NORMAL |
> > FILE_FLAG_OVERLAPPED,
> > - NULL);
> > - if (priv->handle == INVALID_HANDLE_VALUE) {
> > - DWORD errval = GetLastError();
> > - gchar *errstr = g_win32_error_message(errval);
> > - g_set_error(err, SPICE_CLIENT_ERROR,
> > SPICE_CLIENT_ERROR_USB_SERVICE,
> > - "Failed to create service named pipe (%lu) %s",
> > errval, errstr);
> > - g_free(errstr);
> > - return FALSE;
> > - }
> > -
> > - return TRUE;
> > -}
> > -
> > -static void spice_win_usb_driver_finalize(GObject *gobject)
> > -{
> > - SpiceWinUsbDriver *self = SPICE_WIN_USB_DRIVER(gobject);
> > - SpiceWinUsbDriverPrivate *priv = self->priv;
> > -
> > - if (priv->handle)
> > - CloseHandle(priv->handle);
> > -
> > - g_clear_object(&priv->task);
> > -
> > - if (G_OBJECT_CLASS(spice_win_usb_driver_parent_class)-
> > >finalize)
> > - G_OBJECT_CLASS(spice_win_usb_driver_parent_class)-
> > >finalize(gobject);
> > -}
> > -
> > -static void spice_win_usb_driver_class_init(SpiceWinUsbDriverClass
> > *klass)
> > -{
> > - GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
> > -
> > - gobject_class->finalize = spice_win_usb_driver_finalize;
> > -
> > - g_type_class_add_private(klass,
> > sizeof(SpiceWinUsbDriverPrivate));
> > -}
> > -
> > -static void spice_win_usb_driver_initable_iface_init(GInitableIface
> > *iface)
> > -{
> > - iface->init = spice_win_usb_driver_initable_init;
> > -}
> > -
> > -/* ----------------------------------------------------------------
> > -- */
> > -/*
> > callbacks *
> > /
> > -
> > -static
> > -void win_usb_driver_handle_reply_cb(GObject *gobject,
> > - GAsyncResult *read_res,
> > - gpointer user_data)
> > -{
> > - SpiceWinUsbDriver *self;
> > - SpiceWinUsbDriverPrivate *priv;
> > -
> > - GInputStream *istream;
> > - GError *err = NULL;
> > - gssize bytes;
> > -
> > - g_return_if_fail(SPICE_IS_WIN_USB_DRIVER(user_data));
> > - self = SPICE_WIN_USB_DRIVER(user_data);
> > - priv = self->priv;
> > - istream = G_INPUT_STREAM(gobject);
> > -
> > - bytes = g_input_stream_read_finish(istream, read_res, &err);
> > -
> > - SPICE_DEBUG("Finished reading reply-msg from usbclerk:
> > bytes=%ld "
> > - "err_exist?=%d", (long)bytes, err!=NULL);
> > -
> > - g_warn_if_fail(g_input_stream_close(istream, NULL, NULL));
> > - g_clear_object(&istream);
> > -
> > - if (err) {
> > - g_warning("failed to read reply from usbclerk (%s)", err-
> > >message);
> > - g_task_return_error(priv->task, err);
> > - goto failed_reply;
> > - }
> > -
> > - if (bytes == 0) {
> > - g_warning("unexpected EOF from usbclerk");
> > - g_task_return_new_error(priv->task,
> > - SPICE_WIN_USB_DRIVER_ERROR,
> > - SPICE_WIN_USB_DRIVER_ERROR_FAILED,
> > - "unexpected EOF from usbclerk");
> > - goto failed_reply;
> > - }
> > -
> > - if (bytes != sizeof(priv->reply)) {
> > - g_warning("usbclerk size mismatch: read %"G_GSSIZE_FORMAT"
> > bytes,expected "
> > - "%"G_GSSIZE_FORMAT" (header %"G_GSSIZE_FORMAT",
> > size in header %d)",
> > - bytes, sizeof(priv->reply), sizeof(priv-
> > >reply.hdr), priv->reply.hdr.size);
> > - /* For now just warn, do not fail */
> > - }
> > -
> > - if (priv->reply.hdr.magic != USB_CLERK_MAGIC) {
> > - g_warning("usbclerk magic mismatch:
> > mine=0x%04x server=0x%04x",
> > - USB_CLERK_MAGIC, priv->reply.hdr.magic);
> > - g_task_return_new_error(priv->task,
> > - SPICE_WIN_USB_DRIVER_ERROR,
> > - SPICE_WIN_USB_DRIVER_ERROR_MESSAGE,
> > - "usbclerk magic mismatch");
> > - goto failed_reply;
> > - }
> > -
> > - if (priv->reply.hdr.version != USB_CLERK_VERSION) {
> > - g_warning("usbclerk version mismatch:
> > mine=0x%04x server=0x%04x",
> > - USB_CLERK_VERSION, priv->reply.hdr.version);
> > - g_task_return_new_error(priv->task,
> > - SPICE_WIN_USB_DRIVER_ERROR,
> > - SPICE_WIN_USB_DRIVER_ERROR_MESSAGE,
> > - "usbclerk version mismatch");
> > - }
> > -
> > - if (priv->reply.hdr.type != USB_CLERK_REPLY) {
> > - g_warning("usbclerk message with unexpected type %d",
> > - priv->reply.hdr.type);
> > - g_task_return_new_error(priv->task,
> > - SPICE_WIN_USB_DRIVER_ERROR,
> > - SPICE_WIN_USB_DRIVER_ERROR_MESSAGE,
> > - "usbclerk message with unexpected
> > type");
> > - goto failed_reply;
> > - }
> > -
> > - if (priv->reply.hdr.size != bytes) {
> > - g_warning("usbclerk message size mismatch: read
> > %"G_GSSIZE_FORMAT" bytes hdr.size=%d",
> > - bytes, priv->reply.hdr.size);
> > - g_task_return_new_error(priv->task,
> > - SPICE_WIN_USB_DRIVER_ERROR,
> > - SPICE_WIN_USB_DRIVER_ERROR_MESSAGE,
> > - "usbclerk message with unexpected
> > size");
> > - goto failed_reply;
> > - }
> > -
> > - if (priv->reply.status == 0) {
> > - g_task_return_new_error(priv->task,
> > - SPICE_WIN_USB_DRIVER_ERROR,
> > - SPICE_WIN_USB_DRIVER_ERROR_MESSAGE,
> > - "usbclerk error reply");
> > - goto failed_reply;
> > - }
> > -
> > - g_task_return_boolean (priv->task, TRUE);
> > -
> > - failed_reply:
> > - g_clear_object(&priv->task);
> > -}
> > -
> > -/* ----------------------------------------------------------------
> > -- */
> > -/* helper
> > functions */
> > -
> > -static
> > -gboolean spice_win_usb_driver_send_request(SpiceWinUsbDriver *self,
> > guint16 op,
> > - guint16 vid, guint16
> > pid, GError **err)
> > -{
> > - USBClerkDriverOp req;
> > - GOutputStream *ostream;
> > - SpiceWinUsbDriverPrivate *priv;
> > - gsize bytes;
> > - gboolean ret;
> > -
> > - SPICE_DEBUG("sending a request to usbclerk service (op=%d
> > vid=0x%04x pid=0x%04x",
> > - op, vid, pid);
> > -
> > - g_return_val_if_fail(SPICE_IS_WIN_USB_DRIVER(self), FALSE);
> > - priv = self->priv;
> > -
> > - memset(&req, 0, sizeof(req));
> > - req.hdr.magic = USB_CLERK_MAGIC;
> > - req.hdr.version = USB_CLERK_VERSION;
> > - req.hdr.type = op;
> > - req.hdr.size = sizeof(req);
> > - req.vid = vid;
> > - req.pid = pid;
> > -
> > - ostream = g_win32_output_stream_new(priv->handle, FALSE);
> > -
> > - ret = g_output_stream_write_all(ostream, &req, sizeof(req),
> > &bytes, NULL, err);
> > - g_warn_if_fail(g_output_stream_close(ostream, NULL, NULL));
> > - g_object_unref(ostream);
> > - SPICE_DEBUG("write_all request returned %d written bytes
> > %"G_GSIZE_FORMAT
> > - " expecting %"G_GSIZE_FORMAT,
> > - ret, bytes, sizeof(req));
> > - return ret;
> > -}
> > -
> > -static
> > -void spice_win_usb_driver_read_reply_async(SpiceWinUsbDriver *self)
> > -{
> > - SpiceWinUsbDriverPrivate *priv;
> > - GInputStream *istream;
> > -
> > - g_return_if_fail(SPICE_IS_WIN_USB_DRIVER(self));
> > - priv = self->priv;
> > -
> > - SPICE_DEBUG("waiting for a reply from usbclerk");
> > -
> > - istream = g_win32_input_stream_new(priv->handle, FALSE);
> > -
> > - g_input_stream_read_async(istream, &priv->reply, sizeof(priv-
> > >reply),
> > - G_PRIORITY_DEFAULT,
> > - g_task_get_cancellable(priv->task),
> > - win_usb_driver_handle_reply_cb,
> > self);
> > -}
> > -
> > -
> > -/* ----------------------------------------------------------------
> > -- */
> > -/* private
> > api */
> > -
> > -
> > -G_GNUC_INTERNAL
> > -SpiceWinUsbDriver *spice_win_usb_driver_new(GError **err)
> > -{
> > - GObject *self;
> > -
> > - g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
> > -
> > - self = g_initable_new(SPICE_TYPE_WIN_USB_DRIVER, NULL, err,
> > NULL);
> > -
> > - return SPICE_WIN_USB_DRIVER(self);
> > -}
> > -
> > -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;
> > - GTask *task;
> > - SpiceWinUsbDriverPrivate *priv;
> > -
> > - g_return_if_fail(SPICE_IS_WIN_USB_DRIVER(self));
> > - g_return_if_fail(device != NULL);
> > -
> > - priv = self->priv;
> > -
> > - task = g_task_new(self, cancellable, callback, user_data);
> > -
> > - if (priv->task) { /* allow one install/uninstall request at a
> > time */
> > - g_warning("Another request exists -- try later");
> > - g_task_return_new_error(task,
> > - SPICE_WIN_USB_DRIVER_ERROR,
> > SPICE_WIN_USB_DRIVER_ERROR_FAILED,
> > - "Another request exists -- try later");
> > - goto failed_request;
> > - }
> > -
> > -
> > - vid = spice_usb_device_get_vid(device);
> > - pid = spice_usb_device_get_pid(device);
> > -
> > - 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_task_return_error(task, err);
> > - goto failed_request;
> > - }
> > -
> > - /* set up for async read */
> > - priv->task = task;
> > - priv->device = device;
> > -
> > - spice_win_usb_driver_read_reply_async(self);
> > -
> > - return;
> > -
> > - failed_request:
> > - g_clear_object(&task);
> > -}
> > -
> > -/*
> > - * Returns: currently returns 0 (failure) and 1 (success)
> > - * possibly later we'll add error-codes
> > - */
> > -static gboolean
> > -spice_win_usb_driver_op_finish(SpiceWinUsbDriver *self,
> > - GAsyncResult *res, GError **err)
> > -{
> > - GTask *task = G_TASK(res);
> > -
> > - g_return_val_if_fail(SPICE_IS_WIN_USB_DRIVER(self), 0);
> > - g_return_val_if_fail(g_task_is_valid(task, self), FALSE);
> > -
> > - return g_task_propagate_boolean(task, err);
> > -}
> > -
> > -/**
> > - * spice_win_usb_driver_install_async:
> > - * 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_async(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_SESSION_INSTALL,
> > - cancellable, callback, user_data);
> > -}
> > -
> > -G_GNUC_INTERNAL
> > -void spice_win_usb_driver_uninstall_async(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);
> > -}
> > -
> > -G_GNUC_INTERNAL
> > -gboolean spice_win_usb_driver_install_finish(SpiceWinUsbDriver
> > *self,
> > - GAsyncResult *res, GError
> > **err)
> > -{
> > - return spice_win_usb_driver_op_finish(self, res, err);
> > -}
> > -
> > -G_GNUC_INTERNAL
> > -gboolean 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);
> > -
> > - return self->priv->device;
> > -}
> > -
> > -GQuark spice_win_usb_driver_error_quark(void)
> > -{
> > - return g_quark_from_static_string("spice-win-usb-driver-error-
> > quark");
> > -}
> > diff --git a/src/win-usb-driver-install.h b/src/win-usb-driver-
> > install.h
> > deleted file mode 100644
> > index f9afedc..0000000
> > --- a/src/win-usb-driver-install.h
> > +++ /dev/null
> > @@ -1,106 +0,0 @@
> > -/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
> > -/*
> > - Copyright (C) 2011 Red Hat, Inc.
> > -
> > - Red Hat Authors:
> > - Uri Lublin <uril at redhat.com>
> > -
> > - This library is free software; you can redistribute it and/or
> > - modify it under the terms of the GNU Lesser General Public
> > - License as published by the Free Software Foundation; either
> > - version 2.1 of the License, or (at your option) any later
> > version.
> > -
> > - This library is distributed in the hope that it will be useful,
> > - but WITHOUT ANY WARRANTY; without even the implied warranty of
> > - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > GNU
> > - Lesser General Public License for more details.
> > -
> > - You should have received a copy of the GNU Lesser General Public
> > - License along with this library; if not, see <http://www.gnu.org
> > /licenses/>.
> > -*/
> > -
> > -#ifndef SPICE_WIN_USB_DRIVER_H
> > -#define SPICE_WIN_USB_DRIVER_H
> > -
> > -#include "usb-device-manager.h"
> > -
> > -G_BEGIN_DECLS
> > -
> > -GQuark win_usb_driver_error_quark(void);
> > -
> > -
> > -#define
> > SPICE_TYPE_WIN_USB_DRIVER (spice_win_usb_driver_get_type ())
> > -#define SPICE_WIN_USB_DRIVER(obj) (G_TYPE_CHECK_INSTANCE_CAST
> > ((obj), \
> > - SPICE_TYPE_WIN_USB_DRIVER, SpiceWinUsbDriver))
> > -#define SPICE_IS_WIN_USB_DRIVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE
> > ((obj), \
> > - SPICE_TYPE_WIN_USB_DRIVER))
> > -#define SPICE_WIN_USB_DRIVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST
> > ((klass), \
> > - SPICE_TYPE_WIN_USB_DRIVER, SpiceWinUsbDriverClass))
> > -#define SPICE_IS_WIN_USB_DRIVER_CLASS(klass)
> > (G_TYPE_CHECK_CLASS_TYPE ((klass),\
> > - SPICE_TYPE_WIN_USB_DRIVER))
> > -#define SPICE_WIN_USB_DRIVER_GET_CLASS(obj)
> > (G_TYPE_INSTANCE_GET_CLASS ((obj),\
> > - SPICE_TYPE_WIN_USB_DRIVER, SpiceWinUsbDriverClass))
> > -
> > -typedef struct _SpiceWinUsbDriver SpiceWinUsbDriver;
> > -typedef struct _SpiceWinUsbDriverClass SpiceWinUsbDriverClass;
> > -typedef struct
> > _SpiceWinUsbDriverPrivate SpiceWinUsbDriverPrivate;
> > -
> > -struct _SpiceWinUsbDriver
> > -{
> > - GObject parent;
> > -
> > - /*< private >*/
> > - SpiceWinUsbDriverPrivate *priv;
> > - /* Do not add fields to this struct */
> > -};
> > -
> > -struct _SpiceWinUsbDriverClass
> > -{
> > - GObjectClass parent_class;
> > -};
> > -
> > -GType spice_win_usb_driver_get_type(void);
> > -
> > -SpiceWinUsbDriver *spice_win_usb_driver_new(GError **err);
> > -
> > -
> > -void spice_win_usb_driver_install_async(SpiceWinUsbDriver *self,
> > - SpiceUsbDevice *device,
> > - GCancellable *cancellable,
> > - GAsyncReadyCallback
> > callback,
> > - gpointer user_data);
> > -gboolean spice_win_usb_driver_install_finish(SpiceWinUsbDriver
> > *self,
> > - GAsyncResult *res,
> > GError **err);
> > -
> > -void spice_win_usb_driver_uninstall_async(SpiceWinUsbDriver *self,
> > - SpiceUsbDevice *device,
> > - GCancellable
> > *cancellable,
> > - GAsyncReadyCallback
> > callback,
> > - gpointer user_data);
> > -gboolean spice_win_usb_driver_uninstall_finish(SpiceWinUsbDriver
> > *self,
> > - GAsyncResult *res,
> > GError **err);
> > -
> > -
> > -
> > -SpiceUsbDevice *spice_win_usb_driver_get_device(SpiceWinUsbDriver
> > *self);
> > -
> > -#define SPICE_WIN_USB_DRIVER_ERROR
> > spice_win_usb_driver_error_quark()
> > -
> > -/**
> > - * SpiceWinUsbDriverError:
> > - * @SPICE_WIN_USB_DRIVER_ERROR_FAILED: generic error code
> > - * @SPICE_WIN_USB_DRIVER_ERROR_MESSAGE: bad message read from clerk
> > - *
> > - * Error codes returned by spice-client API.
> > - */
> > -typedef enum
> > -{
> > - SPICE_WIN_USB_DRIVER_ERROR_FAILED,
> > - SPICE_WIN_USB_DRIVER_ERROR_MESSAGE,
> > -} SpiceWinUsbDriverError;
> > -
> > -GQuark spice_win_usb_driver_error_quark(void);
> > -
> > -G_END_DECLS
> > -
> > -#endif /* SPICE_WIN_USB_DRIVER_H */
>
> it looks good to me.
>
> Pavel
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20161219/4bafd181/attachment-0001.sig>
More information about the Spice-devel
mailing list