[Spice-devel] [PATCH spice-gtk] usb-device-manager: Define _SpiceUsbDevice instead of SpiceUsbDeviceInfo
Frediano Ziglio
fziglio at redhat.com
Wed May 29 09:15:03 UTC 2019
ping
>
> SpiceUsbDevice* was converted to SpiceUsbDeviceInfo* as _SpiceUsbDevice
> was never defines. Define instead the structure to avoid useless
> casts.
>
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
> src/usb-device-manager.c | 59 ++++++++++++++--------------------------
> 1 file changed, 20 insertions(+), 39 deletions(-)
>
> diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
> index bd421426..acb4659e 100644
> --- a/src/usb-device-manager.c
> +++ b/src/usb-device-manager.c
> @@ -130,7 +130,7 @@ enum {
>
> #ifdef USE_USBREDIR
>
> -typedef struct _SpiceUsbDeviceInfo {
> +struct _SpiceUsbDevice {
> guint8 busnum;
> guint8 devaddr;
> guint16 vid;
> @@ -138,7 +138,7 @@ typedef struct _SpiceUsbDeviceInfo {
> gboolean isochronous;
> libusb_device *libdev;
> gint ref;
> -} SpiceUsbDeviceInfo;
> +};
>
>
> static void channel_new(SpiceSession *session, SpiceChannel *channel,
> @@ -161,7 +161,7 @@ static int
> spice_usb_device_manager_hotplug_cb(libusb_context *ctx,
> static void spice_usb_device_manager_check_redir_on_connect(
> SpiceUsbDeviceManager *self, SpiceChannel *channel);
>
> -static SpiceUsbDeviceInfo *spice_usb_device_new(libusb_device *libdev);
> +static SpiceUsbDevice *spice_usb_device_new(libusb_device *libdev);
> static SpiceUsbDevice *spice_usb_device_ref(SpiceUsbDevice *device);
> static void spice_usb_device_unref(SpiceUsbDevice *device);
>
> @@ -751,11 +751,9 @@ static gboolean
> spice_usb_device_manager_get_device_descriptor(
> * Since: 0.27
> **/
> gconstpointer
> -spice_usb_device_get_libusb_device(const SpiceUsbDevice *device
> G_GNUC_UNUSED)
> +spice_usb_device_get_libusb_device(const SpiceUsbDevice *info G_GNUC_UNUSED)
> {
> #ifdef USE_USBREDIR
> - const SpiceUsbDeviceInfo *info = (const SpiceUsbDeviceInfo *)device;
> -
> g_return_val_if_fail(info != NULL, FALSE);
>
> return info->libdev;
> @@ -1724,11 +1722,11 @@ static gboolean
> probe_isochronous_endpoint(libusb_device *libdev)
> }
>
> /*
> - * SpiceUsbDeviceInfo
> + * SpiceUsbDevice
> */
> -static SpiceUsbDeviceInfo *spice_usb_device_new(libusb_device *libdev)
> +static SpiceUsbDevice *spice_usb_device_new(libusb_device *libdev)
> {
> - SpiceUsbDeviceInfo *info;
> + SpiceUsbDevice *info;
> int vid, pid;
> guint8 bus, addr;
>
> @@ -1741,7 +1739,7 @@ static SpiceUsbDeviceInfo
> *spice_usb_device_new(libusb_device *libdev)
> return NULL;
> }
>
> - info = g_new0(SpiceUsbDeviceInfo, 1);
> + info = g_new0(SpiceUsbDevice, 1);
>
> info->busnum = bus;
> info->devaddr = addr;
> @@ -1754,46 +1752,36 @@ static SpiceUsbDeviceInfo
> *spice_usb_device_new(libusb_device *libdev)
> return info;
> }
>
> -guint8 spice_usb_device_get_busnum(const SpiceUsbDevice *device)
> +guint8 spice_usb_device_get_busnum(const SpiceUsbDevice *info)
> {
> - const SpiceUsbDeviceInfo *info = (const SpiceUsbDeviceInfo *)device;
> -
> g_return_val_if_fail(info != NULL, 0);
>
> return info->busnum;
> }
>
> -guint8 spice_usb_device_get_devaddr(const SpiceUsbDevice *device)
> +guint8 spice_usb_device_get_devaddr(const SpiceUsbDevice *info)
> {
> - const SpiceUsbDeviceInfo *info = (const SpiceUsbDeviceInfo *)device;
> -
> g_return_val_if_fail(info != NULL, 0);
>
> return info->devaddr;
> }
>
> -guint16 spice_usb_device_get_vid(const SpiceUsbDevice *device)
> +guint16 spice_usb_device_get_vid(const SpiceUsbDevice *info)
> {
> - const SpiceUsbDeviceInfo *info = (const SpiceUsbDeviceInfo *)device;
> -
> g_return_val_if_fail(info != NULL, 0);
>
> return info->vid;
> }
>
> -guint16 spice_usb_device_get_pid(const SpiceUsbDevice *device)
> +guint16 spice_usb_device_get_pid(const SpiceUsbDevice *info)
> {
> - const SpiceUsbDeviceInfo *info = (const SpiceUsbDeviceInfo *)device;
> -
> g_return_val_if_fail(info != NULL, 0);
>
> return info->pid;
> }
>
> -gboolean spice_usb_device_is_isochronous(const SpiceUsbDevice *device)
> +gboolean spice_usb_device_is_isochronous(const SpiceUsbDevice *info)
> {
> - const SpiceUsbDeviceInfo *info = (const SpiceUsbDeviceInfo *)device;
> -
> g_return_val_if_fail(info != NULL, 0);
>
> return info->isochronous;
> @@ -1866,21 +1854,17 @@ void _usbdk_hider_update(SpiceUsbDeviceManager
> *manager)
>
> #endif
>
> -static SpiceUsbDevice *spice_usb_device_ref(SpiceUsbDevice *device)
> +static SpiceUsbDevice *spice_usb_device_ref(SpiceUsbDevice *info)
> {
> - SpiceUsbDeviceInfo *info = (SpiceUsbDeviceInfo *)device;
> -
> g_return_val_if_fail(info != NULL, NULL);
> g_atomic_int_inc(&info->ref);
> - return device;
> + return info;
> }
>
> -static void spice_usb_device_unref(SpiceUsbDevice *device)
> +static void spice_usb_device_unref(SpiceUsbDevice *info)
> {
> gboolean ref_count_is_0;
>
> - SpiceUsbDeviceInfo *info = (SpiceUsbDeviceInfo *)device;
> -
> g_return_if_fail(info != NULL);
>
> ref_count_is_0 = g_atomic_int_dec_and_test(&info->ref);
> @@ -1892,13 +1876,12 @@ static void spice_usb_device_unref(SpiceUsbDevice
> *device)
>
> static gboolean
> spice_usb_manager_device_equal_libdev(SpiceUsbDeviceManager *manager,
> - SpiceUsbDevice *device,
> + SpiceUsbDevice *info,
> libusb_device *libdev)
> {
> - SpiceUsbDeviceInfo *info = (SpiceUsbDeviceInfo *)device;
> -
> - if ((device == NULL) || (libdev == NULL))
> + if (info == NULL || libdev == NULL) {
> return FALSE;
> + }
>
> return info->libdev == libdev;
> }
> @@ -1909,11 +1892,9 @@
> spice_usb_manager_device_equal_libdev(SpiceUsbDeviceManager *manager,
> */
> static libusb_device *
> spice_usb_device_manager_device_to_libdev(SpiceUsbDeviceManager *self,
> - SpiceUsbDevice *device)
> + SpiceUsbDevice *info)
> {
> /* Simply return a ref to the cached libdev */
> - SpiceUsbDeviceInfo *info = (SpiceUsbDeviceInfo *)device;
> -
> return libusb_ref_device(info->libdev);
> }
> #endif /* USE_USBREDIR */
More information about the Spice-devel
mailing list