Commit Graph

456 Commits

Author SHA1 Message Date
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
Luca Longinotti
dbd2a4cf55 Version.java: add nano().
*.java: Fix code and comment formatting to be equal everywhere and conform to what I could see as being the
expected usb4java standard.
*.java: Remove Apache-Commons dependency for extremely simple HashCode/Equals involving only the pointer
variable, instead use the Eclipse-generated methods.
2013-06-09 23:03:01 +02:00
Luca Longinotti
68125967a4 LibUsb.java: add missing MASKs, precise TRANSFER_FREE_BUFFER comment, only update references after native
calls return without throwing exceptions.
DescriptorUtils.java: update to use the correct masks and variables, always return "Unknown" on a not-handled
value.
*Descriptor.java: update equals/hashcode to use all fields in the same order as they are defined (makes
checking this much easier in the future!). For example bRefresh was missing or some extra/extraLength checks.
InterfaceDescriptor: there is no need for a dump(DeviceHandle) here, so removed it and updated the call in
Interface.java.
2013-06-09 16:36:31 +02:00
Luca Longinotti
bda2fdab54 Use correct call methods, if it returns void: callVoid, else if it returns object: callObject.
Also move JVM reference to be available to all C files (needed for Transfer callback later) and initialize it
once at startup.
2013-06-09 15:16:04 +02:00
Luca Longinotti
1efc33b0f2 Add resetDevice() to also reset the Java Device object after unref, as it really shouldn't be used anymore
since you don't know if the refcount reached zero and it was deallocated. Every new reference means the
refcount gets increased AND a new reference indeed exits, so this always works, unless you let references go
out of scope or overwrite them, which is clearly incorrect in any case.
Also add missing checks for setDeviceHandle() in Transfer.
2013-06-08 00:20:12 +02:00
Luca Longinotti
00670bb48d Implement Transfer callback fully. Transfer cleanup via FREE_TRANSFER also fully guaranteed. 2013-06-07 23:11:09 +02:00
Luca Longinotti
61756ed405 Add basic callback support, still work in progress. 2013-06-07 18:45:53 +02:00
Luca Longinotti
41c92e07c6 Add support for direct allocTransfer(), without isoPackets argument.
Start working on callback support.
2013-06-07 18:24:07 +02:00
Luca Longinotti
817175b686 Only get JVM if not set already (it doesn't change). 2013-06-07 18:09:13 +02:00
Luca Longinotti
8c140fd201 Fix spacing. 2013-06-07 11:52:07 +02:00
Luca Longinotti
66017bfa88 Add new NOT_SET macro to call after NOT_NULL for functions that call set*() functions.
Right now for example, getting a new config descriptor re-using an old ConfigDescriptor object just overwrites the old pointer, without freeing it or telling the user, resulting in a memory leak.
This way, the user gets notified when he's re-using an object that he hasn't cleaned up yet, and he can react and call the appropriate free/cleanup function.
2013-06-07 11:20:58 +02:00
Luca Longinotti
6f542a6228 Separate input checking from function content by a newline, improves readability by a lot!
Add missing NOT_NULL checks.
Simplify getPortPath() ifdef.
Check for result value in libusb_init and only setContext if the call succeeded.
Use always same style of NULL checks in usb4java.h.
2013-06-07 10:51:23 +02:00
Luca Longinotti
1794bbe71d Fix handleEventsTimeoutCompleted and handleEventsCompleted, they require access to a variable representing an integer, that gets set from somewhere outside, like a transfer callback.
The only way to do this in Java is by direct buffers, which IntBuffers can be if allocated correctly, as explained in the JavaDoc.
2013-06-06 15:24:33 +02:00
Luca Longinotti
bcfca40d56 Fix signature comments. 2013-06-06 14:48:35 +02:00
Luca Longinotti
69cecdb21a Fix memory leak: if you malloc, you must also free, JNI never touches manually allocated memory.
Also, I don't see why there is any need to deviate from using a pointer to using a ByteBuffer here, it will not make memory management automatic, and just makes the DeviceDescriptor "different" for no apparent reason. So changed back to pointer.
2013-06-06 14:08:27 +02:00
Luca Longinotti
6d2afe79ac Don't create new scopes in macros, it only makes sense if you have frequent name collisions, and worsens performance.
Change DIRECT_BUFFER to not call the isDirect() method (expensive!), but instead to check the return value of getDirectBufferAddress, which is always used anyway.
It also detects cases where the JVM doesn't support direct buffers and other error conditions this way.
2013-06-06 12:04:50 +02:00
Luca Longinotti
2d5ecef390 Fix signature comments. 2013-06-06 11:32:44 +02:00
Luca Longinotti
36f14cf52d I see now why ints were used here, because all the constants are ints and as such you don't have to do annoying casts and conversions.
I agree with this on set*() calls, but I argue that it is more correct to return the appropriate, smaller type on get*() calls, the same as with the other classes: the values you can read are of appropriate, original size.
2013-06-06 10:36:49 +02:00
Luca Longinotti
f976026e1d Consistently use ByteBuffers in the LibUsb class, getPortPath was the only method that used a byte array, and I personally prefer consistency here, as it gets used like any other function expected to get a char * + length. 2013-06-06 10:29:40 +02:00
Luca Longinotti
d7ce8ce87b We don't need to concern ourselves with length in getStringDescriptorAscii when using a StringBuffer and appending to it.
In C you need to have a length parameter to know how much you can write, here we can always just get the maximum, which is quite small, and then append to the StringBuffer, which will take care of any length management.
2013-06-06 09:59:21 +02:00
Luca Longinotti
a4d5de493b Fix LongBuffer vs IntBuffer usage for getNextTimeout: it has to work with long.
Fix method signatures.
Add TODO wrt wrong usage of completed flag.
2013-06-06 09:28:50 +02:00
Luca Longinotti
b97aa73220 Work on array directly to avoid a full copy. 2013-06-05 18:22:21 +02:00
Luca Longinotti
2ac3763b78 Replace mentions of struct libusb_context with the typedef libusb_context, as is expected by the API.
Also fix init/exit to not handle the default context in any special way: the default context is reference counted, and it is thus NOT an error to call init on it multiple times, or exit for that matter afterwards.
2013-06-05 17:36:42 +02:00
Luca Longinotti
01fa6c971f Fix typo. 2013-06-05 17:36:29 +02:00
Luca Longinotti
2c5ea3c7a4 Set size to zero on reset. Else getting the size is incorrect, and later when checking in get() it would pass the check and you'd access a NULL ptr. 2013-06-05 16:52:24 +02:00
Luca Longinotti
278733f0cb bSynchAddress is a byte in both Java and libusb.h. 2013-06-05 16:49:08 +02:00
Luca Longinotti
164f6e1b36 numAltsetting is an int, in both the Java class and libusb.h. 2013-06-05 16:47:49 +02:00
Luca Longinotti
f022d9ce75 Sync Transfer class with libusb.h definition (byte instead of int mostly).
Add several yet unimplemented methods.
Update test.
2013-06-05 16:45:32 +02:00
Luca Longinotti
3185cb2c61 Rename pointer to more meaningfull names like in the other files. 2013-06-05 15:19:01 +02:00
Luca Longinotti
1a6ca03894 Remove useless extern keywords from definition.
Add missing definitions.
2013-06-05 15:15:49 +02:00
Luca Longinotti
347cb32002 Improve readability.
Don't get same data twice!
2013-06-05 15:14:21 +02:00
Luca Longinotti
5cfed718f4 Fix autotools run. 2013-06-05 15:09:30 +02:00
Klaus Reimer
4e9cd12c29 Mention usb-api.jar in quickstart 2013-05-07 21:19:26 +02:00
Klaus Reimer
b1883ee8b3 Correct link to libusb API doc 2013-05-07 21:16:14 +02:00
Klaus Reimer
ff2838147a Add autogen.sh 2013-05-07 21:14:21 +02:00
Klaus Reimer
da7d8b4d6c [maven-release-plugin] prepare for next development iteration 2013-05-04 12:24:48 +02:00
Klaus Reimer
b710de927b [maven-release-plugin] prepare release usb4java-1.0.0 2013-05-04 12:24:41 +02:00
Klaus Reimer
5814198efc Disable gpg plugin. 2013-05-04 12:23:52 +02:00
Klaus Reimer
6098423ac7 [maven-release-plugin] rollback the release of usb4java-1.0.0 2013-05-04 12:22:31 +02:00
Klaus Reimer
e3c4079a34 [maven-release-plugin] prepare for next development iteration 2013-05-04 12:16:41 +02:00
Klaus Reimer
b7e3eda677 [maven-release-plugin] prepare release usb4java-1.0.0 2013-05-04 12:16:32 +02:00
Klaus Reimer
9f49fc086f Switch from "usb" to "usb-api" dependency and remove test javadoc report 2013-05-04 11:45:21 +02:00
Klaus Reimer
2043e74ccc Fix site.xml 2013-05-04 11:36:17 +02:00
Klaus Reimer
2a4ecdb159 Remove travis.yml because this project can only be tested with my own
Jenkins
2013-05-03 23:09:05 +02:00
Klaus Reimer
c98960f3eb Create usb4java dist files and link them to download section of site 2013-05-03 22:57:26 +02:00
Klaus Reimer
a7f2ae2bf9 Add Maven info to download section 2013-05-03 21:39:02 +02:00
Klaus Reimer
ffece6a875 Switch back to my own nexus for now. 2013-05-03 20:16:53 +02:00
Klaus Reimer
400db6f2ae Fix reading of active config descriptor value when device is in
unconfigured state
2013-05-03 20:04:05 +02:00