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 () noexcept
 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.
 
Result< void > start () noexcept
 Starts the timer.
 
Result< void > stop () noexcept
 Stops the timer without resetting its period.
 
Result< void > reset () noexcept
 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()

Result< void > ove::Timer::start ( )
inlinenoexcept

Starts the timer.

Returns
Empty Result<void> on success; unexpected Error on failure.

◆ stop()

Result< void > ove::Timer::stop ( )
inlinenoexcept

Stops the timer without resetting its period.

Returns
Empty Result<void> on success; unexpected Error on failure.

◆ reset()

Result< void > ove::Timer::reset ( )
inlinenoexcept

Restarts the timer, resetting the period countdown.

Returns
Empty Result<void> on success; unexpected Error on failure.

◆ 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: