Class WPIUtilJNI
java.lang.Object
org.wpilib.util.WPIUtilJNIWrapper
org.wpilib.util.WPIUtilJNI
WPIUtil JNI.
-
Nested Class Summary
Nested classes/interfaces inherited from class WPIUtilJNIWrapper
WPIUtilJNIWrapper.Helper -
Method Summary
Modifier and TypeMethodDescriptionstatic voidChecks if the MSVC runtime is valid.static voiddestroyEvent(int eventHandle) Destroys an event.static voiddestroySemaphore(int semHandle) Destroys a semaphore.static voidDisable mock time.static voidEnable mock time.static longReturns the timestamp at which the program started.static longReturns the system time.static intmakeEvent(boolean manualReset, boolean initialState) Creates an event.static intmakeSemaphore(int initialCount, int maximumCount) Creates a semaphore.static longnow()Returns the time.static booleanreleaseSemaphore(int semHandle, int releaseCount) Releases N counts of a semaphore.static voidresetEvent(int eventHandle) Sets an event to non-signaled state.static voidsetEvent(int eventHandle) Sets an event to signaled state.static voidsetMockTime(long time) Set mock time.static voidwaitForObject(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 booleanwaitForObjectTimeout(int handle, double timeout) Waits for a handle to be signaled, with timeout.static voidwriteStderr(String str) Write the given string to stderr.Methods inherited from class WPIUtilJNIWrapper
forceLoad, suppressUnused
-
Method Details
-
checkMsvcRuntime
public static void 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
public static void enableMockTime()Enable mock time. The mock time is initially set to 0. This also sets program start time to 0. -
disableMockTime
public static void disableMockTime()Disable mock time. -
setMockTime
public static void setMockTime(long time) Set mock time.- Parameters:
time- The desired time in nanoseconds.
-
now
public static long now()Returns the time.- Returns:
- The time.
-
getProgramStartTime
public static long getProgramStartTime()Returns the timestamp at which the program started.- Returns:
- The program start timestamp in nanoseconds.
-
getSystemTime
public static long getSystemTime()Returns the system time.- Returns:
- The system time.
-
makeEvent
public static int makeEvent(boolean manualReset, boolean initialState) 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
public static void destroyEvent(int eventHandle) Destroys an event. Destruction wakes up any waiters.- Parameters:
eventHandle- event handle
-
setEvent
public static void setEvent(int eventHandle) Sets an event to signaled state.- Parameters:
eventHandle- event handle
-
resetEvent
public static void resetEvent(int eventHandle) Sets an event to non-signaled state.- Parameters:
eventHandle- event handle
-
makeSemaphore
public static int makeSemaphore(int initialCount, int maximumCount) 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
public static void destroySemaphore(int semHandle) Destroys a semaphore. Destruction wakes up any waiters.- Parameters:
semHandle- semaphore handle
-
releaseSemaphore
public static boolean releaseSemaphore(int semHandle, int releaseCount) 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)
-