[Spice-devel] [spice-gtk 11/13] win-usb-dev: report libusb_device via signal

Christophe Fergeau cfergeau at redhat.com
Tue Mar 12 17:30:11 UTC 2019


Maybe "win-usb-dev: pass libusb_device in "uevent" signal" as a
shortlog.

On Sun, Mar 10, 2019 at 04:46:10PM +0200, Yuri Benditovich wrote:
> Change the signal to report libusb_device instead of GUdevDevice
> object. This simplifies the callback procedure in usb-dev-manager
> and avoids additional reenumeration immediately after reenumeration
> that already done by win-usb-dev.
> 
> Signed-off-by: Yuri Benditovich <yuri.benditovich at daynix.com>
> ---
>  src/usb-device-manager.c | 81 +++-------------------------------------
>  src/win-usb-dev.c        | 48 +-----------------------
>  src/win-usb-dev.h        |  2 +-
>  3 files changed, 8 insertions(+), 123 deletions(-)
> 
> diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
> index c1a0c92..f4910b1 100644
> --- a/src/usb-device-manager.c
> +++ b/src/usb-device-manager.c
> @@ -153,11 +153,9 @@ static void channel_event(SpiceChannel *channel, SpiceChannelEvent event,
>                            gpointer user_data);
>  #ifdef G_OS_WIN32
>  static void spice_usb_device_manager_uevent_cb(GUdevClient     *client,
> -                                               GUdevDevice     *udevice,
> +                                               libusb_device   *udevice,
>                                                 int              add,
>                                                 gpointer         user_data);
> -static void spice_usb_device_manager_add_udev(SpiceUsbDeviceManager  *self,
> -                                              GUdevDevice            *udev);
>  #else
>  static int spice_usb_device_manager_hotplug_cb(libusb_context       *ctx,
>                                                 libusb_device        *device,
> @@ -720,28 +718,6 @@ static void spice_usb_device_manager_class_init(SpiceUsbDeviceManagerClass *klas
>  /* ------------------------------------------------------------------ */
>  /* gudev / libusb Helper functions                                    */
>  
> -#ifdef G_OS_WIN32
> -static gboolean spice_usb_device_manager_get_udev_bus_n_address(
> -    SpiceUsbDeviceManager *manager, GUdevDevice *udev,
> -    int *bus, int *address)
> -{
> -    const gchar *bus_str, *address_str;
> -
> -    *bus = *address = 0;
> -
> -   /* 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)
> -        *address = atoi(address_str);
> -
> -    return *bus && *address;
> -}
> -#endif
> -
>  static gboolean spice_usb_device_manager_get_device_descriptor(
>      libusb_device *libdev,
>      struct libusb_device_descriptor *desc)
> @@ -1022,64 +998,19 @@ static void spice_usb_device_manager_remove_dev(SpiceUsbDeviceManager *self,
>  }
>  
>  #ifdef G_OS_WIN32
> -static void spice_usb_device_manager_add_udev(SpiceUsbDeviceManager  *self,
> -                                              GUdevDevice            *udev)
> -{
> -    SpiceUsbDeviceManagerPrivate *priv = self->priv;
> -    libusb_device *libdev = NULL, **dev_list = NULL;
> -    const gchar *devtype;
> -    int i, bus, address;
> -
> -    devtype = g_udev_device_get_property(udev, "DEVTYPE");
> -    /* Check if this is a usb device (and not an interface) */
> -    if (!devtype || strcmp(devtype, "usb_device"))
> -        return;
> -
> -    if (!spice_usb_device_manager_get_udev_bus_n_address(self, udev, &bus, &address)) {
> -        g_warning("USB device without bus number or device address");
> -        return;
> -    }
> -
> -    libusb_get_device_list(priv->context, &dev_list);
> -
> -    for (i = 0; dev_list && dev_list[i]; i++) {
> -        if (spice_usb_device_manager_libdev_match(self, dev_list[i], bus, address)) {
> -            libdev = dev_list[i];
> -            break;
> -        }
> -    }
> -
> -    if (libdev)
> -        spice_usb_device_manager_add_dev(self, libdev);
> -    else
> -        g_warning("Could not find USB device to add " DEV_ID_FMT,
> -                  (guint) bus, (guint) address);
> -
> -    libusb_free_device_list(dev_list, 1);
> -}
> -
> -static void spice_usb_device_manager_remove_udev(SpiceUsbDeviceManager  *self,
> -                                                 GUdevDevice            *udev)
> -{
> -    int bus, address;
> -
> -    if (!spice_usb_device_manager_get_udev_bus_n_address(self, udev, &bus, &address))
> -        return;
> -
> -    spice_usb_device_manager_remove_dev(self, bus, address);
> -}
> -
>  static void spice_usb_device_manager_uevent_cb(GUdevClient     *client,
> -                                               GUdevDevice     *udevice,
> +                                               libusb_device   *dev,
>                                                 int              add,
>                                                 gpointer         user_data)
>  {
>      SpiceUsbDeviceManager *self = SPICE_USB_DEVICE_MANAGER(user_data);
>  
>      if (add)
> -        spice_usb_device_manager_add_udev(self, udevice);
> +        spice_usb_device_manager_add_dev(self, dev);
>      else
> -        spice_usb_device_manager_remove_udev(self, udevice);
> +        spice_usb_device_manager_remove_dev(self,
> +                                libusb_get_bus_number(dev),
> +                                libusb_get_device_address(dev));

indentation

>  }
>  #else
>  struct hotplug_idle_cb_args {
> diff --git a/src/win-usb-dev.c b/src/win-usb-dev.c
> index 5d878ea..f42ab86 100644
> --- a/src/win-usb-dev.c
> +++ b/src/win-usb-dev.c
> @@ -83,9 +83,7 @@ enum
>  static guint signals[LAST_SIGNAL] = { 0, };
>  static GUdevClient *singleton = NULL;
>  
> -static GUdevDevice *g_udev_device_new(GUdevDeviceInfo *udevinfo);
>  static LRESULT CALLBACK wnd_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
> -static gboolean get_usb_dev_info(libusb_device *dev, GUdevDeviceInfo *udevinfo);
>  
>  //uncomment to debug gudev device lists.
>  //#define DEBUG_GUDEV_DEVICE_LISTS
> @@ -249,15 +247,7 @@ static void g_udev_client_initable_iface_init(GInitableIface *iface)
>  
>  static void g_udev_notify_device(GUdevClient *self, libusb_device *dev, int add)
>  {
> -    GUdevDeviceInfo *udevinfo;
> -    GUdevDevice *udevice;
> -    udevinfo = g_new0(GUdevDeviceInfo, 1);
> -    if (get_usb_dev_info(dev, udevinfo)) {
> -        udevice = g_udev_device_new(udevinfo);
> -        g_signal_emit(self, signals[UEVENT_SIGNAL], 0, udevice, add);
> -    } else {
> -        g_free(udevinfo);
> -    }
> +    g_signal_emit(self, signals[UEVENT_SIGNAL], 0, dev, add);

I'd remove g_udev_notify_device and just put these g_signal_emit() where
needed in the code (as was done before the previous commit).

Apart from these,

Acked-by: Christophe Fergeau <cfergeau at redhat.com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20190312/7a637277/attachment-0001.sig>


More information about the Spice-devel mailing list