16#ifdef CONFIG_OVE_STREAM
18#include <ove/stream.h>
37template <
size_t BufSize = 0>
50 explicit Stream(
size_t trigger)
requires (BufSize > 0) {
51#ifdef CONFIG_OVE_ZERO_HEAP
52 static_assert(BufSize > 0,
53 "BufSize must be > 0 in zero-heap mode");
54 int err = ove_stream_init(&handle_, &storage_,
55 buffer_, BufSize, trigger);
57 int err = ove_stream_create(&handle_, BufSize, trigger);
59 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
67#ifdef CONFIG_OVE_ZERO_HEAP
68 ove_stream_deinit(handle_);
70 ove_stream_destroy(handle_);
77#ifdef CONFIG_OVE_ZERO_HEAP
86 other.handle_ =
nullptr;
96 if (handle_) ove_stream_destroy(handle_);
97 handle_ = other.handle_;
98 other.handle_ =
nullptr;
112 [[nodiscard]]
int send(
const void *data,
size_t len,
113 uint32_t timeout_ms,
size_t *bytes_sent) {
114 return ove_stream_send(handle_, data, len, timeout_ms,
126 [[nodiscard]]
int receive(
void *buf,
size_t len,
128 size_t *bytes_received) {
129 return ove_stream_receive(handle_, buf, len, timeout_ms,
141 size_t *bytes_sent) {
142 return ove_stream_send_from_isr(handle_, data, len,
154 size_t *bytes_received) {
155 return ove_stream_receive_from_isr(handle_, buf, len,
164 return ove_stream_reset(handle_);
172 return ove_stream_bytes_available(handle_);
179 bool valid()
const {
return handle_ !=
nullptr; }
185 ove_stream_t
handle()
const {
return handle_; }
188 ove_stream_t handle_ =
nullptr;
189#ifdef CONFIG_OVE_ZERO_HEAP
190 ove_stream_storage_t storage_ = {};
191 uint8_t buffer_[(BufSize > 0 ? BufSize : 1) + 1];
RAII wrapper around an oveRTOS byte-stream (ring-buffer) object.
Definition stream.hpp:38
ove_stream_t handle() const
Returns the raw oveRTOS stream handle.
Definition stream.hpp:185
Stream & operator=(Stream &&other) noexcept
Move-assignment operator — transfers ownership of the kernel handle.
Definition stream.hpp:94
bool valid() const
Returns true if the underlying kernel handle is non-null.
Definition stream.hpp:179
int reset()
Resets the stream, discarding any buffered data.
Definition stream.hpp:163
size_t bytes_available() const
Returns the number of bytes currently available to read.
Definition stream.hpp:171
int send(const void *data, size_t len, uint32_t timeout_ms, size_t *bytes_sent)
Sends bytes into the stream from task context.
Definition stream.hpp:112
int receive(void *buf, size_t len, uint32_t timeout_ms, size_t *bytes_received)
Receives bytes from the stream from task context.
Definition stream.hpp:126
Stream(size_t trigger)
Constructs and initialises the stream with the given receive trigger.
Definition stream.hpp:50
~Stream()
Destroys the stream, releasing the underlying kernel resource.
Definition stream.hpp:65
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).
Definition stream.hpp:140
Stream(Stream &&other) noexcept
Move constructor — transfers ownership of the kernel handle.
Definition stream.hpp:85
int receive_from_isr(void *buf, size_t len, size_t *bytes_received)
Receives bytes from the stream from an ISR context (non-blocking).
Definition stream.hpp:153
Top-level namespace for all oveRTOS C++ abstractions.
Definition app.hpp:19
Common type definitions and concepts for the C++ wrapper layer.