001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.hal;
006
007/**
008 * The NotifierJNI class directly wraps the C++ HAL Notifier.
009 *
010 * <p>This class is not meant for direct use by teams. Instead, the edu.wpi.first.wpilibj.Notifier
011 * class, which corresponds to the C++ Notifier class, should be used.
012 */
013public class NotifierJNI extends JNIWrapper {
014  /**
015   * Initializes the notifier.
016   *
017   * @return True on success.
018   */
019  public static native int initializeNotifier();
020
021  /**
022   * Sets the HAL notifier thread priority.
023   *
024   * @param realTime Set to true to set a real-time priority, false for standard priority.
025   * @param priority Priority to set the thread to. For real-time, this is 1-99 with 99 being
026   *     highest. For non-real-time, this is forced to 0. See "man 7 sched" for more details.
027   * @return True on success.
028   */
029  public static native boolean setHALThreadPriority(boolean realTime, int priority);
030
031  /**
032   * Sets the name of the notifier.
033   *
034   * @param notifierHandle Notifier handle.
035   * @param name Notifier name.
036   */
037  public static native void setNotifierName(int notifierHandle, String name);
038
039  /**
040   * Wakes up the waiter with time=0. Note: after this function is called, all calls to
041   * waitForNotifierAlarm() will immediately start returning 0.
042   *
043   * @param notifierHandle Notifier handle.
044   */
045  public static native void stopNotifier(int notifierHandle);
046
047  /**
048   * Deletes the notifier object when we are done with it.
049   *
050   * @param notifierHandle Notifier handle.
051   */
052  public static native void cleanNotifier(int notifierHandle);
053
054  /**
055   * Sets the notifier to wake up the waiter at triggerTime microseconds.
056   *
057   * @param notifierHandle Notifier handle.
058   * @param triggerTime Trigger time in microseconds.
059   */
060  public static native void updateNotifierAlarm(int notifierHandle, long triggerTime);
061
062  /**
063   * Cancels any pending wakeups set by updateNotifierAlarm(). Does NOT wake up any waiters.
064   *
065   * @param notifierHandle Notifier handle.
066   */
067  public static native void cancelNotifierAlarm(int notifierHandle);
068
069  /**
070   * Block until woken up by an alarm (or stop).
071   *
072   * @param notifierHandle Notifier handle.
073   * @return Time when woken up.
074   */
075  public static native long waitForNotifierAlarm(int notifierHandle);
076}