0.4.1
Loading...
Searching...
No Matches
CallbackTimer Class Reference

Manages a thread which calls a specified function at a specified interval. More...

Public Member Functions

 CallbackTimer ()=default
 Default constructor.
 
 CallbackTimer (CallbackTimer &&)=delete
 Move constructor.
 
 CallbackTimer (const CallbackTimer &)=delete
 Copy constructor.
 
bool is_running () const noexcept
 Checks if the timer is currently running.
 
CallbackTimeroperator= (CallbackTimer &&)=delete
 Move assignment operator.
 
CallbackTimeroperator= (const CallbackTimer &)=delete
 Copy assignment operator.
 
void setInterval (int interval)
 Set the Interval of the timer.
 
void start (int interval, const std::function< void(void *)> &func, void *userData)
 Starts the timer.
 
void stop ()
 Stops the Timer.
 
 ~CallbackTimer ()
 Destructor.
 

Private Attributes

std::atomic< bool > _execute
 Flag whether the timer should execute.
 
std::atomic< int > _interval
 Interval in which the timer is triggered.
 
std::thread _thd
 Thread object which triggers the timer.
 

Detailed Description

Manages a thread which calls a specified function at a specified interval.

Definition at line 21 of file CallbackTimer.hpp.

Constructor & Destructor Documentation

◆ CallbackTimer() [1/3]

CallbackTimer::CallbackTimer ( )
default

Default constructor.

◆ CallbackTimer() [2/3]

CallbackTimer::CallbackTimer ( const CallbackTimer & )
delete

Copy constructor.

◆ CallbackTimer() [3/3]

CallbackTimer::CallbackTimer ( CallbackTimer && )
delete

Move constructor.

◆ ~CallbackTimer()

CallbackTimer::~CallbackTimer ( )

Destructor.

Definition at line 13 of file CallbackTimer.cpp.

Member Function Documentation

◆ is_running()

bool CallbackTimer::is_running ( ) const
nodiscardnoexcept

Checks if the timer is currently running.

Returns
True if the timer is running

Definition at line 56 of file CallbackTimer.cpp.

◆ operator=() [1/2]

CallbackTimer & CallbackTimer::operator= ( CallbackTimer && )
delete

Move assignment operator.

◆ operator=() [2/2]

CallbackTimer & CallbackTimer::operator= ( const CallbackTimer & )
delete

Copy assignment operator.

◆ setInterval()

void CallbackTimer::setInterval ( int interval)

Set the Interval of the timer.

Parameters
[in]intervalInterval in [ms] when to trigger the callback

Definition at line 51 of file CallbackTimer.cpp.

◆ start()

void CallbackTimer::start ( int interval,
const std::function< void(void *)> & func,
void * userData )

Starts the timer.

Parameters
[in]intervalInterval in [ms] when to trigger the callback
[in]funcFunction to call
[in,out]userDataUser Data which will be passed to the callback function

Definition at line 30 of file CallbackTimer.cpp.

◆ stop()

void CallbackTimer::stop ( )

Stops the Timer.

Definition at line 21 of file CallbackTimer.cpp.

Field Documentation

◆ _execute

std::atomic<bool> CallbackTimer::_execute
private

Flag whether the timer should execute.

Definition at line 58 of file CallbackTimer.hpp.

◆ _interval

std::atomic<int> CallbackTimer::_interval
private

Interval in which the timer is triggered.

Definition at line 56 of file CallbackTimer.hpp.

◆ _thd

std::thread CallbackTimer::_thd
private

Thread object which triggers the timer.

Definition at line 60 of file CallbackTimer.hpp.


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