oveRTOS C++ API
C++20 RAII wrappers for the oveRTOS C API
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ove::Queue< T, MaxItems > Class Template Reference

RAII wrapper around an oveRTOS typed message queue. More...

#include <queue.hpp>

Public Member Functions

 Queue ()
 Constructs and initialises the queue.
 
 ~Queue ()
 Destroys the queue, releasing the underlying kernel resource.
 
 Queue (const Queue &)=delete
 
Queueoperator= (const Queue &)=delete
 
 Queue (Queue &&other) noexcept
 Move constructor — transfers ownership of the kernel handle.
 
Queueoperator= (Queue &&other) noexcept
 Move-assignment operator — transfers ownership of the kernel handle.
 
int send (const T &item, uint32_t timeout_ms=OVE_WAIT_FOREVER)
 Sends an item to the back of the queue from task context.
 
int receive (T *item, uint32_t timeout_ms=OVE_WAIT_FOREVER)
 Receives an item from the front of the queue from task context.
 
int send_from_isr (const T &item)
 Sends an item to the queue from an ISR context (non-blocking).
 
int receive_from_isr (T *item)
 Receives an item from the queue from an ISR context (non-blocking).
 
bool valid () const
 Returns true if the underlying kernel handle is non-null.
 
ove_queue_t handle () const
 Returns the raw oveRTOS queue handle.
 

Detailed Description

template<typename T, size_t MaxItems = 0>
class ove::Queue< T, MaxItems >

RAII wrapper around an oveRTOS typed message queue.

Queue<T, MaxItems> stores items of type T in a FIFO buffer. Items are copied into the queue on send() and out of it on receive(), so T must be trivially copyable (or at least safe to copy via memcpy).

In zero-heap mode MaxItems must be greater than zero; the backing buffer is allocated inside the wrapper. On heap-enabled builds MaxItems is also required at compile time (it is passed to the kernel at construction).

Template Parameters
TType of message items; should be trivially copyable.
MaxItemsCompile-time capacity of the queue (must be > 0).
Note
Not copyable. Move-only when heap allocation is enabled.
send(), receive(), and their ISR variants are marked [[nodiscard]].

Constructor & Destructor Documentation

◆ Queue() [1/2]

template<typename T , size_t MaxItems = 0>
ove::Queue< T, MaxItems >::Queue ( )
inline

Constructs and initialises the queue.

Only participates in overload resolution when MaxItems > 0. Asserts at startup if initialisation fails.

◆ Queue() [2/2]

template<typename T , size_t MaxItems = 0>
ove::Queue< T, MaxItems >::Queue ( Queue< T, MaxItems > &&  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=()

template<typename T , size_t MaxItems = 0>
Queue & ove::Queue< T, MaxItems >::operator= ( Queue< T, MaxItems > &&  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.

◆ send()

template<typename T , size_t MaxItems = 0>
int ove::Queue< T, MaxItems >::send ( const T &  item,
uint32_t  timeout_ms = OVE_WAIT_FOREVER 
)
inline

Sends an item to the back of the queue from task context.

Parameters
[in]itemThe item to enqueue (copied into the queue).
[in]timeout_msMaximum time to wait if the queue is full; use OVE_WAIT_FOREVER to block indefinitely.
Returns
OVE_OK on success, or a negative error code on timeout/failure.

◆ receive()

template<typename T , size_t MaxItems = 0>
int ove::Queue< T, MaxItems >::receive ( T *  item,
uint32_t  timeout_ms = OVE_WAIT_FOREVER 
)
inline

Receives an item from the front of the queue from task context.

Parameters
[out]itemPointer to storage for the received item.
[in]timeout_msMaximum time to wait if the queue is empty; use OVE_WAIT_FOREVER to block indefinitely.
Returns
OVE_OK on success, or a negative error code on timeout/failure.

◆ send_from_isr()

template<typename T , size_t MaxItems = 0>
int ove::Queue< T, MaxItems >::send_from_isr ( const T &  item)
inline

Sends an item to the queue from an ISR context (non-blocking).

Parameters
[in]itemThe item to enqueue.
Returns
OVE_OK on success, or a negative error code if the queue is full.

◆ receive_from_isr()

template<typename T , size_t MaxItems = 0>
int ove::Queue< T, MaxItems >::receive_from_isr ( T *  item)
inline

Receives an item from the queue from an ISR context (non-blocking).

Parameters
[out]itemPointer to storage for the received item.
Returns
OVE_OK on success, or a negative error code if the queue is empty.

◆ valid()

template<typename T , size_t MaxItems = 0>
bool ove::Queue< T, MaxItems >::valid ( ) const
inline

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

Returns
true when the queue was successfully initialised.

◆ handle()

template<typename T , size_t MaxItems = 0>
ove_queue_t ove::Queue< T, MaxItems >::handle ( ) const
inline

Returns the raw oveRTOS queue handle.

Returns
The opaque ove_queue_t handle.

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