Implement interruptEventHandler

This commit is contained in:
Klaus Reimer 2018-10-08 22:56:06 +02:00
parent 7ab6e6d3ed
commit b24618df0f
3 changed files with 37 additions and 1 deletions

View File

@ -13,7 +13,7 @@
Add missing SPEED_SUPER_PLUS constant.
</action>
<action dev="kayahr" type="add" date="2018-10-08">
Wrap new libusb functions: setOption, devMemAlloc, devMemFree.
Wrap new libusb functions: setOption, devMemAlloc, devMemFree, interruptEventHandler.
</action>
<action dev="kayahr" type="update" date="2018-10-07">
Updated to libusb 1.0.22.

View File

@ -2134,6 +2134,19 @@ public final class LibUsb
*/
public static native int eventHandlerActive(final Context context);
/**
* Interrupt any active thread that is handling events.
*
* This is mainly useful for interrupting a dedicated event handling thread when an application wishes to call
* {@link #exit()}.
*
* Since version 1.0.21, LIBUSB_API_VERSION >= 0x01000105
*
* @param ctx
* The context to operate on, or NULL for the default context.
*/
public static native void interruptEventHandler(final Context context);
/**
* Acquire the event waiters lock.
*

View File

@ -1098,6 +1098,17 @@ public class LibUsbTest
LibUsb.eventHandlerActive(context);
}
/**
* Tests {@link LibUsb#interruptEventHandler(Context)} with uninitialized USB context.
*/
@Test(expected = IllegalStateException.class)
public void testInterruptEventHandlerWithUninitializedContext()
{
assumeUsbTestsEnabled();
final Context context = new Context();
LibUsb.interruptEventHandler(context);
}
/**
* Tests {@link LibUsb#lockEventWaiters(Context)} with uninitialized USB
* context.
@ -1297,4 +1308,16 @@ public class LibUsbTest
assertNull(listener.removedFd);
assertNull(listener.removedUserData);
}
/**
* Tests the {@link LibUsb#interruptEventHandler(Context)} method. Must not crash.
*/
@Test
public void testInterruptEventHandler()
{
assumeUsbTestsEnabled();
final Context context = new Context();
assertEquals(LibUsb.SUCCESS, LibUsb.init(context));
LibUsb.interruptEventHandler(context);
}
}