Update to new usb-backend interface. --- src/usb-device-cd.c | 47 +++++++++++++++++++++++++-------------------- src/usb-device-cd.h | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 21 deletions(-) create mode 100644 src/usb-device-cd.h diff --git a/src/usb-device-cd.c b/src/usb-device-cd.c index 78e8f408..a76ea43e 100644 --- a/src/usb-device-cd.c +++ b/src/usb-device-cd.c @@ -43,6 +43,7 @@ #endif #include "usb-emulation.h" +#include "usb-device-cd.h" #include "cd-usb-bulk-msd.h" typedef struct SpiceCdLU @@ -74,7 +75,7 @@ struct BufferedBulkRead uint64_t id; }; -struct _SpiceUsbEmulatedDevice +struct SpiceUsbEmulatedDevice { UsbDeviceOps dev_ops; SpiceUsbBackend *backend; @@ -725,11 +726,12 @@ static const UsbDeviceOps devops = .unrealize = usb_cd_unrealize, }; -static int usb_cd_create(SpiceUsbBackend *be, - SpiceUsbBackendDevice *parent, - UsbCreateDeviceParameters *param, - UsbCd **dev) +static UsbCd* usb_cd_create(SpiceUsbBackend *be, + SpiceUsbBackendDevice *parent, + void *opaque_param, + GError **err) { + CdEmulationParams *param = opaque_param; int error = 0; uint32_t unit = 0; UsbCd *d = g_new0(UsbCd, 1); @@ -738,7 +740,7 @@ static int usb_cd_create(SpiceUsbBackend *be, d->dev_ops = devops; d->backend = be; d->parent = parent; - d->delete_on_eject = !!param->device_param.create_cd.delete_on_eject; + d->delete_on_eject = !!param->delete_on_eject; d->locked = !d->delete_on_eject; d->serial[0] = 0x0308; d->serial[1] = 'X'; @@ -753,13 +755,13 @@ static int usb_cd_create(SpiceUsbBackend *be, d->msc = cd_usb_bulk_msd_alloc(d, MAX_LUN_PER_DEVICE); if (!d->msc) { g_clear_pointer(&d, g_free); - param->error = g_error_new(SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED, - _("can't allocate device")); - return 1; + g_set_error(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED, + _("can't allocate device")); + return NULL; } d->units[unit].blockSize = CD_DEV_BLOCK_SIZE; if (!cd_usb_bulk_msd_realize(d->msc, unit, &dev_params)) { - if (open_stream(&d->units[unit], param->device_param.create_cd.filename) && + if (open_stream(&d->units[unit], param->filename) && load_lun(d, unit, TRUE)) { if (d->locked) { cd_usb_bulk_msd_lock(d->msc, unit, TRUE); @@ -767,28 +769,31 @@ static int usb_cd_create(SpiceUsbBackend *be, } else { close_stream(&d->units[unit]); cd_usb_bulk_msd_unrealize(d->msc, unit); - param->error = g_error_new(SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED, - _("can't create device with %s"), - param->device_param.create_cd.filename); - error = 3; + g_set_error(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED, + _("can't create device with %s"), + param->filename); + error = 1; } } else { - error = 2; - param->error = g_error_new(SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED, - _("can't allocate device")); + g_set_error(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED, + _("can't allocate device")); + error = 1; } if (error) { g_clear_pointer(&d->msc, cd_usb_bulk_msd_free); g_clear_pointer(&d, g_free); + return NULL; } - *dev = d; - return error; + return d; } -void spice_usb_device_register_cd(SpiceUsbBackend *be) +SpiceUsbBackendDevice* +create_emulated_cd(SpiceUsbBackend *be, + CdEmulationParams *param, + GError **err) { - spice_usb_backend_register_device_type(be, USB_DEV_TYPE_CD, usb_cd_create); + return spice_usb_backend_create_emulated_device(be, usb_cd_create, param, err); } #endif /* USE_USBREDIR */ diff --git a/src/usb-device-cd.h b/src/usb-device-cd.h new file mode 100644 index 00000000..eb082b78 --- /dev/null +++ b/src/usb-device-cd.h @@ -0,0 +1,37 @@ +/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + Copyright (C) 2019 Red Hat, Inc. + + Red Hat Authors: + Yuri Benditovich<ybendito@xxxxxxxxxx> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef SPICE_GTK_USB_DEVICE_CD_H_ +#define SPICE_GTK_USB_DEVICE_CD_H_ + +#include "usb-backend.h" + +typedef struct CdEmulationParams { + const char *filename; + uint32_t delete_on_eject : 1; +} CdEmulationParams; + +SpiceUsbBackendDevice* +create_emulated_cd(SpiceUsbBackend *be, + CdEmulationParams *param, + GError **err); + +#endif // SPICE_GTK_USB_DEVICE_CD_H_ -- 2.20.1 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel