Commit Graph

503 Commits

Author SHA1 Message Date
Luca Longinotti
2fce3707fc Make libusbx-1.0.15 the only default stable provider for all systems.
Add libusbx-1.0.16-rc3 as an option to test the new upcoming release.
With 1.0.16 libusb and libusbx are merging back together, so the separation doesn't make sense anymore.
The 1.0.16 RCs might give better results on MacOS X, lots of work has gone in the Darwin backend.
Defaults to stable, but just set LIBUSB="beta" in build/common.sh to switch to 1.0.16 RCs.
2013-07-08 17:05:35 +02:00
Luca Longinotti
33b580b5f6 Commit fixes for Mac OS X build. 2013-07-08 12:19:59 +02:00
Luca Longinotti
e97db92e7f Add Win64 rebuild, completing the series. 2013-06-24 11:48:38 +02:00
Luca Longinotti
6aaf3e98f1 Add ARMv7HF build. 2013-06-23 22:25:04 -04:00
Luca Longinotti
d09592e9dc Update build. 2013-06-24 03:48:19 +02:00
Luca Longinotti
a783e6d2d0 Update configure.ac and build to support older automake. 2013-06-24 03:47:24 +02:00
Luca Longinotti
b7ff0b6cba Fix autogen.sh failure on Linux systems. 2013-06-24 02:53:48 +02:00
Luca Longinotti
d9f4ac089c Windows 32bit native build. 2013-06-24 02:12:24 +02:00
Luca Longinotti
8c4d2dddac Add recompiles for win32 and win64. win64 should work, win32 I'm unsure if there will still be problems with having used the MinGW cross-compiler or not. 2013-06-21 15:24:53 +02:00
Luca Longinotti
5c36619972 Add updated linux-32 port. 2013-06-20 23:48:46 +02:00
Luca Longinotti
2034fd81f3 Add up-to-date linux-64 build. 2013-06-20 23:26:32 +02:00
Luca Longinotti
09d582157f Implement equals/hashCode for ControlSetup by comparing the two buffers fully (only thing you can do!).
Change equals/hashCode for IsoPacketDescriptor and related Transfer to use only their pointers to native memory.
This is because two Transfers may be the same on all accounts, but they still are not the same Transfer that's happening.
Also it interfered with removal of Transfers from a list in the callback: Java couldn't clearly distinguish them and started accessing members of some that were already freed, resulting in exceptions.
Furhter, implement toString for IsoPacketDescriptor, Transfer and ControlSetup.
2013-06-18 11:02:25 +02:00
Luca Longinotti
f92a84c979 Read the flags before calling the Java method, as it might free the underlying memory. 2013-06-18 10:51:06 +02:00
Luca Longinotti
faa739dcbd Fix typo. Update libs with new fix. 2013-06-18 10:07:21 +02:00
Luca Longinotti
451b081d3f Commit updated libs. 2013-06-17 09:00:48 +02:00
Luca Longinotti
c0ea9ba0f6 How we interact with libusb from Java is quite inconsistent, and it mainly stems from the fact Java has no
unsigned integers, which is what libusb uses everywhere.
As it was before, there are parts of the library that return bytes & shorts, like the Descriptors (mostly to
be compatible with javax.usb), and others that take and return int, even where an 8 or 16-bit quantity would
be expected by libusb. I suspect this was done to avoid casting and try to side-step the sign-extension
problem with Java as much as possible, but in the end it leads to an API that's inconsistent, that doesn't
express the ranges it can use well (it's an int but in reality only 16 bits for libusb and so on). It also
fails at basic operations in ways you'd not expect because of the above inconsistencies:
if (deviceDescriptor.bDeviceClass() == LibUsb.CLASS_VENDOR_SPEC) { do something; }
will never work, since the constant is an int and the returned short from bDeviceClass() will be cast up to an
int too, but CLASS_VENDOR_SPEC is 0xFF (MSB=1), it will be sign-extended and the comparison will fail always.
There are two solutions I can see here:
A) consistently use int/long everywhere, both input and output. Everything becomes simpler to write, with less
casts, BUT javax.usb compatibility is gone for the Descriptors and it becomes even unclearer what those values
effectively mean and what range they support.
B) restrict the API to use the proper integer sizes as the C API, ie. 8-bit quantities (char, uint8_t, int8_t)
are represented by jbyte, 16-bit by jshort, and all the constants get properly sized too. With this approach
the sizes and ranges are much clearer, comparisons like the above work out-of-the-box, javax.usb compatibility
is maintained for the Descriptors. The downside is more casting and the occasional need to mask off returned
values to kill the sign-extension when you want to use those values as integers (like when printing stuff in
decimal notation).
I chose to try out the approach from B) for now, this commit implements it as explained above.
It requires minimal changes to the javax.usb implementation, just two casts to byte in AbstractDevice.java.
2013-06-17 00:17:48 +02:00
Luca Longinotti
a50fd0ecb5 Also make timeout read a long. 2013-06-16 18:07:47 +02:00
Luca Longinotti
b239bfdedd Make timeouts long: they are unsigned ints in C, and only a Java long can properly represent the full range.
It would be counter-intuitive to have to set negative timeouts in Java to get longer timeouts in C...
Also reorder getVersion() and getStringDescriptorAscii() to their proper places, so they are in the same order
as they appear in the libusbx documentation.
2013-06-16 17:20:19 +02:00
Luca Longinotti
58a2494e4c Use C99-style for-loops, much more readable. 2013-06-14 18:14:53 +02:00
Luca Longinotti
3d939da41f Bump version for testing. 2013-06-14 17:04:15 +02:00
Luca Longinotti
eb5b993eb2 Add updated libraries for Windows and Linux x86_64. 2013-06-13 14:31:21 +02:00
Luca Longinotti
ccdc2f6022 Don't increase refcount on the device returned by getParent() or getDevice().
It's better to be like libusbx itself here and not change the behavior.
But I've added a note to explain to never unref such a device.
2013-06-13 14:26:36 +02:00
Luca Longinotti
266ab299cc Wcast-qual was useuful to discover those errors in extra(): the returned ByteBuffer is fully writable, but the backing memory isn't really intended to be written to (and you never should modify the descriptors in memory).
So fixed by getting a read-only ByteBuffer and passing that back to Java instead.
2013-06-13 13:43:27 +02:00
Luca Longinotti
0f6031ab88 Revert TransferTest to original, since null is now supported again. 2013-06-13 13:40:06 +02:00
Luca Longinotti
95ee591d46 Remove memcpy wrap stuff to support old, broken systems... memcpy is never used here, only libusb uses it and there they don't support it in any particular way, so I don't believe there should be a workaround for this that forces memcpy to be slower on all x86_64 linux systems.
Enable silent building and C99 support.
Enable lots of warnings and don't enable Werror, as there are warnings in libusb.h.
Fix all warnings. Add const to exceptions.
Make it possible to pass null to setDevHandle and setBuffer in Transfer now.
2013-06-13 12:59:42 +02:00
Luca Longinotti
b3e261f050 Fix tests: use direct int buffers where needed, it's Implicit and not Explicit, the class 5 is known.
Setting devHandle or buffer to NULL in Transfer is not supported (doesn't make sense at all...).
2013-06-12 23:18:39 +02:00
Luca Longinotti
8967434994 Fix descriptor dumps. Forgot to shift the masked values, other minor changes. 2013-06-12 23:09:58 +02:00
Luca Longinotti
5b58cb0302 Issue expected exception when default context refcount is zero or smaller.
Make sure that returning a new reference always leads to a new Java object being created, else
freeing/unref'ing that one would lead to the reset of the original object too.
Furthermore, ensure that getDevice also increments the reference count, since if you then free it,
which is usual and not forbidden (libusbx docs just tell you are not obligated to unref it), the
reference count would be wrong and lead to a segfault. This way it would lead at most to keeping a
device around, instead of segfaulting. Still, always free your references!!!
2013-06-12 22:22:58 +02:00
Luca Longinotti
a4d3ab69da Destroying the default context twice, even if it is refcounted, results in a segfault.
Fix submitted to libusbx as pull request #116.
Also fix this inside the Java wrapper, by adding our own refcount (similar to what was in original usb4java,
but allowing multiple calls with the default context), and making the access to said variable thread-safe.
Once libusbx fixes this, the above code can be removed.
2013-06-12 21:39:02 +02:00
Luca Longinotti
0ba3d8869f Fixed test to also use the pointer instead of the Context hashCode. 2013-06-12 18:45:31 +02:00
Luca Longinotti
ea680a9be7 Add linux and windows 64bit updated builds for more testing (linux works at a basic level). 2013-06-12 14:45:08 +02:00
Luca Longinotti
032b7487d4 Add a few capability constants that were missing, from libusbx-1.0.15. 2013-06-12 14:44:24 +02:00
Luca Longinotti
81eea49213 Change to long, this makes sure there will be no collisions or problems in the HashMap even on 64bits.
On 32bits the pointer will only have at most 32bits set, so converting it to a void * (which also is 32bits) will not actually loose any information.
2013-06-12 14:07:42 +02:00
Luca Longinotti
275bc37a77 Right now if you add different PollfdListeners to different contexts, only the last one will be remembered, and subsequent callbacks, even from other contexts, will always use that last one.
This is obviously unexpected and incorrect, yet cannot be fixed by just adding more data on the C side: you'd have to remember the callback object at the very least, which you could in the user_data
field, but you'd have to make it a global reference. Yet, there would be no easy way to later correctly delete that global reference, since to unset the pollfdNotifiers you just pass NULL to the
same function again, and you don't get back any data on what was there before.
The easiest way to fix this was thus to change to a HashMap, Concurrent since access can be from random threads.
The key was chosen to be the Context.hashCode(), as Integer lookup and comparison is fast, and the hashCode depends directly on the contextPointer stored in the Context (which identifies it).
This works for sure on 32bit systems, but I'm still concerned about 64bit systems, where a long would probably make more sense, I need to think about it some more.
2013-06-12 13:38:10 +02:00
Luca Longinotti
a47e3cd3c3 Implement the remaining Control Transfer fill functions and the ControlSetup object.
Everything is done in Java here as it's much easier and cleaner, since those are only convenience functions/structs.
Byte order conversion is conveniently handled by ByteBuffer too, and using slice() we access the same memory all around.
Added some final keywords to LibUsb and BufferUtils.
2013-06-11 18:08:51 +02:00
Luca Longinotti
13e83fd59e Add isochronous transfer functions and async transfer fill functions. They are implemented directly in Java since they are static inline convenience functions in libusb.h and don't really need to call into C via JNI at all to work, this keeps the JNI layer simple and minimal.
Only fill_control/get_control is still outstanding.
getDescriptor() and getStringDescriptor() were removed from native JNI, since they are static inline convenience functions in libusb.h and don't do anything more than calling the appropriate real function.
2013-06-11 15:48:16 +02:00
Luca Longinotti
db62b8496b Add IsoPacketDescriptor.c to Makefile. 2013-06-11 13:14:04 +02:00
Luca Longinotti
95534657c9 Transfer constructor also package private, since you never create them but only get them through allocTransfer(). 2013-06-11 13:06:02 +02:00
Luca Longinotti
51c07e1dbc Add IsoPacketDescriptor objects and get them from the Transfer.
Also add equals/hashcode for Transfer and IsoPacketDescriptor.
2013-06-11 10:32:43 +02:00
Luca Longinotti
47543fa352 Constify wrapper functions (set and wrap). 2013-06-11 09:37:45 +02:00
Luca Longinotti
fddb83de2f Add submitTransfer and cancelTransfer. Rudimentary async I/O should now work (not tested yet!). 2013-06-10 23:32:51 +02:00
Luca Longinotti
d26a0e0d62 Fix NULL deref in InterfaceDescriptor too. 2013-06-10 20:25:17 +02:00
Luca Longinotti
09cf25cfae Fix NULL dereferences. Using the result of unwrap*() directly can lead to dereferencing NULL, for example if called on an already freed object.
InterfaceDescriptor still to do.
2013-06-10 17:42:27 +02:00
Luca Longinotti
cac3297458 Add BufferUtils to centralize creation of appropriate Buffers for LibUsb (various types, directly allocated). 2013-06-10 16:58:41 +02:00
Luca Longinotti
dca1ed7693 Finish work on Transfer implementation. Everything is consistent, fast callbacks are provided, support for FREE_TRANSFER is there and fully cleans up resources.
To support FREE_TRANSFER in the case the user doesn't set (or explicitely sets) a callback of null on the Java side, a small C-callback was created that just takes care of cleaning up the Java objects and resources.
2013-06-10 16:00:17 +02:00
Luca Longinotti
f04e3e4381 Rename trans to transfer inside LibUsb functions, like in Transfer.c.
Add methodID field to transfer_data structure, so that it can be cached at set() time and the callback is faster.
Also update the length when setting a new buffer!
2013-06-10 14:37:30 +02:00
Luca Longinotti
c1c32c3faf Add new transfer_data structure (Java and other objects). Update transfer functions accordingly.
Check all variable names for consistency.
Fix memory leak on failed getDeviceDescriptor.
Use result == LIBUSB_SUCCESS instead of just !result, it is much clearer what the integer that you get as result actually means that way.
2013-06-10 11:39:20 +02:00
Luca Longinotti
1b93df20ca Transfer.java: rename get methods to just be the name of the field with the appropriate type, like in the other classes (Descriptors etc.). This is consistent and easy to use.
Move callback and maxNumIsoPacketSize to C, minimizing what is kept in Java: only the pointer and the transferBuffer. setLength() is still checked here, as that's easiest.
Update the tests to match the changes and add documentation on the new methods.
2013-06-10 10:16:47 +02:00
Luca Longinotti
34262a1b00 Add work on async transfers, not yet completed, I may yet change where certain data is kept and how it is
checked.
2013-06-09 23:55:34 +02:00
Luca Longinotti
2ee0b2b7fd Also do a deep-equals of the arrays and ByteBuffers. 2013-06-09 23:35:20 +02:00