summaryrefslogtreecommitdiff
path: root/gusb/gusb-context.c
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2021-05-20 22:01:47 +0100
committerRichard Hughes <richard@hughsie.com>2021-05-21 10:59:20 +0100
commita050309250f87ec733469c6b8030757ab8304c42 (patch)
treec498596647b1e917122e17e20c3d41eb58ed0da3 /gusb/gusb-context.c
parentf889d9801f490b67558b2c7a71dc1f3e1eb445a7 (diff)
downloadgusb-a050309250f87ec733469c6b8030757ab8304c42.tar.gz
Lower the libusb dep to fix compile on FreeBSD
FreeBSD is not a supported platform of libusb. The native USB access library on FreeBSD is libusb20, which provides both the non-portable FreeBSD-specific API and wrapper functions that are mostly compatible eith libusb 1.0 API. It is an integral part of FreeBSD and the version included in the oldest supported FreeBSD release reports 1.0.9 in its libusb-1.0.pc. Based on a patch by Ting-Wei Lan <lantw@src.gnome.org>, many thanks.
Diffstat (limited to 'gusb/gusb-context.c')
-rw-r--r--gusb/gusb-context.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/gusb/gusb-context.c b/gusb/gusb-context.c
index d811650..36c2dd1 100644
--- a/gusb/gusb-context.c
+++ b/gusb/gusb-context.c
@@ -56,6 +56,11 @@ struct _GUsbContextPrivate
libusb_hotplug_callback_handle hotplug_id;
};
+/* not defined in FreeBSD */
+#ifndef HAVE_LIBUSB_CAP_HAS_HOTPLUG
+#define LIBUSB_CAP_HAS_HOTPLUG 0x0001
+#endif
+
typedef struct {
GMainLoop *loop;
GUsbDevice *device;
@@ -72,6 +77,17 @@ G_DEFINE_TYPE_WITH_CODE (GUsbContext, g_usb_context, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE(G_TYPE_INITABLE,
g_usb_context_initable_iface_init))
+/* not defined in FreeBSD */
+#ifndef HAVE_LIBUSB_HAS_CAPABILITY
+static gboolean
+libusb_has_capability (int cap)
+{
+ if (cap == LIBUSB_CAP_HAS_HOTPLUG)
+ return TRUE;
+ return FALSE;
+}
+#endif
+
static void
g_usb_context_replug_helper_free (GUsbContextReplugHelper *replug_helper)
{
@@ -151,7 +167,7 @@ g_usb_context_set_property (GObject *object,
switch (prop_id) {
case PROP_DEBUG_LEVEL:
priv->debug_level = g_value_get_int (value);
-#ifdef HAVE_LIBUSB_1_0_22
+#ifdef HAVE_LIBUSB_SET_OPTION
libusb_set_option (priv->ctx, LIBUSB_OPTION_LOG_LEVEL, priv->debug_level);
#else
libusb_set_debug (priv->ctx, priv->debug_level);
@@ -452,7 +468,6 @@ g_usb_context_rescan_cb (gpointer user_data)
return TRUE;
}
-
/**
* g_usb_context_get_main_context:
* @context: a #GUsbContext
@@ -710,7 +725,7 @@ g_usb_context_set_debug (GUsbContext *context,
if (debug_level != priv->debug_level) {
priv->debug_level = debug_level;
-#ifdef HAVE_LIBUSB_1_0_22
+#ifdef HAVE_LIBUSB_SET_OPTION
libusb_set_option (priv->ctx, LIBUSB_OPTION_LOG_LEVEL, debug_level);
#else
libusb_set_debug (priv->ctx, debug_level);