[Spice-commits] 3 commits - src/usb-backend.c src/usb-backend.h src/usb-device-manager.c
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Sep 2 11:07:37 UTC 2019
src/usb-backend.c | 15 ++++++++++++---
src/usb-backend.h | 6 +++---
src/usb-device-manager.c | 44 +++++++++++---------------------------------
3 files changed, 26 insertions(+), 39 deletions(-)
New commits:
commit 74f1f756475e70e7081acab902195f2a065407c0
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Thu Jul 25 14:32:07 2019 +0100
usb-device-manager: Use SpiceUsbBackendDevice directly instead of SpiceUsbDevice
They were the same structure.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Victor Toso <victortoso at redhat.com>
diff --git a/src/usb-backend.c b/src/usb-backend.c
index e61ec01..cfd14e2 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;
@@ -517,12 +517,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 66e13f5..5830312 100644
--- a/src/usb-backend.h
+++ b/src/usb-backend.h
@@ -27,7 +27,7 @@
G_BEGIN_DECLS
typedef struct _SpiceUsbBackend SpiceUsbBackend;
-typedef struct _SpiceUsbBackendDevice SpiceUsbBackendDevice;
+typedef struct _SpiceUsbDevice SpiceUsbBackendDevice;
typedef struct _SpiceUsbBackendChannel SpiceUsbBackendChannel;
typedef struct UsbDeviceInformation
@@ -64,8 +64,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 b85b20d..17bca09 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;
}
@@ -1480,16 +1474,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);
}
guint16 spice_usb_device_get_busnum(const SpiceUsbDevice *info)
@@ -1498,7 +1485,7 @@ guint16 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;
}
@@ -1508,7 +1495,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;
}
@@ -1518,7 +1505,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;
}
@@ -1528,7 +1515,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;
}
@@ -1536,7 +1523,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
@@ -1615,21 +1602,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
@@ -1640,7 +1620,7 @@ spice_usb_manager_device_equal_bdev(SpiceUsbDeviceManager *manager,
if ((info == NULL) || (bdev == NULL))
return FALSE;
- return info->bdev == bdev;
+ return info == bdev;
}
/*
@@ -1652,6 +1632,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 */
commit 039d0796af1dcdc965ade98071513d77bae7af43
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Thu Jul 25 14:20:20 2019 +0100
usb-device-manager: Remove isochronous field from _SpiceUsbDevice
Report directly value from SpiceUsbBackendDevice.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Victor Toso <victortoso at redhat.com>
diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
index b3db5de..b85b20d 100644
--- a/src/usb-device-manager.c
+++ b/src/usb-device-manager.c
@@ -123,7 +123,6 @@ enum {
struct _SpiceUsbDevice {
SpiceUsbBackendDevice *bdev;
gint ref;
- gboolean isochronous;
};
@@ -1489,7 +1488,6 @@ static SpiceUsbDevice *spice_usb_device_new(SpiceUsbBackendDevice *bdev)
info->ref = 1;
info->bdev = spice_usb_backend_device_ref(bdev);
- info->isochronous = spice_usb_backend_device_isoch(bdev);
return info;
}
@@ -1538,7 +1536,7 @@ gboolean spice_usb_device_is_isochronous(const SpiceUsbDevice *info)
{
g_return_val_if_fail(info != NULL, 0);
- return info->isochronous;
+ return spice_usb_backend_device_isoch(info->bdev);
}
#ifdef G_OS_WIN32
commit 60342d26ee868436e4561d1530199d99edbc1711
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Thu Jul 25 14:19:38 2019 +0100
usb-backend: Cache isochronous value
Allows to remove _SpiceUsbDevice structure.
_SpiceUsbDevice is only caching this value from SpiceUsbBackendDevice.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Victor Toso <victortoso at redhat.com>
diff --git a/src/usb-backend.c b/src/usb-backend.c
index 3334f56..e61ec01 100644
--- a/src/usb-backend.c
+++ b/src/usb-backend.c
@@ -50,6 +50,8 @@ struct _SpiceUsbBackendDevice
gint ref_count;
SpiceUsbBackendChannel *attached_to;
UsbDeviceInformation device_info;
+ bool cached_isochronous_valid;
+ bool cached_isochronous;
};
struct _SpiceUsbBackend
@@ -346,6 +348,10 @@ gboolean spice_usb_backend_device_isoch(SpiceUsbBackendDevice *dev)
gint i, j, k;
int rc;
+ if (dev->cached_isochronous_valid) {
+ return dev->cached_isochronous;
+ }
+
g_return_val_if_fail(libdev != NULL, 0);
rc = libusb_get_active_config_descriptor(libdev, &conf_desc);
@@ -367,6 +373,9 @@ gboolean spice_usb_backend_device_isoch(SpiceUsbBackendDevice *dev)
}
}
+ dev->cached_isochronous_valid = true;
+ dev->cached_isochronous = isoc_found;
+
libusb_free_config_descriptor(conf_desc);
return isoc_found;
}
More information about the Spice-commits
mailing list