|
nros C++ API
Lightweight ROS 2 client for embedded real-time systems (C++ headers)
|
#include <subscription.hpp>
Classes | |
| class | View |
Public Types | |
| using | TypedSubscriptionFn = void(*)(const M &msg) |
| using | TypedSubscriptionFnWithCtx = void(*)(const M &msg, void *ctx) |
| using | TypedSubscriptionInfoFn = void(*)(const M &msg, const uint8_t *attachment, size_t attachment_len) |
Friends | |
| class | Node |
Typed subscription for a ROS 2 topic.
Mirrors rclcpp::Subscription<M>. The message type M must provide TYPE_NAME, TYPE_HASH, and deserialization support (generated by codegen).
Manual-poll style: call try_recv_raw() after nros::spin_once().
Usage:
Phase 189.M3.x — typed message-handler signatures for the callback-style subscription (rclcpp dispatch model). The executor invokes the handler during spin_once() on each new sample.
| using nros::Subscription< M >::TypedSubscriptionInfoFn = void (*)(const M& msg, const uint8_t* attachment, size_t attachment_len) |
|
inline |
Destructor — releases subscription resources.
Poll-style subscriptions own an RmwSubscriber in storage_ and free it here. Callback-style subscriptions (Phase 189.M3.x) are owned by the executor arena (freed when the executor drops), so the dtor must NOT touch storage_ for them.
|
inline |
|
inline |
Default constructor — creates an uninitialized subscription. Use Node::create_subscription() to initialize.
Get the topic name.
|
inline |
Phase 189.M3.1 — internal: executor HandleId usable with nros_cpp_bind_handle_to_sched_context, or SIZE_MAX when the subscription has no bindable handle.
The current thin-wrapper create path (nros_cpp_subscription_create) stores a bare RmwSubscriber and registers no executor callback entry, so no HandleId exists and this stays SIZE_MAX. The accessor
SubscriptionOptions::sched_context lowering activates transparently once a handle-returning create FFI lands. Node is a friend and sets this on create when a handle is available.
|
inline |
Check if the subscription is initialized and valid.
|
inline |
Register a callback for liveliness-changed events.
Returns Result(ErrorCode::Unsupported) until the active backend wires up liveliness detection.
|
inline |
Register a callback for message-lost events.
|
inline |
Register a callback for requested-deadline-missed events.
|
inline |
|
inline |
Phase 124.A.7 — try to borrow the next message in place. Returns View with data when a message is ready, empty View when not. On error returns Expected::error.
Try to receive a typed message (non-blocking).
Receives raw CDR data into a stack buffer, then deserializes into msg using the codegen-generated M::ffi_deserialize().
| msg | Output message struct (filled on success). |
|
inline |
Try to receive raw CDR data (non-blocking).
Sets out_len to the number of bytes received (0 if no data).
| buf | Buffer to receive CDR data. |
| capacity | Size of the buffer. |
| out_len | Receives the number of bytes (0 if no data available). |
|
inline |
Try to receive raw CDR data plus the sample's wire attachment (non-blocking) — the C++ poll-side analog of the Rust node.subscription(t).generic(..).message_info() builder (Phase 189.M3.4b). The attachment carries out-of-band tags such as a cross-RMW bridge's bridge_origin; out_att_len is 0 when the sample carried none.
| buf | Buffer to receive CDR payload. |
| capacity | Size of buf. |
| out_len | Receives payload length (0 if no data). |
| att | Buffer to receive the attachment. |
| att_capacity | Size of att. |
| out_att_len | Receives attachment length (0 if none). |
|
inline |
Phase 124.D.1 — burst-take.
Drain up to max_msgs queued samples in a single call. The i-th delivered sample lives at buf + i * per_msg_cap with length out_lens[i]. Writes the count to out_count. Returns Result::success() on success (count may be 0), the matching FFI error otherwise.
Backends without a native batch take fall back to a try_recv_raw loop — same shape, same observable result; the batched API just lets sensor loops commit to one call shape regardless of backend support.
|
inline |
Issue 0073 — try_recv that ALSO returns the E2E message-integrity status (CRC + sequence gap/dup) of the received sample. The safety-e2e analog of try_recv: the backend recomputes + compares the CRC the publisher attached and tracks the sequence, writing the verdict to status.
Requires the build to enable safety-e2e on both ends (the zenoh backend's own feature, lowered from a declared [safety] axis); a binary built without it cannot link this (the FFI symbol is gated). With it, but against a publisher built without safety, status.crc_valid reports -1.
| msg | Output message struct (filled on success). |
| status | Receives { gap, duplicate, crc_valid } (crc_valid: 1=valid, 0=mismatch, -1=no CRC on the wire). |