[Spice-commits] 4 commits - src/channel-usbredir.c src/channel-usbredir-priv.h src/usb-backend.c src/usb-backend.h src/usb-device-cd.c src/usb-device-manager.c src/usb-emulation.h tests/cd-emu.c
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sun Jan 19 09:30:11 UTC 2020
src/channel-usbredir-priv.h | 14 ++++-----
src/channel-usbredir.c | 54 ++++++++++++++------------------------
src/usb-backend.c | 50 +++++++++++++++++------------------
src/usb-backend.h | 23 +++++++---------
src/usb-device-cd.c | 4 +-
src/usb-device-manager.c | 62 ++++++++++++--------------------------------
src/usb-emulation.h | 3 --
tests/cd-emu.c | 4 +-
8 files changed, 85 insertions(+), 129 deletions(-)
New commits:
commit 3b485d5a44ea74fc86168d621fab61413751566c
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Thu Dec 12 09:26:09 2019 +0000
channel-usbredir: Remove duplicate field
"spice_device" and "device" points to the same object.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Francesco Giudici <fgiudici at redhat.com>
diff --git a/src/channel-usbredir.c b/src/channel-usbredir.c
index 3921875..0a4ceb5 100644
--- a/src/channel-usbredir.c
+++ b/src/channel-usbredir.c
@@ -63,7 +63,6 @@ enum SpiceUsbredirChannelState {
struct _SpiceUsbredirChannelPrivate {
SpiceUsbDevice *device;
- SpiceUsbDevice *spice_device;
SpiceUsbBackend *context;
SpiceUsbBackendChannel *host;
enum SpiceUsbredirChannelState state;
@@ -285,8 +284,6 @@ static void spice_usbredir_channel_open_acl_cb(
}
if (err) {
g_clear_pointer(&priv->device, spice_usb_backend_device_unref);
- g_boxed_free(spice_usb_device_get_type(), priv->spice_device);
- priv->spice_device = NULL;
priv->state = STATE_DISCONNECTED;
g_task_return_error(priv->task, err);
} else {
@@ -315,8 +312,6 @@ _open_device_async_cb(GTask *task,
if (!spice_usbredir_channel_open_device(channel, &err)) {
g_clear_pointer(&priv->device, spice_usb_backend_device_unref);
- g_boxed_free(spice_usb_device_get_type(), priv->spice_device);
- priv->spice_device = NULL;
}
spice_usbredir_channel_unlock(channel);
@@ -366,8 +361,6 @@ void spice_usbredir_channel_connect_device_async(SpiceUsbredirChannel *channel,
}
priv->device = spice_usb_backend_device_ref(device);
- priv->spice_device = g_boxed_copy(spice_usb_device_get_type(),
- device);
#ifdef USE_POLKIT
if (info->bus != BUS_NUMBER_FOR_EMULATED_USB) {
priv->task = task;
@@ -427,8 +420,6 @@ void spice_usbredir_channel_disconnect_device(SpiceUsbredirChannel *channel)
/* This also closes the libusb handle we passed from open_device */
spice_usb_backend_channel_detach(priv->host);
g_clear_pointer(&priv->device, spice_usb_backend_device_unref);
- g_boxed_free(spice_usb_device_get_type(), priv->spice_device);
- priv->spice_device = NULL;
priv->state = STATE_DISCONNECTED;
break;
}
@@ -472,7 +463,7 @@ void spice_usbredir_channel_disconnect_device_async(SpiceUsbredirChannel *channe
static SpiceUsbDevice *
spice_usbredir_channel_get_spice_usb_device(SpiceUsbredirChannel *channel)
{
- return channel->priv->spice_device;
+ return channel->priv->device;
}
#endif
@@ -604,7 +595,7 @@ void spice_usbredir_channel_unlock(SpiceUsbredirChannel *channel)
typedef struct device_error_data {
SpiceUsbredirChannel *channel;
- SpiceUsbDevice *spice_device;
+ SpiceUsbDevice *device;
GError *error;
struct coroutine *caller;
} device_error_data;
@@ -617,12 +608,11 @@ static gboolean device_error(gpointer user_data)
SpiceUsbredirChannelPrivate *priv = channel->priv;
/* Check that the device has not changed before we manage to run */
- if (data->spice_device == priv->spice_device) {
+ if (data->device == priv->device) {
+ SpiceUsbDeviceManager *manager =
+ spice_usb_device_manager_get(spice_channel_get_session(SPICE_CHANNEL(channel)), NULL);
spice_usbredir_channel_disconnect_device(channel);
- spice_usb_device_manager_device_error(
- spice_usb_device_manager_get(
- spice_channel_get_session(SPICE_CHANNEL(channel)), NULL),
- data->spice_device, data->error);
+ spice_usb_device_manager_device_error(manager, data->device, data->error);
}
coroutine_yieldto(data->caller, NULL);
@@ -703,13 +693,13 @@ static void usbredir_handle_msg(SpiceChannel *c, SpiceMsgIn *in)
spice_usbredir_channel_lock(channel);
if (r == 0)
r = spice_usb_backend_read_guest_data(priv->host, buf, size);
- if (r != 0 && priv->spice_device != NULL) {
- SpiceUsbDevice *spice_device = priv->spice_device;
+ if (r != 0 && priv->device != NULL) {
+ SpiceUsbDevice *device = priv->device;
device_error_data err_data;
gchar *desc;
GError *err;
- desc = spice_usb_device_get_description(spice_device, NULL);
+ desc = spice_usb_device_get_description(device, NULL);
err = spice_usb_backend_get_error_details(r, desc);
g_free(desc);
@@ -717,13 +707,13 @@ static void usbredir_handle_msg(SpiceChannel *c, SpiceMsgIn *in)
err_data.channel = channel;
err_data.caller = coroutine_self();
- err_data.spice_device = g_boxed_copy(spice_usb_device_get_type(), spice_device);
+ err_data.device = spice_usb_backend_device_ref(device);
err_data.error = err;
spice_usbredir_channel_unlock(channel);
g_idle_add(device_error, &err_data);
coroutine_yield(NULL);
- g_boxed_free(spice_usb_device_get_type(), err_data.spice_device);
+ spice_usb_backend_device_unref(err_data.device);
g_error_free(err);
} else {
commit d4f7a71508efb8d0aa598413e61eb92ee171c970
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Thu Dec 12 09:04:38 2019 +0000
Rename SpiceUsbBackendDevice to SpiceUsbDevice
They are the same structure now.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Francesco Giudici <fgiudici at redhat.com>
diff --git a/src/channel-usbredir-priv.h b/src/channel-usbredir-priv.h
index d0cd354..0c448d4 100644
--- a/src/channel-usbredir-priv.h
+++ b/src/channel-usbredir-priv.h
@@ -56,7 +56,7 @@ gboolean spice_usbredir_channel_connect_device_finish(
void spice_usbredir_channel_disconnect_device(SpiceUsbredirChannel *channel);
-SpiceUsbBackendDevice *spice_usbredir_channel_get_device(SpiceUsbredirChannel *channel);
+SpiceUsbDevice *spice_usbredir_channel_get_device(SpiceUsbredirChannel *channel);
void spice_usbredir_channel_lock(SpiceUsbredirChannel *channel);
diff --git a/src/channel-usbredir.c b/src/channel-usbredir.c
index 3825f82..3921875 100644
--- a/src/channel-usbredir.c
+++ b/src/channel-usbredir.c
@@ -62,7 +62,7 @@ enum SpiceUsbredirChannelState {
};
struct _SpiceUsbredirChannelPrivate {
- SpiceUsbBackendDevice *device;
+ SpiceUsbDevice *device;
SpiceUsbDevice *spice_device;
SpiceUsbBackend *context;
SpiceUsbBackendChannel *host;
@@ -477,7 +477,7 @@ spice_usbredir_channel_get_spice_usb_device(SpiceUsbredirChannel *channel)
#endif
G_GNUC_INTERNAL
-SpiceUsbBackendDevice *spice_usbredir_channel_get_device(SpiceUsbredirChannel *channel)
+SpiceUsbDevice *spice_usbredir_channel_get_device(SpiceUsbredirChannel *channel)
{
return channel->priv->device;
}
diff --git a/src/usb-backend.c b/src/usb-backend.c
index d31b341..5b160c8 100644
--- a/src/usb-backend.c
+++ b/src/usb-backend.c
@@ -96,7 +96,7 @@ struct _SpiceUsbBackendChannel
int rules_count;
uint32_t rejected : 1;
uint32_t wait_disconnect_ack : 1;
- SpiceUsbBackendDevice *attached;
+ SpiceUsbDevice *attached;
SpiceUsbredirChannel *usbredir_channel;
SpiceUsbBackend *backend;
GError **error;
@@ -116,7 +116,7 @@ static void get_usb_device_info_from_libusb_device(UsbDeviceInformation *info,
info->protocol = desc.bDeviceProtocol;
}
-static gboolean fill_usb_info(SpiceUsbBackendDevice *dev)
+static gboolean fill_usb_info(SpiceUsbDevice *dev)
{
UsbDeviceInformation *info = &dev->device_info;
get_usb_device_info_from_libusb_device(info, dev->libusb_device);
@@ -129,9 +129,9 @@ static gboolean fill_usb_info(SpiceUsbBackendDevice *dev)
return TRUE;
}
-static SpiceUsbBackendDevice *allocate_backend_device(libusb_device *libdev)
+static SpiceUsbDevice *allocate_backend_device(libusb_device *libdev)
{
- SpiceUsbBackendDevice *dev = g_new0(SpiceUsbBackendDevice, 1);
+ SpiceUsbDevice *dev = g_new0(SpiceUsbDevice, 1);
dev->ref_count = 1;
dev->libusb_device = libdev;
if (!fill_usb_info(dev)) {
@@ -146,7 +146,7 @@ static int LIBUSB_CALL hotplug_callback(libusb_context *ctx,
void *user_data)
{
SpiceUsbBackend *be = user_data;
- SpiceUsbBackendDevice *dev;
+ SpiceUsbDevice *dev;
gboolean arrived = event == LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED;
g_return_val_if_fail(be->hotplug_callback != NULL, 0);
@@ -359,7 +359,7 @@ static void usbredir_unlock_lock(void *user_data)
g_mutex_unlock(mutex);
}
-gboolean spice_usb_backend_device_isoch(SpiceUsbBackendDevice *dev)
+gboolean spice_usb_backend_device_isoch(SpiceUsbDevice *dev)
{
libusb_device *libdev = dev->libusb_device;
struct libusb_config_descriptor *conf_desc;
@@ -548,24 +548,24 @@ void spice_usb_backend_delete(SpiceUsbBackend *be)
SPICE_DEBUG("%s <<", __FUNCTION__);
}
-const UsbDeviceInformation* spice_usb_backend_device_get_info(const SpiceUsbBackendDevice *dev)
+const UsbDeviceInformation* spice_usb_backend_device_get_info(const SpiceUsbDevice *dev)
{
return &dev->device_info;
}
-gconstpointer spice_usb_backend_device_get_libdev(const SpiceUsbBackendDevice *dev)
+gconstpointer spice_usb_backend_device_get_libdev(const SpiceUsbDevice *dev)
{
return dev->libusb_device;
}
-SpiceUsbBackendDevice *spice_usb_backend_device_ref(SpiceUsbBackendDevice *dev)
+SpiceUsbDevice *spice_usb_backend_device_ref(SpiceUsbDevice *dev)
{
LOUD_DEBUG("%s >> %p", __FUNCTION__, dev);
g_atomic_int_inc(&dev->ref_count);
return dev;
}
-void spice_usb_backend_device_unref(SpiceUsbBackendDevice *dev)
+void spice_usb_backend_device_unref(SpiceUsbDevice *dev)
{
LOUD_DEBUG("%s >> %p(%d)", __FUNCTION__, dev, dev->ref_count);
if (g_atomic_int_dec_and_test(&dev->ref_count)) {
@@ -580,7 +580,7 @@ void spice_usb_backend_device_unref(SpiceUsbBackendDevice *dev)
}
}
-static int check_edev_device_filter(SpiceUsbBackendDevice *dev,
+static int check_edev_device_filter(SpiceUsbDevice *dev,
const struct usbredirfilter_rule *rules,
int count)
{
@@ -617,7 +617,7 @@ static int check_edev_device_filter(SpiceUsbBackendDevice *dev,
dev->device_info.bcdUSB, 0);
}
-int spice_usb_backend_device_check_filter(SpiceUsbBackendDevice *dev,
+int spice_usb_backend_device_check_filter(SpiceUsbDevice *dev,
const struct usbredirfilter_rule *rules, int count)
{
if (dev->libusb_device != NULL) {
@@ -837,7 +837,7 @@ usbredir_control_packet(void *priv, uint64_t id, struct usb_redir_control_packet
uint8_t *data, int data_len)
{
SpiceUsbBackendChannel *ch = priv;
- SpiceUsbBackendDevice *d = ch->attached;
+ SpiceUsbDevice *d = ch->attached;
SpiceUsbEmulatedDevice *edev = d ? d->edev : NULL;
struct usb_redir_control_packet_header response = *h;
uint8_t reqtype = h->requesttype & 0x7f;
@@ -892,7 +892,7 @@ usbredir_bulk_packet(void *priv, uint64_t id, struct usb_redir_bulk_packet_heade
uint8_t *data, int data_len)
{
SpiceUsbBackendChannel *ch = priv;
- SpiceUsbBackendDevice *d = ch->attached;
+ SpiceUsbDevice *d = ch->attached;
SpiceUsbEmulatedDevice *edev = d ? d->edev : NULL;
struct usb_redir_bulk_packet_header hout = *h;
uint32_t len = (h->length_high << 16) | h->length;
@@ -924,7 +924,7 @@ usbredir_bulk_packet(void *priv, uint64_t id, struct usb_redir_bulk_packet_heade
static void usbredir_device_reset(void *priv)
{
SpiceUsbBackendChannel *ch = priv;
- SpiceUsbBackendDevice *d = ch->attached;
+ SpiceUsbDevice *d = ch->attached;
SpiceUsbEmulatedDevice *edev = d ? d->edev : NULL;
SPICE_DEBUG("%s ch %p", __FUNCTION__, ch);
if (edev) {
@@ -1000,7 +1000,7 @@ usbredir_get_alt_setting(void *priv, uint64_t id, struct usb_redir_get_alt_setti
static void usbredir_cancel_data(void *priv, uint64_t id)
{
SpiceUsbBackendChannel *ch = priv;
- SpiceUsbBackendDevice *d = ch->attached;
+ SpiceUsbDevice *d = ch->attached;
SpiceUsbEmulatedDevice *edev = d ? d->edev : NULL;
if (!edev) {
SPICE_DEBUG("%s: device not attached", __FUNCTION__);
@@ -1052,7 +1052,7 @@ static void
usbredir_hello(void *priv, struct usb_redir_hello_header *hello)
{
SpiceUsbBackendChannel *ch = priv;
- SpiceUsbBackendDevice *d = ch->attached;
+ SpiceUsbDevice *d = ch->attached;
SpiceUsbEmulatedDevice *edev = d ? d->edev : NULL;
struct usb_redir_device_connect_header device_connect;
struct usb_redir_ep_info_header ep_info = { 0 };
@@ -1175,7 +1175,7 @@ static struct usbredirparser *create_parser(SpiceUsbBackendChannel *ch)
}
static gboolean attach_edev(SpiceUsbBackendChannel *ch,
- SpiceUsbBackendDevice *dev,
+ SpiceUsbDevice *dev,
GError **error)
{
if (!dev->edev) {
@@ -1207,7 +1207,7 @@ static gboolean attach_edev(SpiceUsbBackendChannel *ch,
}
gboolean spice_usb_backend_channel_attach(SpiceUsbBackendChannel *ch,
- SpiceUsbBackendDevice *dev,
+ SpiceUsbDevice *dev,
GError **error)
{
int rc;
@@ -1261,7 +1261,7 @@ gboolean spice_usb_backend_channel_attach(SpiceUsbBackendChannel *ch,
void spice_usb_backend_channel_detach(SpiceUsbBackendChannel *ch)
{
- SpiceUsbBackendDevice *d = ch->attached;
+ SpiceUsbDevice *d = ch->attached;
SpiceUsbEmulatedDevice *edev = d ? d->edev : NULL;
SPICE_DEBUG("%s >> ch %p, was attached %p", __FUNCTION__, ch, ch->attached);
if (!d) {
@@ -1398,7 +1398,7 @@ spice_usb_backend_channel_get_guest_filter(SpiceUsbBackendChannel *ch,
}
}
-gchar *spice_usb_backend_device_get_description(SpiceUsbBackendDevice *dev,
+gchar *spice_usb_backend_device_get_description(SpiceUsbDevice *dev,
const gchar *format)
{
guint16 bus, address, vid, pid;
@@ -1439,7 +1439,7 @@ gchar *spice_usb_backend_device_get_description(SpiceUsbBackendDevice *dev,
}
void spice_usb_backend_device_report_change(SpiceUsbBackend *be,
- SpiceUsbBackendDevice *dev)
+ SpiceUsbDevice *dev)
{
gchar *desc;
g_return_if_fail(dev && dev->edev);
@@ -1449,7 +1449,7 @@ void spice_usb_backend_device_report_change(SpiceUsbBackend *be,
g_free(desc);
}
-void spice_usb_backend_device_eject(SpiceUsbBackend *be, SpiceUsbBackendDevice *dev)
+void spice_usb_backend_device_eject(SpiceUsbBackend *be, SpiceUsbDevice *dev)
{
g_return_if_fail(dev);
@@ -1468,7 +1468,7 @@ spice_usb_backend_create_emulated_device(SpiceUsbBackend *be,
GError **err)
{
SpiceUsbEmulatedDevice *edev;
- SpiceUsbBackendDevice *dev;
+ SpiceUsbDevice *dev;
struct libusb_device_descriptor *desc;
uint16_t device_desc_size;
uint8_t address = 0;
@@ -1484,7 +1484,7 @@ spice_usb_backend_create_emulated_device(SpiceUsbBackend *be,
}
}
- dev = g_new0(SpiceUsbBackendDevice, 1);
+ dev = g_new0(SpiceUsbDevice, 1);
dev->device_info.bus = BUS_NUMBER_FOR_EMULATED_USB;
dev->device_info.address = address;
dev->ref_count = 1;
diff --git a/src/usb-backend.h b/src/usb-backend.h
index 4e86fdf..3802dee 100644
--- a/src/usb-backend.h
+++ b/src/usb-backend.h
@@ -27,7 +27,6 @@
G_BEGIN_DECLS
typedef struct _SpiceUsbBackend SpiceUsbBackend;
-typedef struct _SpiceUsbDevice SpiceUsbBackendDevice;
typedef struct _SpiceUsbBackendChannel SpiceUsbBackendChannel;
#define BUS_NUMBER_FOR_EMULATED_USB G_MAXUINT16
@@ -44,7 +43,7 @@ typedef struct UsbDeviceInformation
uint8_t protocol;
} UsbDeviceInformation;
-typedef void(*usb_hot_plug_callback)(void *user_data, SpiceUsbBackendDevice *dev, gboolean added);
+typedef void(*usb_hot_plug_callback)(void *user_data, SpiceUsbDevice *dev, gboolean added);
enum {
USB_REDIR_ERROR_IO = -1,
@@ -65,17 +64,17 @@ gboolean spice_usb_backend_register_hotplug(SpiceUsbBackend *be,
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(const SpiceUsbBackendDevice *dev);
-const UsbDeviceInformation* spice_usb_backend_device_get_info(const SpiceUsbBackendDevice *dev);
-gboolean spice_usb_backend_device_isoch(SpiceUsbBackendDevice *dev);
-void spice_usb_backend_device_eject(SpiceUsbBackend *be, SpiceUsbBackendDevice *device);
-void spice_usb_backend_device_report_change(SpiceUsbBackend *be, SpiceUsbBackendDevice *device);
+SpiceUsbDevice *spice_usb_backend_device_ref(SpiceUsbDevice *dev);
+void spice_usb_backend_device_unref(SpiceUsbDevice *dev);
+gconstpointer spice_usb_backend_device_get_libdev(const SpiceUsbDevice *dev);
+const UsbDeviceInformation* spice_usb_backend_device_get_info(const SpiceUsbDevice *dev);
+gboolean spice_usb_backend_device_isoch(SpiceUsbDevice *dev);
+void spice_usb_backend_device_eject(SpiceUsbBackend *be, SpiceUsbDevice *device);
+void spice_usb_backend_device_report_change(SpiceUsbBackend *be, SpiceUsbDevice *device);
/* returns 0 if the device passes the filter otherwise returns the error value from
* usbredirhost_check_device_filter() such as -EIO or -ENOMEM */
-int spice_usb_backend_device_check_filter(SpiceUsbBackendDevice *dev,
+int spice_usb_backend_device_check_filter(SpiceUsbDevice *dev,
const struct usbredirfilter_rule *rules, int count);
/* Spice USB backend channel API */
@@ -86,7 +85,7 @@ void spice_usb_backend_channel_delete(SpiceUsbBackendChannel *ch);
int spice_usb_backend_read_guest_data(SpiceUsbBackendChannel *ch, uint8_t *data, int count);
GError *spice_usb_backend_get_error_details(int error_code, gchar *device_desc);
gboolean spice_usb_backend_channel_attach(SpiceUsbBackendChannel *ch,
- SpiceUsbBackendDevice *dev,
+ SpiceUsbDevice *dev,
GError **error);
void spice_usb_backend_channel_detach(SpiceUsbBackendChannel *ch);
void spice_usb_backend_channel_flush_writes(SpiceUsbBackendChannel *ch);
@@ -94,6 +93,6 @@ void spice_usb_backend_channel_get_guest_filter(SpiceUsbBackendChannel *ch,
const struct usbredirfilter_rule **rules,
int *count);
void spice_usb_backend_return_write_data(SpiceUsbBackendChannel *ch, void *data);
-gchar *spice_usb_backend_device_get_description(SpiceUsbBackendDevice *dev, const gchar *format);
+gchar *spice_usb_backend_device_get_description(SpiceUsbDevice *dev, const gchar *format);
G_END_DECLS
diff --git a/src/usb-device-cd.c b/src/usb-device-cd.c
index 2f421c4..2e8ef5d 100644
--- a/src/usb-device-cd.c
+++ b/src/usb-device-cd.c
@@ -75,7 +75,7 @@ struct BufferedBulkRead {
struct SpiceUsbEmulatedDevice {
UsbDeviceOps dev_ops;
SpiceUsbBackend *backend;
- SpiceUsbBackendDevice *parent;
+ SpiceUsbDevice *parent;
struct usbredirparser *parser;
UsbCdBulkMsdDevice* msc;
SpiceCdLU units[MAX_LUN_PER_DEVICE];
@@ -709,7 +709,7 @@ static const UsbDeviceOps devops =
};
static UsbCd* usb_cd_create(SpiceUsbBackend *be,
- SpiceUsbBackendDevice *parent,
+ SpiceUsbDevice *parent,
void *opaque_param,
GError **err)
{
diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
index cf6d7f1..1810e18 100644
--- a/src/usb-device-manager.c
+++ b/src/usb-device-manager.c
@@ -126,12 +126,12 @@ static void channel_destroy(SpiceSession *session, SpiceChannel *channel,
static void channel_event(SpiceChannel *channel, SpiceChannelEvent event,
gpointer user_data);
static void spice_usb_device_manager_hotplug_cb(void *user_data,
- SpiceUsbBackendDevice *dev,
+ SpiceUsbDevice *dev,
gboolean added);
static void spice_usb_device_manager_check_redir_on_connect(SpiceUsbDeviceManager *manager,
SpiceChannel *channel);
-static SpiceUsbDevice *spice_usb_device_new(SpiceUsbBackendDevice *bdev);
+static SpiceUsbDevice *spice_usb_device_new(SpiceUsbDevice *bdev);
static SpiceUsbDevice *spice_usb_device_ref(SpiceUsbDevice *device);
static void spice_usb_device_unref(SpiceUsbDevice *device);
@@ -142,7 +142,7 @@ static void _usbdk_hider_clear(SpiceUsbDeviceManager *manager);
static gboolean spice_usb_manager_device_equal_bdev(SpiceUsbDeviceManager *manager,
SpiceUsbDevice *device,
- SpiceUsbBackendDevice *bdev);
+ SpiceUsbDevice *bdev);
static void
_spice_usb_device_manager_connect_device_async(SpiceUsbDeviceManager *manager,
@@ -755,7 +755,7 @@ spice_usb_device_manager_find_device(SpiceUsbDeviceManager *manager,
}
static void spice_usb_device_manager_add_dev(SpiceUsbDeviceManager *manager,
- SpiceUsbBackendDevice *bdev)
+ SpiceUsbDevice *bdev)
{
SpiceUsbDeviceManagerPrivate *priv = manager->priv;
const UsbDeviceInformation *b_info = spice_usb_backend_device_get_info(bdev);
@@ -803,7 +803,7 @@ static void spice_usb_device_manager_add_dev(SpiceUsbDeviceManager *manager,
}
static void spice_usb_device_manager_remove_dev(SpiceUsbDeviceManager *manager,
- SpiceUsbBackendDevice *bdev)
+ SpiceUsbDevice *bdev)
{
SpiceUsbDeviceManagerPrivate *priv = manager->priv;
SpiceUsbDevice *device;
@@ -831,7 +831,7 @@ static void spice_usb_device_manager_remove_dev(SpiceUsbDeviceManager *manager,
struct hotplug_idle_cb_args {
SpiceUsbDeviceManager *manager;
- SpiceUsbBackendDevice *device;
+ SpiceUsbDevice *device;
gboolean added;
};
@@ -854,7 +854,7 @@ static gboolean spice_usb_device_manager_hotplug_idle_cb(gpointer user_data)
/* Can be called from both the main-thread as well as the event_thread */
static void spice_usb_device_manager_hotplug_cb(void *user_data,
- SpiceUsbBackendDevice *dev,
+ SpiceUsbDevice *dev,
gboolean added)
{
SpiceUsbDeviceManager *manager = SPICE_USB_DEVICE_MANAGER(user_data);
@@ -947,7 +947,7 @@ spice_usb_device_manager_get_channel_for_dev(SpiceUsbDeviceManager *manager,
for (i = 0; i < priv->channels->len; i++) {
SpiceUsbredirChannel *channel = g_ptr_array_index(priv->channels, i);
spice_usbredir_channel_lock(channel);
- SpiceUsbBackendDevice *bdev = spice_usbredir_channel_get_device(channel);
+ SpiceUsbDevice *bdev = spice_usbredir_channel_get_device(channel);
if (spice_usb_manager_device_equal_bdev(manager, device, bdev)) {
spice_usbredir_channel_unlock(channel);
return channel;
@@ -1431,7 +1431,7 @@ gchar *spice_usb_device_get_description(SpiceUsbDevice *device, const gchar *for
/*
* SpiceUsbDevice
*/
-static SpiceUsbDevice *spice_usb_device_new(SpiceUsbBackendDevice *bdev)
+static SpiceUsbDevice *spice_usb_device_new(SpiceUsbDevice *bdev)
{
g_return_val_if_fail(bdev != NULL, NULL);
@@ -1482,7 +1482,7 @@ gboolean spice_usb_device_is_isochronous(const SpiceUsbDevice *info)
{
g_return_val_if_fail(info != NULL, 0);
- return spice_usb_backend_device_isoch((SpiceUsbBackendDevice*) info);
+ return spice_usb_backend_device_isoch((SpiceUsbDevice*) info);
}
#ifdef G_OS_WIN32
@@ -1574,7 +1574,7 @@ static void spice_usb_device_unref(SpiceUsbDevice *info)
static gboolean
spice_usb_manager_device_equal_bdev(SpiceUsbDeviceManager *manager,
SpiceUsbDevice *info,
- SpiceUsbBackendDevice *bdev)
+ SpiceUsbDevice *bdev)
{
if ((info == NULL) || (bdev == NULL)) {
return FALSE;
diff --git a/src/usb-emulation.h b/src/usb-emulation.h
index 5d67fee..02a0381 100644
--- a/src/usb-emulation.h
+++ b/src/usb-emulation.h
@@ -27,7 +27,7 @@
typedef struct SpiceUsbEmulatedDevice SpiceUsbEmulatedDevice;
typedef SpiceUsbEmulatedDevice*
(*SpiceUsbEmulatedDeviceCreate)(SpiceUsbBackend *be,
- SpiceUsbBackendDevice *parent,
+ SpiceUsbDevice *parent,
void *create_params,
GError **err);
@@ -84,4 +84,3 @@ spice_usb_backend_create_emulated_device(SpiceUsbBackend *be,
SpiceUsbEmulatedDeviceCreate create_proc,
void *create_params,
GError **err);
-
diff --git a/tests/cd-emu.c b/tests/cd-emu.c
index c96c0ba..d99ca88 100644
--- a/tests/cd-emu.c
+++ b/tests/cd-emu.c
@@ -36,11 +36,11 @@
#include "usb-device-cd.h"
-static SpiceUsbBackendDevice *device = NULL;
+static SpiceUsbDevice *device = NULL;
/* simple usb manager hotplug callback emulation. */
static void
-test_hotplug_callback(void *user_data, SpiceUsbBackendDevice *dev, gboolean added)
+test_hotplug_callback(void *user_data, SpiceUsbDevice *dev, gboolean added)
{
// ignore not emulated devices
const UsbDeviceInformation *info = spice_usb_backend_device_get_info(dev);
commit 7d1c1a4861a6306cc89af1ee3cf406b39c6b9f15
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Tue Dec 10 10:50:23 2019 +0000
channel-usbredir: Remove duplicate argument to spice_usbredir_channel_connect_device_async
Now that SpiceUsbBackendDevice and SpiceUsbDevice are the same
structure is useless to pass the same argument twice.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Francesco Giudici <fgiudici at redhat.com>
diff --git a/src/channel-usbredir-priv.h b/src/channel-usbredir-priv.h
index 1230628..d0cd354 100644
--- a/src/channel-usbredir-priv.h
+++ b/src/channel-usbredir-priv.h
@@ -44,13 +44,11 @@ gboolean spice_usbredir_channel_disconnect_device_finish(SpiceUsbredirChannel *c
/* Note the context must be set, and the channel must be brought up
(through spice_channel_connect()), before calling this. */
-void spice_usbredir_channel_connect_device_async(
- SpiceUsbredirChannel *channel,
- SpiceUsbBackendDevice *device,
- SpiceUsbDevice *spice_device,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
+void spice_usbredir_channel_connect_device_async(SpiceUsbredirChannel *channel,
+ SpiceUsbDevice *device,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
gboolean spice_usbredir_channel_connect_device_finish(
SpiceUsbredirChannel *channel,
GAsyncResult *res,
diff --git a/src/channel-usbredir.c b/src/channel-usbredir.c
index e407bac..3825f82 100644
--- a/src/channel-usbredir.c
+++ b/src/channel-usbredir.c
@@ -329,13 +329,11 @@ _open_device_async_cb(GTask *task,
}
G_GNUC_INTERNAL
-void spice_usbredir_channel_connect_device_async(
- SpiceUsbredirChannel *channel,
- SpiceUsbBackendDevice *device,
- SpiceUsbDevice *spice_device,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+void spice_usbredir_channel_connect_device_async(SpiceUsbredirChannel *channel,
+ SpiceUsbDevice *device,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
SpiceUsbredirChannelPrivate *priv = channel->priv;
#ifdef USE_POLKIT
@@ -347,9 +345,9 @@ void spice_usbredir_channel_connect_device_async(
g_return_if_fail(device != NULL);
CHANNEL_DEBUG(channel, "connecting device %04x:%04x (%p) to channel %p",
- spice_usb_device_get_vid(spice_device),
- spice_usb_device_get_pid(spice_device),
- spice_device, channel);
+ spice_usb_device_get_vid(device),
+ spice_usb_device_get_pid(device),
+ device, channel);
task = g_task_new(channel, cancellable, callback, user_data);
@@ -369,7 +367,7 @@ void spice_usbredir_channel_connect_device_async(
priv->device = spice_usb_backend_device_ref(device);
priv->spice_device = g_boxed_copy(spice_usb_device_get_type(),
- spice_device);
+ device);
#ifdef USE_POLKIT
if (info->bus != BUS_NUMBER_FOR_EMULATED_USB) {
priv->task = task;
diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
index 019f044..cf6d7f1 100644
--- a/src/usb-device-manager.c
+++ b/src/usb-device-manager.c
@@ -917,7 +917,7 @@ static void spice_usb_device_manager_check_redir_on_connect(SpiceUsbDeviceManage
spice_usb_device_ref(device));
spice_usbredir_channel_connect_device_async(SPICE_USBREDIR_CHANNEL(channel),
- device, device, NULL,
+ device, NULL,
spice_usb_device_manager_channel_connect_cb,
task);
return; /* We've taken the channel! */
@@ -1099,7 +1099,8 @@ _spice_usb_device_manager_connect_device_async(SpiceUsbDeviceManager *manager,
continue; /* Skip already used channels */
}
- spice_usbredir_channel_connect_device_async(channel, device, device,
+ spice_usbredir_channel_connect_device_async(channel,
+ device,
cancellable,
spice_usb_device_manager_channel_connect_cb,
task);
commit f3d42c570e0ce4ae40d4f5f8f2005551b5d25b0f
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Tue Dec 10 10:42:01 2019 +0000
usb-device-manager: Remove spice_usb_device_manager_device_to_bdev
Now that SpiceUsbBackendDevice and SpiceUsbDevice are the same
there's no much sense to call it.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Francesco Giudici <fgiudici at redhat.com>
diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
index c6a6b9c..019f044 100644
--- a/src/usb-device-manager.c
+++ b/src/usb-device-manager.c
@@ -143,9 +143,6 @@ static void _usbdk_hider_clear(SpiceUsbDeviceManager *manager);
static gboolean spice_usb_manager_device_equal_bdev(SpiceUsbDeviceManager *manager,
SpiceUsbDevice *device,
SpiceUsbBackendDevice *bdev);
-static SpiceUsbBackendDevice *
-spice_usb_device_manager_device_to_bdev(SpiceUsbDeviceManager *manager,
- SpiceUsbDevice *device);
static void
_spice_usb_device_manager_connect_device_async(SpiceUsbDeviceManager *manager,
@@ -896,7 +893,6 @@ static void spice_usb_device_manager_check_redir_on_connect(SpiceUsbDeviceManage
SpiceUsbDeviceManagerPrivate *priv = manager->priv;
GTask *task;
SpiceUsbDevice *device;
- SpiceUsbBackendDevice *bdev;
guint i;
if (priv->redirect_on_connect == NULL) {
@@ -910,8 +906,7 @@ static void spice_usb_device_manager_check_redir_on_connect(SpiceUsbDeviceManage
continue;
}
- bdev = spice_usb_device_manager_device_to_bdev(manager, device);
- if (spice_usb_backend_device_check_filter(bdev,
+ if (spice_usb_backend_device_check_filter(device,
priv->redirect_on_connect_rules,
priv->redirect_on_connect_rules_count) == 0) {
/* Note: re-uses spice_usb_device_manager_connect_device_async's
@@ -922,14 +917,11 @@ static void spice_usb_device_manager_check_redir_on_connect(SpiceUsbDeviceManage
spice_usb_device_ref(device));
spice_usbredir_channel_connect_device_async(SPICE_USBREDIR_CHANNEL(channel),
- bdev, device, NULL,
+ device, device, NULL,
spice_usb_device_manager_channel_connect_cb,
task);
- spice_usb_backend_device_unref(bdev);
return; /* We've taken the channel! */
}
-
- spice_usb_backend_device_unref(bdev);
}
}
@@ -1014,11 +1006,8 @@ GPtrArray* spice_usb_device_manager_get_devices_with_filter(SpiceUsbDeviceManage
SpiceUsbDevice *device = g_ptr_array_index(priv->devices, i);
if (rules) {
- SpiceUsbBackendDevice *bdev =
- spice_usb_device_manager_device_to_bdev(manager, device);
gboolean filter_ok =
- (spice_usb_backend_device_check_filter(bdev, rules, count) == 0);
- spice_usb_backend_device_unref(bdev);
+ (spice_usb_backend_device_check_filter(device, rules, count) == 0);
if (!filter_ok) {
continue;
}
@@ -1094,7 +1083,6 @@ _spice_usb_device_manager_connect_device_async(SpiceUsbDeviceManager *manager,
task = g_task_new(manager, cancellable, callback, user_data);
SpiceUsbDeviceManagerPrivate *priv = manager->priv;
- SpiceUsbBackendDevice *bdev;
guint i;
if (spice_usb_device_manager_is_device_connected(manager, device)) {
@@ -1111,12 +1099,10 @@ _spice_usb_device_manager_connect_device_async(SpiceUsbDeviceManager *manager,
continue; /* Skip already used channels */
}
- bdev = spice_usb_device_manager_device_to_bdev(manager, device);
- spice_usbredir_channel_connect_device_async(channel, bdev, device,
+ spice_usbredir_channel_connect_device_async(channel, device, device,
cancellable,
spice_usb_device_manager_channel_connect_cb,
task);
- spice_usb_backend_device_unref(bdev);
return;
}
@@ -1372,13 +1358,10 @@ spice_usb_device_manager_can_redirect_device(SpiceUsbDeviceManager *manager,
if (guest_filter_rules) {
gboolean filter_ok;
- SpiceUsbBackendDevice *bdev;
- bdev = spice_usb_device_manager_device_to_bdev(manager, device);
- filter_ok = (spice_usb_backend_device_check_filter(bdev,
+ filter_ok = (spice_usb_backend_device_check_filter(device,
guest_filter_rules,
guest_filter_rules_count) == 0);
- spice_usb_backend_device_unref(bdev);
if (!filter_ok) {
g_set_error_literal(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
_("Some USB devices are blocked by host policy"));
@@ -1598,16 +1581,4 @@ spice_usb_manager_device_equal_bdev(SpiceUsbDeviceManager *manager,
return info == bdev;
}
-
-/*
- * Caller must libusb_unref_device the libusb_device returned by this function.
- * Returns a libusb_device, or NULL upon failure
- */
-static SpiceUsbBackendDevice *
-spice_usb_device_manager_device_to_bdev(SpiceUsbDeviceManager *manager,
- SpiceUsbDevice *info)
-{
- /* Simply return a ref to the cached libdev */
- return spice_usb_backend_device_ref(info);
-}
#endif /* USE_USBREDIR */
More information about the Spice-commits
mailing list