Dev Essential  1.6.3
Loading...
Searching...
No Matches
a_util::system::Timer Class Reference

#include <timer_decl.h>

Public Member Functions

 Timer ()
 Default CTOR.
 
 ~Timer ()
 DTOR - Calls stop()
 
 Timer (std::uint64_t period_us, void(*function)())
 
template<typename M, typename T>
 Timer (std::uint64_t period_us, M method, T &instance)
 
void setCallback (void(*function)())
 
template<typename M, typename T>
void setCallback (M method, T &instance)
 
void setPeriod (std::uint64_t period_us)
 
std::uint64_t getPeriod () const
 
bool start ()
 
bool stop ()
 
bool isRunning () const
 

Detailed Description

Periodic timer running in a separate thread

  • Invokes a callback periodically
  • If an invocation takes longer than the period, any missed expirations are lost!
  • The callback is invoked from a different thread, take care about thread safety!

Constructor & Destructor Documentation

◆ Timer() [1/2]

a_util::system::Timer::Timer ( std::uint64_t period_us,
void(* function )() )

CTOR for functions as callbacks

To start the timer, call start

Parameters
[in]period_usDuration between calls to function (in microseconds) 0 -> One shot timer
[in]functionPointer to callback function

◆ Timer() [2/2]

template<typename M, typename T>
a_util::system::Timer::Timer ( std::uint64_t period_us,
M method,
T & instance )
inline

CTOR for methods as callbacks

To start the timer, call start

Template Parameters
MMethod type to call
TClass containing the method
Parameters
[in]period_usDuration between calls to function (in microseconds). 0 -> One shot timer
[in]methodMethod used as callback
[in]instanceInstance of the class the method to invoke from

Member Function Documentation

◆ getPeriod()

std::uint64_t a_util::system::Timer::getPeriod ( ) const

Get the currently configured period of the timer

Returns
Period of the timer in microseconds

◆ isRunning()

bool a_util::system::Timer::isRunning ( ) const

Check whether the timer is currently running

Returns
true if timer is running, false otherwise

◆ setCallback() [1/2]

template<typename M, typename T>
void a_util::system::Timer::setCallback ( M method,
T & instance )
inline

Set the callback for the timer

Template Parameters
MMethod type to call
TClass containing the method
Parameters
[in]methodMethod used as callback
[in]instanceInstance of the class the method to invoke from

◆ setCallback() [2/2]

void a_util::system::Timer::setCallback ( void(* function )())

Set the callback for the timer

Parameters
[in]functionPointer to callback function

◆ setPeriod()

void a_util::system::Timer::setPeriod ( std::uint64_t period_us)

Set the period used by this timer, restarting the timer if already running

Parameters
[in]period_usDuration in microseconds between invocations of callback function. 0 -> One shot timer

◆ start()

bool a_util::system::Timer::start ( )

Start the timer

Returns
true on success, false if the timer is already running

◆ stop()

bool a_util::system::Timer::stop ( )

Stop the timer - blocks until the callback returns

Returns
true on success, false if the timer is already stopped

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