Core: Add get_version() call
authorPete Batard <pete@akeo.ie>
Tue, 10 Apr 2012 10:58:53 +0000 (11:58 +0100)
committerPete Batard <pete@akeo.ie>
Tue, 10 Apr 2012 11:46:10 +0000 (12:46 +0100)
* Also some formatting/typo improvements

examples/xusb.c
libusb/core.c
libusb/libusb-1.0.def
libusb/libusb-1.0.rc
libusb/libusb.h
libusb/libusbi.h

index b1d338f..aa46b8e 100644 (file)
@@ -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;
index f19d663..b50af56 100644 (file)
@@ -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;
+}
index 96abd17..1d6a5d2 100644 (file)
@@ -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
index 1aba015..86cb853 100644 (file)
 #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
index 12a5f8f..da4683c 100644 (file)
@@ -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);
 
index fa8597c..c3d2158 100644 (file)
@@ -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) { ... }