Last of the patches I wanted to have for the 1.0.15 release.Unless there are comments, my plan will be to integrate this patch in 24 hours and declare RC.
This patch adds a new caps attribute to the backend struct. I preferred to do it this way because I think it makes sense to have our backend attributes within the backend struct, especially as we may have to set them at runtime (in that case, we will have to remove the const qualifiers on our backend instances, which shouldn't be an issue, but for HID this wasn't necessary).
Because I don't really want to guess what libusb will do, I introduced LIBUSB_CAP_HAS_HID_ACCESS at 0x100, which should leave us enough room, and internally USBI_CAP_HAS_HID_ACCESS defined to 0x10000. The latter is meant to be used as a bitmask, which oughta simplify our testing for it, while the former isn't, hence the need for two separate constants.
You'll also note that I bumped LIBUSBX_API_VERSION on account of libusb_has_capability() returning nonzero rather than 1 when a capability is supported. I'm pretty confident that nobody was using libusb_has_capability(), since we had nothing to test until now, or that if they did, they probably weren't testing for an explicit value, but since we're effectively modifying the API, we might as well not take any risks.
Also, even if as of right now, this isn't actually required, I've updated the doc for _has_capability() to indicate that it should always performed after init, so that a backend has a chance to update its caps at runtime.
Finally, I'm not sure if we want to test for libusb_has_capability(LIBUSB_CAP_HAS_HID_ACCESS) in xusb. Ideally, we probably should do that for the HID specific tests, but I'd rather avoid having to take some time to do just that. Note that I did test that libusb_has_capability() was working as expected with regards to HID on Windows and Linux.
Oh, and just a note on *BSD - I expect the platform to behave the same as Linux, so I set the HID cap as enabled there, but maybe this isn't correct. At any rate I'll try to run some *BSD tests on a VM during the RC duration, but if someone knows something about HID and *BSD, please speak now.
Regards, /Pete
>From 91fe7e72bf998620845180e28f9ad83ac39d712d Mon Sep 17 00:00:00 2001 From: Pete Batard <p...@akeo.ie> Date: Sun, 17 Mar 2013 22:13:53 +0000 Subject: [PATCH] Core: Add HID capability detection for all backends * Note that LIBUSBX_API_VERSION is incremented as a result of libusb_has_capability() returning nonzero rather than 1 when a capability is supported. --- libusb/core.c | 6 +++++- libusb/libusb.h | 4 +++- libusb/libusbi.h | 8 +++++++- libusb/os/darwin_usb.c | 1 + libusb/os/linux_usbfs.c | 1 + libusb/os/openbsd_usb.c | 1 + libusb/os/wince_usb.c | 1 + libusb/os/windows_usb.c | 1 + 8 files changed, 21 insertions(+), 4 deletions(-) diff --git a/libusb/core.c b/libusb/core.c index b3df73a..25a4b55 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -1740,15 +1740,19 @@ void API_EXPORTED libusb_exit(struct libusb_context *ctx) /** \ingroup misc * Check at runtime if the loaded library has a given capability. + * This call should be performed after \ref libusb_init(), to ensure the + * backend has updated its capability set. * * \param capability the \ref libusb_capability to check for - * \returns 1 if the running library has the capability, 0 otherwise + * \returns nonzero if the running library has the capability, 0 otherwise */ int API_EXPORTED libusb_has_capability(uint32_t capability) { switch (capability) { case LIBUSB_CAP_HAS_CAPABILITY: return 1; + case LIBUSB_CAP_HAS_HID_ACCESS: + return (usbi_backend->caps && USBI_CAP_HAS_HID_ACCESS); } return 0; } diff --git a/libusb/libusb.h b/libusb/libusb.h index d7e84c0..9fef28b 100644 --- a/libusb/libusb.h +++ b/libusb/libusb.h @@ -136,7 +136,7 @@ typedef unsigned __int32 uint32_t; * Internally, LIBUSBX_API_VERSION is defined as follows: * (libusbx major << 24) | (libusbx minor << 16) | (16 bit incremental) */ -#define LIBUSBX_API_VERSION 0x010000FF +#define LIBUSBX_API_VERSION 0x01000101 #ifdef __cplusplus extern "C" { @@ -995,6 +995,8 @@ struct libusb_transfer { enum libusb_capability { /** The libusb_has_capability() API is available. */ LIBUSB_CAP_HAS_CAPABILITY = 0, + /** The backend can access HID devices */ + LIBUSB_CAP_HAS_HID_ACCESS = 0x100 }; /** \ingroup lib diff --git a/libusb/libusbi.h b/libusb/libusbi.h index eed549e..3d9a19d 100644 --- a/libusb/libusbi.h +++ b/libusb/libusbi.h @@ -52,8 +52,11 @@ #define USB_MAXINTERFACES 32 #define USB_MAXCONFIG 8 +/* Backend specific capabilities */ +#define USBI_CAP_HAS_HID_ACCESS 0x10000 + /* The following is used to silence warnings for unused variables */ -#define UNUSED(var) (void)(var) +#define UNUSED(var) do { (void)(var); } while(0) struct list_head { struct list_head *prev, *next; @@ -446,6 +449,9 @@ struct usbi_os_backend { /* A human-readable name for your backend, e.g. "Linux usbfs" */ const char *name; + /* Binary mask for backend specific capabilities */ + uint32_t caps; + /* Perform initialization of your backend. You might use this function * to determine specific capabilities of the system, allocate required * data structures for later, etc. diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c index 08bd7f0..30ee3ff 100644 --- a/libusb/os/darwin_usb.c +++ b/libusb/os/darwin_usb.c @@ -1782,6 +1782,7 @@ static int darwin_clock_gettime(int clk_id, struct timespec *tp) { const struct usbi_os_backend darwin_backend = { .name = "Darwin", + .caps = 0, .init = darwin_init, .exit = darwin_exit, .get_device_list = darwin_get_device_list, diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c index 99bbd07..e1a5fbd 100644 --- a/libusb/os/linux_usbfs.c +++ b/libusb/os/linux_usbfs.c @@ -2527,6 +2527,7 @@ static clockid_t op_get_timerfd_clockid(void) const struct usbi_os_backend linux_usbfs_backend = { .name = "Linux usbfs", + .caps = USBI_CAP_HAS_HID_ACCESS, .init = op_init, .exit = NULL, .get_device_list = op_get_device_list, diff --git a/libusb/os/openbsd_usb.c b/libusb/os/openbsd_usb.c index 88e2c7a..914e947 100644 --- a/libusb/os/openbsd_usb.c +++ b/libusb/os/openbsd_usb.c @@ -89,6 +89,7 @@ static int _access_endpoint(struct libusb_transfer *); const struct usbi_os_backend openbsd_backend = { "Synchronous OpenBSD backend", + USBI_CAP_HAS_HID_ACCESS, NULL, /* init() */ NULL, /* exit() */ obsd_get_device_list, diff --git a/libusb/os/wince_usb.c b/libusb/os/wince_usb.c index 354c0e6..e4f7c7b 100644 --- a/libusb/os/wince_usb.c +++ b/libusb/os/wince_usb.c @@ -973,6 +973,7 @@ static int wince_clock_gettime(int clk_id, struct timespec *tp) const struct usbi_os_backend wince_backend = { "Windows CE", + 0, wince_init, wince_exit, diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c index d8156b8..f59f92d 100644 --- a/libusb/os/windows_usb.c +++ b/libusb/os/windows_usb.c @@ -2262,6 +2262,7 @@ static int windows_clock_gettime(int clk_id, struct timespec *tp) // NB: MSVC6 does not support named initializers. const struct usbi_os_backend windows_backend = { "Windows", + USBI_CAP_HAS_HID_ACCESS, windows_init, windows_exit, -- 1.8.0.msysgit.0
------------------------------------------------------------------------------ Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________ libusbx-devel mailing list libusbx-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libusbx-devel