Package edu.wpi.first.util
Class WPIUtilJNI
java.lang.Object
edu.wpi.first.util.WPIUtilJNI
- Direct Known Subclasses:
DataLogJNI
public class WPIUtilJNI extends Object
WPIUtil JNI.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WPIUtilJNI.Helper
Sets whether JNI should be loaded in the static block. -
Constructor Summary
Constructors Modifier Constructor Description protected
WPIUtilJNI()
Utility class. -
Method Summary
Modifier and Type Method Description static int
createEvent(boolean manualReset, boolean initialState)
Creates an event.static int
createSemaphore(int initialCount, int maximumCount)
Creates a semaphore.static void
destroyEvent(int eventHandle)
Destroys an event.static void
destroySemaphore(int semHandle)
Destroys a semaphore.static void
disableMockTime()
Disable mock time.static void
enableMockTime()
Enable mock time.static void
forceLoad()
Force load the library.static long
getSystemTime()
Returns the system time.static long
now()
Returns the time.static boolean
releaseSemaphore(int semHandle, int releaseCount)
Releases N counts of a semaphore.static void
resetEvent(int eventHandle)
Sets an event to non-signaled state.static void
setEvent(int eventHandle)
Sets an event to signaled state.static void
setMockTime(long time)
Set mock time.static void
waitForObject(int handle)
Waits for a handle to be signaled.static int[]
waitForObjects(int[] handles)
Waits for one or more handles to be signaled.static int[]
waitForObjectsTimeout(int[] handles, double timeout)
Waits for one or more handles to be signaled, with timeout.static boolean
waitForObjectTimeout(int handle, double timeout)
Waits for a handle to be signaled, with timeout.static void
writeStderr(String str)
Write the given string to stderr.
-
Constructor Details
-
WPIUtilJNI
protected WPIUtilJNI()Utility class.
-
-
Method Details
-
forceLoad
Force load the library.- Throws:
IOException
- if the library failed to load
-
writeStderr
Write the given string to stderr.- Parameters:
str
- String to write.
-
enableMockTime
Enable mock time. -
disableMockTime
Disable mock time. -
setMockTime
Set mock time.- Parameters:
time
- The desired time in microseconds.
-
now
Returns the time.- Returns:
- The time.
-
getSystemTime
Returns the system time.- Returns:
- The system time.
-
createEvent
Creates an event. Events have binary state (signaled or not signaled) and may be either automatically reset or manually reset. Automatic-reset events go to non-signaled state when a WaitForObject is woken up by the event; manual-reset events require ResetEvent() to be called to set the event to non-signaled state; if ResetEvent() is not called, any waiter on that event will immediately wake when called.- Parameters:
manualReset
- true for manual reset, false for automatic resetinitialState
- true to make the event initially in signaled state- Returns:
- Event handle
-
destroyEvent
Destroys an event. Destruction wakes up any waiters.- Parameters:
eventHandle
- event handle
-
setEvent
Sets an event to signaled state.- Parameters:
eventHandle
- event handle
-
resetEvent
Sets an event to non-signaled state.- Parameters:
eventHandle
- event handle
-
createSemaphore
Creates a semaphore. Semaphores keep an internal counter. Releasing the semaphore increases the count. A semaphore with a non-zero count is considered signaled. When a waiter wakes up it atomically decrements the count by 1. This is generally useful in a single-supplier, multiple-consumer scenario.- Parameters:
initialCount
- initial value for the semaphore's internal countermaximumCount
- maximum value for the samephore's internal counter- Returns:
- Semaphore handle
-
destroySemaphore
Destroys a semaphore. Destruction wakes up any waiters.- Parameters:
semHandle
- semaphore handle
-
releaseSemaphore
Releases N counts of a semaphore.- Parameters:
semHandle
- semaphore handlereleaseCount
- amount to add to semaphore's internal counter; must be positive- Returns:
- True on successful release, false on failure (e.g. release count would exceed maximum value, or handle invalid)
-
waitForObject
Waits for a handle to be signaled.- Parameters:
handle
- handle to wait on- Throws:
InterruptedException
- on failure (e.g. object was destroyed)
-
waitForObjectTimeout
Waits for a handle to be signaled, with timeout.- Parameters:
handle
- handle to wait ontimeout
- timeout in seconds- Returns:
- True if timeout reached without handle being signaled
- Throws:
InterruptedException
- on failure (e.g. object was destroyed)
-
waitForObjects
Waits for one or more handles to be signaled.Invalid handles are treated as signaled; the returned array will have the handle error bit set for any invalid handles.
- Parameters:
handles
- array of handles to wait on- Returns:
- array of signaled handles
- Throws:
InterruptedException
- on failure (e.g. no objects were signaled)
-
waitForObjectsTimeout
public static int[] waitForObjectsTimeout(int[] handles, double timeout) throws InterruptedExceptionWaits for one or more handles to be signaled, with timeout.Invalid handles are treated as signaled; the returned array will have the handle error bit set for any invalid handles.
- Parameters:
handles
- array of handles to wait ontimeout
- timeout in seconds- Returns:
- array of signaled handles; empty if timeout reached without any handle being signaled
- Throws:
InterruptedException
- on failure (e.g. no objects were signaled and no timeout)
-