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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • forceLoad

      public static void forceLoad() throws IOException
      Force load the library.
      Throws:
      IOException - if the library failed to load
    • 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.
    • disableMockTime

      public static void disableMockTime()
      Disable mock time.
    • setMockTime

      public static void setMockTime​(long time)
      Set mock time.
      Parameters:
      time - The desired time in microseconds.
    • now

      public static long now()
      Returns the time.
      Returns:
      The time.
    • getSystemTime

      public static long getSystemTime()
      Returns the system time.
      Returns:
      The system time.
    • createEvent

      public static int createEvent​(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
    • createSemaphore

      public static int createSemaphore​(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 samephore'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)