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

RAII wrapper around an oveRTOS byte-stream (ring-buffer) object. More...

#include <stream.hpp>

Public Member Functions

 Stream (size_t trigger)
 Constructs and initialises the stream with the given receive trigger.
 
 ~Stream ()
 Destroys the stream, releasing the underlying kernel resource.
 
 Stream (const Stream &)=delete
 
Streamoperator= (const Stream &)=delete
 
 Stream (Stream &&other) noexcept
 Move constructor — transfers ownership of the kernel handle.
 
Streamoperator= (Stream &&other) noexcept
 Move-assignment operator — transfers ownership of the kernel handle.
 
int send (const void *data, size_t len, uint32_t timeout_ms, size_t *bytes_sent)
 Sends bytes into the stream from task context.
 
int receive (void *buf, size_t len, uint32_t timeout_ms, size_t *bytes_received)
 Receives bytes from the stream from task context.
 
int send_from_isr (const void *data, size_t len, size_t *bytes_sent)
 Sends bytes into the stream from an ISR context (non-blocking).
 
int receive_from_isr (void *buf, size_t len, size_t *bytes_received)
 Receives bytes from the stream from an ISR context (non-blocking).
 
int reset ()
 Resets the stream, discarding any buffered data.
 
size_t bytes_available () const
 Returns the number of bytes currently available to read.
 
bool valid () const
 Returns true if the underlying kernel handle is non-null.
 
ove_stream_t handle () const
 Returns the raw oveRTOS stream handle.
 

Detailed Description

template<size_t BufSize = 0>
class ove::Stream< BufSize >

RAII wrapper around an oveRTOS byte-stream (ring-buffer) object.

A stream provides a producer/consumer byte buffer with configurable capacity and a watermark trigger level. Receivers block until at least trigger bytes are available; senders block if the buffer is full.

In zero-heap mode the buffer is stored inline in the wrapper.

Template Parameters
BufSizeCompile-time buffer capacity in bytes (must be > 0).
Note
Not copyable. Move-only when heap allocation is enabled.

Constructor & Destructor Documentation

◆ Stream() [1/2]

template<size_t BufSize = 0>
ove::Stream< BufSize >::Stream ( size_t  trigger)
inlineexplicit

Constructs and initialises the stream with the given receive trigger.

Only participates in overload resolution when BufSize > 0.

Parameters
[in]triggerMinimum number of bytes that must be available before a blocked receiver is woken.

Asserts at startup if initialisation fails.

◆ Stream() [2/2]

template<size_t BufSize = 0>
ove::Stream< BufSize >::Stream ( Stream< BufSize > &&  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<size_t BufSize = 0>
Stream & ove::Stream< BufSize >::operator= ( Stream< BufSize > &&  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<size_t BufSize = 0>
int ove::Stream< BufSize >::send ( const void *  data,
size_t  len,
uint32_t  timeout_ms,
size_t *  bytes_sent 
)
inline

Sends bytes into the stream from task context.

Parameters
[in]dataPointer to the data to send.
[in]lenNumber of bytes to send.
[in]timeout_msMaximum time to wait if the buffer is full.
[out]bytes_sentReceives the number of bytes actually written.
Returns
OVE_OK on success, or a negative error code.

◆ receive()

template<size_t BufSize = 0>
int ove::Stream< BufSize >::receive ( void *  buf,
size_t  len,
uint32_t  timeout_ms,
size_t *  bytes_received 
)
inline

Receives bytes from the stream from task context.

Parameters
[out]bufBuffer to receive the data.
[in]lenMaximum number of bytes to read.
[in]timeout_msMaximum time to wait for data.
[out]bytes_receivedReceives the number of bytes actually read.
Returns
OVE_OK on success, or a negative error code.

◆ send_from_isr()

template<size_t BufSize = 0>
int ove::Stream< BufSize >::send_from_isr ( const void *  data,
size_t  len,
size_t *  bytes_sent 
)
inline

Sends bytes into the stream from an ISR context (non-blocking).

Parameters
[in]dataPointer to the data to send.
[in]lenNumber of bytes to send.
[out]bytes_sentReceives the number of bytes actually written.
Returns
OVE_OK on success, or a negative error code if the buffer is full.

◆ receive_from_isr()

template<size_t BufSize = 0>
int ove::Stream< BufSize >::receive_from_isr ( void *  buf,
size_t  len,
size_t *  bytes_received 
)
inline

Receives bytes from the stream from an ISR context (non-blocking).

Parameters
[out]bufBuffer to receive the data.
[in]lenMaximum number of bytes to read.
[out]bytes_receivedReceives the number of bytes actually read.
Returns
OVE_OK on success, or a negative error code if insufficient data.

◆ reset()

template<size_t BufSize = 0>
int ove::Stream< BufSize >::reset ( )
inline

Resets the stream, discarding any buffered data.

Returns
OVE_OK on success, or a negative error code.

◆ bytes_available()

template<size_t BufSize = 0>
size_t ove::Stream< BufSize >::bytes_available ( ) const
inline

Returns the number of bytes currently available to read.

Returns
Number of readable bytes in the stream buffer.

◆ valid()

template<size_t BufSize = 0>
bool ove::Stream< BufSize >::valid ( ) const
inline

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

Returns
true when the stream was successfully initialised.

◆ handle()

template<size_t BufSize = 0>
ove_stream_t ove::Stream< BufSize >::handle ( ) const
inline

Returns the raw oveRTOS stream handle.

Returns
The opaque ove_stream_t handle.

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