mirror of https://github.com/nirenjan/libx52.git
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`.debian-packaging
parent
1d51429f10
commit
40c14fed24
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <libusb.h>
|
#include <libusb.h>
|
||||||
#include "libusbx52.h"
|
#include "libusbx52.h"
|
||||||
|
|
||||||
|
@ -129,6 +130,26 @@ void libusb_set_debug(libusb_context *ctx, int level)
|
||||||
ctx->debug_level = 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)
|
ssize_t libusb_get_device_list(libusb_context *ctx, libusb_device ***list)
|
||||||
{
|
{
|
||||||
/* Allocate a list of num_devices, each pointing to a corresponding
|
/* Allocate a list of num_devices, each pointing to a corresponding
|
||||||
|
|
|
@ -41,7 +41,16 @@ static libusb_device_handle *libusbx52_init(void)
|
||||||
return NULL;
|
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);
|
libusb_set_debug(global_context, LIBUSB_LOG_LEVEL_ERROR);
|
||||||
|
#endif
|
||||||
|
|
||||||
count = libusb_get_device_list(global_context, &list);
|
count = libusb_get_device_list(global_context, &list);
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
|
|
|
@ -69,7 +69,16 @@ int libx52_init(libx52_device **dev)
|
||||||
rc = LIBX52_ERROR_INIT_FAILURE;
|
rc = LIBX52_ERROR_INIT_FAILURE;
|
||||||
goto err_recovery;
|
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);
|
libusb_set_debug(x52_dev->ctx, LIBUSB_LOG_LEVEL_WARNING);
|
||||||
|
#endif
|
||||||
|
|
||||||
count = libusb_get_device_list(x52_dev->ctx, &list);
|
count = libusb_get_device_list(x52_dev->ctx, &list);
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
|
|
Loading…
Reference in New Issue