10#ifndef NROS_RCLCPP_STREAM_HPP
11#define NROS_RCLCPP_STREAM_HPP
17#include "rclcpp/size_bound.hpp"
34template <
typename S>
class Client;
45template <
typename A>
class Client;
81 if (ret != 0)
return Result(ret);
97 Result wait_next(
void* executor_handle, uint32_t timeout_ms, T& out, uint32_t poll_ms = 10) {
104 template <
size_t Cap>
106 uint32_t poll_ms = 10) {
108 if (poll_ms == 0) poll_ms = 1;
116 const uint64_t budget_ns =
static_cast<uint64_t
>(timeout_ms) * 1000000ULL;
132 if (now_ns - start_ns >= budget_ns)
break;
138 bool is_valid()
const {
return take_fn_ !=
nullptr; }
141 Stream(
Stream&& other) noexcept : storage_(other.storage_), take_fn_(other.take_fn_) {
142 other.storage_ =
nullptr;
143 other.take_fn_ =
nullptr;
147 if (
this != &other) {
148 storage_ = other.storage_;
149 take_fn_ = other.take_fn_;
150 other.storage_ =
nullptr;
151 other.take_fn_ =
nullptr;
157 Stream() : storage_(nullptr), take_fn_(nullptr) {}
163 template <
typename M>
friend class ::rclcpp::PollSubscription;
164 template <
typename A>
friend class ::rclcpp_action::Client;
166 using TakeFn =
nros_cpp_ret_t (*)(
void*, uint8_t*, size_t,
size_t*);
168 Stream(
void* storage, TakeFn fn) : storage_(storage), take_fn_(fn) {}
170 void bind(
void* storage, TakeFn fn) {
bool ok() const
Returns true if the operation succeeded.
Definition result.hpp:227
ErrorCode code() const
Get the underlying error code.
Definition result.hpp:233
static constexpr ResultOf success()
Named constructors.
Definition result.hpp:239
Stream()
Default constructor – creates an unbound stream.
Definition stream.hpp:157
Stream(Stream &&other) noexcept
Definition stream.hpp:141
Result wait_next_sized(void *executor_handle, uint32_t timeout_ms, T &out, uint32_t poll_ms=10)
Definition stream.hpp:105
bool is_valid() const
Check if the stream is connected to a valid source.
Definition stream.hpp:138
Stream & operator=(Stream &&other) noexcept
Definition stream.hpp:146
Result try_next(T &out)
Definition stream.hpp:72
Result try_next_sized(T &out)
Definition stream.hpp:76
Result wait_next(void *executor_handle, uint32_t timeout_ms, T &out, uint32_t poll_ms=10)
Definition stream.hpp:97
Definition client.hpp:256
int nros_cpp_ret_t
Definition future.hpp:25
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.
Definition result.hpp:118
@ NotInitialized
Definition result.hpp:131
@ Timeout
Operation deadline elapsed before completion.
Definition result.hpp:120
@ TryAgain
Transient — no data ready yet (non-blocking take). Retry later.
Definition result.hpp:148
ResultOf< void > Result
Definition result.hpp:247
**auto handle
Definition client.hpp:127
rclcpp::Result, rclcpp::ErrorCode, and the RCLCPP_TRY macro.
nros_cpp_ret_t nros_cpp_spin_once(void *handle, int32_t timeout_ms)
uint64_t nros_cpp_time_ns(void)