[PATCH] Core: Add get_version() call
Pete Batard
pete at akeo.ie
Tue Apr 10 07:48:32 EDT 2012
If we're going to have a nano updated on each commit, might as well make
good use of it ;)
This patch introduces a new libusb_get_version() call to the API, that
application developers can use to get the major, minor, micro and nano
of the current library being used. The version is returned as a
libusb_version structure:
struct libusb_version {
uint16_t major;
uint16_t minor;
uint16_t micro;
uint16_t nano;
};
The "choice" of uint16_t is mostly due to MSVC DLL versioning
limitations, Microsoft restricts us to a set 4 words there, though I
doubt this should limit us much.
An example of the use of libusb_get_version() can be found in the
updated xusb sample.
Regards,
/Pete
-------------- next part --------------
>From 37dfd16c8c2f36c81c86de303072def0dc405e32 Mon Sep 17 00:00:00 2001
From: Pete Batard <pete at akeo.ie>
Date: Tue, 10 Apr 2012 11:58:53 +0100
Subject: [PATCH] Core: Add get_version() call
* Also some formatting/typo improvements
---
examples/xusb.c | 6 +-----
libusb/core.c | 14 +++++++++++++-
libusb/libusb-1.0.def | 2 ++
libusb/libusb-1.0.rc | 9 ++++++---
libusb/libusb.h | 31 +++++++++++++++++++++----------
libusb/libusbi.h | 1 +
6 files changed, 44 insertions(+), 19 deletions(-)
diff --git a/examples/xusb.c b/examples/xusb.c
index b1d338f..aa46b8e 100644
--- a/examples/xusb.c
+++ b/examples/xusb.c
@@ -758,9 +758,7 @@ int main(int argc, char** argv)
{
bool show_help = false;
bool debug_mode = false;
-#ifdef HAS_GETVERSION
const struct libusb_version* version;
-#endif
int j, r;
size_t i, arglen;
unsigned tmp_vid, tmp_pid;
@@ -859,10 +857,8 @@ int main(int argc, char** argv)
return 0;
}
-#ifdef HAS_GETVERSION
- version = libusb_getversion(); */
+ version = libusb_get_version();
printf("Using libusbx v%d.%d.%d.%d\n\n", version->major, version->minor, version->micro, version->nano);
-#endif
r = libusb_init(NULL);
if (r < 0)
return r;
diff --git a/libusb/core.c b/libusb/core.c
index f19d663..b50af56 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -42,6 +42,8 @@ const struct usbi_os_backend * const usbi_backend = &windows_backend;
#endif
struct libusb_context *usbi_default_context = NULL;
+const struct libusb_version libusb_version_internal =
+ { LIBUSB_MAJOR, LIBUSB_MINOR, LIBUSB_MICRO, LIBUSB_NANO};
static int default_context_refcnt = 0;
static usbi_mutex_static_t default_context_lock = USBI_MUTEX_INITIALIZER;
@@ -577,7 +579,7 @@ struct libusb_device *usbi_get_device_by_session_id(struct libusb_context *ctx,
* \param ctx the context to operate on, or NULL for the default context
* \param list output location for a list of devices. Must be later freed with
* libusb_free_device_list().
- * \returns The number of devices in the outputted list, or any
+ * \returns the number of devices in the outputted list, or any
* \ref libusb_error according to errors encountered by the backend.
*/
ssize_t API_EXPORTED libusb_get_device_list(libusb_context *ctx,
@@ -1760,3 +1762,13 @@ DEFAULT_VISIBILITY const char * LIBUSB_CALL libusb_error_name(int error_code)
}
return "**UNKNOWN**";
}
+
+/** \ingroup misc
+ * Fills a libusb_version struct with the full version (major, minor,
+ * micro, nano) of this library
+ */
+DEFAULT_VISIBILITY
+const struct libusb_version * LIBUSB_CALL libusb_get_version(void)
+{
+ return &libusb_version_internal;
+}
diff --git a/libusb/libusb-1.0.def b/libusb/libusb-1.0.def
index 96abd17..1d6a5d2 100644
--- a/libusb/libusb-1.0.def
+++ b/libusb/libusb-1.0.def
@@ -62,6 +62,8 @@ EXPORTS
libusb_get_pollfds at 4 = libusb_get_pollfds
libusb_get_string_descriptor_ascii
libusb_get_string_descriptor_ascii at 16 = libusb_get_string_descriptor_ascii
+ libusb_get_version
+ libusb_get_version at 0 = libusb_get_version
libusb_handle_events
libusb_handle_events at 4 = libusb_handle_events
libusb_handle_events_completed
diff --git a/libusb/libusb-1.0.rc b/libusb/libusb-1.0.rc
index 1aba015..86cb853 100644
--- a/libusb/libusb-1.0.rc
+++ b/libusb/libusb-1.0.rc
@@ -12,9 +12,13 @@
#define LU_STR(s) #s
#define LU_XSTR(s) LU_STR(s)
#if LIBUSB_NANO > 0
-#define LIBUSB_VERSIONSTRING LU_XSTR(LIBUSB_MAJOR) "." LU_XSTR(LIBUSB_MINOR) "." LU_XSTR(LIBUSB_MICRO) "." LU_XSTR(LIBUSB_NANO) LIBUSB_RC "\0"
+#define LIBUSB_VERSIONSTRING \
+ LU_XSTR(LIBUSB_MAJOR) "." LU_XSTR(LIBUSB_MINOR) "." \
+ LU_XSTR(LIBUSB_MICRO) "." LU_XSTR(LIBUSB_NANO) LIBUSB_RC "\0"
#else
-#define LIBUSB_VERSIONSTRING LU_XSTR(LIBUSB_MAJOR) "." LU_XSTR(LIBUSB_MINOR) "." LU_XSTR(LIBUSB_MICRO) LIBUSB_RC "\0"
+#define LIBUSB_VERSIONSTRING \
+ LU_XSTR(LIBUSB_MAJOR) "." LU_XSTR(LIBUSB_MINOR) "." \
+ LU_XSTR(LIBUSB_MICRO) LIBUSB_RC "\0"
#endif
#endif
@@ -35,7 +39,6 @@ BEGIN
BEGIN
BLOCK "040904b0"
BEGIN
- VALUE "Comments", "\0"
VALUE "CompanyName", "libusbx.org\0"
VALUE "FileDescription", "C library for writing portable USB drivers in userspace\0"
VALUE "FileVersion", LIBUSB_VERSIONSTRING
diff --git a/libusb/libusb.h b/libusb/libusb.h
index 12a5f8f..da4683c 100644
--- a/libusb/libusb.h
+++ b/libusb/libusb.h
@@ -639,6 +639,16 @@ struct libusb_device;
struct libusb_device_handle;
/** \ingroup lib
+ * Structure providing the version of libusbx currently in use
+ */
+struct libusb_version {
+ uint16_t major;
+ uint16_t minor;
+ uint16_t micro;
+ uint16_t nano;
+};
+
+/** \ingroup lib
* Structure representing a libusbx session. The concept of individual libusbx
* sessions allows for your program to use two libraries (or dynamically
* load two modules) which both independently use libusb. This will prevent
@@ -689,20 +699,20 @@ typedef struct libusb_device_handle libusb_device_handle;
* Speed codes. Indicates the speed at which the device is operating.
*/
enum libusb_speed {
- /** The OS doesn't report or know the device speed. */
- LIBUSB_SPEED_UNKNOWN = 0,
+ /** The OS doesn't report or know the device speed. */
+ LIBUSB_SPEED_UNKNOWN = 0,
- /** The device is operating at low speed (1.5MBit/s). */
- LIBUSB_SPEED_LOW = 1,
+ /** The device is operating at low speed (1.5MBit/s). */
+ LIBUSB_SPEED_LOW = 1,
- /** The device is operating at full speed (12MBit/s). */
- LIBUSB_SPEED_FULL = 2,
+ /** The device is operating at full speed (12MBit/s). */
+ LIBUSB_SPEED_FULL = 2,
- /** The device is operating at high speed (480MBit/s). */
- LIBUSB_SPEED_HIGH = 3,
+ /** The device is operating at high speed (480MBit/s). */
+ LIBUSB_SPEED_HIGH = 3,
- /** The device is operating at super speed (5000MBit/s). */
- LIBUSB_SPEED_SUPER = 4,
+ /** The device is operating at super speed (5000MBit/s). */
+ LIBUSB_SPEED_SUPER = 4,
};
/** \ingroup misc
@@ -929,6 +939,7 @@ enum libusb_capability {
int LIBUSB_CALL libusb_init(libusb_context **ctx);
void LIBUSB_CALL libusb_exit(libusb_context *ctx);
void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level);
+const struct libusb_version * LIBUSB_CALL libusb_get_version(void);
int LIBUSB_CALL libusb_has_capability(uint32_t capability);
const char * LIBUSB_CALL libusb_error_name(int errcode);
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index fa8597c..c3d2158 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -32,6 +32,7 @@
#endif
#include <libusb.h>
+#include "version.h"
/* Inside the libusbx code, mark all public functions as follows:
* return_type API_EXPORTED function_name(params) { ... }
--
1.7.9.msysgit.0
More information about the libusbx
mailing list