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

Hans de Goede hdegoede at redhat.com
Thu Sep 1 03:23:51 PDT 2011


libusb_strerror is not going upstream because of i18n worries, provide
our own for now.

Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 gtk/Makefile.am         |    4 ++-
 gtk/channel-usbredir.c  |    6 +---
 gtk/gusb/gusb-context.c |    6 +---
 gtk/gusb/gusb-source.c  |    6 +---
 gtk/gusb/gusb-util.c    |   65 +++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gusb/gusb-util.h    |   32 +++++++++++++++++++++++
 6 files changed, 106 insertions(+), 13 deletions(-)
 create mode 100644 gtk/gusb/gusb-util.c
 create mode 100644 gtk/gusb/gusb-util.h

diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 74a45dc..6759d45 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -173,7 +173,9 @@ GUSB_SRCS =				\
 	gusb/gusb-device-list.h		\
 	gusb/gusb-marshal.h		\
 	gusb/gusb-source.c		\
-	gusb/gusb-source.h
+	gusb/gusb-source.h		\
+	gusb/gusb-util.c		\
+	gusb/gusb-util.h
 else
 GUSB_SRCS =
 endif
diff --git a/gtk/channel-usbredir.c b/gtk/channel-usbredir.c
index b567fcc..bb90dca 100644
--- a/gtk/channel-usbredir.c
+++ b/gtk/channel-usbredir.c
@@ -25,6 +25,7 @@
 #include <usbredirhost.h>
 #include <gusb/gusb-context-private.h>
 #include <gusb/gusb-device-private.h>
+#include <gusb/gusb-util.h>
 #include "channel-usbredir-priv.h"
 #endif
 
@@ -33,9 +34,6 @@
 
 #include "spice-channel-priv.h"
 
-/* libusb_strerror is awaiting merging upstream */
-#define libusb_strerror(error) "unknown"
-
 /**
  * SECTION:channel-usbredir
  * @short_description: usb redirection
@@ -140,7 +138,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);
+                    gusb_strerror(rc), rc);
         return FALSE;
     }
 
diff --git a/gtk/gusb/gusb-context.c b/gtk/gusb/gusb-context.c
index 339b821..01eac06 100644
--- a/gtk/gusb/gusb-context.c
+++ b/gtk/gusb/gusb-context.c
@@ -30,12 +30,10 @@
 
 #include <libusb-1.0/libusb.h>
 
+#include "gusb-util.h"
 #include "gusb-context.h"
 #include "gusb-context-private.h"
 
-/* libusb_strerror is awaiting merging upstream */
-#define libusb_strerror(error) "unknown"
-
 static void g_usb_context_finalize (GObject *object);
 
 #define G_USB_CONTEXT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), G_USB_TYPE_CONTEXT, GUsbContextPrivate))
@@ -282,7 +280,7 @@ g_usb_context_new (GError **error)
 			     G_USB_CONTEXT_ERROR,
 			     G_USB_CONTEXT_ERROR_INTERNAL,
 			     "failed to init libusb: %s [%i]",
-			     libusb_strerror (rc), rc);
+			     gusb_strerror (rc), rc);
 		return NULL;
 	}
 
diff --git a/gtk/gusb/gusb-source.c b/gtk/gusb/gusb-source.c
index 0324e68..bb0af49 100644
--- a/gtk/gusb/gusb-source.c
+++ b/gtk/gusb/gusb-source.c
@@ -33,6 +33,7 @@
 #include <poll.h>
 #include <stdlib.h>
 
+#include "gusb-util.h"
 #include "gusb-context.h"
 #include "gusb-context-private.h"
 #include "gusb-source.h"
@@ -53,9 +54,6 @@ g_usb_source_error_quark (void)
 	return quark;
 }
 
-/* libusb_strerror is awaiting merging upstream */
-#define libusb_strerror(error) "unknown"
-
 struct _GUsbSource {
 	GSource		 source;
 	GSList		*pollfds;
@@ -193,7 +191,7 @@ g_usb_source_dispatch (GSource *source,
 	rc = libusb_handle_events_timeout (usb_source->ctx, &tv);
 	if (rc < 0) {
 		g_warning ("failed to handle event: %s [%i]",
-			   libusb_strerror (rc), rc);
+			   gusb_strerror (rc), rc);
 	}
 
 	if (callback)
diff --git a/gtk/gusb/gusb-util.c b/gtk/gusb/gusb-util.c
new file mode 100644
index 0000000..ca91700
--- /dev/null
+++ b/gtk/gusb/gusb-util.c
@@ -0,0 +1,65 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2011 Hans de Goede <hdegoede at redhat.com>
+ *
+ * Licensed under the GNU Lesser General Public License Version 2.1
+ *
+ * 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 <libusb-1.0/libusb.h>
+
+#include "gusb-util.h"
+
+/* libusb_strerror is not going upstream in the forseeable future because of
+   i18n worries, provide our own implementation for now, later this can
+   hopefully became just a wrapper of the upstream version */
+const gchar* gusb_strerror(gint error_code)
+{
+    enum libusb_error error = error_code;
+
+    switch (error) {
+    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";
+}
diff --git a/gtk/gusb/gusb-util.h b/gtk/gusb/gusb-util.h
new file mode 100644
index 0000000..c270853
--- /dev/null
+++ b/gtk/gusb/gusb-util.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2011 Hans de Goede <hdegoede at redhat.com>
+ *
+ * Licensed under the GNU Lesser General Public License Version 2.1
+ *
+ * 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 __GUSB_UTIL_H__
+#define __GUSB_UTIL_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+const gchar* gusb_strerror(gint error_code);
+
+G_END_DECLS
+
+#endif /* __GUSB_UTIL_H__ */
-- 
1.7.6.1



More information about the Spice-devel mailing list