As per the roadmap. This is something I realized right after 1.0.12, as
LOG_LEVEL_XYZ is lilely to be generic enoug to conflict with other apps
and headers that may define those as well.
This is also in part the source of Trac #31, which is an issue with
libusb-compat, as libusb-compat's core.c does redefine the LOG_LEVEL_XYZ
enums.
Regards,
/Pete
>From acc7770224bd9bdd74a7464bcec8be20a8c3b334 Mon Sep 17 00:00:00 2001
From: Pete Batard <p...@akeo.ie>
Date: Mon, 2 Jul 2012 23:39:19 +0100
Subject: [PATCH] Core: Prefix LOG_LEVEL_ with LIBUSB_ to avoid conflicts
* The LOG_LEVEL_ enums, that were moved to the public API
in 933a319469bcccc962031c989e39d9d1f44f2885 may conflict
with applications/headers that also define their own
LOG_LEVEL_ values internally.
* As a matter of fact, as per Trac #31, this produces a
conflict with libusb-compat, as it defines its own levels.
---
examples/xusb.c | 2 +-
libusb/core.c | 24 ++++++++++++------------
libusb/libusb.h | 20 ++++++++++----------
libusb/libusbi.h | 16 ++++++++--------
4 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/examples/xusb.c b/examples/xusb.c
index 0eafd8c..3e8d262 100644
--- a/examples/xusb.c
+++ b/examples/xusb.c
@@ -1021,7 +1021,7 @@ int main(int argc, char** argv)
if (r < 0)
return r;
- libusb_set_debug(NULL, debug_mode?LOG_LEVEL_DEBUG:LOG_LEVEL_INFO);
+ libusb_set_debug(NULL,
debug_mode?LIBUSB_LOG_LEVEL_DEBUG:LIBUSB_LOG_LEVEL_INFO);
test_device(VID, PID);
diff --git a/libusb/core.c b/libusb/core.c
index 8845909..31f93ba 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -1567,11 +1567,11 @@ int API_EXPORTED
libusb_attach_kernel_driver(libusb_device_handle *dev,
/** \ingroup lib
* Set log message verbosity.
*
- * The default level is \ref LOG_LEVEL_NONE, which means no messages are ever
+ * The default level is LIBUSB_LOG_LEVEL_NONE, which means no messages are ever
* printed. If you choose to increase the message verbosity level, ensure
* that your application does not close the stdout/stderr file descriptors.
*
- * You are advised to use level \ref LOG_LEVEL_WARNING. libusbx is conservative
+ * You are advised to use level LIBUSB_LOG_LEVEL_WARNING. libusbx is
conservative
* with its message logging and most of the time, will only log messages that
* explain error conditions and other oddities. This will help you debug
* your software.
@@ -1636,7 +1636,7 @@ int API_EXPORTED libusb_init(libusb_context **context)
memset(ctx, 0, sizeof(*ctx));
#ifdef ENABLE_DEBUG_LOGGING
- ctx->debug = LOG_LEVEL_DEBUG;
+ ctx->debug = LIBUSB_LOG_LEVEL_DEBUG;
#endif
dbg = getenv("LIBUSB_DEBUG");
@@ -1807,14 +1807,14 @@ void usbi_log_v(struct libusb_context *ctx, enum
usbi_log_level level,
USBI_GET_CONTEXT(ctx);
if (ctx == NULL)
return;
- global_debug = (ctx->debug == LOG_LEVEL_DEBUG);
+ global_debug = (ctx->debug == LIBUSB_LOG_LEVEL_DEBUG);
if (!ctx->debug)
return;
- if (level == LOG_LEVEL_WARNING && ctx->debug < LOG_LEVEL_WARNING)
+ if (level == LIBUSB_LOG_LEVEL_WARNING && ctx->debug <
LIBUSB_LOG_LEVEL_WARNING)
return;
- if (level == LOG_LEVEL_INFO && ctx->debug < LOG_LEVEL_INFO)
+ if (level == LIBUSB_LOG_LEVEL_INFO && ctx->debug <
LIBUSB_LOG_LEVEL_INFO)
return;
- if (level == LOG_LEVEL_DEBUG && ctx->debug < LOG_LEVEL_DEBUG)
+ if (level == LIBUSB_LOG_LEVEL_DEBUG && ctx->debug <
LIBUSB_LOG_LEVEL_DEBUG)
return;
#endif
@@ -1832,19 +1832,19 @@ void usbi_log_v(struct libusb_context *ctx, enum
usbi_log_level level,
now.tv_usec -= timestamp_origin.tv_usec;
switch (level) {
- case LOG_LEVEL_INFO:
+ case LIBUSB_LOG_LEVEL_INFO:
prefix = "info";
break;
- case LOG_LEVEL_WARNING:
+ case LIBUSB_LOG_LEVEL_WARNING:
prefix = "warning";
break;
- case LOG_LEVEL_ERROR:
+ case LIBUSB_LOG_LEVEL_ERROR:
prefix = "error";
break;
- case LOG_LEVEL_DEBUG:
+ case LIBUSB_LOG_LEVEL_DEBUG:
prefix = "debug";
break;
- case LOG_LEVEL_NONE:
+ case LIBUSB_LOG_LEVEL_NONE:
break;
default:
prefix = "unknown";
diff --git a/libusb/libusb.h b/libusb/libusb.h
index fd231ea..ac5f0ea 100644
--- a/libusb/libusb.h
+++ b/libusb/libusb.h
@@ -951,20 +951,20 @@ enum libusb_capability {
/** \ingroup lib
* Log message levels.
- * - LOG_LEVEL_NONE (0) : no messages ever printed by the library (default)
- * - LOG_LEVEL_ERROR (1) : error messages are printed to stderr
- * - LOG_LEVEL_WARNING (2) : warning and error messages are printed to stderr
- * - LOG_LEVEL_INFO (3) : informational messages are printed to stdout,
warning
+ * - LIBUSB_LOG_LEVEL_NONE (0) : no messages ever printed by the library
(default)
+ * - LIBUSB_LOG_LEVEL_ERROR (1) : error messages are printed to stderr
+ * - LIBUSB_LOG_LEVEL_WARNING (2) : warning and error messages are printed to
stderr
+ * - LIBUSB_LOG_LEVEL_INFO (3) : informational messages are printed to
stdout, warning
* and error messages are printed to stderr
- * - LOG_LEVEL_DEBUG (4) : debug and informational messages are printed to
stdout,
+ * - LIBUSB_LOG_LEVEL_DEBUG (4) : debug and informational messages are
printed to stdout,
* warnings and errors to stderr
*/
enum usbi_log_level {
- LOG_LEVEL_NONE = 0,
- LOG_LEVEL_ERROR,
- LOG_LEVEL_WARNING,
- LOG_LEVEL_INFO,
- LOG_LEVEL_DEBUG,
+ LIBUSB_LOG_LEVEL_NONE = 0,
+ LIBUSB_LOG_LEVEL_ERROR,
+ LIBUSB_LOG_LEVEL_WARNING,
+ LIBUSB_LOG_LEVEL_INFO,
+ LIBUSB_LOG_LEVEL_DEBUG,
};
int LIBUSB_CALL libusb_init(libusb_context **ctx);
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index 27362f7..f7f1316 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -140,15 +140,15 @@ void usbi_log_v(struct libusb_context *ctx, enum
usbi_log_level level,
#ifdef ENABLE_LOGGING
#define _usbi_log(ctx, level, ...) usbi_log(ctx, level, __FUNCTION__,
__VA_ARGS__)
-#define usbi_dbg(...) _usbi_log(NULL, LOG_LEVEL_DEBUG, __VA_ARGS__)
+#define usbi_dbg(...) _usbi_log(NULL, LIBUSB_LOG_LEVEL_DEBUG, __VA_ARGS__)
#else
#define _usbi_log(ctx, level, ...) do { (void)(ctx); } while(0)
#define usbi_dbg(...) do {} while(0)
#endif
-#define usbi_info(ctx, ...) _usbi_log(ctx, LOG_LEVEL_INFO, __VA_ARGS__)
-#define usbi_warn(ctx, ...) _usbi_log(ctx, LOG_LEVEL_WARNING, __VA_ARGS__)
-#define usbi_err(ctx, ...) _usbi_log(ctx, LOG_LEVEL_ERROR, __VA_ARGS__)
+#define usbi_info(ctx, ...) _usbi_log(ctx, LIBUSB_LOG_LEVEL_INFO, __VA_ARGS__)
+#define usbi_warn(ctx, ...) _usbi_log(ctx, LIBUSB_LOG_LEVEL_WARNING,
__VA_ARGS__)
+#define usbi_err(ctx, ...) _usbi_log(ctx, LIBUSB_LOG_LEVEL_ERROR, __VA_ARGS__)
#else /* !defined(_MSC_VER) || _MSC_VER >= 1400 */
@@ -166,16 +166,16 @@ void usbi_log_v(struct libusb_context *ctx, enum
usbi_log_level level,
static inline void usbi_info(struct libusb_context *ctx, const char *format,
...)
- LOG_BODY(ctx,LOG_LEVEL_INFO)
+ LOG_BODY(ctx,LIBUSB_LOG_LEVEL_INFO)
static inline void usbi_warn(struct libusb_context *ctx, const char *format,
...)
- LOG_BODY(ctx,LOG_LEVEL_WARNING)
+ LOG_BODY(ctx,LIBUSB_LOG_LEVEL_WARNING)
static inline void usbi_err( struct libusb_context *ctx, const char *format,
...)
- LOG_BODY(ctx,LOG_LEVEL_ERROR)
+ LOG_BODY(ctx,LIBUSB_LOG_LEVEL_ERROR)
static inline void usbi_dbg(const char *format, ...)
- LOG_BODY(NULL,LOG_LEVEL_DEBUG)
+ LOG_BODY(NULL,LIBUSB_LOG_LEVEL_DEBUG)
#endif /* !defined(_MSC_VER) || _MSC_VER >= 1400 */
--
1.7.11.msysgit.0
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel