WPILibC++ 2023.4.3
frc::Notifier Class Reference

Notifiers run a callback function on a separate thread at a specified period. More...

#include <frc/Notifier.h>

Public Member Functions

 Notifier (std::function< void()> handler)
 Create a Notifier for timer event notification. More...
 
template<typename Callable , typename Arg , typename... Args, typename = std::enable_if_t<std::is_invocable_v<Callable, Arg, Args...>>>
 Notifier (Callable &&f, Arg &&arg, Args &&... args)
 
 Notifier (int priority, std::function< void()> handler)
 Create a Notifier for timer event notification. More...
 
template<typename Callable , typename Arg , typename... Args>
 Notifier (int priority, Callable &&f, Arg &&arg, Args &&... args)
 
 ~Notifier ()
 Free the resources for a timer event. More...
 
 Notifier (Notifier &&rhs)
 
Notifieroperator= (Notifier &&rhs)
 
void SetName (std::string_view name)
 Sets the name of the notifier. More...
 
void SetHandler (std::function< void()> handler)
 Change the handler function. More...
 
void StartSingle (units::second_t delay)
 Register for single event notification. More...
 
void StartPeriodic (units::second_t period)
 Register for periodic event notification. More...
 
void Stop ()
 Stop timer events from occurring. More...
 

Static Public Member Functions

static bool SetHALThreadPriority (bool realTime, int32_t priority)
 Sets the HAL notifier thread priority. More...
 

Detailed Description

Notifiers run a callback function on a separate thread at a specified period.

If StartSingle() is used, the callback will run once. If StartPeriodic() is used, the callback will run repeatedly with the given period until stop() is called.

Constructor & Destructor Documentation

◆ Notifier() [1/5]

frc::Notifier::Notifier ( std::function< void()>  handler)
explicit

Create a Notifier for timer event notification.

Parameters
handlerThe handler is called at the notification time which is set using StartSingle or StartPeriodic.

◆ Notifier() [2/5]

template<typename Callable , typename Arg , typename... Args, typename = std::enable_if_t<std::is_invocable_v<Callable, Arg, Args...>>>
frc::Notifier::Notifier ( Callable &&  f,
Arg &&  arg,
Args &&...  args 
)
inline

◆ Notifier() [3/5]

frc::Notifier::Notifier ( int  priority,
std::function< void()>  handler 
)
explicit

Create a Notifier for timer event notification.

This overload makes the underlying thread run with a real-time priority. This is useful for reducing scheduling jitter on processes which are sensitive to timing variance, like model-based control.

Parameters
priorityThe FIFO real-time scheduler priority ([1..99] where a higher number represents higher priority). See "man 7 sched" for more details.
handlerThe handler is called at the notification time which is set using StartSingle or StartPeriodic.

◆ Notifier() [4/5]

template<typename Callable , typename Arg , typename... Args>
frc::Notifier::Notifier ( int  priority,
Callable &&  f,
Arg &&  arg,
Args &&...  args 
)
inline

◆ ~Notifier()

frc::Notifier::~Notifier ( )

Free the resources for a timer event.

◆ Notifier() [5/5]

frc::Notifier::Notifier ( Notifier &&  rhs)

Member Function Documentation

◆ operator=()

Notifier & frc::Notifier::operator= ( Notifier &&  rhs)

◆ SetHALThreadPriority()

static bool frc::Notifier::SetHALThreadPriority ( bool  realTime,
int32_t  priority 
)
static

Sets the HAL notifier thread priority.

The HAL notifier thread is responsible for managing the FPGA's notifier interrupt and waking up user's Notifiers when it's their time to run. Giving the HAL notifier thread real-time priority helps ensure the user's real-time Notifiers, if any, are notified to run in a timely manner.

Parameters
realTimeSet to true to set a real-time priority, false for standard priority.
priorityPriority to set the thread to. For real-time, this is 1-99 with 99 being highest. For non-real-time, this is forced to 0. See "man 7 sched" for more details.
Returns
True on success.

◆ SetHandler()

void frc::Notifier::SetHandler ( std::function< void()>  handler)

Change the handler function.

Parameters
handlerHandler

◆ SetName()

void frc::Notifier::SetName ( std::string_view  name)

Sets the name of the notifier.

Used for debugging purposes only.

Parameters
nameName

◆ StartPeriodic()

void frc::Notifier::StartPeriodic ( units::second_t  period)

Register for periodic event notification.

A timer event is queued for periodic event notification. Each time the interrupt occurs, the event will be immediately requeued for the same time interval.

The user-provided callback should be written in a nonblocking manner so the callback can be recalled at the next periodic event notification.

Parameters
periodPeriod to call the handler starting one period after the call to this method.

◆ StartSingle()

void frc::Notifier::StartSingle ( units::second_t  delay)

Register for single event notification.

A timer event is queued for a single event after the specified delay.

Parameters
delayAmount of time to wait before the handler is called.

◆ Stop()

void frc::Notifier::Stop ( )

Stop timer events from occurring.

Stop any repeating timer events from occurring. This will also remove any single notification events from the queue.

If a timer-based call to the registered handler is in progress, this function will block until the handler call is complete.


The documentation for this class was generated from the following file: