oveRTOS C++ API
C++20 RAII wrappers for the oveRTOS C API
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ove::Timer Class Reference

RAII wrapper around an oveRTOS software timer. More...

#include <timer.hpp>

Public Member Functions

template<typename F >
requires TimerCallback<F>
 Timer (F callback, void *user_data, uint32_t period_ms, bool one_shot=false)
 Constructs and initialises the timer.
 
 ~Timer ()
 Destroys the timer, stopping it if running and releasing the kernel resource.
 
 Timer (const Timer &)=delete
 
Timeroperator= (const Timer &)=delete
 
 Timer (Timer &&other) noexcept
 Move constructor — transfers ownership of the kernel handle.
 
Timeroperator= (Timer &&other) noexcept
 Move-assignment operator — transfers ownership of the kernel handle.
 
int start ()
 Starts the timer.
 
int stop ()
 Stops the timer without resetting its period.
 
int reset ()
 Restarts the timer, resetting the period countdown.
 
bool valid () const
 Returns true if the underlying kernel handle is non-null.
 
ove_timer_t handle () const
 Returns the raw oveRTOS timer handle.
 

Detailed Description

RAII wrapper around an oveRTOS software timer.

A software timer calls a user-provided callback either once (one_shot) or periodically at the specified interval. The timer is created in the stopped state; call start() to activate it.

Note
Not copyable. Move-only when heap allocation is enabled.
start(), stop(), and reset() are marked [[nodiscard]] because their return value indicates whether the RTOS accepted the request.

Constructor & Destructor Documentation

◆ Timer() [1/2]

template<typename F >
requires TimerCallback<F>
ove::Timer::Timer ( callback,
void *  user_data,
uint32_t  period_ms,
bool  one_shot = false 
)
inline

Constructs and initialises the timer.

The timer is created in the stopped state.

Template Parameters
FCallable type satisfying TimerCallback.
Parameters
[in]callbackFunction pointer called when the timer fires.
[in]user_dataOpaque pointer forwarded to the callback.
[in]period_msTimer period in milliseconds.
[in]one_shotIf true, the timer fires once and stops; if false, it repeats indefinitely.

Asserts at startup if initialisation fails.

◆ Timer() [2/2]

ove::Timer::Timer ( Timer &&  other)
inlinenoexcept

Move constructor — transfers ownership of the kernel handle.

Parameters
otherThe source; its handle is set to null after the move.

Member Function Documentation

◆ operator=()

Timer & ove::Timer::operator= ( Timer &&  other)
inlinenoexcept

Move-assignment operator — transfers ownership of the kernel handle.

Parameters
otherThe source; its handle is set to null after the move.
Returns
Reference to this object.

◆ start()

int ove::Timer::start ( )
inline

Starts the timer.

Returns
OVE_OK on success, or a negative error code.

◆ stop()

int ove::Timer::stop ( )
inline

Stops the timer without resetting its period.

Returns
OVE_OK on success, or a negative error code.

◆ reset()

int ove::Timer::reset ( )
inline

Restarts the timer, resetting the period countdown.

Returns
OVE_OK on success, or a negative error code.

◆ valid()

bool ove::Timer::valid ( ) const
inline

Returns true if the underlying kernel handle is non-null.

Returns
true when the timer was successfully initialised.

◆ handle()

ove_timer_t ove::Timer::handle ( ) const
inline

Returns the raw oveRTOS timer handle.

Returns
The opaque ove_timer_t handle.

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