[Spice-devel,spice-gtk,4/4] usbredir: provide out own libusb_strerror for now

Submitted by Hans de Goede on Aug. 31, 2011, 8:21 p.m.

Details

Message ID 1314796919-22484-4-git-send-email-hdegoede@redhat.com
State New, archived
Headers show

Not browsing as part of any series.

Commit Message

Hans de Goede Aug. 31, 2011, 8:21 p.m.
libusb_strerror is not going upstream because of i18n worries, provide
our own for now.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 gtk/channel-usbredir.c |   40 +++++++++++++++++++++++++++++++++++++---
 1 files changed, 37 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/gtk/channel-usbredir.c b/gtk/channel-usbredir.c
index b567fcc..57b5a5a 100644
--- a/gtk/channel-usbredir.c
+++ b/gtk/channel-usbredir.c
@@ -33,8 +33,42 @@ 
 
 #include "spice-channel-priv.h"
 
-/* libusb_strerror is awaiting merging upstream */
-#define libusb_strerror(error) "unknown"
+/* libusb_strerror is not going upstream because of i18n worries, provide
+   our own for now */
+static const char* my_libusb_strerror(enum libusb_error errcode)
+{
+    switch (errcode) {
+    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";
+}
 
 /**
  * SECTION:channel-usbredir
@@ -140,7 +174,7 @@  gboolean spice_usbredir_channel_connect(SpiceUsbredirChannel *channel,
     if (rc != 0) {
         g_set_error(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
                     "Could not open usb device: %s [%i]",
-                    libusb_strerror(rc), rc);
+                    my_libusb_strerror(rc), rc);
         return FALSE;
     }
 

Comments

Hi

- This function needs to be protected by #ifdef USE_USBREDIR
- Could the string made translatable? if not why?
- Could it be moved to gtk/gusb, so that it could also benefit friendly errors?

On Wed, Aug 31, 2011 at 3:21 PM, Hans de Goede <hdegoede@redhat.com> wrote:
> libusb_strerror is not going upstream because of i18n worries, provide
> our own for now.
>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  gtk/channel-usbredir.c |   40 +++++++++++++++++++++++++++++++++++++---
>  1 files changed, 37 insertions(+), 3 deletions(-)
>
> diff --git a/gtk/channel-usbredir.c b/gtk/channel-usbredir.c
> index b567fcc..57b5a5a 100644
> --- a/gtk/channel-usbredir.c
> +++ b/gtk/channel-usbredir.c
> @@ -33,8 +33,42 @@
>
>  #include "spice-channel-priv.h"
>
> -/* libusb_strerror is awaiting merging upstream */
> -#define libusb_strerror(error) "unknown"
> +/* libusb_strerror is not going upstream because of i18n worries, provide
> +   our own for now */
> +static const char* my_libusb_strerror(enum libusb_error errcode)
> +{
> +    switch (errcode) {
> +    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";
> +}
>
>  /**
>  * SECTION:channel-usbredir
> @@ -140,7 +174,7 @@ gboolean spice_usbredir_channel_connect(SpiceUsbredirChannel *channel,
>     if (rc != 0) {
>         g_set_error(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
>                     "Could not open usb device: %s [%i]",
> -                    libusb_strerror(rc), rc);
> +                    my_libusb_strerror(rc), rc);
>         return FALSE;
>     }
>
> --
> 1.7.6.1
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
>
Hi,

On 08/31/2011 03:57 PM, Marc-André Lureau wrote:
> Hi
>
> - This function needs to be protected by #ifdef USE_USBREDIR
> - Could the string made translatable? if not why?

Currently we don't do any translations in spice-gtk at all, try
adding a _() around any string, last time I tried it failed with
no such variable/function: _

> - Could it be moved to gtk/gusb, so that it could also benefit friendly errors?

Yes that is a good idea, I will send a new version moving it to gusb

Regards,

Hans

>
> On Wed, Aug 31, 2011 at 3:21 PM, Hans de Goede<hdegoede@redhat.com>  wrote:
>> libusb_strerror is not going upstream because of i18n worries, provide
>> our own for now.
>>
>> Signed-off-by: Hans de Goede<hdegoede@redhat.com>
>> ---
>>   gtk/channel-usbredir.c |   40 +++++++++++++++++++++++++++++++++++++---
>>   1 files changed, 37 insertions(+), 3 deletions(-)
>>
>> diff --git a/gtk/channel-usbredir.c b/gtk/channel-usbredir.c
>> index b567fcc..57b5a5a 100644
>> --- a/gtk/channel-usbredir.c
>> +++ b/gtk/channel-usbredir.c
>> @@ -33,8 +33,42 @@
>>
>>   #include "spice-channel-priv.h"
>>
>> -/* libusb_strerror is awaiting merging upstream */
>> -#define libusb_strerror(error) "unknown"
>> +/* libusb_strerror is not going upstream because of i18n worries, provide
>> +   our own for now */
>> +static const char* my_libusb_strerror(enum libusb_error errcode)
>> +{
>> +    switch (errcode) {
>> +    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";
>> +}
>>
>>   /**
>>   * SECTION:channel-usbredir
>> @@ -140,7 +174,7 @@ gboolean spice_usbredir_channel_connect(SpiceUsbredirChannel *channel,
>>      if (rc != 0) {
>>          g_set_error(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
>>                      "Could not open usb device: %s [%i]",
>> -                    libusb_strerror(rc), rc);
>> +                    my_libusb_strerror(rc), rc);
>>          return FALSE;
>>      }
>>
>> --
>> 1.7.6.1
>>
>> _______________________________________________
>> Spice-devel mailing list
>> Spice-devel@lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/spice-devel
>>
>
>
>