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 () noexcept
 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.
 
void send (const void *data, size_t len, size_t &bytes_sent)
 Sends bytes into the stream, blocking indefinitely.
 
bool try_send (const void *data, size_t len, size_t &bytes_sent)
 Non-blocking send.
 
template<class Rep , class Period >
Result< void > try_send_for (const void *data, size_t len, const std::chrono::duration< Rep, Period > &rel, size_t &bytes_sent) noexcept
 Bounded-wait send.
 
template<class Clock , class Duration >
Result< void > try_send_until (const void *data, size_t len, const std::chrono::time_point< Clock, Duration > &deadline, size_t &bytes_sent) noexcept
 Deadline-based send templated over the clock.
 
void receive (void *buf, size_t len, size_t &bytes_received)
 Receives bytes from the stream, blocking indefinitely.
 
bool try_receive (void *buf, size_t len, size_t &bytes_received)
 Non-blocking receive.
 
template<class Rep , class Period >
Result< void > try_receive_for (void *buf, size_t len, const std::chrono::duration< Rep, Period > &rel, size_t &bytes_received) noexcept
 Bounded-wait receive.
 
template<class Clock , class Duration >
Result< void > try_receive_until (void *buf, size_t len, const std::chrono::time_point< Clock, Duration > &deadline, size_t &bytes_received) noexcept
 Deadline-based receive templated over the clock.
 
Result< void > send_from_isr (const void *data, size_t len, size_t &bytes_sent) noexcept
 Sends bytes into the stream from an ISR context (non-blocking).
 
Result< void > receive_from_isr (void *buf, size_t len, size_t &bytes_received) noexcept
 Receives bytes from the stream from an ISR context (non-blocking).
 
Result< void > reset () noexcept
 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>
void ove::Stream< BufSize >::send ( const void *  data,
size_t  len,
size_t &  bytes_sent 
)
inline

Sends bytes into the stream, blocking indefinitely.

Forever-wait form: failure means the handle is unusable. Aborts via OVE_STATIC_INIT_ASSERT (same pattern as Queue::send). Even on success, bytes_sent may be less than len if the substrate's internal buffer dictates a smaller commit — caller must inspect bytes_sent.

Parameters
[in]dataPointer to the data to send.
[in]lenNumber of bytes to send.
[out]bytes_sentNumber of bytes actually written.

◆ try_send()

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

Non-blocking send.

Parameters
[out]bytes_sentNumber of bytes actually written (may be < len even on success).
Returns
true if any bytes were written, false if the buffer was full.

◆ try_send_for()

template<size_t BufSize = 0>
template<class Rep , class Period >
Result< void > ove::Stream< BufSize >::try_send_for ( const void *  data,
size_t  len,
const std::chrono::duration< Rep, Period > &  rel,
size_t &  bytes_sent 
)
inlinenoexcept

Bounded-wait send.

Parameters
[in]dataPointer to the data to send.
[in]lenNumber of bytes to send.
[in]relRelative timeout (any std::chrono::duration unit).
[out]bytes_sentNumber of bytes actually written (the substrate may write a non-zero count even on a Timeout failure if some bytes committed before the deadline — always inspect this).
Returns
Empty Result<void> on success; unexpected Error::Timeout if the deadline elapsed; unexpected with another Error value on backend failure.

◆ try_send_until()

template<size_t BufSize = 0>
template<class Clock , class Duration >
Result< void > ove::Stream< BufSize >::try_send_until ( const void *  data,
size_t  len,
const std::chrono::time_point< Clock, Duration > &  deadline,
size_t &  bytes_sent 
)
inlinenoexcept

Deadline-based send templated over the clock.

Same clock-templating rationale as Mutex::try_lock_until.

Returns
As try_send_for.

◆ receive()

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

Receives bytes from the stream, blocking indefinitely.

Forever-wait form: failure means the handle is unusable. Aborts via OVE_STATIC_INIT_ASSERT. Like send, bytes_received may be less than len on success — caller must inspect it.

Parameters
[out]bufBuffer to receive the data.
[in]lenMaximum number of bytes to read.
[out]bytes_receivedNumber of bytes actually read.

◆ try_receive()

template<size_t BufSize = 0>
bool ove::Stream< BufSize >::try_receive ( void *  buf,
size_t  len,
size_t &  bytes_received 
)
inline

Non-blocking receive.

Returns
true if any bytes were read, false if the buffer was empty.

◆ try_receive_for()

template<size_t BufSize = 0>
template<class Rep , class Period >
Result< void > ove::Stream< BufSize >::try_receive_for ( void *  buf,
size_t  len,
const std::chrono::duration< Rep, Period > &  rel,
size_t &  bytes_received 
)
inlinenoexcept

Bounded-wait receive.

Parameters
[out]bufDestination buffer.
[in]lenMaximum bytes to read.
[in]relRelative timeout.
[out]bytes_receivedNumber of bytes actually read (may be non-zero even on a Timeout failure if some bytes arrived before the deadline).
Returns
Empty Result<void> on success; unexpected Error::Timeout / Error::Eof / backend-specific Error otherwise.

◆ try_receive_until()

template<size_t BufSize = 0>
template<class Clock , class Duration >
Result< void > ove::Stream< BufSize >::try_receive_until ( void *  buf,
size_t  len,
const std::chrono::time_point< Clock, Duration > &  deadline,
size_t &  bytes_received 
)
inlinenoexcept

Deadline-based receive templated over the clock.

Returns
As try_receive_for.

◆ send_from_isr()

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

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

Parameters
[out]bytes_sentNumber of bytes actually written (may be non-zero even on Error::QueueFull when a partial commit succeeded before the buffer filled).
Returns
Empty Result<void> on full success; unexpected with the appropriate Error variant otherwise.

◆ receive_from_isr()

template<size_t BufSize = 0>
Result< void > ove::Stream< BufSize >::receive_from_isr ( void *  buf,
size_t  len,
size_t &  bytes_received 
)
inlinenoexcept

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

Parameters
[out]bytes_receivedNumber of bytes actually read (may be non-zero even on a failure if partial data was available).
Returns
Empty Result<void> on full success; unexpected with the appropriate Error variant otherwise.

◆ reset()

template<size_t BufSize = 0>
Result< void > ove::Stream< BufSize >::reset ( )
inlinenoexcept

Resets the stream, discarding any buffered data.

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

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