From f0c40ad8113f672269cf1a65d9c2b73d35b907b2 Mon Sep 17 00:00:00 2001 From: Michael Plante Date: Thu, 29 Jul 2010 13:11:49 +0100 Subject: merged backend integration changes from official branch --- libusb/core.c | 29 ++++++++++++++--------------- libusb/descriptor.c | 4 ++-- libusb/io.c | 5 +++-- libusb/libusb-1.0.rc | 7 +++++++ libusb/libusb-1.0.rc.in | 7 +++++++ libusb/libusb.h | 34 ++++++++++++++++++---------------- libusb/libusbi.h | 33 ++++++++++++++++++--------------- 7 files changed, 69 insertions(+), 50 deletions(-) (limited to 'libusb') diff --git a/libusb/core.c b/libusb/core.c index 5c29eac..6a78c51 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -24,9 +24,6 @@ #include #include #include -#ifndef OS_WINDOWS -#include "os/poll_posix.h" -#endif #include "libusbi.h" @@ -914,7 +911,7 @@ API_EXPORTED int LIBUSB_API libusb_open(libusb_device *dev, libusb_device_handle struct libusb_context *ctx = DEVICE_CTX(dev); struct libusb_device_handle *_handle; size_t priv_size = usbi_backend->device_handle_priv_size; - ssize_t r; + int r; usbi_dbg("open %d.%d", dev->bus_number, dev->device_address); _handle = malloc(sizeof(*_handle) + priv_size); @@ -936,7 +933,7 @@ API_EXPORTED int LIBUSB_API libusb_open(libusb_device *dev, libusb_device_handle libusb_unref_device(dev); usbi_mutex_destroy(&_handle->lock); free(_handle); - return (int)r; + return r; } usbi_mutex_lock(&ctx->open_devs_lock); @@ -944,14 +941,12 @@ API_EXPORTED int LIBUSB_API libusb_open(libusb_device *dev, libusb_device_handle usbi_mutex_unlock(&ctx->open_devs_lock); *handle = _handle; - /* At this point, we want to interrupt any existing event handlers so * that they realise the addition of the new device's poll fd. One * example when this is desirable is if the user is running a separate * dedicated libusb events handling thread, which is running with a long * or infinite timeout. We want to interrupt that iteration of the loop, * so that it picks up the new fd, and then continues. */ - usbi_fd_notification(ctx); return 0; @@ -1674,18 +1669,22 @@ void usbi_log(struct libusb_context *ctx, enum usbi_log_level level, } /** \ingroup misc - * Returns a constant string with an English short description of the given - * error code. The caller should never free() the returned pointer since it - * points to a constant string. + * Returns a constant NULL-terminated string with an English short description + * of the given error code. The caller should never free() the returned pointer + * since it points to a constant string. * The returned string is encoded in ASCII form and always starts with a - * capital letter and ends without any dot. + * capital letter and ends without any punctuation. + * Future versions of libusb may return NULL if the library is compiled without + * these messages included (e.g. for embedded systems). + * This function is intended to be used for debugging purposes only. + * * \param errcode the error code whose description is desired - * \returns a short description of the error code in English + * \returns a short description of the error code in English, or NULL if the + * error descriptions are unavailable */ -API_EXPORTED const char* LIBUSB_API libusb_strerror(enum libusb_error errcode) +API_EXPORTED const char *LIBUSB_API libusb_strerror(enum libusb_error errcode) { - switch (errcode) - { + switch (errcode) { case LIBUSB_SUCCESS: return "Success"; case LIBUSB_ERROR_IO: diff --git a/libusb/descriptor.c b/libusb/descriptor.c index d5d9a75..c713109 100644 --- a/libusb/descriptor.c +++ b/libusb/descriptor.c @@ -65,7 +65,7 @@ int usbi_parse_descriptor(unsigned char *source, char *descriptor, void *dest, } } - return (int)(sp - source); + return (int) (sp - source); } static void clear_endpoint(struct libusb_endpoint_descriptor *endpoint) @@ -639,7 +639,7 @@ API_EXPORTED int LIBUSB_API libusb_get_config_descriptor_by_value(libusb_device else if (idx == -1) return LIBUSB_ERROR_NOT_FOUND; else - return libusb_get_config_descriptor(dev, (uint8_t)idx, config); + return libusb_get_config_descriptor(dev, (uint8_t) idx, config); } /** \ingroup desc diff --git a/libusb/io.c b/libusb/io.c index febe121..8d94400 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -23,9 +23,10 @@ #include #include #include +#include -#ifndef OS_WINDOWS -#include "os/poll_posix.h" +#ifdef HAVE_SYS_TIME_H +#include #endif #ifdef USBI_TIMERFD_AVAILABLE diff --git a/libusb/libusb-1.0.rc b/libusb/libusb-1.0.rc index a369128..835979b 100644 --- a/libusb/libusb-1.0.rc +++ b/libusb/libusb-1.0.rc @@ -1,3 +1,10 @@ +/* + * For Windows: input this file to the Resoure Compiler to produce a binary + * .res file. This is then embedded in the resultant library (like any other + * compilation object). + * The information can then be queried using standard APIs and can also be + * viewed with utilities such as Windows Explorer. + */ #include "winresrc.h" #ifdef _DEBUG diff --git a/libusb/libusb-1.0.rc.in b/libusb/libusb-1.0.rc.in index 9d4923e..27db214 100644 --- a/libusb/libusb-1.0.rc.in +++ b/libusb/libusb-1.0.rc.in @@ -1,3 +1,10 @@ +/* + * For Windows: input this file to the Resoure Compiler to produce a binary + * .res file. This is then embedded in the resultant library (like any other + * compilation object). + * The information can then be queried using standard APIs and can also be + * viewed with utilities such as Windows Explorer. + */ #include "winresrc.h" #ifdef _DEBUG diff --git a/libusb/libusb.h b/libusb/libusb.h index 8c229e6..d195ff2 100644 --- a/libusb/libusb.h +++ b/libusb/libusb.h @@ -21,28 +21,31 @@ #ifndef __LIBUSB_H__ #define __LIBUSB_H__ -#include +/* MSVC doesn't like inline, but does accept __inline ?? */ #ifdef _MSC_VER #define inline __inline -#else -#include #endif + +#include #include #include #include +#if defined(__linux) || defined(__APPLE__) || defined(__CYGWIN__) +#include +#endif + /* 'interface' might be defined as a macro on Windows, so we need to * undefine it so as not to break the current libusb API, because * libusb_config_descriptor has an 'interface' member * As this can be problematic if you include windows.h after libusb.h * in your sources, we force windows.h to be included first. */ -#if (defined(_WIN32) || defined(__CYGWIN__)) +#if defined(_WIN32) || defined(__CYGWIN__) #include -#endif - #if defined(interface) #undef interface #endif +#endif #if (defined(_WIN32) || defined(__CYGWIN__))&&defined(LIBUSB_DLL_BUILD) #define LIBUSB_EXP __declspec(dllexport) @@ -68,14 +71,14 @@ extern "C" { * \param x the host-endian value to convert * \returns the value in little-endian byte order */ -static inline uint16_t libusb_cpu_to_le16(uint16_t x) { +static inline uint16_t libusb_cpu_to_le16(const uint16_t x) +{ union { uint8_t b8[2]; uint16_t b16; } _tmp; - uint16_t _tmp2 = (uint16_t)(x); - _tmp.b8[1] = _tmp2 >> 8; - _tmp.b8[0] = _tmp2 & 0xff; + _tmp.b8[1] = x >> 8; + _tmp.b8[0] = x & 0xff; return _tmp.b16; } @@ -808,7 +811,7 @@ struct libusb_transfer { LIBUSB_EXP int LIBUSB_API libusb_init(libusb_context **ctx); LIBUSB_EXP void LIBUSB_API libusb_exit(libusb_context *ctx); LIBUSB_EXP void LIBUSB_API libusb_set_debug(libusb_context *ctx, int level); -LIBUSB_EXP const char* LIBUSB_API libusb_strerror(enum libusb_error errcode); +LIBUSB_EXP const char *LIBUSB_API libusb_strerror(enum libusb_error errcode); LIBUSB_EXP ssize_t LIBUSB_API libusb_get_device_list(libusb_context *ctx, libusb_device ***list); @@ -1181,8 +1184,8 @@ static inline int libusb_get_descriptor(libusb_device_handle *dev, uint8_t desc_type, uint8_t desc_index, unsigned char *data, int length) { return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN, - LIBUSB_REQUEST_GET_DESCRIPTOR, (desc_type << 8) | desc_index, - 0, data, (uint16_t)length, 1000); + LIBUSB_REQUEST_GET_DESCRIPTOR, (desc_type << 8) | desc_index, 0, data, + (uint16_t) length, 1000); } /** \ingroup desc @@ -1203,9 +1206,8 @@ static inline int libusb_get_string_descriptor(libusb_device_handle *dev, uint8_t desc_index, uint16_t langid, unsigned char *data, int length) { return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN, - LIBUSB_REQUEST_GET_DESCRIPTOR, - (uint16_t)((LIBUSB_DT_STRING << 8) | desc_index), - langid, data, (uint16_t)length, 1000); + LIBUSB_REQUEST_GET_DESCRIPTOR, (uint16_t)((LIBUSB_DT_STRING << 8) | desc_index), + langid, data, (uint16_t) length, 1000); } LIBUSB_EXP int LIBUSB_API libusb_get_string_descriptor_ascii(libusb_device_handle *dev, diff --git a/libusb/libusbi.h b/libusb/libusbi.h index a72ab1e..cca5fa0 100644 --- a/libusb/libusbi.h +++ b/libusb/libusbi.h @@ -22,10 +22,8 @@ #define __LIBUSBI_H__ #include -#if !defined(OS_WINDOWS) || defined(__CYGWIN__) -#include -#endif #include +#include #include @@ -150,14 +148,17 @@ void usbi_log_v(struct libusb_context *ctx, enum usbi_log_level level, #define LOG_BODY(ctxt, level) { } #endif -void inline usbi_info(struct libusb_context *ctx, const char *format, ...) +static inline void usbi_info(struct libusb_context *ctx, const char *format, + ...) LOG_BODY(ctx,LOG_LEVEL_INFO) -void inline usbi_warn(struct libusb_context *ctx, const char *format, ...) +static inline void usbi_warn(struct libusb_context *ctx, const char *format, + ...) LOG_BODY(ctx,LOG_LEVEL_WARNING) -void inline usbi_err( struct libusb_context *ctx, const char *format, ...) +static inline void usbi_err( struct libusb_context *ctx, const char *format, + ...) LOG_BODY(ctx,LOG_LEVEL_ERROR) -void inline usbi_dbg(const char *format, ...) +static inline void usbi_dbg(const char *format, ...) #if defined(ENABLE_DEBUG_LOGGING) || defined(INCLUDE_DEBUG_LOGGING) LOG_BODY(NULL,LOG_LEVEL_DEBUG) #else @@ -173,14 +174,16 @@ void inline usbi_dbg(const char *format, ...) #define ITRANSFER_CTX(transfer) \ (TRANSFER_CTX(__USBI_TRANSFER_TO_LIBUSB_TRANSFER(transfer))) -/* Internal abstraction for thread synchronization */ -#if defined(OS_LINUX) || defined(OS_DARWIN) +/* Internal abstractions for thread synchronization and poll */ +#if defined(THREADS_POSIX) #include -#elif defined(OS_WINDOWS) && (defined(__CYGWIN__) || defined(USE_PTHREAD)) -#include -#include #elif defined(OS_WINDOWS) #include +#endif + +#if defined(OS_LINUX) || defined(OS_DARWIN) +#include +#elif defined(OS_WINDOWS) #include #endif @@ -312,15 +315,15 @@ struct usbi_transfer { }; #define __USBI_TRANSFER_TO_LIBUSB_TRANSFER(transfer) \ - ((struct libusb_transfer *)(((char *)(transfer)) \ + ((struct libusb_transfer *)(((unsigned char *)(transfer)) \ + sizeof(struct usbi_transfer))) #define __LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer) \ - ((struct usbi_transfer *)(((char *)(transfer)) \ + ((struct usbi_transfer *)(((unsigned char *)(transfer)) \ - sizeof(struct usbi_transfer))) static inline void *usbi_transfer_get_os_priv(struct usbi_transfer *transfer) { - return ((char *)transfer) + sizeof(struct usbi_transfer) + return ((unsigned char *)transfer) + sizeof(struct usbi_transfer) + sizeof(struct libusb_transfer) + (transfer->num_iso_packets * sizeof(struct libusb_iso_packet_descriptor)); -- cgit v1.2.1