summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Batard <pbatard@gmail.com>2010-09-20 16:09:23 +0100
committerPete Batard <pbatard@gmail.com>2010-09-20 16:09:23 +0100
commit6a3c5a6fa427395371ef792815d17e061b309bb1 (patch)
tree4903c6be8465a0b1bcc0e9ef0b61ff119c76ccc1
parentdfc99bb006d057f3f64f84ce935f1781e61ba5d7 (diff)
downloadlibusb-6a3c5a6fa427395371ef792815d17e061b309bb1.tar.gz
merged latest official changes
* up to e65f69a7ef3de357c867ddaac9598efe407078b6
-rw-r--r--configure.ac4
-rw-r--r--doc/doxygen.cfg.in2
-rw-r--r--libusb/core.c78
-rw-r--r--libusb/descriptor.c12
-rw-r--r--libusb/io.c56
-rw-r--r--libusb/libusb.h101
-rw-r--r--libusb/libusbi.h9
-rw-r--r--libusb/libusbi.h.in9
-rw-r--r--libusb/sync.c7
-rw-r--r--msvc/config.h2
10 files changed, 184 insertions, 96 deletions
diff --git a/configure.ac b/configure.ac
index a2a76b0..760b272 100644
--- a/configure.ac
+++ b/configure.ac
@@ -170,9 +170,9 @@ saved_cflags="$CFLAGS"
CFLAGS="$CFLAGS -Werror -fvisibility=hidden"
AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]),
[VISIBILITY_CFLAGS="-fvisibility=hidden"
- AC_DEFINE([API_EXPORTED], [__attribute__((visibility("default")))], [Default visibility]) ],
+ AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__((visibility("default")))], [Default visibility]) ],
[ VISIBILITY_CFLAGS=""
- AC_DEFINE([API_EXPORTED], [], [Default visibility]) ],
+ AC_DEFINE([DEFAULT_VISIBILITY], [], [Default visibility]) ],
])
CFLAGS="$saved_cflags"
diff --git a/doc/doxygen.cfg.in b/doc/doxygen.cfg.in
index 574b52f..128e1de 100644
--- a/doc/doxygen.cfg.in
+++ b/doc/doxygen.cfg.in
@@ -1054,7 +1054,7 @@ INCLUDE_FILE_PATTERNS =
# undefined via #undef or recursively expanded use the := operator
# instead of the = operator.
-PREDEFINED = API_EXPORTED=
+PREDEFINED = API_EXPORTED= LIBUSB_CALL= DEFAULT_VISIBILITY=
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
# this tag can be used to specify a list of macro names that should be expanded.
diff --git a/libusb/core.c b/libusb/core.c
index fd44731..46c2b9c 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -600,7 +600,7 @@ struct libusb_device *usbi_get_device_by_session_id(struct libusb_context *ctx,
* \returns the number of devices in the outputted list, or LIBUSB_ERROR_NO_MEM
* on memory allocation failure.
*/
-API_EXPORTED ssize_t LIBUSB_CALL libusb_get_device_list(libusb_context *ctx,
+ssize_t API_EXPORTED libusb_get_device_list(libusb_context *ctx,
libusb_device ***list)
{
struct discovered_devs *discdevs = discovered_devs_alloc();
@@ -646,7 +646,7 @@ out:
* \param list the list to free
* \param unref_devices whether to unref the devices in the list
*/
-API_EXPORTED void LIBUSB_CALL libusb_free_device_list(libusb_device **list,
+void API_EXPORTED libusb_free_device_list(libusb_device **list,
int unref_devices)
{
if (!list)
@@ -667,7 +667,7 @@ API_EXPORTED void LIBUSB_CALL libusb_free_device_list(libusb_device **list,
* \param dev a device
* \returns the bus number
*/
-API_EXPORTED uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev)
+uint8_t API_EXPORTED libusb_get_bus_number(libusb_device *dev)
{
return dev->bus_number;
}
@@ -677,7 +677,7 @@ API_EXPORTED uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev)
* \param dev a device
* \returns the device address
*/
-API_EXPORTED uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev)
+uint8_t API_EXPORTED libusb_get_device_address(libusb_device *dev)
{
return dev->device_address;
}
@@ -723,7 +723,7 @@ static const struct libusb_endpoint_descriptor *find_endpoint(
* \returns LIBUSB_ERROR_NOT_FOUND if the endpoint does not exist
* \returns LIBUSB_ERROR_OTHER on other failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev,
+int API_EXPORTED libusb_get_max_packet_size(libusb_device *dev,
unsigned char endpoint)
{
struct libusb_config_descriptor *config;
@@ -772,7 +772,7 @@ API_EXPORTED int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev,
* \returns LIBUSB_ERROR_NOT_FOUND if the endpoint does not exist
* \returns LIBUSB_ERROR_OTHER on other failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_get_max_iso_packet_size(libusb_device *dev,
+int API_EXPORTED libusb_get_max_iso_packet_size(libusb_device *dev,
unsigned char endpoint)
{
struct libusb_config_descriptor *config;
@@ -808,7 +808,8 @@ API_EXPORTED int LIBUSB_CALL libusb_get_max_iso_packet_size(libusb_device *dev,
* \param dev the device to reference
* \returns the same device
*/
-API_EXPORTED libusb_device* LIBUSB_CALL libusb_ref_device(libusb_device *dev)
+DEFAULT_VISIBILITY
+libusb_device * LIBUSB_CALL libusb_ref_device(libusb_device *dev)
{
usbi_mutex_lock(&dev->lock);
dev->refcnt++;
@@ -821,7 +822,7 @@ API_EXPORTED libusb_device* LIBUSB_CALL libusb_ref_device(libusb_device *dev)
* causes the reference count to reach zero, the device shall be destroyed.
* \param dev the device to unreference
*/
-API_EXPORTED void LIBUSB_CALL libusb_unref_device(libusb_device *dev)
+void API_EXPORTED libusb_unref_device(libusb_device *dev)
{
int refcnt;
@@ -910,7 +911,8 @@ void usbi_fd_notification(struct libusb_context *ctx)
* \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
* \returns another LIBUSB_ERROR code on other failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_open(libusb_device *dev, libusb_device_handle **handle)
+int API_EXPORTED libusb_open(libusb_device *dev,
+ libusb_device_handle **handle)
{
struct libusb_context *ctx = DEVICE_CTX(dev);
struct libusb_device_handle *_handle;
@@ -972,7 +974,8 @@ API_EXPORTED int LIBUSB_CALL libusb_open(libusb_device *dev, libusb_device_handl
* \param product_id the idProduct value to search for
* \returns a handle for the first found device, or NULL on error or if the
* device could not be found. */
-API_EXPORTED libusb_device_handle* LIBUSB_CALL libusb_open_device_with_vid_pid(
+DEFAULT_VISIBILITY
+libusb_device_handle * LIBUSB_CALL libusb_open_device_with_vid_pid(
libusb_context *ctx, uint16_t vendor_id, uint16_t product_id)
{
struct libusb_device **devs;
@@ -1031,7 +1034,7 @@ static void do_close(struct libusb_context *ctx,
*
* \param dev_handle the handle to close
*/
-API_EXPORTED void LIBUSB_CALL libusb_close(libusb_device_handle *dev_handle)
+void API_EXPORTED libusb_close(libusb_device_handle *dev_handle)
{
struct libusb_context *ctx;
unsigned char dummy = 1;
@@ -1092,7 +1095,8 @@ API_EXPORTED void LIBUSB_CALL libusb_close(libusb_device_handle *dev_handle)
* \param dev_handle a device handle
* \returns the underlying device
*/
-API_EXPORTED libusb_device* LIBUSB_CALL libusb_get_device(libusb_device_handle *dev_handle)
+DEFAULT_VISIBILITY
+libusb_device * LIBUSB_CALL libusb_get_device(libusb_device_handle *dev_handle)
{
return dev_handle->dev;
}
@@ -1117,7 +1121,7 @@ API_EXPORTED libusb_device* LIBUSB_CALL libusb_get_device(libusb_device_handle *
* \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
* \returns another LIBUSB_ERROR code on other failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_get_configuration(libusb_device_handle *dev,
+int API_EXPORTED libusb_get_configuration(libusb_device_handle *dev,
int *config)
{
int r = LIBUSB_ERROR_NOT_SUPPORTED;
@@ -1186,7 +1190,7 @@ API_EXPORTED int LIBUSB_CALL libusb_get_configuration(libusb_device_handle *dev,
* \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
* \returns another LIBUSB_ERROR code on other failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_set_configuration(libusb_device_handle *dev,
+int API_EXPORTED libusb_set_configuration(libusb_device_handle *dev,
int configuration)
{
usbi_dbg("configuration %d", configuration);
@@ -1217,7 +1221,7 @@ API_EXPORTED int LIBUSB_CALL libusb_set_configuration(libusb_device_handle *dev,
* \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
* \returns a LIBUSB_ERROR code on other failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_claim_interface(libusb_device_handle *dev,
+int API_EXPORTED libusb_claim_interface(libusb_device_handle *dev,
int interface_number)
{
int r = 0;
@@ -1254,7 +1258,7 @@ out:
* \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
* \returns another LIBUSB_ERROR code on other failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_release_interface(libusb_device_handle *dev,
+int API_EXPORTED libusb_release_interface(libusb_device_handle *dev,
int interface_number)
{
int r;
@@ -1299,7 +1303,7 @@ out:
* \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
* \returns another LIBUSB_ERROR code on other failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_set_interface_alt_setting(libusb_device_handle *dev,
+int API_EXPORTED libusb_set_interface_alt_setting(libusb_device_handle *dev,
int interface_number, int alternate_setting)
{
usbi_dbg("interface %d altsetting %d",
@@ -1334,7 +1338,7 @@ API_EXPORTED int LIBUSB_CALL libusb_set_interface_alt_setting(libusb_device_hand
* \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
* \returns another LIBUSB_ERROR code on other failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_clear_halt(libusb_device_handle *dev,
+int API_EXPORTED libusb_clear_halt(libusb_device_handle *dev,
unsigned char endpoint)
{
usbi_dbg("endpoint %x", endpoint);
@@ -1360,7 +1364,7 @@ API_EXPORTED int LIBUSB_CALL libusb_clear_halt(libusb_device_handle *dev,
* device has been disconnected
* \returns another LIBUSB_ERROR code on other failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_reset_device(libusb_device_handle *dev)
+int API_EXPORTED libusb_reset_device(libusb_device_handle *dev)
{
usbi_dbg("");
return usbi_backend->reset_device(dev);
@@ -1371,16 +1375,19 @@ API_EXPORTED int LIBUSB_CALL libusb_reset_device(libusb_device_handle *dev)
* is active, you cannot claim the interface, and libusb will be unable to
* perform I/O.
*
+ * This functionality is not available on Windows.
+ *
* \param dev a device handle
* \param interface_number the interface to check
* \returns 0 if no kernel driver is active
* \returns 1 if a kernel driver is active
* \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
- * \returns LIBUSB_ERROR_NOT_SUPPORTED on Windows
+ * \returns LIBUSB_ERROR_NOT_SUPPORTED on platforms where the functionality
+ * is not available
* \returns another LIBUSB_ERROR code on other failure
* \see libusb_detach_kernel_driver()
*/
-API_EXPORTED int LIBUSB_CALL libusb_kernel_driver_active(libusb_device_handle *dev,
+int API_EXPORTED libusb_kernel_driver_active(libusb_device_handle *dev,
int interface_number)
{
usbi_dbg("interface %d", interface_number);
@@ -1392,8 +1399,9 @@ API_EXPORTED int LIBUSB_CALL libusb_kernel_driver_active(libusb_device_handle *d
/** \ingroup dev
* Detach a kernel driver from an interface. If successful, you will then be
- * able to claim the interface and perform I/O. This call is only effective
- * on Linux and returns LIBUSB_ERROR_NOT_SUPPORTED on all other platforms.
+ * able to claim the interface and perform I/O.
+ *
+ * This functionality is not available on Darwin or Windows.
*
* \param dev a device handle
* \param interface_number the interface to detach the driver from
@@ -1401,11 +1409,12 @@ API_EXPORTED int LIBUSB_CALL libusb_kernel_driver_active(libusb_device_handle *d
* \returns LIBUSB_ERROR_NOT_FOUND if no kernel driver was active
* \returns LIBUSB_ERROR_INVALID_PARAM if the interface does not exist
* \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
- * \returns LIBUSB_ERROR_NOT_SUPPORTED on non Linux platforms
+ * \returns LIBUSB_ERROR_NOT_SUPPORTED on platforms where the functionality
+ * is not available
* \returns another LIBUSB_ERROR code on other failure
* \see libusb_kernel_driver_active()
*/
-API_EXPORTED int LIBUSB_CALL libusb_detach_kernel_driver(libusb_device_handle *dev,
+int API_EXPORTED libusb_detach_kernel_driver(libusb_device_handle *dev,
int interface_number)
{
usbi_dbg("interface %d", interface_number);
@@ -1420,19 +1429,22 @@ API_EXPORTED int LIBUSB_CALL libusb_detach_kernel_driver(libusb_device_handle *d
* using libusb_detach_kernel_driver(). This call is only effective on
* Linux and returns LIBUSB_ERROR_NOT_SUPPORTED on all other platforms.
*
+ * This functionality is not available on Darwin or Windows.
+ *
* \param dev a device handle
* \param interface_number the interface to attach the driver from
* \returns 0 on success
* \returns LIBUSB_ERROR_NOT_FOUND if no kernel driver was active
* \returns LIBUSB_ERROR_INVALID_PARAM if the interface does not exist
* \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
- * \returns LIBUSB_ERROR_NOT_SUPPORTED on non Linux platforms
+ * \returns LIBUSB_ERROR_NOT_SUPPORTED on platforms where the functionality
+ * is not available
* \returns LIBUSB_ERROR_BUSY if the driver cannot be attached because the
* interface is claimed by a program or driver
* \returns another LIBUSB_ERROR code on other failure
* \see libusb_kernel_driver_active()
*/
-API_EXPORTED int LIBUSB_CALL libusb_attach_kernel_driver(libusb_device_handle *dev,
+int API_EXPORTED libusb_attach_kernel_driver(libusb_device_handle *dev,
int interface_number)
{
usbi_dbg("interface %d", interface_number);
@@ -1471,7 +1483,7 @@ API_EXPORTED int LIBUSB_CALL libusb_attach_kernel_driver(libusb_device_handle *d
* \param ctx the context to operate on, or NULL for the default context
* \param level debug level to set
*/
-API_EXPORTED void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level)
+void API_EXPORTED libusb_set_debug(libusb_context *ctx, int level)
{
USBI_GET_CONTEXT(ctx);
if (!ctx->debug_fixed)
@@ -1491,7 +1503,7 @@ API_EXPORTED void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level)
* \returns 0 on success, or a LIBUSB_ERROR code on failure
* \see contexts
*/
-API_EXPORTED int LIBUSB_CALL libusb_init(libusb_context **context)
+int API_EXPORTED libusb_init(libusb_context **context)
{
char *dbg = getenv("LIBUSB_DEBUG");
struct libusb_context *ctx;
@@ -1573,7 +1585,7 @@ err_unlock:
* before your application terminates.
* \param ctx the context to deinitialize, or NULL for the default context
*/
-API_EXPORTED void LIBUSB_CALL libusb_exit(struct libusb_context *ctx)
+void API_EXPORTED libusb_exit(struct libusb_context *ctx)
{
USBI_GET_CONTEXT(ctx);
usbi_dbg("");
@@ -1679,7 +1691,8 @@ void usbi_log(struct libusb_context *ctx, enum usbi_log_level level,
* \returns a short description of the error code in English, or NULL if the
* error descriptions are unavailable
*/
-API_EXPORTED const char *LIBUSB_CALL libusb_strerror(enum libusb_error error_code)
+DEFAULT_VISIBILITY
+const char * LIBUSB_CALL libusb_strerror(enum libusb_error error_code)
{
switch (error_code) {
case LIBUSB_SUCCESS:
@@ -1718,7 +1731,8 @@ API_EXPORTED const char *LIBUSB_CALL libusb_strerror(enum libusb_error error_cod
* Fills a libusb_version struct with the full version (major, minor,
* micro, nano) of this library
*/
-API_EXPORTED const struct libusb_version* LIBUSB_CALL libusb_getversion(void)
+DEFAULT_VISIBILITY
+const struct libusb_version * LIBUSB_CALL libusb_getversion(void)
{
return &libusb_version_internal;
}
diff --git a/libusb/descriptor.c b/libusb/descriptor.c
index df7dfb5..54a47b4 100644
--- a/libusb/descriptor.c
+++ b/libusb/descriptor.c
@@ -430,7 +430,7 @@ err:
* \param desc output location for the descriptor data
* \returns 0 on success or a LIBUSB_ERROR code on failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_get_device_descriptor(libusb_device *dev,
+int API_EXPORTED libusb_get_device_descriptor(libusb_device *dev,
struct libusb_device_descriptor *desc)
{
unsigned char raw_desc[DEVICE_DESC_LENGTH];
@@ -466,7 +466,7 @@ API_EXPORTED int LIBUSB_CALL libusb_get_device_descriptor(libusb_device *dev,
* \returns another LIBUSB_ERROR code on error
* \see libusb_get_config_descriptor
*/
-API_EXPORTED int LIBUSB_CALL libusb_get_active_config_descriptor(libusb_device *dev,
+int API_EXPORTED libusb_get_active_config_descriptor(libusb_device *dev,
struct libusb_config_descriptor **config)
{
struct libusb_config_descriptor *_config = malloc(sizeof(*_config));
@@ -531,7 +531,7 @@ err:
* \see libusb_get_active_config_descriptor()
* \see libusb_get_config_descriptor_by_value()
*/
-API_EXPORTED int LIBUSB_CALL libusb_get_config_descriptor(libusb_device *dev,
+int API_EXPORTED libusb_get_config_descriptor(libusb_device *dev,
uint8_t config_index, struct libusb_config_descriptor **config)
{
struct libusb_config_descriptor *_config;
@@ -630,7 +630,7 @@ int usbi_get_config_index_by_value(struct libusb_device *dev,
* \see libusb_get_active_config_descriptor()
* \see libusb_get_config_descriptor()
*/
-API_EXPORTED int LIBUSB_CALL libusb_get_config_descriptor_by_value(libusb_device *dev,
+int API_EXPORTED libusb_get_config_descriptor_by_value(libusb_device *dev,
uint8_t bConfigurationValue, struct libusb_config_descriptor **config)
{
int idx;
@@ -651,7 +651,7 @@ API_EXPORTED int LIBUSB_CALL libusb_get_config_descriptor_by_value(libusb_device
*
* \param config the configuration descriptor to free
*/
-API_EXPORTED void LIBUSB_CALL libusb_free_config_descriptor(
+void API_EXPORTED libusb_free_config_descriptor(
struct libusb_config_descriptor *config)
{
if (!config)
@@ -673,7 +673,7 @@ API_EXPORTED void LIBUSB_CALL libusb_free_config_descriptor(
* \param length size of data buffer
* \returns number of bytes returned in data, or LIBUSB_ERROR code on failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_get_string_descriptor_ascii(libusb_device_handle *dev,
+int API_EXPORTED libusb_get_string_descriptor_ascii(libusb_device_handle *dev,
uint8_t desc_index, unsigned char *data, int length)
{
unsigned char tbuf[255]; /* Some devices choke on size > 255 */
diff --git a/libusb/io.c b/libusb/io.c
index 39285e7..90590ef 100644
--- a/libusb/io.c
+++ b/libusb/io.c
@@ -582,6 +582,10 @@ while (user_has_not_requested_exit)
*
* \section pollmain The more advanced option
*
+ * \note This functionality is currently only available on Unix-like platforms.
+ * On Windows, libusb_get_pollfds() simply returns NULL. Exposing event sources
+ * on Windows will require some further thought and design.
+ *
* In more advanced applications, you will already have a main loop which
* is monitoring other event sources: network sockets, X11 events, mouse
* movements, etc. Through exposing a set of file descriptors, libusb is
@@ -1177,7 +1181,9 @@ out:
* \param iso_packets number of isochronous packet descriptors to allocate
* \returns a newly allocated transfer, or NULL on error
*/
-API_EXPORTED struct libusb_transfer* LIBUSB_CALL libusb_alloc_transfer(int iso_packets)
+DEFAULT_VISIBILITY
+struct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer(
+ int iso_packets)
{
size_t os_alloc_size = usbi_backend->transfer_priv_size
+ (usbi_backend->add_iso_packet_size * iso_packets);
@@ -1212,7 +1218,7 @@ API_EXPORTED struct libusb_transfer* LIBUSB_CALL libusb_alloc_transfer(int iso_p
*
* \param transfer the transfer to free
*/
-API_EXPORTED void LIBUSB_CALL libusb_free_transfer(struct libusb_transfer *transfer)
+void API_EXPORTED libusb_free_transfer(struct libusb_transfer *transfer)
{
struct usbi_transfer *itransfer;
if (!transfer)
@@ -1236,7 +1242,7 @@ API_EXPORTED void LIBUSB_CALL libusb_free_transfer(struct libusb_transfer *trans
* \returns LIBUSB_ERROR_BUSY if the transfer has already been submitted.
* \returns another LIBUSB_ERROR code on other failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_submit_transfer(struct libusb_transfer *transfer)
+int API_EXPORTED libusb_submit_transfer(struct libusb_transfer *transfer)
{
struct libusb_context *ctx = TRANSFER_CTX(transfer);
struct usbi_transfer *itransfer =
@@ -1292,7 +1298,7 @@ out:
* cancelled.
* \returns a LIBUSB_ERROR code on failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_cancel_transfer(struct libusb_transfer *transfer)
+int API_EXPORTED libusb_cancel_transfer(struct libusb_transfer *transfer)
{
struct usbi_transfer *itransfer =
__LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer);
@@ -1464,7 +1470,7 @@ int usbi_handle_transfer_cancellation(struct usbi_transfer *transfer)
* \returns 1 if the lock was not obtained (i.e. another thread holds the lock)
* \see \ref mtasync
*/
-API_EXPORTED int LIBUSB_CALL libusb_try_lock_events(libusb_context *ctx)
+int API_EXPORTED libusb_try_lock_events(libusb_context *ctx)
{
int r;
USBI_GET_CONTEXT(ctx);
@@ -1505,7 +1511,7 @@ API_EXPORTED int LIBUSB_CALL libusb_try_lock_events(libusb_context *ctx)
* \param ctx the context to operate on, or NULL for the default context
* \see \ref mtasync
*/
-API_EXPORTED void LIBUSB_CALL libusb_lock_events(libusb_context *ctx)
+void API_EXPORTED libusb_lock_events(libusb_context *ctx)
{
USBI_GET_CONTEXT(ctx);
usbi_mutex_lock(&ctx->events_lock);
@@ -1520,7 +1526,7 @@ API_EXPORTED void LIBUSB_CALL libusb_lock_events(libusb_context *ctx)
* \param ctx the context to operate on, or NULL for the default context
* \see \ref mtasync
*/
-API_EXPORTED void LIBUSB_CALL libusb_unlock_events(libusb_context *ctx)
+void API_EXPORTED libusb_unlock_events(libusb_context *ctx)
{
USBI_GET_CONTEXT(ctx);
ctx->event_handler_active = 0;
@@ -1555,7 +1561,7 @@ API_EXPORTED void LIBUSB_CALL libusb_unlock_events(libusb_context *ctx)
* \returns 0 if this thread must give up the events lock
* \see \ref fullstory "Multi-threaded I/O: the full story"
*/
-API_EXPORTED int LIBUSB_CALL libusb_event_handling_ok(libusb_context *ctx)
+int API_EXPORTED libusb_event_handling_ok(libusb_context *ctx)
{
int r;
USBI_GET_CONTEXT(ctx);
@@ -1583,7 +1589,7 @@ API_EXPORTED int LIBUSB_CALL libusb_event_handling_ok(libusb_context *ctx)
* \returns 0 if there are no threads currently handling events
* \see \ref mtasync
*/
-API_EXPORTED int LIBUSB_CALL libusb_event_handler_active(libusb_context *ctx)
+int API_EXPORTED libusb_event_handler_active(libusb_context *ctx)
{
int r;
USBI_GET_CONTEXT(ctx);
@@ -1620,7 +1626,7 @@ API_EXPORTED int LIBUSB_CALL libusb_event_handler_active(libusb_context *ctx)
* \param ctx the context to operate on, or NULL for the default context
* \see \ref mtasync
*/
-API_EXPORTED void LIBUSB_CALL libusb_lock_event_waiters(libusb_context *ctx)
+void API_EXPORTED libusb_lock_event_waiters(libusb_context *ctx)
{
USBI_GET_CONTEXT(ctx);
usbi_mutex_lock(&ctx->event_waiters_lock);
@@ -1631,7 +1637,7 @@ API_EXPORTED void LIBUSB_CALL libusb_lock_event_waiters(libusb_context *ctx)
* \param ctx the context to operate on, or NULL for the default context
* \see \ref mtasync
*/
-API_EXPORTED void LIBUSB_CALL libusb_unlock_event_waiters(libusb_context *ctx)
+void API_EXPORTED libusb_unlock_event_waiters(libusb_context *ctx)
{
USBI_GET_CONTEXT(ctx);
usbi_mutex_unlock(&ctx->event_waiters_lock);
@@ -1662,7 +1668,7 @@ API_EXPORTED void LIBUSB_CALL libusb_unlock_event_waiters(libusb_context *ctx)
* \returns 1 if the timeout expired
* \see \ref mtasync
*/
-API_EXPORTED int LIBUSB_CALL libusb_wait_for_event(libusb_context *ctx, struct timeval *tv)
+int API_EXPORTED libusb_wait_for_event(libusb_context *ctx, struct timeval *tv)
{
struct timespec timeout;
int r;
@@ -1942,7 +1948,7 @@ static int get_next_timeout(libusb_context *ctx, struct timeval *tv,
* non-blocking mode
* \returns 0 on success, or a LIBUSB_ERROR code on failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_handle_events_timeout(libusb_context *ctx,
+int API_EXPORTED libusb_handle_events_timeout(libusb_context *ctx,
struct timeval *tv)
{
int r;
@@ -1996,7 +2002,7 @@ retry:
* \param ctx the context to operate on, or NULL for the default context
* \returns 0 on success, or a LIBUSB_ERROR code on failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_handle_events(libusb_context *ctx)
+int API_EXPORTED libusb_handle_events(libusb_context *ctx)
{
struct timeval tv;
tv.tv_sec = 60;
@@ -2021,7 +2027,7 @@ API_EXPORTED int LIBUSB_CALL libusb_handle_events(libusb_context *ctx)
* \returns 0 on success, or a LIBUSB_ERROR code on failure
* \see \ref mtasync
*/
-API_EXPORTED int LIBUSB_CALL libusb_handle_events_locked(libusb_context *ctx,
+int API_EXPORTED libusb_handle_events_locked(libusb_context *ctx,
struct timeval *tv)
{
int r;
@@ -2065,7 +2071,7 @@ API_EXPORTED int LIBUSB_CALL libusb_handle_events_locked(libusb_context *ctx,
* or through regular activity on the file descriptors.
* \see \ref pollmain "Polling libusb file descriptors for event handling"
*/
-API_EXPORTED int LIBUSB_CALL libusb_pollfds_handle_timeouts(libusb_context *ctx)
+int API_EXPORTED libusb_pollfds_handle_timeouts(libusb_context *ctx)
{
#if defined(USBI_OS_HANDLES_TIMEOUT)
return 1;
@@ -2105,7 +2111,7 @@ API_EXPORTED int LIBUSB_CALL libusb_pollfds_handle_timeouts(libusb_context *ctx)
* \returns 0 if there are no pending timeouts, 1 if a timeout was returned,
* or LIBUSB_ERROR_OTHER on failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_get_next_timeout(libusb_context *ctx,
+int API_EXPORTED libusb_get_next_timeout(libusb_context *ctx,
struct timeval *tv)
{
#ifndef USBI_OS_HANDLES_TIMEOUT
@@ -2191,7 +2197,7 @@ API_EXPORTED int LIBUSB_CALL libusb_get_next_timeout(libusb_context *ctx,
* \param user_data User data to be passed back to callbacks (useful for
* passing context information)
*/
-API_EXPORTED void LIBUSB_CALL libusb_set_pollfd_notifiers(libusb_context *ctx,
+void API_EXPORTED libusb_set_pollfd_notifiers(libusb_context *ctx,
libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb,
void *user_data)
{
@@ -2256,11 +2262,16 @@ void usbi_remove_pollfd(struct libusb_context *ctx, int fd)
* The returned list is NULL-terminated and should be freed with free() when
* done. The actual list contents must not be touched.
*
+ * As file descriptors are a Unix-specific concept, this function is not
+ * available on Windows and will always return NULL.
+ *
* \param ctx the context to operate on, or NULL for the default context
- * \returns a NULL-terminated list of libusb_pollfd structures, or NULL on
- * error
+ * \returns a NULL-terminated list of libusb_pollfd structures
+ * \returns NULL on error
+ * \returns NULL on platforms where the functionality is not available
*/
-API_EXPORTED const struct libusb_pollfd** LIBUSB_CALL libusb_get_pollfds(
+DEFAULT_VISIBILITY
+const struct libusb_pollfd ** LIBUSB_CALL libusb_get_pollfds(
libusb_context *ctx)
{
#ifndef OS_WINDOWS
@@ -2286,8 +2297,6 @@ out:
usbi_mutex_unlock(&ctx->pollfds_lock);
return (const struct libusb_pollfd **) ret;
#else
- usbi_err(ctx, "external polling of libusb's internal descriptors "\
- "is not yet supported on Windows platforms");
return NULL;
#endif
}
@@ -2334,4 +2343,3 @@ void usbi_handle_disconnect(struct libusb_device_handle *handle)
}
}
-
diff --git a/libusb/libusb.h b/libusb/libusb.h
index f72c29e..e2cc606 100644
--- a/libusb/libusb.h
+++ b/libusb/libusb.h
@@ -47,6 +47,38 @@
#endif
#endif
+/** \def LIBUSB_CALL
+ * \ingroup misc
+ * libusb's Windows calling convention.
+ *
+ * Under Windows, the selection of available compilers and configurations
+ * means that, unlike other platforms, there is not <em>one true calling
+ * convention</em> (calling convention: the manner in which parameters are
+ * passed to funcions in the generated assembly code).
+ *
+ * Matching the Windows API itself, libusb uses the WINAPI convention (which
+ * translates to the <tt>stdcall</tt> convention) and guarantees that the
+ * library is compiled in this way. The public header file also includes
+ * appropriate annotations so that your own software will use the right
+ * convention, even if another convention is being used by default within
+ * your codebase.
+ *
+ * The one consideration that you must apply in your software is to mark
+ * all functions which you use as libusb callbacks with this LIBUSB_CALL
+ * annotation, so that they too get compiled for the correct calling
+ * convention.
+ *
+ * On non-Windows operating systems, this macro is defined as nothing. This
+ * means that you can apply it to your code without worrying about
+ * cross-platform compatibility.
+ */
+/* LIBUSB_CALL must be defined on both definition and declaration of libusb
+ * functions. You'd think that declaration would be enough, but cygwin will
+ * complain about conflicting types unless both are marked this way.
+ * The placement of this macro is important too; it must appear after the
+ * return type, before the function name. See internal documentation for
+ * API_EXPORTED.
+ */
#if defined(_WIN32) || defined(__CYGWIN__)
#define LIBUSB_CALL WINAPI
#else
@@ -815,49 +847,61 @@ struct libusb_transfer {
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 char *LIBUSB_CALL libusb_strerror(enum libusb_error errcode);
-const struct libusb_version *LIBUSB_CALL libusb_getversion(void);
+const char * LIBUSB_CALL libusb_strerror(enum libusb_error errcode);
+const struct libusb_version * LIBUSB_CALL libusb_getversion(void);
ssize_t LIBUSB_CALL libusb_get_device_list(libusb_context *ctx,
libusb_device ***list);
-void LIBUSB_CALL libusb_free_device_list(libusb_device **list, int unref_devices);
-libusb_device* LIBUSB_CALL libusb_ref_device(libusb_device *dev);
+void LIBUSB_CALL libusb_free_device_list(libusb_device **list,
+ int unref_devices);
+libusb_device * LIBUSB_CALL libusb_ref_device(libusb_device *dev);
void LIBUSB_CALL libusb_unref_device(libusb_device *dev);
-int LIBUSB_CALL libusb_get_configuration(libusb_device_handle *dev, int *config);
+int LIBUSB_CALL libusb_get_configuration(libusb_device_handle *dev,
+ int *config);
int LIBUSB_CALL libusb_get_device_descriptor(libusb_device *dev,
struct libusb_device_descriptor *desc);
int LIBUSB_CALL libusb_get_active_config_descriptor(libusb_device *dev,
struct libusb_config_descriptor **config);
-int LIBUSB_CALL libusb_get_config_descriptor(libusb_device *dev, uint8_t config_index,
- struct libusb_config_descriptor **config);
+int LIBUSB_CALL libusb_get_config_descriptor(libusb_device *dev,
+ uint8_t config_index, struct libusb_config_descriptor **config);
int LIBUSB_CALL libusb_get_config_descriptor_by_value(libusb_device *dev,
uint8_t bConfigurationValue, struct libusb_config_descriptor **config);
-void LIBUSB_CALL libusb_free_config_descriptor(struct libusb_config_descriptor *config);
+void LIBUSB_CALL libusb_free_config_descriptor(
+ struct libusb_config_descriptor *config);
uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev);
uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev);
-int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev, unsigned char endpoint);
-int LIBUSB_CALL libusb_get_max_iso_packet_size(libusb_device *dev, unsigned char endpoint);
+int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev,
+ unsigned char endpoint);
+int LIBUSB_CALL libusb_get_max_iso_packet_size(libusb_device *dev,
+ unsigned char endpoint);
int LIBUSB_CALL libusb_open(libusb_device *dev, libusb_device_handle **handle);
void LIBUSB_CALL libusb_close(libusb_device_handle *dev_handle);
-libusb_device* LIBUSB_CALL libusb_get_device(libusb_device_handle *dev_handle);
+libusb_device * LIBUSB_CALL libusb_get_device(libusb_device_handle *dev_handle);
-int LIBUSB_CALL libusb_set_configuration(libusb_device_handle *dev, int configuration);
-int LIBUSB_CALL libusb_claim_interface(libusb_device_handle *dev, int interface_number);
-int LIBUSB_CALL libusb_release_interface(libusb_device_handle *dev, int interface_number);
+int LIBUSB_CALL libusb_set_configuration(libusb_device_handle *dev,
+ int configuration);
+int LIBUSB_CALL libusb_claim_interface(libusb_device_handle *dev,
+ int interface_number);
+int LIBUSB_CALL libusb_release_interface(libusb_device_handle *dev,
+ int interface_number);
-libusb_device_handle* LIBUSB_CALL libusb_open_device_with_vid_pid(libusb_context *ctx,
- uint16_t vendor_id, uint16_t product_id);
+libusb_device_handle * LIBUSB_CALL libusb_open_device_with_vid_pid(
+ libusb_context *ctx, uint16_t vendor_id, uint16_t product_id);
int LIBUSB_CALL libusb_set_interface_alt_setting(libusb_device_handle *dev,
int interface_number, int alternate_setting);
-int LIBUSB_CALL libusb_clear_halt(libusb_device_handle *dev, unsigned char endpoint);
+int LIBUSB_CALL libusb_clear_halt(libusb_device_handle *dev,
+ unsigned char endpoint);
int LIBUSB_CALL libusb_reset_device(libusb_device_handle *dev);
-int LIBUSB_CALL libusb_kernel_driver_active(libusb_device_handle *dev, int interface_number);
-int LIBUSB_CALL libusb_detach_kernel_driver(libusb_device_handle *dev, int interface_number);
-int LIBUSB_CALL libusb_attach_kernel_driver(libusb_device_handle *dev, int interface_number);
+int LIBUSB_CALL libusb_kernel_driver_active(libusb_device_handle *dev,
+ int interface_number);
+int LIBUSB_CALL libusb_detach_kernel_driver(libusb_device_handle *dev,
+ int interface_number);
+int LIBUSB_CALL libusb_attach_kernel_driver(libusb_device_handle *dev,
+ int interface_number);
/* async I/O */
@@ -931,7 +975,7 @@ static inline void libusb_fill_control_setup(unsigned char *buffer,
setup->wLength = libusb_cpu_to_le16(wLength);
}
-struct libusb_transfer* LIBUSB_CALL libusb_alloc_transfer(int iso_packets);
+struct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer(int iso_packets);
int LIBUSB_CALL libusb_submit_transfer(struct libusb_transfer *transfer);
int LIBUSB_CALL libusb_cancel_transfer(struct libusb_transfer *transfer);
void LIBUSB_CALL libusb_free_transfer(struct libusb_transfer *transfer);
@@ -1229,11 +1273,14 @@ void LIBUSB_CALL libusb_lock_event_waiters(libusb_context *ctx);
void LIBUSB_CALL libusb_unlock_event_waiters(libusb_context *ctx);
int LIBUSB_CALL libusb_wait_for_event(libusb_context *ctx, struct timeval *tv);
-int LIBUSB_CALL libusb_handle_events_timeout(libusb_context *ctx, struct timeval *tv);
+int LIBUSB_CALL libusb_handle_events_timeout(libusb_context *ctx,
+ struct timeval *tv);
int LIBUSB_CALL libusb_handle_events(libusb_context *ctx);
-int LIBUSB_CALL libusb_handle_events_locked(libusb_context *ctx, struct timeval *tv);
+int LIBUSB_CALL libusb_handle_events_locked(libusb_context *ctx,
+ struct timeval *tv);
int LIBUSB_CALL libusb_pollfds_handle_timeouts(libusb_context *ctx);
-int LIBUSB_CALL libusb_get_next_timeout(libusb_context *ctx, struct timeval *tv);
+int LIBUSB_CALL libusb_get_next_timeout(libusb_context *ctx,
+ struct timeval *tv);
/** \ingroup poll
* File descriptor for polling
@@ -1259,7 +1306,8 @@ struct libusb_pollfd {
* libusb_set_pollfd_notifiers() call
* \see libusb_set_pollfd_notifiers()
*/
-typedef void (LIBUSB_CALL *libusb_pollfd_added_cb)(int fd, short events, void *user_data);
+typedef void (LIBUSB_CALL *libusb_pollfd_added_cb)(int fd, short events,
+ void *user_data);
/** \ingroup poll
* Callback function, invoked when a file descriptor should be removed from
@@ -1272,7 +1320,8 @@ typedef void (LIBUSB_CALL *libusb_pollfd_added_cb)(int fd, short events, void *u
*/
typedef void (LIBUSB_CALL *libusb_pollfd_removed_cb)(int fd, void *user_data);
-const struct libusb_pollfd** LIBUSB_CALL libusb_get_pollfds(libusb_context *ctx);
+const struct libusb_pollfd ** LIBUSB_CALL libusb_get_pollfds(
+ libusb_context *ctx);
void LIBUSB_CALL libusb_set_pollfd_notifiers(libusb_context *ctx,
libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb,
void *user_data);
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index 73e827b..e641bc7 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -29,6 +29,15 @@
#include <libusb.h>
+/* Inside the libusb code, mark all public functions as follows:
+ * return_type API_EXPORTED function_name(params) { ... }
+ * But if the function returns a pointer, mark it as follows:
+ * DEFAULT_VISIBILITY return_type * LIBUSB_CALL function_name(params) { ... }
+ * In the libusb public header, mark all declarations as:
+ * return_type LIBUSB_CALL function_name(params);
+ */
+#define API_EXPORTED LIBUSB_CALL DEFAULT_VISIBILITY
+
#define DEVICE_DESC_LENGTH 18
#define USB_MAXENDPOINTS 32
diff --git a/libusb/libusbi.h.in b/libusb/libusbi.h.in
index d8ba6fc..18980c0 100644
--- a/libusb/libusbi.h.in
+++ b/libusb/libusbi.h.in
@@ -29,6 +29,15 @@
#include <libusb.h>
+/* Inside the libusb code, mark all public functions as follows:
+ * return_type API_EXPORTED function_name(params) { ... }
+ * But if the function returns a pointer, mark it as follows:
+ * DEFAULT_VISIBILITY return_type * LIBUSB_CALL function_name(params) { ... }
+ * In the libusb public header, mark all declarations as:
+ * return_type LIBUSB_CALL function_name(params);
+ */
+#define API_EXPORTED LIBUSB_CALL DEFAULT_VISIBILITY
+
#define DEVICE_DESC_LENGTH 18
#define USB_MAXENDPOINTS 32
diff --git a/libusb/sync.c b/libusb/sync.c
index 8c3f0a0..f6dc2a7 100644
--- a/libusb/sync.c
+++ b/libusb/sync.c
@@ -69,7 +69,7 @@ static void LIBUSB_CALL ctrl_transfer_cb(struct libusb_transfer *transfer)
* \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
* \returns another LIBUSB_ERROR code on other failures
*/
-API_EXPORTED int LIBUSB_CALL libusb_control_transfer(libusb_device_handle *dev_handle,
+int API_EXPORTED libusb_control_transfer(libusb_device_handle *dev_handle,
uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
unsigned char *data, uint16_t wLength, unsigned int timeout)
{
@@ -252,7 +252,7 @@ static int do_sync_bulk_transfer(struct libusb_device_handle *dev_handle,
* \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
* \returns another LIBUSB_ERROR code on other failures
*/
-API_EXPORTED int LIBUSB_CALL libusb_bulk_transfer(struct libusb_device_handle *dev_handle,
+int API_EXPORTED libusb_bulk_transfer(struct libusb_device_handle *dev_handle,
unsigned char endpoint, unsigned char *data, int length, int *transferred,
unsigned int timeout)
{
@@ -301,11 +301,10 @@ API_EXPORTED int LIBUSB_CALL libusb_bulk_transfer(struct libusb_device_handle *d
* \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
* \returns another LIBUSB_ERROR code on other error
*/
-API_EXPORTED int LIBUSB_CALL libusb_interrupt_transfer(
+int API_EXPORTED libusb_interrupt_transfer(
struct libusb_device_handle *dev_handle, unsigned char endpoint,
unsigned char *data, int length, int *transferred, unsigned int timeout)
{
return do_sync_bulk_transfer(dev_handle, endpoint, data, length,
transferred, timeout, LIBUSB_TRANSFER_TYPE_INTERRUPT);
}
-
diff --git a/msvc/config.h b/msvc/config.h
index 8dc8840..29261fe 100644
--- a/msvc/config.h
+++ b/msvc/config.h
@@ -6,7 +6,7 @@
#endif
/* Default visibility */
-#define API_EXPORTED /**/
+#define DEFAULT_VISIBILITY /**/
/* Debug message logging (forced) */
//#define ENABLE_DEBUG_LOGGING 1