10#ifndef NROS_CPP_STREAM_HPP
11#define NROS_CPP_STREAM_HPP
17#include "nros/size_bound.hpp"
53 Result try_next(T& out) {
return try_next_sized<::nros::rx_buffer_capacity<T>::value>(out); }
62 if (ret != 0)
return Result(ret);
78 Result wait_next(
void* executor_handle, uint32_t timeout_ms, T& out, uint32_t poll_ms = 10) {
79 return wait_next_sized<::nros::rx_buffer_capacity<T>::value>(executor_handle, timeout_ms,
87 uint32_t poll_ms = 10) {
89 if (poll_ms == 0) poll_ms = 1;
97 const uint64_t budget_ns =
static_cast<uint64_t
>(timeout_ms) * 1000000ULL;
105 Result rn = try_next_sized<Cap>(out);
113 if (now_ns - start_ns >= budget_ns)
break;
119 bool is_valid()
const {
return take_fn_ !=
nullptr; }
122 Stream(
Stream&& other) noexcept : storage_(other.storage_), take_fn_(other.take_fn_) {
123 other.storage_ =
nullptr;
124 other.take_fn_ =
nullptr;
128 if (
this != &other) {
129 storage_ = other.storage_;
130 take_fn_ = other.take_fn_;
131 other.storage_ =
nullptr;
132 other.take_fn_ =
nullptr;
138 Stream() : storage_(nullptr), take_fn_(nullptr) {}
147 using TakeFn =
nros_cpp_ret_t (*)(
void*, uint8_t*, size_t,
size_t*);
149 Stream(
void* storage, TakeFn fn) : storage_(storage), take_fn_(fn) {}
151 void bind(
void* storage, TakeFn fn) {
Definition action_client.hpp:73
static constexpr Result success()
Named constructors.
Definition result.hpp:112
ErrorCode code() const
Get the underlying error code.
Definition result.hpp:106
bool ok() const
Returns true if the operation succeeded.
Definition result.hpp:100
Result wait_next(void *executor_handle, uint32_t timeout_ms, T &out, uint32_t poll_ms=10)
Definition stream.hpp:78
bool is_valid() const
Check if the stream is connected to a valid source.
Definition stream.hpp:119
Stream(Stream &&other) noexcept
Definition stream.hpp:122
Stream & operator=(Stream &&other) noexcept
Definition stream.hpp:127
Stream()
Default constructor – creates an unbound stream.
Definition stream.hpp:138
Result try_next_sized(T &out)
Definition stream.hpp:57
Result wait_next_sized(void *executor_handle, uint32_t timeout_ms, T &out, uint32_t poll_ms=10)
Definition stream.hpp:86
Result try_next(T &out)
Definition stream.hpp:53
Definition subscription.hpp:100
int nros_cpp_ret_t
Definition future.hpp:21
nros_cpp_ret_t nros_cpp_spin_once(void *handle, int32_t timeout_ms)
uint64_t nros_cpp_time_ns(void)
@ Error
Generic failure not covered by a more specific code.
@ Timeout
Operation deadline elapsed before completion.
@ TryAgain
Transient — no data ready yet (non-blocking take). Retry later.
nros::Result, nros::ErrorCode, and the NROS_TRY macro.
int nros_cpp_ret_t
Definition stream.hpp:21
nros_cpp_ret_t nros_cpp_spin_once(void *handle, int32_t timeout_ms)
uint64_t nros_cpp_time_ns(void)