Class WPIUtilJNI


public class WPIUtilJNI extends WPIUtilJNIWrapper
WPIUtil JNI.
  • Method Details

    • checkMsvcRuntime

      public static void checkMsvcRuntime()
      Checks if the MSVC runtime is valid. Throws a runtime exception if not.
    • writeStderr

      public static void writeStderr(String str)
      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 reset
      initialState - 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 counter
      maximumCount - 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 handle
      releaseCount - 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

      public static void waitForObject(int handle) throws InterruptedException
      Waits for a handle to be signaled.
      Parameters:
      handle - handle to wait on
      Throws:
      InterruptedException - on failure (e.g. object was destroyed)
    • waitForObjectTimeout

      public static boolean waitForObjectTimeout(int handle, double timeout) throws InterruptedException
      Waits for a handle to be signaled, with timeout.
      Parameters:
      handle - handle to wait on
      timeout - timeout in seconds
      Returns:
      True if timeout reached without handle being signaled
      Throws:
      InterruptedException - on failure (e.g. object was destroyed)
    • waitForObjects

      public static int[] waitForObjects(int[] handles) throws InterruptedException
      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 on
      timeout - 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)