Commit Graph

91 Commits

Author SHA1 Message Date
Alan Ott ebadfd6d5b Re-activated the cleanup code in read_thread(). For some unknown reason in
the past, I thought it would be a good idea to move this to hid_close(), but
I can't now understand why, as freeing these objects in read_thread() makes
sense because they are created in read_thread().

This code never made it into hid_close(), so it's now re-activated in
read_thread().

Reported-by: Ludovic Rousseau <ludovic.rousseau@gmail.com>
2010-10-23 13:27:44 -04:00
Alan Ott 3a3ac5e084 This eliminates a race condition on hid_close(). Previous to this patch,
hid_close() would hang on pthread_join() if hid_close() was called while the
reading thread was executing read_callback() _before_ the call to
libusb_submit_transfer(). This caused libusb_cancel_transfer() to fail, and
the read thread would never stop (and hid_close() would never return).

This patch simply sets the shutdown_thread flag from read_close(). This way,
even if hid_close() is called while there is no transfer pending, the loop
in read_thread() will exit, causing read_thread() to end. For this to not
leak resources, read_thread() also now has to call libusb_cancel_transfer().
Note that necessarily, one of the calls to libusb_submit_transfer() will
fail (and return an error code), but that's ok, because one of them is
guaranteed to succeed.

Reported-by: Ludovic Rousseau <ludovic.rousseau@gmail.com>
2010-10-23 12:53:27 -04:00
Alan Ott 0d7ed387b0 Changed the default back to blocking. This got inadvertently changed.
Reported-by: Ludovic Rousseau <ludovic.rousseau@gmail.com>
2010-10-21 09:22:17 -04:00
Alan Ott ad65e15c1c Added a pthread_barrier to ensure that the read_thread() function (thread)
has been initialized before hid_open_path() returns. There was a race
condition if hid_close() was called immediately after hid_open(), because
hid_close() was trying to destroy objects that read_thread() had sometimes
not created yet.

Reported-by: Ludovic Rousseau <rousseau@debian.org>
2010-10-13 10:20:19 -04:00
Ludovic Rousseau b8ceae83b8 Do not ovewrite CFLAGS
Signed-off-by: Alan Ott <alan@signal11.us>
2010-10-08 22:07:13 -04:00
Ludovic Rousseau fcec7ca07f Fix warning: ordered comparison of pointer with integer zero
iconv_open() returns a iconv_t so is always a positive value.

In case of error the returned value is (iconv_t)-1 so compare with this
specific value instead of < 0

Signed-off-by: Alan Ott <alan@signal11.us>
2010-10-08 22:05:17 -04:00
Ludovic Rousseau 218d146c37 Fix warning: comparison of unsigned expression < 0 is always false
iconv() returns a size_t so is always a positive value.

In case of error the returned value is (size_t)-1 so compare with this
specific value instead of < 0

Signed-off-by: Alan Ott <alan@signal11.us>
2010-10-08 22:04:32 -04:00
Ludovic Rousseau 8c80bbd8b7 Fix warning: declaration of ‘index’ shadows a global declaration
hid-libusb.c:172: warning: declaration of ‘index’ shadows a global declaration
/usr/include/string.h:487: warning: shadowed declaration is here

Use idx instead of index to avoid collision with index()

Signed-off-by: Alan Ott <alan@signal11.us>
2010-10-08 22:03:40 -04:00
Ludovic Rousseau 547a864690 Fix a buffer overflow
hid-libusb.c:223: warning: array subscript is above array bounds

sizeof(wbuf) gives the size of the wbuf array in char. It is also the
number of element only if wbuf is an array of char.

Here wbuf is an array of wchar_t so the last element of the array is
wbuf[sizeof(wbuf)/sizeof(wbuf[0])-1]

Signed-off-by: Alan Ott <alan@signal11.us>
2010-10-08 22:02:36 -04:00
Ludovic Rousseau 8c63a6d474 Fix warning: declaration of ‘i’ shadows a previous local
Use a "d" variable to index the devices instead of the generic "i"

Signed-off-by: Alan Ott <alan@signal11.us>
2010-10-08 19:57:05 -04:00
Ludovic Rousseau 095159d825 Fix warning: no previous prototype for ‘new_hid_device’
Local functions should be declared as static

Signed-off-by: Alan Ott <alan@signal11.us>
2010-10-08 19:55:23 -04:00
Ludovic Rousseau bfcaf8f2d3 Fix compiler warning function declaration isn’t a prototype
Functions with no arguments should use void

hid-libusb.c:93: warning: function declaration isn’t a prototype
hid-libusb.c:97: warning: function declaration isn’t a prototype
hid-libusb.c:1010: warning: function declaration isn’t a prototype

Signed-off-by: Alan Ott <alan@signal11.us>
2010-10-08 19:53:57 -04:00
Alan Ott a4b5d7bb1d Remove old build file which shouldn't be in here anymore. The Makefile is the right way to build the project. 2010-09-20 09:18:36 -04:00
Alan Ott a039425436 Put extern "C" around the functions. 2010-09-16 21:44:33 -04:00
Alan Ott 381a170d10 Return non-error for the nonblocking function. 2010-09-13 15:00:34 -04:00
Alan Ott 09cb41aada Additional licenses. HIDAPI is now GPLv3, BSD, or the original license,
at the discretion of the user. This should provide maximum flexibility and
freedom.
2010-09-13 11:15:24 -04:00
Alan Ott defb938797 Limit the receive queue to 30 reports on Linux. 2010-08-23 13:14:34 -04:00
Alan Ott 14dd2eeba4 Took out printf()s. 2010-08-21 14:03:52 -04:00
Alan Ott e0c8032b7b Updated README for Linux. 2010-08-21 14:01:04 -04:00
Alan Ott 17c4c9251c Changed hid_error() to return const. 2010-08-21 13:22:03 -04:00
Alan Ott 4214841ae3 Added the get_*_string() functions for the libusb implementation. 2010-08-21 13:09:23 -04:00
Alan Ott 0c07642ab5 Support for getting USB Strings using the applications locale.
If the locale's language is not supported by the device, it defaults to
the first language available on the device.
2010-08-19 22:53:53 -04:00
Alan Ott 2dedc16309 Fixed get_usb_string() to use the first language the device says it supports. 2010-08-18 21:54:45 -04:00
Alan Ott 28ab1e6ac1 Changed to use pkg-config 2010-08-17 22:50:31 -04:00
Alan Ott 32d785dbfe Changed to use pkg-config for libusb and fixed the position of libusb_close() in hid_enumerate(). 2010-08-17 22:13:54 -04:00
Alan Ott 35a8d0aecc Made the input loop only try to read endpoint->wMaxPacketSize. This way, messages don't get queued up, and are reported immediately. 2010-08-16 23:49:43 -04:00
Alan Ott 89d84b1e02 Don't send the report number if it's not needed for feature and output reports. 2010-08-16 23:32:20 -04:00
Alan Ott 461963e4b7 Libusb implementation for Linux. 2010-08-16 17:02:20 -04:00
Alan Ott 65331407a7 Made the hid_error() return wchar_t* so we can get translated error messages. 2010-08-10 14:58:59 -04:00
Alan Ott 54c8061ec5 Fixed compile warning. 2010-07-28 21:43:51 -04:00
Alan Ott 65264446c3 Cleaned up output (printf()) 2010-07-28 21:43:11 -04:00
Alan Ott ca9d652e4a Added .gitignore to linux/ directory. 2010-07-28 21:17:03 -04:00
Alan Ott 6983cb4da0 Made hid_close() NULL-tolerant. 2010-07-28 21:14:36 -04:00
Alan Ott da1ab35011 Fixed up the header comments. 2010-07-28 20:32:41 -04:00
Alan Ott aa3d51925a Changed the interface to use a pointer instead of an int as the device handle.
This is only implemented on Linux so far.
2010-07-24 11:05:36 -04:00
Alan Ott 844fd35c0c Set/Get Feature Support for Linux. 2010-07-10 21:48:24 -04:00
Alan Ott d2489f8755 Support for getting USB strings (Manufacturer, Product, Serial) from
the device during runtime (as opposed to enumerate-time).
2010-07-07 23:48:29 -04:00
Alan Ott d6db1ec8ca Worked around a problem in Linux kernels prior to 2.6.34.
Fixed non-blocking operation.
2010-07-03 15:33:22 -04:00
Alan Ott 0782bc31f0 README and Makefile for Linux. 2010-07-03 15:26:16 -04:00
Alan Ott ebc18502b7 Added the hidapi_enumerate() interface on Linux.
Added manufacturer and product strings to the hid_device struct.
2010-07-01 17:39:24 -04:00
Alan Ott 6c0ee6befc Made the hidapi_enumerate() functional.
Added non-blocking operation.
2010-07-01 17:10:45 -04:00