Package edu.wpi.first.util
Class WPIUtilJNI
java.lang.Object
edu.wpi.first.util.WPIUtilJNI
- Direct Known Subclasses:
DataLogJNI
WPIUtil JNI.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Sets whether JNI should be loaded in the static block. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Checks if the MSVC runtime is valid.static int
createEvent
(boolean manualReset, boolean initialState) Creates an event.static long
createFileLogger
(String file, long log, String key) Create a native FileLogger.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
Disable mock time.static void
Enable mock time.static void
Force load the library.static void
freeFileLogger
(long fileTail) Free a native FileLogger.static long
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
-
checkMsvcRuntime
Checks if the MSVC runtime is valid. Throws a runtime exception if not. -
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 semaphore'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 InterruptedException Waits 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)
-
createFileLogger
Create a native FileLogger. When the specified file is modified, appended data will be appended to the specified data log.- Parameters:
file
- path to the filelog
- data log implementation handlekey
- log key to append data to- Returns:
- The FileLogger handle.
-
freeFileLogger
Free a native FileLogger. This causes the FileLogger to stop appending data to the log.- Parameters:
fileTail
- The FileLogger handle.
-