mirror of https://github.com/rusefi/usb4java.git
Implement setOption
This commit is contained in:
parent
0172799fcb
commit
a68a6f33c3
|
@ -1,14 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<document xmlns="http://maven.apache.org/changes/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0
|
||||
<document xmlns="http://maven.apache.org/changes/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0
|
||||
http://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd">
|
||||
<properties>
|
||||
<title>Changelog</title>
|
||||
<author email="k@ailis.de">Klaus Reimer</author>
|
||||
</properties>
|
||||
<body>
|
||||
<body>
|
||||
<release version="1.3.0" date="2018-10-07" description="Major update">
|
||||
<action dev="kayahr" type="update" date="2018-10-08">
|
||||
Wrap new libusb functions: setOption.
|
||||
</action>
|
||||
<action dev="kayahr" type="update" date="2018-10-07">
|
||||
Updated to libusb 1.0.22.
|
||||
</action>
|
||||
|
@ -25,23 +28,23 @@
|
|||
(javax-usb extension) and libusb4java (Native code).
|
||||
</action>
|
||||
<action dev="llongi" type="add" date="2013-09-14">
|
||||
Add hotplug support to low-level API.
|
||||
Add hotplug support to low-level API.
|
||||
</action>
|
||||
<action dev="llongi" type="add" date="2013-09-14">
|
||||
Add asynchronous I/O support to low-level API.
|
||||
Add asynchronous I/O support to low-level API.
|
||||
</action>
|
||||
</release>
|
||||
<release version="1.1.0" date="2013-07-13" description="Major update">
|
||||
<action dev="kayahr" type="update" date="2013-07-13">
|
||||
Using reunited libusb/libusbx 1.0.16 as backend.
|
||||
Using reunited libusb/libusbx 1.0.16 as backend.
|
||||
</action>
|
||||
<action dev="kayahr" type="add" date="2013-07-13">
|
||||
Add new libusb constants: LOW_SPEED_OPERATION, FULL_SPEED_OPERATION,
|
||||
Add new libusb constants: LOW_SPEED_OPERATION, FULL_SPEED_OPERATION,
|
||||
HIGH_SPEED_OPERATION, SUPER_SPEED_OPERATION, BM_LPM_SUPPORT,
|
||||
BM_LTM_SUPPORT, BT_WIRELESS_USB_DEVICE_CAPABILITY, BT_USB_2_0_EXTENSION,
|
||||
BT_SS_USB_DEVICE_CAPABILITY, BT_CONTAINER_ID, CAP_HAS_HOTPLUG,
|
||||
CAP_HAS_HID_ACCESS, CAP_SUPPORTS_DETACH_KERNEL_DRIVER, DT_BOS,
|
||||
DT_DEVICE_CAPABILITY, DT_SS_ENDPOINT_COMPANION
|
||||
DT_DEVICE_CAPABILITY, DT_SS_ENDPOINT_COMPANION
|
||||
</action>
|
||||
<action dev="kayahr" type="add" date="2013-07-13">
|
||||
Wrap new libusb methods: getPortNumbers, setAutoDetachKernelDriver,
|
||||
|
@ -62,26 +65,26 @@
|
|||
</release>
|
||||
<release version="1.0.0" date="2013-05-01" description="Major update">
|
||||
<action dev="kayahr" type="add" date="2013-05-01">
|
||||
Rewritten library to use libusb 1.0 as backend.
|
||||
Rewritten library to use libusb 1.0 as backend.
|
||||
</action>
|
||||
<action dev="kayahr" type="add" date="2013-02-16">
|
||||
Made library loading more universal to support loading shared libraries
|
||||
for platforms not officially supported by usb4java.
|
||||
for platforms not officially supported by usb4java.
|
||||
</action>
|
||||
<action dev="kayahr" type="add" date="2013-02-16">
|
||||
Add native library for linux-arm platform (Raspberry Pi).
|
||||
Add native library for linux-arm platform (Raspberry Pi).
|
||||
</action>
|
||||
<action dev="kayahr" type="update" date="2013-02-16">
|
||||
Native libraries are no longer extracted to a temporary directory when
|
||||
they are not in a JAR file.
|
||||
</action>
|
||||
</action>
|
||||
<action dev="kayahr" type="fix" date="2013-02-18">
|
||||
Improve error handling during native lib loading so javax-usb no
|
||||
longer hides the important exceptions.
|
||||
</action>
|
||||
</action>
|
||||
<action dev="kayahr" type="fix" date="2013-02-20">
|
||||
Fix logic error in AbstractIrpQueue#isBusy().
|
||||
</action>
|
||||
</action>
|
||||
</release>
|
||||
<release version="0.5.0" date="2013-02-15" description="Major update">
|
||||
<action dev="kayahr" type="add" date="2013-02-15">
|
||||
|
@ -108,7 +111,7 @@
|
|||
</release>
|
||||
<release version="0.3.3" date="2011-03-28" description="Minor update">
|
||||
<action dev="kayahr" type="fix" date="2011-03-28">
|
||||
Fixed library paths in dylibs so they can be placed in
|
||||
Fixed library paths in dylibs so they can be placed in
|
||||
*.app/Contents/MacOS.
|
||||
</action>
|
||||
</release>
|
||||
|
@ -141,7 +144,7 @@
|
|||
<action dev="kayahr" type="fix" date="2011-02-08">
|
||||
libusb reports broken bus root devices when detaching USB devices
|
||||
and when user has no root permissions on linux. Fixed it by
|
||||
only trusting root devices which are also in the device list of a bus.
|
||||
only trusting root devices which are also in the device list of a bus.
|
||||
</action>
|
||||
</release>
|
||||
</body>
|
||||
|
|
|
@ -59,6 +59,44 @@ public final class LibUsb
|
|||
*/
|
||||
public static final int LOG_LEVEL_DEBUG = 4;
|
||||
|
||||
|
||||
// Available option values for {@link #setOption()}
|
||||
|
||||
/**
|
||||
* Set the log message verbosity.
|
||||
*
|
||||
* The default level is {@link #LOG_LEVEL_NONE}, which means no messages are ever
|
||||
* printed. If you choose to increase the message verbosity level, ensure
|
||||
* that your application does not close the stderr file descriptor.
|
||||
*
|
||||
* You are advised to use level {@link #LOG_LEVEL_WARNING}. libusb is conservative
|
||||
* with its message logging and most of the time, will only log messages that
|
||||
* explain error conditions and other oddities. This will help you debug
|
||||
* your software.
|
||||
*
|
||||
* If the LIBUSB_DEBUG environment variable was set when libusb was
|
||||
* initialized, this function does nothing: the message verbosity is fixed
|
||||
* to the value in the environment variable.
|
||||
*
|
||||
* If libusb was compiled without any message logging, this function does
|
||||
* nothing: you'll never get any messages.
|
||||
*
|
||||
* If libusb was compiled with verbose debug message logging, this function
|
||||
* does nothing: you'll always get messages from all levels.
|
||||
*/
|
||||
public static final int OPTION_LOG_LEVEL = 0;
|
||||
|
||||
/**
|
||||
* Use the UsbDk backend for a specific context, if available.
|
||||
*
|
||||
* This option should be set immediately after calling {@link #init()}, otherwise
|
||||
* unspecified behavior may occur.
|
||||
*
|
||||
* Only valid on Windows.
|
||||
*/
|
||||
public static final int OPTION_USE_USBDK = 1;
|
||||
|
||||
|
||||
// Error codes. Most libusb functions return 0 on success or one of these
|
||||
// codes on failure. You can call errorName() to retrieve a string
|
||||
// representation of an error code.
|
||||
|
@ -720,9 +758,53 @@ public final class LibUsb
|
|||
* context.
|
||||
* @param level
|
||||
* The log level to set.
|
||||
*
|
||||
* @deprecated Use {@link #setOption()} instead using the {@link #OPTION_LOG_LEVEL} option.
|
||||
*/
|
||||
public static native void setDebug(final Context context, final int level);
|
||||
|
||||
/**
|
||||
* Set an option in the library.
|
||||
*
|
||||
* Use this function to configure a specific option within the library.
|
||||
*
|
||||
* Some options require one or more arguments to be provided. Consult each option's documentation for specific
|
||||
* requirements.
|
||||
*
|
||||
* Since libusb version 1.0.22, LIBUSB_API_VERSION >= 0x01000106
|
||||
*
|
||||
* @param context
|
||||
* The {@link Context} on which to operate.
|
||||
* @param option
|
||||
* Which option to set.
|
||||
* @return {@link #SUCCESS} on success, {@link #ERROR_INVALID_PARAM} if the option or arguments are invalid,
|
||||
* {@link #ERROR_NOT_SUPPORTED} if the option is valid but not supported on this platform.
|
||||
*/
|
||||
public static int setOption(final Context context, final int option) {
|
||||
return setOption(context, option, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an option in the library.
|
||||
*
|
||||
* Use this function to configure a specific option within the library.
|
||||
*
|
||||
* Some options require one or more arguments to be provided. Consult each option's documentation for specific
|
||||
* requirements.
|
||||
*
|
||||
* Since libusb version 1.0.22, LIBUSB_API_VERSION >= 0x01000106
|
||||
*
|
||||
* @param context
|
||||
* The {@link Context} on which to operate.
|
||||
* @param option
|
||||
* Which option to set.
|
||||
* @param value
|
||||
* Required argument for the specified option.
|
||||
* @return {@link #SUCCESS} on success, {@link #ERROR_INVALID_PARAM} if the option or arguments are invalid,
|
||||
* {@link #ERROR_NOT_SUPPORTED} if the option is valid but not supported on this platform.
|
||||
*/
|
||||
public static native int setOption(final Context context, final int option, final int value);
|
||||
|
||||
/**
|
||||
* Returns the version of the libusb runtime.
|
||||
*
|
||||
|
@ -1462,7 +1544,7 @@ public final class LibUsb
|
|||
* A simple wrapper around
|
||||
* {@link #getStringDescriptorAscii(DeviceHandle, byte, StringBuffer)}.
|
||||
* It simply returns the string (maximum length of 127) if possible. If not
|
||||
* possible (NULL handle or 0-index specified or error occured) then null is
|
||||
* possible (NULL handle or 0-index specified or error occurred) then null is
|
||||
* returned.
|
||||
*
|
||||
* This method is not part of libusb.
|
||||
|
@ -1810,7 +1892,7 @@ public final class LibUsb
|
|||
* A suitably-sized data buffer for either input or output
|
||||
* (depending on direction bits within bmRequestType).
|
||||
* @param timeout
|
||||
* Timeout (in millseconds) that this function should wait before
|
||||
* Timeout (in milliseconds) that this function should wait before
|
||||
* giving up due to no response being received. For an unlimited
|
||||
* timeout, use value 0.
|
||||
* @return on success the number of bytes actually transferred,
|
||||
|
@ -1854,7 +1936,7 @@ public final class LibUsb
|
|||
* @param transferred
|
||||
* Output location for the number of bytes actually transferred.
|
||||
* @param timeout
|
||||
* timeout (in millseconds) that this function should wait before
|
||||
* timeout (in milliseconds) that this function should wait before
|
||||
* giving up due to no response being received. For an unlimited
|
||||
* timeout, use value 0.
|
||||
* @return 0 on success (and populates transferred), {@link #ERROR_TIMEOUT}
|
||||
|
@ -1901,7 +1983,7 @@ public final class LibUsb
|
|||
* @param transferred
|
||||
* Output location for the number of bytes actually transferred.
|
||||
* @param timeout
|
||||
* Timeout (in millseconds) that this function should wait before
|
||||
* Timeout (in milliseconds) that this function should wait before
|
||||
* giving up due to no response being received. For an unlimited
|
||||
* timeout, use value 0.
|
||||
* @return 0 on success (and populates transferred), {@link #ERROR_TIMEOUT}
|
||||
|
@ -2018,7 +2100,7 @@ public final class LibUsb
|
|||
*
|
||||
* You only need to use this lock if you are developing an application which
|
||||
* calls poll() or select() on libusb's file descriptors directly, and may
|
||||
* potentially be handling events from 2 threads simultaenously. If you
|
||||
* potentially be handling events from 2 threads simultaneously. If you
|
||||
* stick to libusb's event handling loop functions (e.g.
|
||||
* {@link #handleEvents(Context)}) then you do not need to be concerned with
|
||||
* this locking.
|
||||
|
|
|
@ -192,6 +192,37 @@ public class LibUsbTest
|
|||
assertTrue(LibUsb.getApiVersion() >= 0x1000102);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link LibUsb#setOption(Context, int, int)} method with valid options and values.
|
||||
*/
|
||||
@Test
|
||||
public void testSetOption()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
final Context context = new Context();
|
||||
assertEquals(LibUsb.SUCCESS, LibUsb.init(context));
|
||||
assertEquals(LibUsb.SUCCESS, LibUsb.setOption(context, LibUsb.OPTION_LOG_LEVEL, LibUsb.LOG_LEVEL_NONE));
|
||||
assertEquals(LibUsb.SUCCESS, LibUsb.setOption(context, LibUsb.OPTION_LOG_LEVEL, LibUsb.LOG_LEVEL_DEBUG));
|
||||
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
|
||||
assertEquals(LibUsb.SUCCESS, LibUsb.setOption(context, LibUsb.OPTION_USE_USBDK));
|
||||
} else {
|
||||
assertEquals(LibUsb.ERROR_NOT_SUPPORTED, LibUsb.setOption(context, LibUsb.OPTION_USE_USBDK));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link LibUsb#setOption(Context, int, int)} method with invalid options and values.
|
||||
*/
|
||||
@Test
|
||||
public void testSetOptionWithInvalidParameters()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
final Context context = new Context();
|
||||
assertEquals(LibUsb.SUCCESS, LibUsb.init(context));
|
||||
assertEquals(LibUsb.ERROR_INVALID_PARAM, LibUsb.setOption(context, LibUsb.OPTION_LOG_LEVEL, 234));
|
||||
assertEquals(LibUsb.ERROR_INVALID_PARAM, LibUsb.setOption(context, 123));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the initialization and deinitialization of libusb with default
|
||||
* context.
|
||||
|
@ -254,6 +285,7 @@ public class LibUsbTest
|
|||
* context
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Deprecated
|
||||
public void testSetDebugWithUninitializedContext()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
|
@ -262,8 +294,19 @@ public class LibUsbTest
|
|||
}
|
||||
|
||||
/**
|
||||
* Tests {@link LibUsb#getDeviceList(Context, DeviceList)} method with
|
||||
* uninitialized USB context.
|
||||
* Tests {@link LibUsb#setOption(Context, int, int)} method with uninitialized USB context.
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Deprecated
|
||||
public void testSetOptionWithUninitializedContext()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
final Context context = new Context();
|
||||
LibUsb.setOption(context, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link LibUsb#getDeviceList(Context, DeviceList)} method with uninitialized USB context.
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testGetDeviceListWithUninitializedContext()
|
||||
|
|
Loading…
Reference in New Issue