On Thu, Jun 28, 2012 at 04:46:33AM +0300, Uri Lublin wrote: > --- > gtk/spice-usb-device-priv.h | 38 +++++++++++++ > gtk/spice-usb-device.c | 124 +++++++++++++++++++++++++++++++++++++++++++ > gtk/spice-usb-device.h | 57 ++++++++++++++++++++ > 3 files changed, 219 insertions(+), 0 deletions(-) > create mode 100644 gtk/spice-usb-device-priv.h > create mode 100644 gtk/spice-usb-device.c > create mode 100644 gtk/spice-usb-device.h > > diff --git a/gtk/spice-usb-device-priv.h b/gtk/spice-usb-device-priv.h > new file mode 100644 > index 0000000..80b3f5c > --- /dev/null > +++ b/gtk/spice-usb-device-priv.h > @@ -0,0 +1,38 @@ > +/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */ > +/* > + Copyright (C) 2011, 2012 Red Hat, Inc. > + > + Red Hat Authors: > + Uri Lublin <uril@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_USB_DEVICE_PRIV_H__ > +#define __SPICE_USB_DEVICE_PRIV_H__ > + > +#include <libusb.h> > + > +G_BEGIN_DECLS > + > +SpiceUsbDevice *spice_usb_device_new(void); > +void spice_usb_device_set_info(SpiceUsbDevice *self, libusb_device *libdev); > + > +guint8 spice_usb_device_get_busnum(SpiceUsbDevice *device); > +guint8 spice_usb_device_get_devaddr(SpiceUsbDevice *device); > +guint16 spice_usb_device_get_vid(SpiceUsbDevice *device); > +guint16 spice_usb_device_get_pid(SpiceUsbDevice *device); > + > +G_END_DECLS > + > +#endif /* __SPICE_USB_DEVICE_PRIV_H__ */ > diff --git a/gtk/spice-usb-device.c b/gtk/spice-usb-device.c > new file mode 100644 > index 0000000..24ac1dd > --- /dev/null > +++ b/gtk/spice-usb-device.c > @@ -0,0 +1,124 @@ > +/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */ > +/* > + Copyright (C) 2011, 2012 Red Hat, Inc. > + > + Red Hat Authors: > + Hans de Goede <hdegoede@xxxxxxxxxx> > + Uri Lublin <uril@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/>. > +*/ > + > +#include "config.h" > + > +#include <glib-object.h> > +#include "spice-usb-device.h" > +#include "spice-usb-device-priv.h" > +#include "usbutil.h" > +#include "glib-compat.h" > + > +#define SPICE_USB_DEVICE_GET_PRIVATE(o) \ > + (G_TYPE_INSTANCE_GET_PRIVATE ((o), SPICE_TYPE_USB_DEVICE, SpiceUsbDevicePrivate)) > + > +struct _SpiceUsbDevicePrivate { > + guint8 bus; > + guint8 addr; > + guint16 vid; > + guint16 pid; > +}; > + > + > +G_DEFINE_TYPE(SpiceUsbDevice, spice_usb_device, G_TYPE_OBJECT) > + > +/* ------------------------------------------------------------------ */ > + > +static void spice_usb_device_init(SpiceUsbDevice *self) > +{ > + self->priv = SPICE_USB_DEVICE_GET_PRIVATE(self); > +} > + > +static void spice_usb_device_class_init(SpiceUsbDeviceClass *klass) > +{ > + g_type_class_add_private(klass, sizeof(SpiceUsbDevicePrivate)); > +} > + > +SpiceUsbDevice *spice_usb_device_new(void) > +{ > + GObject *obj; > + SpiceUsbDevice *device; > + > + obj = g_object_new(SPICE_TYPE_USB_DEVICE, NULL); > + > + device = SPICE_USB_DEVICE(obj); > + > + return device; > +} > + > +void spice_usb_device_set_info(SpiceUsbDevice *self, libusb_device *libdev) When USE_USBREDIR is not defined, there still is a libusb_device definition available? > +{ > + SpiceUsbDevicePrivate *priv; > + > + g_return_if_fail(SPICE_IS_USB_DEVICE(self)); > + priv = self->priv; > + > + g_warn_if_fail(libdev != NULL); > + > +#ifdef USE_USBREDIR > + if (libdev) { > + struct libusb_device_descriptor desc; > + int errcode; > + const gchar *errstr; > + > + priv->bus = libusb_get_bus_number(libdev); > + priv->addr = libusb_get_device_address(libdev); > + > + errcode = libusb_get_device_descriptor(libdev, &desc); > + if (errcode < 0) { > + errstr = spice_usbutil_libusb_strerror(errcode); > + g_warning("cannot get device descriptor for (%p) %d.%d -- %s(%d)", > + libdev, priv->bus, priv->addr, errstr, errcode); > + priv->vid = -1; > + priv->pid = -1; Won't you get a warning with some compilers if you assign -1 to an unsigned integer ? Christophe
Attachment:
pgplKGo6Ys950.pgp
Description: PGP signature
_______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/spice-devel