diff options
author | Pete Batard <pete@akeo.ie> | 2012-04-10 11:58:53 +0100 |
---|---|---|
committer | Pete Batard <pete@akeo.ie> | 2012-04-10 12:46:10 +0100 |
commit | 37dfd16c8c2f36c81c86de303072def0dc405e32 (patch) | |
tree | 4a277ac5a82e5cf8090eeece3070b2501d696615 | |
parent | 5b82831df2aca7508c131b7fa7964770b689a67b (diff) | |
download | libusb-37dfd16c8c2f36c81c86de303072def0dc405e32.tar.gz |
Core: Add get_version() call
* Also some formatting/typo improvements
-rw-r--r-- | examples/xusb.c | 6 | ||||
-rw-r--r-- | libusb/core.c | 14 | ||||
-rw-r--r-- | libusb/libusb-1.0.def | 2 | ||||
-rw-r--r-- | libusb/libusb-1.0.rc | 9 | ||||
-rw-r--r-- | libusb/libusb.h | 31 | ||||
-rw-r--r-- | 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@4 = libusb_get_pollfds libusb_get_string_descriptor_ascii libusb_get_string_descriptor_ascii@16 = libusb_get_string_descriptor_ascii + libusb_get_version + libusb_get_version@0 = libusb_get_version libusb_handle_events libusb_handle_events@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) { ... } |