Re: [spice-gtk] usbutil: replace local function with libusb_strerror()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 
> From: Victor Toso <me@xxxxxxxxxxxxxx>
> 
> As libusb_strerror() does exactly what spice_usbutil_libusb_strerror()
> is doing. Notice that we can change the description language with
> libusb_setlocale() but keeping it in English by default (as it is) for
> now.
> 
> Signed-off-by: Victor Toso <victortoso@xxxxxxxxxx>

Acked-by: Frediano Ziglio <fziglio@xxxxxxxxxx>

> ---
>  src/channel-usbredir.c   |  2 +-
>  src/usb-device-manager.c |  8 ++++----
>  src/usbutil.c            | 36 ------------------------------------
>  src/usbutil.h            |  1 -
>  src/win-usb-dev.c        |  4 ++--
>  5 files changed, 7 insertions(+), 44 deletions(-)
> 
> diff --git a/src/channel-usbredir.c b/src/channel-usbredir.c
> index 1910ff6..a54f67b 100644
> --- a/src/channel-usbredir.c
> +++ b/src/channel-usbredir.c
> @@ -292,7 +292,7 @@ static gboolean spice_usbredir_channel_open_device(
>      if (rc != 0) {
>          g_set_error(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
>                      "Could not open usb device: %s [%i]",
> -                    spice_usbutil_libusb_strerror(rc), rc);
> +                    libusb_strerror(rc), rc);
>          return FALSE;
>      }
>  
> diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
> index bd42142..9391d6a 100644
> --- a/src/usb-device-manager.c
> +++ b/src/usb-device-manager.c
> @@ -281,7 +281,7 @@ static gboolean
> spice_usb_device_manager_initable_init(GInitable  *initable,
>      /* Initialize libusb */
>      rc = libusb_init(&priv->context);
>      if (rc < 0) {
> -        const char *desc = spice_usbutil_libusb_strerror(rc);
> +        const char *desc = libusb_strerror(rc);
>          g_warning("Error initializing USB support: %s [%i]", desc, rc);
>          g_set_error(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
>                      "Error initializing USB support: %s [%i]", desc, rc);
> @@ -308,7 +308,7 @@ static gboolean
> spice_usb_device_manager_initable_init(GInitable  *initable,
>          LIBUSB_HOTPLUG_MATCH_ANY, LIBUSB_HOTPLUG_MATCH_ANY,
>          spice_usb_device_manager_hotplug_cb, self, &priv->hp_handle);
>      if (rc < 0) {
> -        const char *desc = spice_usbutil_libusb_strerror(rc);
> +        const char *desc = libusb_strerror(rc);
>          g_warning("Error initializing USB hotplug support: %s [%i]", desc,
>          rc);
>          g_set_error(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
>                    "Error initializing USB hotplug support: %s [%i]", desc,
>                    rc);
> @@ -730,7 +730,7 @@ static gboolean
> spice_usb_device_manager_get_device_descriptor(
>  
>          bus = libusb_get_bus_number(libdev);
>          addr = libusb_get_device_address(libdev);
> -        errstr = spice_usbutil_libusb_strerror(errcode);
> +        errstr = libusb_strerror(errcode);
>          g_warning("cannot get device descriptor for (%p) %d.%d -- %s(%d)",
>                    libdev, bus, addr, errstr, errcode);
>          return FALSE;
> @@ -1068,7 +1068,7 @@ static gpointer
> spice_usb_device_manager_usb_ev_thread(gpointer user_data)
>      while (g_atomic_int_get(&priv->event_thread_run)) {
>          rc = libusb_handle_events(priv->context);
>          if (rc && rc != LIBUSB_ERROR_INTERRUPTED) {
> -            const char *desc = spice_usbutil_libusb_strerror(rc);
> +            const char *desc = libusb_strerror(rc);
>              g_warning("Error handling USB events: %s [%i]", desc, rc);
>              break;
>          }
> diff --git a/src/usbutil.c b/src/usbutil.c
> index e96ab11..5052ef3 100644
> --- a/src/usbutil.c
> +++ b/src/usbutil.c
> @@ -58,42 +58,6 @@ static GMutex usbids_load_mutex;
>  static int usbids_vendor_count = 0; /* < 0: failed, 0: empty, > 0: loaded */
>  static usb_vendor_info *usbids_vendor_info = NULL;
>  
> -G_GNUC_INTERNAL
> -const char *spice_usbutil_libusb_strerror(enum libusb_error error_code)
> -{
> -    switch (error_code) {
> -    case LIBUSB_SUCCESS:
> -        return "Success";
> -    case LIBUSB_ERROR_IO:
> -        return "Input/output error";
> -    case LIBUSB_ERROR_INVALID_PARAM:
> -        return "Invalid parameter";
> -    case LIBUSB_ERROR_ACCESS:
> -        return "Access denied (insufficient permissions)";
> -    case LIBUSB_ERROR_NO_DEVICE:
> -        return "No such device (it may have been disconnected)";
> -    case LIBUSB_ERROR_NOT_FOUND:
> -        return "Entity not found";
> -    case LIBUSB_ERROR_BUSY:
> -        return "Resource busy";
> -    case LIBUSB_ERROR_TIMEOUT:
> -        return "Operation timed out";
> -    case LIBUSB_ERROR_OVERFLOW:
> -        return "Overflow";
> -    case LIBUSB_ERROR_PIPE:
> -        return "Pipe error";
> -    case LIBUSB_ERROR_INTERRUPTED:
> -        return "System call interrupted (perhaps due to signal)";
> -    case LIBUSB_ERROR_NO_MEM:
> -        return "Insufficient memory";
> -    case LIBUSB_ERROR_NOT_SUPPORTED:
> -        return "Operation not supported or unimplemented on this platform";
> -    case LIBUSB_ERROR_OTHER:
> -        return "Other error";
> -    }
> -    return "Unknown error";
> -}
> -
>  #ifdef __linux__
>  /* <Sigh> libusb does not allow getting the manufacturer and product strings
>     without opening the device, so grab them directly from sysfs */
> diff --git a/src/usbutil.h b/src/usbutil.h
> index de5e92a..50e3949 100644
> --- a/src/usbutil.h
> +++ b/src/usbutil.h
> @@ -28,7 +28,6 @@
>  
>  G_BEGIN_DECLS
>  
> -const char *spice_usbutil_libusb_strerror(enum libusb_error error_code);
>  void spice_usb_util_get_device_strings(int bus, int address,
>                                         int vendor_id, int product_id,
>                                         gchar **manufacturer, gchar
>                                         **product);
> diff --git a/src/win-usb-dev.c b/src/win-usb-dev.c
> index a4dfa78..b0274dd 100644
> --- a/src/win-usb-dev.c
> +++ b/src/win-usb-dev.c
> @@ -113,7 +113,7 @@ g_udev_client_list_devices(GUdevClient *self, GList
> **devs,
>  
>      rc = libusb_get_device_list(priv->ctx, &lusb_list);
>      if (rc < 0) {
> -        const char *errstr = spice_usbutil_libusb_strerror(rc);
> +        const char *errstr = libusb_strerror(rc);
>          g_warning("%s: libusb_get_device_list failed - %s", name, errstr);
>          g_set_error(err, G_UDEV_CLIENT_ERROR, G_UDEV_CLIENT_LIBUSB_FAILED,
>                      "%s: Error getting device list from libusb: %s
>                      [%"G_GSSIZE_FORMAT"]",
> @@ -170,7 +170,7 @@ g_udev_client_initable_init(GInitable *initable,
> GCancellable *cancellable,
>  
>      rc = libusb_init(&priv->ctx);
>      if (rc < 0) {
> -        const char *errstr = spice_usbutil_libusb_strerror(rc);
> +        const char *errstr = libusb_strerror(rc);
>          g_warning("Error initializing USB support: %s [%i]", errstr, rc);
>          g_set_error(err, G_UDEV_CLIENT_ERROR, G_UDEV_CLIENT_LIBUSB_FAILED,
>                      "Error initializing USB support: %s [%i]", errstr, rc);
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]