[Spice-devel] [PATCH spice-gtk 3/3] usb-device-manager: Use SpiceUsbBackendDevice directly instead of SpiceUsbDevice
Frediano Ziglio
fziglio at redhat.com
Thu Jul 25 13:43:53 UTC 2019
They were the same structure.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
src/usb-backend.c | 6 +++---
src/usb-backend.h | 6 +++---
src/usb-device-manager.c | 42 +++++++++++-----------------------------
3 files changed, 17 insertions(+), 37 deletions(-)
diff --git a/src/usb-backend.c b/src/usb-backend.c
index 7e0e4a8a..26bda8b9 100644
--- a/src/usb-backend.c
+++ b/src/usb-backend.c
@@ -44,7 +44,7 @@
#define LOUD_DEBUG(x, ...)
-struct _SpiceUsbBackendDevice
+struct _SpiceUsbDevice
{
libusb_device *libusb_device;
gint ref_count;
@@ -512,12 +512,12 @@ void spice_usb_backend_delete(SpiceUsbBackend *be)
SPICE_DEBUG("%s <<", __FUNCTION__);
}
-const UsbDeviceInformation* spice_usb_backend_device_get_info(SpiceUsbBackendDevice *dev)
+const UsbDeviceInformation* spice_usb_backend_device_get_info(const SpiceUsbBackendDevice *dev)
{
return &dev->device_info;
}
-gconstpointer spice_usb_backend_device_get_libdev(SpiceUsbBackendDevice *dev)
+gconstpointer spice_usb_backend_device_get_libdev(const SpiceUsbBackendDevice *dev)
{
return dev->libusb_device;
}
diff --git a/src/usb-backend.h b/src/usb-backend.h
index 69a490b5..6eb02cb5 100644
--- a/src/usb-backend.h
+++ b/src/usb-backend.h
@@ -28,7 +28,7 @@
G_BEGIN_DECLS
typedef struct _SpiceUsbBackend SpiceUsbBackend;
-typedef struct _SpiceUsbBackendDevice SpiceUsbBackendDevice;
+typedef struct _SpiceUsbDevice SpiceUsbBackendDevice;
typedef struct _SpiceUsbBackendChannel SpiceUsbBackendChannel;
typedef struct UsbDeviceInformation
@@ -65,8 +65,8 @@ void spice_usb_backend_deregister_hotplug(SpiceUsbBackend *be);
/* Spice USB backend device API */
SpiceUsbBackendDevice *spice_usb_backend_device_ref(SpiceUsbBackendDevice *dev);
void spice_usb_backend_device_unref(SpiceUsbBackendDevice *dev);
-gconstpointer spice_usb_backend_device_get_libdev(SpiceUsbBackendDevice *dev);
-const UsbDeviceInformation* spice_usb_backend_device_get_info(SpiceUsbBackendDevice *dev);
+gconstpointer spice_usb_backend_device_get_libdev(const SpiceUsbBackendDevice *dev);
+const UsbDeviceInformation* spice_usb_backend_device_get_info(const SpiceUsbBackendDevice *dev);
gboolean spice_usb_backend_device_isoch(SpiceUsbBackendDevice *dev);
/* returns 0 if the device passes the filter */
int spice_usb_backend_device_check_filter(SpiceUsbBackendDevice *dev,
diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
index bf1c23bd..897aa09c 100644
--- a/src/usb-device-manager.c
+++ b/src/usb-device-manager.c
@@ -120,12 +120,6 @@ enum {
#ifdef USE_USBREDIR
-struct _SpiceUsbDevice {
- SpiceUsbBackendDevice *bdev;
- gint ref;
-};
-
-
static void channel_new(SpiceSession *session, SpiceChannel *channel,
gpointer user_data);
static void channel_destroy(SpiceSession *session, SpiceChannel *channel,
@@ -637,7 +631,7 @@ spice_usb_device_get_libusb_device(const SpiceUsbDevice *info G_GNUC_UNUSED)
#ifdef USE_USBREDIR
g_return_val_if_fail(info != NULL, FALSE);
- return spice_usb_backend_device_get_libdev(info->bdev);
+ return spice_usb_backend_device_get_libdev(info);
#endif
return NULL;
}
@@ -1476,16 +1470,9 @@ gchar *spice_usb_device_get_description(SpiceUsbDevice *device, const gchar *for
*/
static SpiceUsbDevice *spice_usb_device_new(SpiceUsbBackendDevice *bdev)
{
- SpiceUsbDevice *info;
-
g_return_val_if_fail(bdev != NULL, NULL);
- info = g_new0(SpiceUsbDevice, 1);
-
- info->ref = 1;
- info->bdev = spice_usb_backend_device_ref(bdev);
-
- return info;
+ return spice_usb_backend_device_ref(bdev);
}
guint8 spice_usb_device_get_busnum(const SpiceUsbDevice *info)
@@ -1494,7 +1481,7 @@ guint8 spice_usb_device_get_busnum(const SpiceUsbDevice *info)
g_return_val_if_fail(info != NULL, 0);
- b_info = spice_usb_backend_device_get_info(info->bdev);
+ b_info = spice_usb_backend_device_get_info(info);
return b_info->bus;
}
@@ -1504,7 +1491,7 @@ guint8 spice_usb_device_get_devaddr(const SpiceUsbDevice *info)
g_return_val_if_fail(info != NULL, 0);
- b_info = spice_usb_backend_device_get_info(info->bdev);
+ b_info = spice_usb_backend_device_get_info(info);
return b_info->address;
}
@@ -1514,7 +1501,7 @@ guint16 spice_usb_device_get_vid(const SpiceUsbDevice *info)
g_return_val_if_fail(info != NULL, 0);
- b_info = spice_usb_backend_device_get_info(info->bdev);
+ b_info = spice_usb_backend_device_get_info(info);
return b_info->vid;
}
@@ -1524,7 +1511,7 @@ guint16 spice_usb_device_get_pid(const SpiceUsbDevice *info)
g_return_val_if_fail(info != NULL, 0);
- b_info = spice_usb_backend_device_get_info(info->bdev);
+ b_info = spice_usb_backend_device_get_info(info);
return b_info->pid;
}
@@ -1532,7 +1519,7 @@ gboolean spice_usb_device_is_isochronous(const SpiceUsbDevice *info)
{
g_return_val_if_fail(info != NULL, 0);
- return spice_usb_backend_device_isoch(info->bdev);
+ return spice_usb_backend_device_isoch((SpiceUsbBackendDevice*) info);
}
#ifdef G_OS_WIN32
@@ -1605,21 +1592,14 @@ void _usbdk_hider_update(SpiceUsbDeviceManager *manager)
static SpiceUsbDevice *spice_usb_device_ref(SpiceUsbDevice *info)
{
g_return_val_if_fail(info != NULL, NULL);
- g_atomic_int_inc(&info->ref);
- return info;
+ return spice_usb_backend_device_ref(info);
}
static void spice_usb_device_unref(SpiceUsbDevice *info)
{
- gboolean ref_count_is_0;
-
g_return_if_fail(info != NULL);
- ref_count_is_0 = g_atomic_int_dec_and_test(&info->ref);
- if (ref_count_is_0) {
- spice_usb_backend_device_unref(info->bdev);
- g_free(info);
- }
+ spice_usb_backend_device_unref(info);
}
static gboolean
@@ -1630,7 +1610,7 @@ spice_usb_manager_device_equal_bdev(SpiceUsbDeviceManager *manager,
if ((info == NULL) || (bdev == NULL))
return FALSE;
- return info->bdev == bdev;
+ return info == bdev;
}
/*
@@ -1642,6 +1622,6 @@ spice_usb_device_manager_device_to_bdev(SpiceUsbDeviceManager *self,
SpiceUsbDevice *info)
{
/* Simply return a ref to the cached libdev */
- return spice_usb_backend_device_ref(info->bdev);
+ return spice_usb_backend_device_ref(info);
}
#endif /* USE_USBREDIR */
--
2.20.1
More information about the Spice-devel
mailing list