HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes
tt::timer Class Reference

#include <ttauri/timer.hpp>

Public Types

using duration = hires_utc_clock::duration
 
using time_point = hires_utc_clock::time_point
 
using callback_type = std::function<void(time_point,bool)>
 Timer callback.
 
using callback_ptr_type = std::shared_ptr<callback_type>
 

Public Member Functions

 timer (std::string name) noexcept
 
void start () noexcept
 Start the timer thread.
 
void stop () noexcept
 Stop the timer thread.
 
template<typename Callback >
std::shared_ptr< callback_typeadd_callback (duration interval, Callback callback) noexcept
 Add a callback function to be executed each interval.
 
void remove_callback (callback_ptr_type const &callback_ptr) noexcept
 Remove the callback function.
 

Static Public Attributes

static std::unique_ptr< timerglobal
 Global maintenance timer.
 

Detailed Description

A timer which will execute callbacks at given intervals.

Member Typedef Documentation

◆ callback_type

Timer callback.

Parameters
current_timeThe current time of executing this timer.
lastTrue if this is the last time this timer is called, on emergency stop.

Member Function Documentation

◆ add_callback()

template<typename Callback >
std::shared_ptr< callback_type > tt::timer::add_callback ( duration interval,
Callback callback )
inlinenoexcept

Add a callback function to be executed each interval.

The callback will be executed at each interval when: cpu_utc_clock::now() % interval == 0

Since there is only a single thread, please make sure the callback executes quickly.

Parameters
intervalThe interval to execute the callback at.
callbackThe callback function.
Returns
An shared_ptr to retain the callback function, when the shared_ptr is removed then the callback can no longer be called.

◆ remove_callback()

void tt::timer::remove_callback ( callback_ptr_type const & callback_ptr)
noexcept

Remove the callback function.

◆ start()

void tt::timer::start ( )
noexcept

Start the timer thread.

Normally it is not needed to call this yourself. If there are no callbacks registered the thread will exit itself.

◆ stop()

void tt::timer::stop ( )
noexcept

Stop the timer thread.

Maybe called to emergency stop the timer thread, this will cause all callbacks to be called with last=true.

Field Documentation

◆ global

std::unique_ptr<timer> tt::timer::global
inlinestatic

Global maintenance timer.


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