summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac7
-rw-r--r--gusb/Makefile.am6
-rw-r--r--gusb/gusb-context.c6
-rw-r--r--gusb/gusb-device.c77
-rw-r--r--gusb/gusb-device.h1
-rw-r--r--gusb/gusb-source.c6
-rw-r--r--gusb/gusb-util.c65
-rw-r--r--gusb/gusb-util.h32
8 files changed, 136 insertions, 64 deletions
diff --git a/configure.ac b/configure.ac
index ddc8476..57530f1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -124,13 +124,6 @@ AM_CONDITIONAL(HAVE_GUDEV, test x$enable_gudev = xyes)
dnl **** Check for libusb1 ****
PKG_CHECK_MODULES(USB, libusb-1.0 >= 1.0.0)
-AC_CHECK_LIB(usb-1.0,
- libusb_strerror,
- has_new_libusb=yes,
- has_new_libusb=no)
-if test x$has_new_libusb = xyes; then
- AC_DEFINE(HAVE_NEW_USB,1,[Got new libusb])
-fi
dnl ---------------------------------------------------------------------------
dnl - Build self tests
diff --git a/gusb/Makefile.am b/gusb/Makefile.am
index 37d5733..e2690b0 100644
--- a/gusb/Makefile.am
+++ b/gusb/Makefile.am
@@ -25,7 +25,8 @@ libgusbbase_include_HEADERS = \
gusb-device.h \
gusb-device-private.h \
gusb-device-list.h \
- gusb-source.h
+ gusb-source.h \
+ gusb-util.h
libgusb_la_SOURCES = \
gusb-context.c \
@@ -33,7 +34,8 @@ libgusb_la_SOURCES = \
gusb-device-list.c \
gusb-marshal.c \
gusb-marshal.h \
- gusb-source.c
+ gusb-source.c \
+ gusb-util.c
libgusb_la_LIBADD = \
$(GLIB_LIBS) \
diff --git a/gusb/gusb-context.c b/gusb/gusb-context.c
index 91b0ec8..2abd5b4 100644
--- a/gusb/gusb-context.c
+++ b/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/gusb/gusb-device.c b/gusb/gusb-device.c
index 8403cc1..93846bd 100644
--- a/gusb/gusb-device.c
+++ b/gusb/gusb-device.c
@@ -35,12 +35,10 @@
#include "gusb-context.h"
#include "gusb-source.h"
+#include "gusb-util.h"
#include "gusb-device.h"
#include "gusb-device-private.h"
-/* libusb_strerror is awaiting merging upstream */
-#define libusb_strerror(error) "unknown"
-
static void g_usb_device_finalize (GObject *object);
#define G_USB_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), G_USB_TYPE_DEVICE, GUsbDevicePrivate))
@@ -137,7 +135,7 @@ g_usb_device_get_descriptor (GUsbDevice *device, GError **error)
G_USB_DEVICE_ERROR,
G_USB_DEVICE_ERROR_INTERNAL,
"Failed to get USB descriptor for device: %s",
- libusb_strerror (r));
+ gusb_strerror (r));
goto out;
}
priv->has_descriptor = TRUE;
@@ -150,56 +148,41 @@ g_usb_device_libusb_error_to_gerror (GUsbDevice *device,
gint rc,
GError **error)
{
- gboolean ret = FALSE;
+ gint error_code = G_USB_DEVICE_ERROR_INTERNAL;
+ /* Put the rc in libusb's error enum so that gcc warns us if we're
+ missing an error code */
+ enum libusb_error result = rc;
- switch (rc) {
+ switch (result) {
case LIBUSB_SUCCESS:
- ret = TRUE;
- break;
- case LIBUSB_ERROR_TIMEOUT:
- g_set_error (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_TIMED_OUT,
- "the request timed out on %04x:%04x",
- g_usb_device_get_vid (device),
- g_usb_device_get_pid (device));
- break;
+ return TRUE;
+ case LIBUSB_ERROR_INVALID_PARAM:
+ case LIBUSB_ERROR_NOT_FOUND:
+ case LIBUSB_ERROR_NO_MEM:
+ case LIBUSB_ERROR_OTHER:
+ case LIBUSB_ERROR_INTERRUPTED:
+ error_code = G_USB_DEVICE_ERROR_INTERNAL; break;
+ case LIBUSB_ERROR_IO:
+ case LIBUSB_ERROR_OVERFLOW:
case LIBUSB_ERROR_PIPE:
- g_set_error (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_NOT_SUPPORTED,
- "not supported on %04x:%04x",
- g_usb_device_get_vid (device),
- g_usb_device_get_pid (device));
- break;
+ error_code = G_USB_DEVICE_ERROR_IO; break;
+ case LIBUSB_ERROR_TIMEOUT:
+ error_code = G_USB_DEVICE_ERROR_TIMED_OUT; break;
+ case LIBUSB_ERROR_NOT_SUPPORTED:
+ error_code = G_USB_DEVICE_ERROR_NOT_SUPPORTED; break;
case LIBUSB_ERROR_NO_DEVICE:
- g_set_error (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_NO_DEVICE,
- "device %04x:%04x has been disconnected",
- g_usb_device_get_vid (device),
- g_usb_device_get_pid (device));
- break;
case LIBUSB_ERROR_ACCESS:
- g_set_error_literal (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_NO_DEVICE,
- "no permissions to open device");
- break;
case LIBUSB_ERROR_BUSY:
- g_set_error_literal (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_NO_DEVICE,
- "device is busy");
- break;
- default:
- g_set_error (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_INTERNAL,
- "unknown failure: %s [%i]",
- libusb_strerror (rc), rc);
+ error_code = G_USB_DEVICE_ERROR_NO_DEVICE; break;
}
- return ret;
+
+ g_set_error (error, G_USB_DEVICE_ERROR, error_code,
+ "USB error on device %04x:%04x : %s [%i]",
+ g_usb_device_get_vid (device),
+ g_usb_device_get_pid (device),
+ gusb_strerror (rc), rc);
+
+ return FALSE;
}
/**
diff --git a/gusb/gusb-device.h b/gusb/gusb-device.h
index b8f3b4f..acb6572 100644
--- a/gusb/gusb-device.h
+++ b/gusb/gusb-device.h
@@ -77,6 +77,7 @@ typedef enum {
**/
typedef enum {
G_USB_DEVICE_ERROR_INTERNAL,
+ G_USB_DEVICE_ERROR_IO,
G_USB_DEVICE_ERROR_TIMED_OUT,
G_USB_DEVICE_ERROR_NOT_SUPPORTED,
G_USB_DEVICE_ERROR_NO_DEVICE,
diff --git a/gusb/gusb-source.c b/gusb/gusb-source.c
index 9932cdf..e6c2801 100644
--- a/gusb/gusb-source.c
+++ b/gusb/gusb-source.c
@@ -35,6 +35,7 @@
#include "gusb-context.h"
#include "gusb-context-private.h"
+#include "gusb-util.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;
@@ -197,7 +195,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/gusb/gusb-util.c b/gusb/gusb-util.c
new file mode 100644
index 0000000..ca91700
--- /dev/null
+++ b/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@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/gusb/gusb-util.h b/gusb/gusb-util.h
new file mode 100644
index 0000000..c270853
--- /dev/null
+++ b/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@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__ */