[Spice-commits] 4 commits - src/usb-backend.c
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Jul 23 13:56:53 UTC 2019
src/usb-backend.c | 114 +++++++++++++++++++++++++++---------------------------
1 file changed, 59 insertions(+), 55 deletions(-)
New commits:
commit cb19a9a84ec432ca3670ff57c08fdb47f2c46f54
Author: Yuri Benditovich <yuri.benditovich at daynix.com>
Date: Tue Jul 23 10:27:04 2019 +0300
usb-redir: cosmetic changes in hotplug_callback
Unify parameter name for libusb_device.
Use g_return_val_if_fail for unexpected condition.
Remove redundant casting.
Signed-off-by: Yuri Benditovich <yuri.benditovich at daynix.com>
Acked-by: Victor Toso <victortoso at redhat.com>
diff --git a/src/usb-backend.c b/src/usb-backend.c
index 53ac430..e837579 100644
--- a/src/usb-backend.c
+++ b/src/usb-backend.c
@@ -108,21 +108,22 @@ static SpiceUsbBackendDevice *allocate_backend_device(libusb_device *libdev)
}
static int LIBUSB_CALL hotplug_callback(libusb_context *ctx,
- libusb_device *device,
+ libusb_device *libdev,
libusb_hotplug_event event,
void *user_data)
{
- SpiceUsbBackend *be = (SpiceUsbBackend *)user_data;
- if (be->hotplug_callback) {
- SpiceUsbBackendDevice *dev;
- gboolean val = event == LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED;
- dev = allocate_backend_device(device);
- if (dev) {
- SPICE_DEBUG("created dev %p, usblib dev %p", dev, device);
- libusb_ref_device(device);
- be->hotplug_callback(be->hotplug_user_data, dev, val);
- spice_usb_backend_device_unref(dev);
- }
+ SpiceUsbBackend *be = user_data;
+ SpiceUsbBackendDevice *dev;
+ gboolean arrived = event == LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED;
+
+ g_return_val_if_fail(be->hotplug_callback != NULL, 0);
+
+ dev = allocate_backend_device(libdev);
+ if (dev) {
+ SPICE_DEBUG("created dev %p, usblib dev %p", dev, libdev);
+ libusb_ref_device(libdev);
+ be->hotplug_callback(be->hotplug_user_data, dev, arrived);
+ spice_usb_backend_device_unref(dev);
}
return 0;
}
commit 66fe2ddd93fb258a60130f0d4246c7a734c8190c
Author: Yuri Benditovich <yuri.benditovich at daynix.com>
Date: Tue Jul 23 10:27:03 2019 +0300
usb-redir: change parameter name 'bdev' to 'dev'
Unify with other places for better readability.
Signed-off-by: Yuri Benditovich <yuri.benditovich at daynix.com>
Acked-by: Victor Toso <victortoso at redhat.com>
diff --git a/src/usb-backend.c b/src/usb-backend.c
index c2268e3..53ac430 100644
--- a/src/usb-backend.c
+++ b/src/usb-backend.c
@@ -83,10 +83,10 @@ static void get_usb_device_info_from_libusb_device(UsbDeviceInformation *info,
info->protocol = desc.bDeviceProtocol;
}
-static gboolean fill_usb_info(SpiceUsbBackendDevice *bdev)
+static gboolean fill_usb_info(SpiceUsbBackendDevice *dev)
{
- UsbDeviceInformation *info = &bdev->device_info;
- get_usb_device_info_from_libusb_device(info, bdev->libusb_device);
+ UsbDeviceInformation *info = &dev->device_info;
+ get_usb_device_info_from_libusb_device(info, dev->libusb_device);
if (info->address == 0xff || /* root hub (HCD) */
info->address <= 1 || /* root hub or bad address */
commit 392cb50ce4655691498e2b98c138b852a98731ea
Author: Yuri Benditovich <yuri.benditovich at daynix.com>
Date: Tue Jul 23 10:27:02 2019 +0300
usb-redir: split fill_usb_info procedure for further reuse
Utility procedure get_usb_device_info_from_libusb_device
will be reused later.
Signed-off-by: Yuri Benditovich <yuri.benditovich at daynix.com>
Acked-by: Victor Toso <victortoso at redhat.com>
diff --git a/src/usb-backend.c b/src/usb-backend.c
index a33cbe6..c2268e3 100644
--- a/src/usb-backend.c
+++ b/src/usb-backend.c
@@ -69,27 +69,30 @@ struct _SpiceUsbBackendChannel
GError **error;
};
-static gboolean fill_usb_info(SpiceUsbBackendDevice *bdev)
+static void get_usb_device_info_from_libusb_device(UsbDeviceInformation *info,
+ libusb_device *libdev)
{
- UsbDeviceInformation *info = &bdev->device_info;
-
struct libusb_device_descriptor desc;
- libusb_device *libdev = bdev->libusb_device;
libusb_get_device_descriptor(libdev, &desc);
info->bus = libusb_get_bus_number(libdev);
info->address = libusb_get_device_address(libdev);
- if (info->address == 0xff || /* root hub (HCD) */
- info->address <= 1 || /* root hub or bad address */
- (desc.bDeviceClass == LIBUSB_CLASS_HUB) /*hub*/) {
- return FALSE;
- }
-
info->vid = desc.idVendor;
info->pid = desc.idProduct;
info->class = desc.bDeviceClass;
info->subclass = desc.bDeviceSubClass;
info->protocol = desc.bDeviceProtocol;
+}
+static gboolean fill_usb_info(SpiceUsbBackendDevice *bdev)
+{
+ UsbDeviceInformation *info = &bdev->device_info;
+ get_usb_device_info_from_libusb_device(info, bdev->libusb_device);
+
+ if (info->address == 0xff || /* root hub (HCD) */
+ info->address <= 1 || /* root hub or bad address */
+ (info->class == LIBUSB_CLASS_HUB) /*hub*/) {
+ return FALSE;
+ }
return TRUE;
}
commit a01457a69018932eb8605576153beb2d5931a3af
Author: Yuri Benditovich <yuri.benditovich at daynix.com>
Date: Tue Jul 23 10:27:01 2019 +0300
usb-redir: move 3 static procedures up for further reuse
Procedures moved without changes, they will be reused
in later commits.
Signed-off-by: Yuri Benditovich <yuri.benditovich at daynix.com>
Acked-by: Victor Toso <victortoso at redhat.com>
diff --git a/src/usb-backend.c b/src/usb-backend.c
index a2c502d..a33cbe6 100644
--- a/src/usb-backend.c
+++ b/src/usb-backend.c
@@ -69,6 +69,61 @@ struct _SpiceUsbBackendChannel
GError **error;
};
+static gboolean fill_usb_info(SpiceUsbBackendDevice *bdev)
+{
+ UsbDeviceInformation *info = &bdev->device_info;
+
+ struct libusb_device_descriptor desc;
+ libusb_device *libdev = bdev->libusb_device;
+ libusb_get_device_descriptor(libdev, &desc);
+ info->bus = libusb_get_bus_number(libdev);
+ info->address = libusb_get_device_address(libdev);
+ if (info->address == 0xff || /* root hub (HCD) */
+ info->address <= 1 || /* root hub or bad address */
+ (desc.bDeviceClass == LIBUSB_CLASS_HUB) /*hub*/) {
+ return FALSE;
+ }
+
+ info->vid = desc.idVendor;
+ info->pid = desc.idProduct;
+ info->class = desc.bDeviceClass;
+ info->subclass = desc.bDeviceSubClass;
+ info->protocol = desc.bDeviceProtocol;
+
+ return TRUE;
+}
+
+static SpiceUsbBackendDevice *allocate_backend_device(libusb_device *libdev)
+{
+ SpiceUsbBackendDevice *dev = g_new0(SpiceUsbBackendDevice, 1);
+ dev->ref_count = 1;
+ dev->libusb_device = libdev;
+ if (!fill_usb_info(dev)) {
+ g_clear_pointer(&dev, g_free);
+ }
+ return dev;
+}
+
+static int LIBUSB_CALL hotplug_callback(libusb_context *ctx,
+ libusb_device *device,
+ libusb_hotplug_event event,
+ void *user_data)
+{
+ SpiceUsbBackend *be = (SpiceUsbBackend *)user_data;
+ if (be->hotplug_callback) {
+ SpiceUsbBackendDevice *dev;
+ gboolean val = event == LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED;
+ dev = allocate_backend_device(device);
+ if (dev) {
+ SPICE_DEBUG("created dev %p, usblib dev %p", dev, device);
+ libusb_ref_device(device);
+ be->hotplug_callback(be->hotplug_user_data, dev, val);
+ spice_usb_backend_device_unref(dev);
+ }
+ }
+ return 0;
+}
+
/* lock functions for usbredirhost and usbredirparser */
static void *usbredir_alloc_lock(void) {
GMutex *mutex;
@@ -131,41 +186,6 @@ gboolean spice_usb_backend_device_isoch(SpiceUsbBackendDevice *dev)
return isoc_found;
}
-static gboolean fill_usb_info(SpiceUsbBackendDevice *bdev)
-{
- UsbDeviceInformation *info = &bdev->device_info;
-
- struct libusb_device_descriptor desc;
- libusb_device *libdev = bdev->libusb_device;
- libusb_get_device_descriptor(libdev, &desc);
- info->bus = libusb_get_bus_number(libdev);
- info->address = libusb_get_device_address(libdev);
- if (info->address == 0xff || /* root hub (HCD) */
- info->address <= 1 || /* root hub or bad address */
- (desc.bDeviceClass == LIBUSB_CLASS_HUB) /*hub*/) {
- return FALSE;
- }
-
- info->vid = desc.idVendor;
- info->pid = desc.idProduct;
- info->class = desc.bDeviceClass;
- info->subclass = desc.bDeviceSubClass;
- info->protocol = desc.bDeviceProtocol;
-
- return TRUE;
-}
-
-static SpiceUsbBackendDevice *allocate_backend_device(libusb_device *libdev)
-{
- SpiceUsbBackendDevice *dev = g_new0(SpiceUsbBackendDevice, 1);
- dev->ref_count = 1;
- dev->libusb_device = libdev;
- if (!fill_usb_info(dev)) {
- g_clear_pointer(&dev, g_free);
- }
- return dev;
-}
-
static gboolean is_channel_ready(SpiceUsbredirChannel *channel)
{
return spice_channel_get_state(SPICE_CHANNEL(channel)) == SPICE_CHANNEL_STATE_READY;
@@ -237,26 +257,6 @@ void spice_usb_backend_interrupt_event_handler(SpiceUsbBackend *be)
}
}
-static int LIBUSB_CALL hotplug_callback(libusb_context *ctx,
- libusb_device *device,
- libusb_hotplug_event event,
- void *user_data)
-{
- SpiceUsbBackend *be = (SpiceUsbBackend *)user_data;
- if (be->hotplug_callback) {
- SpiceUsbBackendDevice *dev;
- gboolean val = event == LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED;
- dev = allocate_backend_device(device);
- if (dev) {
- SPICE_DEBUG("created dev %p, usblib dev %p", dev, device);
- libusb_ref_device(device);
- be->hotplug_callback(be->hotplug_user_data, dev, val);
- spice_usb_backend_device_unref(dev);
- }
- }
- return 0;
-}
-
void spice_usb_backend_deregister_hotplug(SpiceUsbBackend *be)
{
g_return_if_fail(be != NULL);
More information about the Spice-commits
mailing list