From 40c14fed24ceb675b85a4d851947adaabe51e5f1 Mon Sep 17 00:00:00 2001 From: nirenjan Date: Fri, 1 Feb 2019 21:31:57 -0800 Subject: [PATCH] Update calls to libusb_set_debug With the release of libusb 1.0.22, `libusb_set_debug` has been deprecated and replaced by `libusb_set_option`. This function is a new generic API to add additional functionality in the future without having to introduce new functions. This change checks for `LIBUSB_API_VERSION` of at least `0x01000106`, which is the version corresponding to 1.0.22, and if it matches, it replaces the calls to `libusb_set_debug` with equivalent calls to `libusb_set_option`. --- lib/libusbx52/usb_x52_stub.c | 21 +++++++++++++++++++++ lib/libusbx52/util/log_actions.c | 9 +++++++++ lib/libx52/x52_core.c | 9 +++++++++ 3 files changed, 39 insertions(+) diff --git a/lib/libusbx52/usb_x52_stub.c b/lib/libusbx52/usb_x52_stub.c index 1293fd6..a65de70 100644 --- a/lib/libusbx52/usb_x52_stub.c +++ b/lib/libusbx52/usb_x52_stub.c @@ -8,6 +8,7 @@ #include #include +#include #include #include "libusbx52.h" @@ -129,6 +130,26 @@ void libusb_set_debug(libusb_context *ctx, int level) ctx->debug_level = level; } +#if defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x01000106) +int libusb_set_option(libusb_context *ctx, enum libusb_option option, ...) +{ + va_list args; + va_start(args, option); + + /* Check if the option was provided */ + if (option == LIBUSB_OPTION_LOG_LEVEL) { + int level = va_arg(args, int); + + /* Set the debug level */ + ctx->debug_level = level; + } + + va_end(args); + + return 0; +} +#endif + ssize_t libusb_get_device_list(libusb_context *ctx, libusb_device ***list) { /* Allocate a list of num_devices, each pointing to a corresponding diff --git a/lib/libusbx52/util/log_actions.c b/lib/libusbx52/util/log_actions.c index e94a01d..a350d0d 100644 --- a/lib/libusbx52/util/log_actions.c +++ b/lib/libusbx52/util/log_actions.c @@ -41,7 +41,16 @@ static libusb_device_handle *libusbx52_init(void) return NULL; } + #if defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x01000106) + /* + * Use the libusb_set_option flag instead of libusb_set_debug. This + * was introduced in libusb 1.0.22 + */ + libusb_set_option(global_context, LIBUSB_OPTION_LOG_LEVEL, + LIBUSB_LOG_LEVEL_ERROR); + #else libusb_set_debug(global_context, LIBUSB_LOG_LEVEL_ERROR); + #endif count = libusb_get_device_list(global_context, &list); for (i = 0; i < count; i++) { diff --git a/lib/libx52/x52_core.c b/lib/libx52/x52_core.c index ed693e9..156068d 100644 --- a/lib/libx52/x52_core.c +++ b/lib/libx52/x52_core.c @@ -69,7 +69,16 @@ int libx52_init(libx52_device **dev) rc = LIBX52_ERROR_INIT_FAILURE; goto err_recovery; } + #if defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x01000106) + /* + * Use the libusb_set_option flag instead of libusb_set_debug. This + * was introduced in libusb 1.0.22 + */ + libusb_set_option(x52_dev->ctx, LIBUSB_OPTION_LOG_LEVEL, + LIBUSB_LOG_LEVEL_WARNING); + #else libusb_set_debug(x52_dev->ctx, LIBUSB_LOG_LEVEL_WARNING); + #endif count = libusb_get_device_list(x52_dev->ctx, &list); for (i = 0; i < count; i++) {