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 () noexcept
 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.
 
void send (const T &item)
 Sends an item to the back of the queue, blocking indefinitely.
 
bool try_send (const T &item)
 Non-blocking send.
 
template<class Rep , class Period >
Result< void > try_send_for (const T &item, const std::chrono::duration< Rep, Period > &rel) noexcept
 Bounded-wait send.
 
template<class Clock , class Duration >
Result< void > try_send_until (const T &item, const std::chrono::time_point< Clock, Duration > &deadline) noexcept
 Deadline-based send templated over the clock. See Mutex::try_lock_until for the templated-clock rationale.
 
void receive (T &out)
 Receives an item from the front of the queue, blocking indefinitely.
 
bool try_receive (T &out)
 Non-blocking receive.
 
template<class Rep , class Period >
Result< void > try_receive_for (T &out, const std::chrono::duration< Rep, Period > &rel) noexcept
 Bounded-wait receive.
 
template<class Clock , class Duration >
Result< void > try_receive_until (T &out, const std::chrono::time_point< Clock, Duration > &deadline) noexcept
 Deadline-based receive templated over the clock.
 
Result< void > send_from_isr (const T &item) noexcept
 Sends an item to the queue from an ISR context (non-blocking).
 
Result< void > receive_from_isr (T &out) noexcept
 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>
void ove::Queue< T, MaxItems >::send ( const T &  item)
inline

Sends an item to the back of the queue, blocking indefinitely.

Forever-wait form: failure means the handle is unusable. Aborts via OVE_STATIC_INIT_ASSERT (same pattern as Mutex::lock, Semaphore::acquire).

◆ try_send()

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

Non-blocking send.

Returns
true on success, false if the queue was full.

◆ try_send_for()

template<typename T , size_t MaxItems = 0>
template<class Rep , class Period >
Result< void > ove::Queue< T, MaxItems >::try_send_for ( const T &  item,
const std::chrono::duration< Rep, Period > &  rel 
)
inlinenoexcept

Bounded-wait send.

Parameters
[in]itemThe item to enqueue (copied into the queue).
[in]relRelative timeout (any std::chrono::duration unit).
Returns
Empty Result<void> on success; unexpected Error::QueueFull / Error::Timeout if the queue stayed full through the deadline; unexpected with another Error value on backend failure.

◆ try_send_until()

template<typename T , size_t MaxItems = 0>
template<class Clock , class Duration >
Result< void > ove::Queue< T, MaxItems >::try_send_until ( const T &  item,
const std::chrono::time_point< Clock, Duration > &  deadline 
)
inlinenoexcept

Deadline-based send templated over the clock. See Mutex::try_lock_until for the templated-clock rationale.

Returns
As try_send_forResult<void> with the appropriate Error on timeout / backend failure.

◆ receive()

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

Receives an item from the front of the queue, blocking indefinitely.

Forever-wait form: failure means the handle is unusable. Aborts via OVE_STATIC_INIT_ASSERT.

Parameters
[out]outReference to storage for the received item.

◆ try_receive()

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

Non-blocking receive.

Returns
true on success, false if the queue was empty.

◆ try_receive_for()

template<typename T , size_t MaxItems = 0>
template<class Rep , class Period >
Result< void > ove::Queue< T, MaxItems >::try_receive_for ( T &  out,
const std::chrono::duration< Rep, Period > &  rel 
)
inlinenoexcept

Bounded-wait receive.

Parameters
[out]outReference to storage for the received item.
[in]relRelative timeout (any std::chrono::duration unit).
Returns
Empty Result<void> on success (item written to out); unexpected Error::QueueEmpty / Error::Timeout if the queue stayed empty through the deadline; unexpected with another Error value on backend failure.

◆ try_receive_until()

template<typename T , size_t MaxItems = 0>
template<class Clock , class Duration >
Result< void > ove::Queue< T, MaxItems >::try_receive_until ( T &  out,
const std::chrono::time_point< Clock, Duration > &  deadline 
)
inlinenoexcept

Deadline-based receive templated over the clock.

Returns
As try_receive_for.

◆ send_from_isr()

template<typename T , size_t MaxItems = 0>
Result< void > ove::Queue< T, MaxItems >::send_from_isr ( const T &  item)
inlinenoexcept

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

Parameters
[in]itemThe item to enqueue.
Returns
Empty Result<void> on success; unexpected Error::QueueFull if the queue was full; unexpected with another Error value on backend failure.

◆ receive_from_isr()

template<typename T , size_t MaxItems = 0>
Result< void > ove::Queue< T, MaxItems >::receive_from_isr ( T &  out)
inlinenoexcept

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

Parameters
[out]outReference to storage for the received item.
Returns
Empty Result<void> on success; unexpected Error::QueueEmpty if the queue was empty; unexpected with another Error value on backend failure.

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