nros C++ API
Lightweight ROS 2 client for embedded real-time systems (C++ headers)
Loading...
Searching...
No Matches
node.hpp
Go to the documentation of this file.
1// nros-cpp: Node class
2// Freestanding C++ — no exceptions, no STL required
3
9
10#ifndef NROS_RCLCPP_NODE_HPP
11#define NROS_RCLCPP_NODE_HPP
12
13#include <cstdint>
14#include <cstddef>
15#include <type_traits> // SFINAE on the callback-style create_service
16#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0) // hosted-family: hosted-console
17#include <cstdlib> // getenv — env-aware init
18#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0) // hosted-family: hosted-console
19// <stdio.h> + unqualified `::fprintf`: `<cstdio>` need not put
20// the C names in `std` on a freestanding libstdc++, and `std::fprintf` then fails.
21#include <stdio.h>
22#endif
23#endif
24
25// `<map>` is `NROS_CPP_STD` ONLY, and the `|| __STDC_HOSTED__` arm above is
26// exactly what it must not have.
27//
28// It used to sit in that block beside `<cstdlib>`/`<cstdio>`, which is
29// safe for THOSE: Zephyr's minimal libcpp ships `cstdlib` and `cstdio`, so the
30// hosted arm can be satisfied. It ships no `map`. And `__STDC_HOSTED__` is 1 on
31// Zephyr — the compiler is hosted, the include path is not — so the arm fired
32// and the header failed to open. MEASURED, `g++ -nostdinc++ -I zephyr/cxx-compat`:
33//
34// node.hpp:18:10: fatal error: map: No such file or directory
35//
36// That is one half of the both-probes rule, which the repo records:
37// `__STDC_HOSTED__` alone is a claim about the COMPILER and the question is
38// about the INCLUDE PATH.
39//
40// The fix is not `__has_include(<map>)`. It is to guard the include with the
41// same condition as the only code that needs it. Both consumers —
42// `Node::declare_parameters` below and `lifecycle.hpp`'s twin, which includes
43// no `<map>` of its own and relies on this one — sit inside
44// `NROS_CPP_HAS_STD_STRING`, which implies `NROS_CPP_STD`
45// because every capability probe is `#if defined(NROS_CPP_STD)`. So this is the
46// narrowest guard that still covers every use, and it restores the property
47// the block below states as the rule: a hosted STL include lives inside an
48// `NROS_CPP_STD` region, never one an `||` arm can reach from a freestanding
49// board.
50#if defined(NROS_CPP_STD) // hosted-family: container-interop
51#include <map> // rclcpp::Node::declare_parameters<T>'s argument
52#endif
53
54// ffi.h MUST come before qos.hpp so qos.hpp's
55// `#ifndef NROS_CPP_FFI_H` guard sees the canonical types and skips
56// its local redefinitions.
57#include "rclcpp/detail/nros_cpp_ffi.h"
58
59#include "rclcpp/detail/traits.hpp"
60#include "rclcpp/handle.hpp" // `Node::SharedPtr`
61#include "rclcpp/result.hpp"
62#include "rclcpp/owned.hpp" // The return type of the poll `create_service`
63#include "rclcpp/detail/hosted_block.hpp"
64#include "rclcpp/detail/nros_cpp_config_generated.h"
65// `rclcpp::init` below reads `NROS_ENTRY_LOCATOR` /
66// `NROS_ENTRY_DOMAIN_ID`, so the ladder that derives them from Kconfig must be
67// visible in EVERY TU that calls it, not only in one that also includes
68// `<rclcpp/detail/main.hpp>`. A ported `main.cpp` includes `<rclcpp/rclcpp.hpp>` and
69// nothing else: on a Zephyr guest it compiled with the macro undefined, passed
70// a null locator, and the backend's default dialled the GUEST's own loopback
71// (`ConnectionFailed`, then `create_publisher`'s abort). Where nothing bakes a
72// locator the header yields `""`, which `nros_cpp_init` reads as absent — the
73// same answer a null gave.
74#include "rclc/detail/entry_config.h"
75#include "rclcpp/qos.hpp"
76// rclcpp-style named-options structs
77// (`SubscriptionOptions` / `PublisherOptions`) used by the 4-arg
78// `create_subscription` / `create_publisher` overloads below.
79#include "rclcpp/options.hpp"
80// Heavy entity headers (publisher / subscription / service /
81// client / action_server / action_client) are no longer pulled in here.
82// Each entity header provides the out-of-line definition of its
83// corresponding `Node::create_X<T>()` template and includes `node.hpp`
84// itself. Consumers that #include `rclcpp/rclcpp.hpp` (the umbrella) still
85// get every entity + every create method via that path; consumers that
86// only want lightweight Node access can include this header directly
87// and pay for only the light entities (timer, guard_condition,
88// executor) below.
89#include "rclcpp/timer.hpp"
90// `Node::get_clock()` / `Node::now()`. `clock.hpp` pulls in
91// `time.hpp` and `duration.hpp`, so a node that stamps a header needs no
92// further include.
93#include "rclcpp/clock.hpp"
94// `ComponentNode` is merged into `Node`, so the two things its
95// header pulled in for the merged members come here with them:
96// * `log.hpp` — `NROS_ERROR`, the OVERRIDABLE sink `report_component_failure`
97// routes through so a freestanding image can be given a boot diagnostic.
98// * `declared_qos.hpp` — `rclcpp::declared_depth` + `DECLARED_DEPTH_UNDECLARED`,
99// read by `Node::check_declared_depth`.
100// Neither includes a nano-ros header of its own, so neither can close a cycle
101// back onto `node.hpp`. `component.hpp` — which DOES include this file — is why
102// the member-pointer `create_subscription_in` / `create_subscription_in_group`
103// family is DECLARED here and DEFINED there.
104#include "rclcpp/detail/declared_qos.hpp"
105#include "rclcpp/detail/declared_params.hpp" // Each node's DECLARED parameters
106// `rclcpp::ParameterType`, `ParameterDescriptor`,
107// `ParameterWrite` and the on-set callback types, which the parameter methods
108// below name. Freestanding (`<cstdint>`, `const char*`, the FFI header) and it
109// includes nothing that includes this file. `nros.hpp` included it already;
110// the declarations here are why it moves onto node.hpp's own include list.
111#include "rclcpp/node_parameters.hpp"
112// `rclcpp::ParameterValue` / `rclcpp::Parameter`, which the
113// hosted parameter overloads below take and return. It includes
114// `node_parameters.hpp` and the traits header only, so no cycle.
115#include "rclcpp/parameter_value.hpp"
116#include "rclcpp/logging.hpp"
118#include "rclcpp/executor.hpp"
119// `rclcpp::TopicEndpointInfo` and the visitor
120// typedef used by the graph forwarders below.
121#include "rclcpp/graph.hpp"
122// Callback-group token (value type, no heap).
123#include "rclcpp/callback_group.hpp"
124// The parameter facade is declared here; the store it read
125// is gone. The hosted block no longer holds a `ParameterServer` — the
126// facade forwards to the EXECUTOR's store — so this header needs
127// `parameter.hpp` for nothing of its own. It is kept because what that header
128// still holds (`rclcpp::Seq<T, N>`) is a public surface a consumer reaches
129// through the node header, and `parameter.hpp` depends on `result.hpp` and
130// `<nros/parameter.h>` only,
131// so there is no cycle.
132#include "rclcpp/parameter.hpp"
133
134// `<chrono>` is the one capability whose predicate is not the uniform one —
135// it needs `<ratio>` as a prerequisite too. The three measured corrections that
136// established that live with the predicate, at the one detection site.
137#include "rclcpp/detail/std_detect.hpp"
138
139// Named by `Node::register_service_`'s request-id overload;
140// DEFINED in `rclcpp/service.hpp` (under the guard the RMW ABI and
141// `<rclc/detail/request_id.h>` share).
142struct rmw_request_id_t;
143
144// The hosted-node macro (`NROS_CPP_` + ~~`NODE_HOSTED`~~) IS GONE. It was the
145// conjunction of all four capability probes, wrapped around every hosted-shape member at once. Each
146// member now names the ONE capability its signature actually uses: the `std::string`-keyed
147// forwarders `NROS_CPP_HAS_STD_STRING`, the `std::shared_ptr` spellings `NROS_CPP_HAS_SHARED_PTR`,
148// and nothing needs
149// `<vector>` or `<functional>` any more. The rule it served is unchanged: a
150// probe gates METHODS, never a member.
151
152// ~~`NROS_RCLCPP_MAX_PARAMS`~~ IS GONE. It sized an inline
153// `nros::ParameterServer` on the merged node's hosted block — a SECOND
154// parameter store, node-local, which `ros2 param get` could not see and a
155// sibling node did not share. The member is deleted and the facade forwards to
156// the executor's store (`rclcpp/node_parameters.hpp`), so there is no per-node
157// arena left for a number to bound.
158//
159// The image's one parameter arena is now `NROS_PARAMS_MAX_PARAMETERS` on
160// `nros-params` (default 32, a build knob), and it is shared across every node
161// on the executor rather than multiplied by the node count. Do not reintroduce
162// a per-facade capacity: a second number is how a second store starts.
163
164// No per-backend `nros_rmw_<x>_register()`
165// declarations here. Nothing in these headers called them: registration is the
166// generated strong `nros_app_register_backends()`, and a caller that registers
167// by hand includes its backend's own header.
168
169// Pin (cross-space, C++-FFI half): ErrorCode must stay
170// value-identical to the NROS_CPP_RET_* codes (nros_cpp_ffi.h, included
171// above) that every shim below feeds into Result().
172static_assert(NROS_CPP_RET_NOT_FOUND == -4 && NROS_CPP_RET_ALREADY_EXISTS == -5 &&
173 NROS_CPP_RET_FULL == -6 && NROS_CPP_RET_NOT_INIT == -7 &&
174 NROS_CPP_RET_TRY_AGAIN == -14 && NROS_CPP_RET_REENTRANT == -15 &&
175 NROS_CPP_RET_UNSUPPORTED == -16,
176 "nros_cpp_ret_t diverged from the shared numbering: NROS_CPP_RET_* must "
177 "keep the rcl_ret_t values");
178
179// Forward declarations of the heavy entity class
180// templates. Full definitions live in the corresponding `*.hpp`,
181// which also provide the out-of-line `Node::create_X<>` template
182// bodies — consumers only pay for the entities they #include.
183//
184// Six of them are DECLARED in the upstream namespace,
185// because that is where their definition now lives, and this header names them
186// that way. (Each also had an `nros::` migration alias, declared beside its
187// type in that type's own header; they are deleted.)
188namespace rclcpp {
189// The node itself, defined further down in this header. Forward
190// declared up here because the `rclcpp::` free functions BELOW take it by
191// reference and are named by `Node`'s own qualified friend declarations, which
192// require a prior declaration of the function AND of its parameter type.
193class Node;
194template <typename M> class Publisher;
195template <typename M> class Subscription;
196template <typename S> class Service;
197template <typename S> class Client;
198class GenericPublisher; // `rclcpp/generic.hpp`
199class GenericSubscription; // `rclcpp/generic.hpp`
200template <typename M> class SubscriptionHandle;
201} // namespace rclcpp
202
203namespace rclcpp_action {
204template <typename A> class Server;
205template <typename A> class Client;
206} // namespace rclcpp_action
207
208namespace rclcpp {
209
210// L1 polling-mode action wrappers.
211template <typename A> class PollingActionServer;
212template <typename A> class PollingActionClient;
213// The two poll-side subscribers (`polling_subscription.hpp`).
214template <typename M> class PollSubscription;
215template <typename M> class PollingSubscription;
216// The poll-side service server (`polling_service.hpp`).
217template <typename S> class PollService;
218// The poll-side (future-style) service client
219// (`polling_client.hpp`), and the dispatch client's handle
220// (`client_handle.hpp`).
221template <typename S> class PollClient;
222template <typename S> class ClientHandle;
223
224class Node;
225class Context;
226
227namespace detail {
231inline void refuse_param_declare(Node& node, int32_t code);
232} // namespace detail
233
244namespace node_interfaces {
245
247template <int Tag> class NodeInterfaceHandle {
248 public:
251 NodeInterfaceHandle() : node_(nullptr) {}
252 explicit NodeInterfaceHandle(Node* node) : node_(node) {}
254 Node* node() const { return node_; }
255 explicit operator bool() const { return node_ != nullptr; }
258 const NodeInterfaceHandle* operator->() const { return this; }
262 inline Context get_context() const;
263
264 private:
265 Node* node_;
266};
267
273
274#ifdef NROS_CPP_STD // hosted-family: parameter-interop
293class NodeParametersInterface {
294 public:
295 using SharedPtr = NodeParametersInterface;
296 NodeParametersInterface() : node_(nullptr) {}
297 explicit NodeParametersInterface(Node* node) : node_(node) {}
298 NodeParametersInterface* operator->() { return this; }
299 const NodeParametersInterface* operator->() const { return this; }
300 explicit operator bool() const { return node_ != nullptr; }
301 Node* node() const { return node_; }
302
303 inline bool has_parameter(const ::std::string& name) const;
304 inline ParameterValue declare_parameter(const ::std::string& name,
305 const ParameterValue& default_value);
306 template <typename D>
307 inline ParameterValue declare_parameter(const ::std::string& name,
308 const ParameterValue& default_value,
309 const D& descriptor);
310 inline bool get_parameter(const ::std::string& name, Parameter& out) const;
311 inline Parameter get_parameter(const ::std::string& name) const;
312 inline const ::std::map<::std::string, ParameterValue>& get_parameter_overrides() const;
313
314 private:
315 Node* node_;
316};
317
327struct OnSetParametersCallbackHandle {
328 using SharedPtr = ::std::shared_ptr<OnSetParametersCallbackHandle>;
329 using WeakPtr = ::std::weak_ptr<OnSetParametersCallbackHandle>;
333 using OnParametersSetCallbackType = ::std::function<bool(const ::std::vector<Parameter>&)>;
334
335 OnSetParametersCallbackHandle() : node(nullptr), token(0), registered(false) {}
336 OnSetParametersCallbackHandle(const OnSetParametersCallbackHandle&) = delete;
337 OnSetParametersCallbackHandle& operator=(const OnSetParametersCallbackHandle&) = delete;
338 ~OnSetParametersCallbackHandle() { unregister(); }
339
341 void unregister() {
342 if (registered) {
343 (void)::rclcpp::detail::node_param_remove_on_set_callback(node, token);
344 registered = false;
345 }
346 }
347
349 static bool trampoline(const ParameterWrite* write, void* context) {
350 auto* self = static_cast<OnSetParametersCallbackHandle*>(context);
351 if (write == nullptr || self == nullptr || !self->callback) {
352 return true;
353 }
354 ::std::vector<Parameter> params;
355 params.push_back(Parameter::from_write(*write));
356 return self->callback(params);
357 }
358
359 OnParametersSetCallbackType callback;
360 const nros_cpp_node_t* node;
361 OnSetParametersCallbackToken token;
362 bool registered;
363};
364#endif // NROS_CPP_STD
365
366} // namespace node_interfaces
367
408 void* executor;
412 const char* launch_name;
414 const char* launch_namespace;
425 const nros_cpp_qos_override_t* qos_overrides;
428
429 constexpr NodeHandle()
430 : executor(nullptr), launch_name(nullptr), launch_namespace(nullptr),
431 qos_overrides(nullptr), qos_override_count(0) {}
432 explicit constexpr NodeHandle(void* exec)
433 : executor(exec), launch_name(nullptr), launch_namespace(nullptr), qos_overrides(nullptr),
435
437 constexpr NodeHandle(void* exec, const char* name, const char* ns)
438 : executor(exec), launch_name(name), launch_namespace(ns), qos_overrides(nullptr),
440
443 constexpr NodeHandle(void* exec, const char* name, const char* ns,
444 const nros_cpp_qos_override_t* overrides, size_t override_count)
445 : executor(exec), launch_name(name), launch_namespace(ns), qos_overrides(overrides),
446 qos_override_count(override_count) {}
447 constexpr bool valid() const { return executor != nullptr; }
448
451 constexpr const char* resolve_name(const char* fallback) const {
452 return (launch_name != nullptr && launch_name[0] != '\0') ? launch_name : fallback;
453 }
454
455 constexpr const char* resolve_namespace(const char* fallback) const {
456 return (launch_namespace != nullptr && launch_namespace[0] != '\0') ? launch_namespace
457 : fallback;
458 }
459};
460
468// `constexpr` at namespace scope is implicitly const, so it already has internal
469// linkage per TU — `inline` bought nothing and cost C++14 compatibility, which
470// nano-ros otherwise keeps (see `just check cpp`'s freestanding c++14 syntax
471// gate). PX4 builds every module with -std=gnu++14 -Werror, so an inline
472// variable here made <rclcpp/rclcpp.hpp> uncompilable in a PX4 module.
473constexpr uint8_t kDomainIdExplicitZero = 255;
474
475namespace detail {
476
487inline void report_component_failure(const char* node_name, const char* what, int32_t code) {
488 // Route through the OVERRIDABLE sink first, so a freestanding image can
489 // see this at all. A bisect once ran aground here: on Zephyr both
490 // arms below compile to nothing, so a component that failed to register
491 // halted SILENTLY -- the board printed only the Zephyr banner, identical
492 // to a healthy boot, and "is it broken?" had no answer on the target where
493 // it mattered. An earlier fix closed exactly this class for the Rust side; the
494 // C++ side still had it.
495 NROS_ERROR("node \"%s\": FAILED at %s (code=%d)", (node_name != nullptr) ? node_name : "?",
496 (what != nullptr) ? what : "?", static_cast<int>(code));
497#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0) // hosted-family: hosted-console
498 ::fprintf(stderr, "[nros] FATAL: node \"%s\" failed to construct at %s (code=%d)\n",
499 (node_name != nullptr) ? node_name : "?", (what != nullptr) ? what : "?",
500 static_cast<int>(code));
501#endif
502}
503
511constexpr int32_t DECLARED_DEPTH_MISMATCH = -403;
512
516inline void report_declared_depth_mismatch(const char* node_name, const char* topic, int declared,
517 int passed) {
518 NROS_ERROR("node \"%s\": topic \"%s\" DECLARED depth %d but the QoS "
519 "passed states %d. Depth multiplies the executor arena, so they must agree.",
520 (node_name != nullptr) ? node_name : "?", (topic != nullptr) ? topic : "?", declared,
521 passed);
522#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0) // hosted-family: hosted-console
523 ::fprintf(stderr,
524 "[nros] FATAL: node \"%s\": topic \"%s\" was DECLARED depth %d in "
525 "the contract sidecar (<stem>.contract.yaml) but the QoS passed to "
526 "create_subscription_in states depth %d. Depth multiplies the executor "
527 "arena (cost is (depth+1)*bound per subscription), so the two must agree. "
528 "Fix the contract row or the call site.\n",
529 (node_name != nullptr) ? node_name : "?", (topic != nullptr) ? topic : "?", declared,
530 passed);
531#else
532 (void)node_name;
533 (void)topic;
534 (void)declared;
535 (void)passed;
536#endif
537}
538
545inline void report_callback_group_mismatch(const char* node_name, const char* how, const char* name,
546 int len, const char* list) {
547 const char* node = (node_name != nullptr) ? node_name : "?";
548 const char* group = (name != nullptr) ? name : "?";
549 const char* declared = (list != nullptr) ? list : "";
550 // "created": the code made a group the keyword never declared.
551 // "declared": the keyword declared a group the constructor never made.
552 const bool created = (how != nullptr && how[0] == 'c');
553 if (created) {
554 NROS_ERROR("node \"%s\": created callback group \"%.*s\", not in CALLBACK_GROUPS \"%s\"",
555 node, len, group, declared);
556 } else {
557 NROS_ERROR("node \"%s\": CALLBACK_GROUPS \"%s\" declares \"%.*s\", never created", node,
558 declared, len, group);
559 }
560#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0) // hosted-family: hosted-console
561 ::fprintf(stderr,
562 created ? "[nros] FATAL: node \"%s\" created callback group \"%.*s\", which its "
563 "registration's CALLBACK_GROUPS \"%s\" does not declare.\n"
564 : "[nros] FATAL: node \"%s\" never created callback group \"%.*s\", which "
565 "its registration's CALLBACK_GROUPS \"%s\" declares.\n",
566 node, len, group, declared);
567 ::fprintf(
568 stderr,
569 " The sched task derivation ranks the declared list and the executor binds what the "
570 "code creates, so the two must name the same groups (ONE declared group and none "
571 "created is node-level placement, and is allowed). Fix the "
572 "nano_ros_node_register(... CALLBACK_GROUPS ...) line or the create_callback_group "
573 "call.\n");
574#endif
575}
576
583
587inline void report_declared_policy_mismatch(const char* node_name, const char* topic,
588 const char* policy, const char* declared,
589 const char* passed) {
590 NROS_ERROR("node \"%s\": topic \"%s\" DECLARED %s %s but the QoS passed states %s. An "
591 "incompatible-QoS match never delivers, so they must agree.",
592 (node_name != nullptr) ? node_name : "?", (topic != nullptr) ? topic : "?", policy,
593 declared, passed);
594#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0) // hosted-family: hosted-console
595 ::fprintf(stderr,
596 "[nros] FATAL: node \"%s\": topic \"%s\" was DECLARED %s %s in the contract "
597 "sidecar (<stem>.contract.yaml) but the QoS passed to create_subscription_in "
598 "states %s. Fix the contract row or the call site.\n",
599 (node_name != nullptr) ? node_name : "?", (topic != nullptr) ? topic : "?", policy,
600 declared, passed);
601#else
602 (void)node_name;
603 (void)topic;
604 (void)policy;
605 (void)declared;
606 (void)passed;
607#endif
608}
609
611inline const char* declared_reliability_spelling(int ordinal) {
612 return ordinal == static_cast<int>(::rclcpp::ReliabilityPolicy::Reliable) ? "reliable"
613 : ordinal == static_cast<int>(::rclcpp::ReliabilityPolicy::BestEffort)
614 ? "best_effort"
615 : "system_default";
616}
617
619inline const char* declared_durability_spelling(int ordinal) {
620 return ordinal == static_cast<int>(::rclcpp::DurabilityPolicy::Volatile) ? "volatile"
621 : ordinal == static_cast<int>(::rclcpp::DurabilityPolicy::TransientLocal)
622 ? "transient_local"
623 : "system_default";
624}
625
628constexpr int32_t DECLARED_PARAM_MISMATCH = -446;
629
634inline void report_declared_param_mismatch(const char* fqn, const char* param, const char* contract,
635 int declared, int passed) {
636 const char* f = (fqn != nullptr) ? fqn : "?";
637 const char* p = (param != nullptr) ? param : "?";
638 const char* c = (contract != nullptr) ? contract : "?";
639 if (declared == ::rclcpp::DECLARED_PARAM_UNDECLARED) {
640 NROS_ERROR("node \"%s\": parameter \"%s\" is not declared in its contract (%s).", f, p, c);
641 } else {
642 NROS_ERROR("node \"%s\": parameter \"%s\" is declared %s in its contract (%s) but the "
643 "code declares it as %s.",
644 f, p, ::rclcpp::declared_param_type_name(declared), c,
645 ::rclcpp::declared_param_type_name(passed));
646 }
647#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0) // hosted-family: hosted-console
648 if (declared == ::rclcpp::DECLARED_PARAM_UNDECLARED) {
649 ::fprintf(stderr,
650 "[nros] FATAL: node \"%s\": parameter \"%s\" is not declared in its "
651 "contract (%s, `params:`). The parameter store is sized from that "
652 "declaration, so a parameter it does not name has no slot. Declare it "
653 "there with its type, or stop declaring it in the code.\n",
654 f, p, c);
655 } else {
656 ::fprintf(stderr,
657 "[nros] FATAL: node \"%s\": parameter \"%s\" is declared `%s` in its "
658 "contract (%s) but the code declares it as `%s`. Fix the contract or "
659 "the code so they state one type.\n",
660 f, p, ::rclcpp::declared_param_type_name(declared), c,
661 ::rclcpp::declared_param_type_name(passed));
662 }
663#endif
664}
665
669constexpr int32_t PARAM_VALUE_TYPE_MISMATCH = -447;
670
673// This used to be a silent `return default_value`.
674constexpr const char* PARAM_STORE_FULL_WHAT =
675 "declare_parameter: parameter store full; raise `max_parameters` under [knobs.params] "
676 "(NROS_PARAMS_MAX_PARAMETERS / CONFIG_NROS_PARAMS_MAX_PARAMETERS)";
677
679constexpr const char* PARAM_DECLARE_REFUSED_WHAT =
680 "declare_parameter: the parameter store refused it, so its launch/YAML value is not applied";
681
683constexpr const char* PARAM_VALUE_TYPE_MISMATCH_WHAT =
684 "declare_parameter: its launch/YAML value has another type than the code declares (the "
685 "line above says what to write)";
686
687// ~~`detail::NodeHosted`~~ IS GONE. It was the lazily allocated
688// block behind `Node::hosted_`, and by W3 it held one member:
689// `rclcpp::NodeOptions`, a type with no data members (every accessor is a
690// REFUSE-LOUD template, `options.hpp`). Allocating a heap block to store an
691// empty object bought nothing, so `get_node_options()` answers a constant and
692// the block, the member and the `operator new` go. (Later
693// `NodeOptions` gained one real field, `clock_type`, kept inline on the node.)
694
695} // namespace detail
696
707inline Result init_in(const char* locator = nullptr, uint8_t domain_id = 0);
708
728inline Result init_in(const char* locator, uint8_t domain_id, const char* session_name);
729
748inline Result init_in(const char* locator, uint8_t domain_id, const char* session_name,
749 const char* node_namespace);
750
768inline Result init_with_rmw(const char* rmw, const char* locator = nullptr, uint8_t domain_id = 0,
769 const char* session_name = "node");
770
793inline Result init_in(int argc, char const* const* argv, const char* session_name = nullptr);
794
798inline Result shutdown_in();
799
800// The remaining `rclcpp::` free functions `Node` befriends. A
801// QUALIFIED friend declaration (`friend Result(::rclcpp::ok)();`) names an
802// existing entity; it cannot introduce one. These four live in `nros.hpp`,
803// which includes this header, so without these declarations the friendship
804// would be unresolvable and the private `executor_handle_` unreachable from the
805// functions whose whole job is to set it. Default arguments stay on the
806// definitions — a default may be added by a later declaration, never repeated.
807inline bool ok();
808inline Result create_node(::rclcpp::Node& out, const char* name, const char* ns);
809inline Result create_node_on(::rclcpp::Node& out, void* executor_handle, const char* name,
810 const char* ns);
811inline Result spin_once(int32_t timeout_ms);
812inline Result spin_in();
813inline Result spin_in(uint32_t duration_ms, int32_t poll_ms);
814inline void* global_handle();
815
816} // namespace rclcpp
817
818// ============================================================================
819// rclcpp:: — the HOME of the C++ node type (not an alias onto
820// `nros::`). The direction was flipped:
821// the class was DEFINED here and `nros::Node` became the migration alias, the
822// same shape the other nine types already carried (`clock.hpp`, `duration.hpp`,
823// `time.hpp`, `publisher.hpp`, `subscription.hpp`, `client.hpp`, `service.hpp`,
824// `action_client.hpp`, `action_server.hpp`). The aliases are deleted;
825// `rclcpp::` is now the only namespace.
826//
827// `Node` was the TENTH and was held back because two pending changes were stacked
828// on this header. Both merged. The measurement that blocked it before — the
829// parity extractor rooting our native surface at `{"nros"}` alone, so a class
830// defined here re-bucketed ~60 members to `theirs-only` — is gone too:
831// `scripts/api-parity.py` roots every C++ TU at `OUR_CPP_ROOTS`, both halves of
832// the vocabulary we ship.
833//
834// The ours-only names the body below reaches (`ErrorCode`, `detail::*`,
835// `NodeHandle`, `SchedContext`, the polling entity templates) are spelled
836// `::rclcpp::`-qualified. That qualifier used to be `::nros::` and
837// told an adopted name from an ours-only one; the namespace no longer carries
838// that distinction.
839// ============================================================================
840namespace rclcpp {
874class Node {
875 public:
878 Node() : handle_(), initialized_(false), executor_handle_(nullptr), clock_(RCL_ROS_TIME) {}
879
880 // ==== construction ====================================================
881 //
882 // Upstream constructs a node from a name and THROWS on failure. The C++ API
883 // has no exceptions, so the constructor is kept [clause 2] and the
884 // failure channel changes [clause 1]: the node records the failure and
885 // `ok()` reports it.
886
895 explicit Node(const char* name, const char* ns = nullptr)
896 : handle_(), initialized_(false), executor_handle_(nullptr), clock_(RCL_ROS_TIME) {
897 (void)this->init(name, ns);
898#if defined(NROS_AMENT_START_PARAMETER_SERVICES)
899 // Upstream starts the six parameter services in every node
900 // (`NodeOptions::start_parameter_services` defaults to true). The ament
901 // verbs define this when the runtime carries `param_services`, so a
902 // ported node gets them with no call of ours; elsewhere the entry or
903 // the user calls `start_parameter_services()`. Idempotent per executor.
904 if (initialized_) (void)this->start_parameter_services();
905#endif
906 }
907
913 Result init(const char* name, const char* ns = nullptr) {
914 if (initialized_) return Result(::rclcpp::ErrorCode::AlreadyExists);
915 if (!Node::global_initialized()) return Result(::rclcpp::ErrorCode::NotInitialized);
916 executor_handle_ = Node::global_storage();
917 return Node::create(*this, name, ns);
918 }
919
924 Result init_on(void* executor_handle, const char* name, const char* ns = nullptr) {
925 if (initialized_) return Result(::rclcpp::ErrorCode::AlreadyExists);
927 executor_handle_ = executor_handle;
928 return Node::create(*this, name, ns);
929 }
930
958 explicit Node(::rclcpp::NodeHandle handle, const char* name, const char* ns = nullptr)
959 : handle_(), initialized_(false), executor_handle_(nullptr), clock_(RCL_ROS_TIME) {
960 if (!handle.valid()) {
961 this->set_error("ctor (null executor handle)", -1);
962 return;
963 }
964 Result r =
965 this->init_on(handle.executor, handle.resolve_name(name), handle.resolve_namespace(ns));
966 if (!r.ok()) {
967 this->set_error("node create", r.raw());
968 return;
969 }
970 // The launch's QoS overrides, installed before the
971 // derived constructor body creates a single entity (a base is fully
972 // constructed before the derived body runs), which is the ordering
973 // the `configure` shape gets from the entry's own call.
974 if (handle.qos_overrides != nullptr && handle.qos_override_count != 0) {
975 nros_cpp_ret_t qrc = ::nros_cpp_node_set_qos_overrides(&handle_, handle.qos_overrides,
976 handle.qos_override_count);
977 if (qrc != NROS_CPP_RET_OK) {
978 this->set_error("set_qos_overrides", static_cast<int32_t>(qrc));
979 }
980 }
981 }
982
998 bool ok() const { return initialized_ && !__atomic_load_n(&has_error_, __ATOMIC_ACQUIRE); }
999
1002 const char* error_what() const {
1003 // Acquire-fence on the flag so a standalone call (not preceded by
1004 // ok()) still sees the released `error_what_` write.
1005 (void)__atomic_load_n(&has_error_, __ATOMIC_ACQUIRE);
1006 return error_what_;
1007 }
1008
1009 int32_t error_code() const {
1010 (void)__atomic_load_n(&has_error_, __ATOMIC_ACQUIRE);
1011 return error_code_;
1012 }
1013
1014 // ==== the HOSTED shape ================================================
1015 //
1016 // Upstream's own signatures, verbatim, on the same type. Everything below
1017 // is spelled in `std::shared_ptr` / `std::string` / `std::vector` /
1018 // `std::function`, so where those are absent the SIGNATURES are absent with
1019 // them — a gate on METHODS, never on a member.
1020 //
1021 // ONE NAME, TWO SIGNATURES. The out-ref
1022 // family above and the `shared_ptr` family below are OVERLOADS, and the
1023 // compiler separates them without ambiguity because the hosted forms put
1024 // `M` only in the return type — so a call that passes an out-param deduces
1025 // nothing for them and they drop out, while an explicit
1026 // `create_publisher<M>("chatter", 10)` cannot bind an out-ref parameter to
1027 // a string literal. On a FREESTANDING target the hosted overload does not
1028 // exist at all, so that same ported line fails to compile naming the
1029 // out-ref overload — mechanical, which is what clause 2 asks for.
1030 //
1031 // Each member below is gated on the ONE capability its
1032 // signature uses, not on a conjunction of all four.
1033
1037 Node(const char* name, const ::rclcpp::NodeOptions& options) : Node(name, nullptr) {
1038 apply_options_(options);
1039 }
1040
1044 Node(const char* name, const char* ns, const ::rclcpp::NodeOptions& options) : Node(name, ns) {
1045 apply_options_(options);
1046 }
1047
1051 const ::rclcpp::NodeOptions& get_node_options() const { return options_; }
1052
1053#ifdef NROS_CPP_HAS_STD_STRING // hosted-family: string-interop
1055 explicit Node(const ::std::string& name) : Node(name.c_str(), nullptr) {}
1056
1058 Node(const ::std::string& name, const ::rclcpp::NodeOptions& options)
1059 : Node(name.c_str(), options) {}
1060
1062 Node(const ::std::string& name, const ::std::string& ns,
1063 const ::rclcpp::NodeOptions& options = ::rclcpp::NodeOptions())
1064 : Node(name.c_str(), ns.c_str(), options) {}
1065#endif // NROS_CPP_HAS_STD_STRING
1066
1080 using SharedPtr = ::rclcpp::Handle<Node>;
1082 using ConstSharedPtr = ::rclcpp::Handle<const Node>;
1085 using WeakPtr = ::rclcpp::Handle<Node>;
1087 using ConstWeakPtr = ::rclcpp::Handle<const Node>;
1088
1103
1109 return ::rclcpp::node_interfaces::NodeBaseInterface(this);
1110 }
1111
1113 return ::rclcpp::node_interfaces::NodeClockInterface(this);
1114 }
1115
1117 return ::rclcpp::node_interfaces::NodeGraphInterface(this);
1118 }
1119
1121 return ::rclcpp::node_interfaces::NodeLoggingInterface(this);
1122 }
1123
1125 return ::rclcpp::node_interfaces::NodeWaitablesInterface(this);
1126 }
1127
1128#if defined(NROS_CPP_HAS_SHARED_PTR) // hosted-family: shared-ptr-interop
1143 template <typename... Args> static ::std::shared_ptr<Node> make_shared(Args&&... args) {
1144 return ::std::make_shared<Node>(static_cast<Args&&>(args)...);
1145 }
1146
1148 template <typename... Args> static ::std::unique_ptr<Node> make_unique(Args&&... args) {
1149 return ::std::unique_ptr<Node>(new Node(static_cast<Args&&>(args)...));
1150 }
1151#endif // NROS_CPP_HAS_SHARED_PTR
1152
1156 bool initialized() const { return initialized_; }
1157
1160 Node& nros_node() { return *this; }
1162 const Node& nros_node() const { return *this; }
1163
1164#ifdef NROS_CPP_HAS_STD_STRING // hosted-family: string-interop
1165 // -- entity creation, upstream's signatures (bodies in `nros.hpp`) -------
1166
1172 template <typename M>
1173 typename ::rclcpp::Publisher<M>::SharedPtr create_publisher(const ::std::string& topic,
1174 const ::rclcpp::QoS& qos);
1175
1177 template <typename M>
1178 typename ::rclcpp::Publisher<M>::SharedPtr create_publisher(const ::std::string& topic,
1179 ::size_t depth);
1180
1183 template <typename M, typename Cb>
1184 typename ::rclcpp::Subscription<M>::SharedPtr
1185 create_subscription(const ::std::string& topic, const ::rclcpp::QoS& qos, Cb cb);
1186
1188 template <typename M, typename Cb>
1189 typename ::rclcpp::Subscription<M>::SharedPtr create_subscription(const ::std::string& topic,
1190 ::size_t depth, Cb cb);
1191
1193 template <typename M, typename Cb>
1194 typename ::rclcpp::Subscription<M>::SharedPtr
1195 create_subscription(const ::std::string& topic, const ::rclcpp::QoS& qos, Cb cb,
1196 const ::rclcpp::SubscriptionOptions& options) {
1197 return this->create_subscription<M>(topic.c_str(), qos, ::rclcpp::tr::forward_rvalue(cb),
1198 options);
1199 }
1200
1202 template <typename M, typename Cb>
1203 typename ::rclcpp::Subscription<M>::SharedPtr
1204 create_subscription(const ::std::string& topic, ::size_t depth, Cb cb,
1205 const ::rclcpp::SubscriptionOptions& options) {
1206 return this->create_subscription<M>(topic.c_str(), depth, ::rclcpp::tr::forward_rvalue(cb),
1207 options);
1208 }
1209
1220 template <typename S>
1221 ::rclcpp::Owned<::rclcpp::PollService<S>>
1222 create_service(const ::std::string& name, const ::rclcpp::QoS& qos = ::rclcpp::QoS::services());
1223
1225 template <typename S, typename F,
1226 typename = typename std::enable_if<std::is_convertible<
1227 F, void (*)(const typename S::Request&, typename S::Response&)>::value>::type>
1228 typename ::rclcpp::Service<S>::SharedPtr
1229 create_service(const ::std::string& name, F callback,
1230 const ::rclcpp::QoS& qos = ::rclcpp::QoS::services());
1231
1237 template <typename S, typename F,
1238 typename = typename std::enable_if<
1240 !std::is_convertible<F, void (*)(const typename S::Request&,
1241 typename S::Response&)>::value>::type,
1242 typename = void>
1243 typename ::rclcpp::Service<S>::SharedPtr
1244 create_service(const ::std::string&, F, const ::rclcpp::QoS& = ::rclcpp::QoS::services());
1245
1247 template <typename S, typename F>
1248 typename ::rclcpp::Service<S>::SharedPtr create_service(const ::std::string& name, F callback,
1249 const ::rclcpp::QoS& qos,
1250 const ::rclcpp::CallbackGroup* group) {
1251 return this->template create_service<S>(name.c_str(),
1252 ::rclcpp::tr::forward_rvalue(callback), qos, group);
1253 }
1254
1271 template <typename S>
1272 ::rclcpp::Owned<::rclcpp::PollClient<S>>
1273 create_client(const ::std::string& name, const ::rclcpp::QoS& qos = ::rclcpp::QoS::services());
1274
1276 template <typename S, typename F,
1277 typename = typename std::enable_if<
1278 std::is_convertible<F, void (*)(const typename S::Response&)>::value>::type>
1279 typename ::rclcpp::Client<S>::SharedPtr
1280 create_client(const ::std::string& name, F callback,
1281 const ::rclcpp::QoS& qos = ::rclcpp::QoS::services());
1282
1284 template <typename S, typename F,
1285 typename = typename std::enable_if<
1287 !std::is_convertible<F, void (*)(const typename S::Response&)>::value>::type,
1288 typename = void>
1289 typename ::rclcpp::Client<S>::SharedPtr
1290 create_client(const ::std::string&, F, const ::rclcpp::QoS& = ::rclcpp::QoS::services());
1291
1292#endif // NROS_CPP_HAS_STD_STRING
1293
1294 // -- the ported publisher line, on EVERY target ---------------------------
1295 //
1296 // OUTSIDE the hosted gate (now deleted), and that is the point
1297 // rather than a placement detail. `create_publisher<M>("chatter", 10)` is the single most
1298 // copied line in the porting corpus, and it used to be gated: the return
1299 // type was `std::shared_ptr<Publisher<M>>`, so on a minimal freestanding
1300 // libcpp the overload did not exist and the line did not compile.
1301 // `ported_create_publisher_freestanding_probe.cpp` asserted exactly that,
1302 // and the lane's own error text named the reason — "the hosted overload
1303 // returns std::shared_ptr and there is no allocator here".
1304 //
1305 // The return type is `Publisher<M>::SharedPtr` = `rclcpp::Owned<Publisher<M>>`
1306 // now, which needs no allocator and exists everywhere, so the reason is
1307 // gone and the gate goes with it. ONE API, byte-for-byte the
1308 // same shape on every target, reached by removing what made it differ.
1309 //
1310 // The `const char*` key is what makes it freestanding — a `std::string`
1311 // parameter would have re-imposed the gate through the argument instead of
1312 // the return. A string literal binds here exactly (array-to-pointer), so a
1313 // ported call reaches this overload on a hosted target too; the
1314 // `std::string` forwarders above stay for a caller that already holds one.
1315
1317 template <typename M>
1318 typename ::rclcpp::Publisher<M>::SharedPtr
1319 create_publisher(const char* topic,
1320 const ::rclcpp::QoS& qos = ::rclcpp::QoS::default_profile());
1321
1323 template <typename M>
1324 typename ::rclcpp::Publisher<M>::SharedPtr create_publisher(const char* topic, ::size_t depth);
1325
1326 // The DISPATCH verbs join it, for the same reason. Their
1327 // results have been freestanding handles for a while (the arena holds
1328 // the subscription, the server, the client and the callable), so the
1329 // `std::string` key was the only thing still keeping them hosted. The
1330 // `std::string` overloads in the hosted block forward here.
1331
1334 template <typename M, typename Cb>
1335 typename ::rclcpp::Subscription<M>::SharedPtr
1336 create_subscription(const char* topic, const ::rclcpp::QoS& qos, Cb cb);
1337
1339 template <typename M, typename Cb>
1340 typename ::rclcpp::Subscription<M>::SharedPtr create_subscription(const char* topic,
1341 ::size_t depth, Cb cb);
1342
1349 template <typename M, typename Cb>
1350 typename ::rclcpp::Subscription<M>::SharedPtr
1351 create_subscription(const char* topic, const ::rclcpp::QoS& qos, Cb cb,
1352 const ::rclcpp::SubscriptionOptions& options);
1353
1355 template <typename M, typename Cb>
1356 typename ::rclcpp::Subscription<M>::SharedPtr
1357 create_subscription(const char* topic, ::size_t depth, Cb cb,
1358 const ::rclcpp::SubscriptionOptions& options);
1359
1360 // -- generic (type-erased) pub/sub ----------------------------------------
1361 //
1362 // Bodies in `rclcpp.hpp`, types in `rclcpp/generic.hpp`. rclcpp's name-only
1363 // spellings are REFUSE-LOUD; the hash-taking ones are the nano-ros form.
1364
1369 ::rclcpp::Owned<::rclcpp::GenericPublisher>
1370 create_generic_publisher(const char* topic, const char* type, const char* type_hash,
1371 const ::rclcpp::QoS& qos = ::rclcpp::QoS::default_profile());
1372
1376 template <typename Cb>
1378 create_generic_subscription(const char* topic, const char* type, const char* type_hash,
1379 const ::rclcpp::QoS& qos, Cb callback);
1380
1383 template <typename A, typename B, typename... R>
1384 void create_generic_publisher(const A& topic, const B& type, const ::rclcpp::QoS& qos,
1385 const R&...) {
1386 (void)topic;
1387 (void)type;
1388 (void)qos;
1389 static_assert(::rclcpp::detail::refuse<A>::value, NROS_RCLCPP_REFUSE_GENERIC_BY_NAME);
1390 }
1391
1394 template <typename A, typename B, typename Cb, typename... R>
1395 void create_generic_subscription(const A& topic, const B& type, const ::rclcpp::QoS& qos,
1396 Cb&& callback, const R&...) {
1397 (void)topic;
1398 (void)type;
1399 (void)qos;
1400 (void)callback;
1401 static_assert(::rclcpp::detail::refuse<A>::value, NROS_RCLCPP_REFUSE_GENERIC_BY_NAME);
1402 }
1403
1406 template <typename S>
1407 ::rclcpp::Owned<::rclcpp::PollService<S>>
1408 create_service(const char* name, const ::rclcpp::QoS& qos = ::rclcpp::QoS::services());
1409
1411 template <typename S, typename F,
1412 typename = typename ::rclcpp::tr::enable_if<::rclcpp::tr::is_convertible<
1413 F, void (*)(const typename S::Request&, typename S::Response&)>::value>::type>
1414 typename ::rclcpp::Service<S>::SharedPtr
1415 create_service(const char* name, F callback,
1416 const ::rclcpp::QoS& qos = ::rclcpp::QoS::services());
1417
1423 template <typename S, typename F,
1424 typename = typename ::rclcpp::tr::enable_if<
1426 !::rclcpp::tr::is_convertible<F, void (*)(const typename S::Request&,
1427 typename S::Response&)>::value>::type,
1428 typename = void>
1429 typename ::rclcpp::Service<S>::SharedPtr
1430 create_service(const char*, F, const ::rclcpp::QoS& = ::rclcpp::QoS::services());
1431
1438 template <typename S, typename F>
1439 typename ::rclcpp::Service<S>::SharedPtr create_service(const char* name, F callback,
1440 const ::rclcpp::QoS& qos,
1441 const ::rclcpp::CallbackGroup* group);
1442
1445 template <typename S>
1446 ::rclcpp::Owned<::rclcpp::PollClient<S>>
1447 create_client(const char* name, const ::rclcpp::QoS& qos = ::rclcpp::QoS::services());
1448
1450 template <typename S, typename F,
1451 typename = typename ::rclcpp::tr::enable_if<::rclcpp::tr::is_convertible<
1452 F, void (*)(const typename S::Response&)>::value>::type>
1453 typename ::rclcpp::Client<S>::SharedPtr
1454 create_client(const char* name, F callback,
1455 const ::rclcpp::QoS& qos = ::rclcpp::QoS::services());
1456
1458 template <
1459 typename S, typename F,
1460 typename = typename ::rclcpp::tr::enable_if<
1462 !::rclcpp::tr::is_convertible<F, void (*)(const typename S::Response&)>::value>::type,
1463 typename = void>
1464 typename ::rclcpp::Client<S>::SharedPtr
1465 create_client(const char*, F, const ::rclcpp::QoS& = ::rclcpp::QoS::services());
1466
1467 // -- parameters (bodies in `nros.hpp`) ----------------------------------
1468 //
1469 // Forwarders onto THE parameter store - the `nros_params::ParameterServer`
1470 // the EXECUTOR owns, reached across the FFI by `rclcpp/node_parameters.hpp`.
1471 // Declared here with the class and DEFINED in `nros.hpp` beside the other
1472 // out-of-line members, which is where the reasoning lives.
1473 //
1474 // These used to read an inline `ParameterServer` member on the
1475 // hosted block instead: a second store, node-local, that the six
1476 // `rcl_interfaces/srv/*` servers could not read - so a parameter declared
1477 // through this facade was invisible to `ros2 param get` and a sibling node
1478 // did not share it.
1479 //
1480 // OUTSIDE the hosted gate (now deleted), and that is part of the
1481 // one-store change rather than a tidy-up. The member leaving was "the last thing that made
1482 // the hosted gate decide whether a node HAS parameters rather than
1483 // whether it can spell them" - but the declarations stayed inside the gate,
1484 // so a freestanding node still had no parameter method, and
1485 // `nros::ParameterServer<Cap>` (deleted with this wave) was the only C++
1486 // parameter surface it had. Deleting that class while the gate stood would
1487 // have removed the capability from freestanding C++ instead of moving it,
1488 // which is what W4's ordering rule exists to prevent. The scalar FFI is
1489 // `<cstdint>` and a `const char*`; nothing about it needs the STL, and
1490 // `rclcpp::Seq<T, N>` gives the array form the same reach. Only the
1491 // `std::string`-KEYED overloads below need it, and they keep the gate - a
1492 // gate on METHODS, never on a member, which is what
1493 // `check-cpp-capability-layout` asks.
1494
1496 template <typename T> T declare_parameter(const char* name, T default_value = T());
1499 template <typename T> bool get_parameter(const char* name, T& out) const;
1501 template <typename T> T get_parameter(const char* name) const;
1505 template <typename T> Result set_parameter(const char* name, T value);
1507 bool has_parameter(const char* name) const;
1508
1509 // ---- the rest of rclcpp's parameter surface ---------------------------
1510 //
1511 // All of it forwards to the executor's ONE store through
1512 // `rclcpp/node_parameters.hpp`. OUTSIDE any capability gate for the same
1513 // reason the four above are: the FFI is `<cstdint>` and `const char*`, so
1514 // a freestanding node can spell every one of them, and a gate here would
1515 // decide whether a node HAS parameters rather than whether it can name
1516 // them.
1517
1526 template <typename T>
1527 T declare_parameter(const char* name, T default_value, const ParameterDescriptor& descriptor);
1528
1532 template <typename T> bool get_parameter_or(const char* name, T& out, T fallback) const;
1533
1537 Result undeclare_parameter(const char* name);
1538
1541 ParameterType get_parameter_type(const char* name) const;
1542
1549 Result get_parameter_types(const char* const* names, ::size_t count, ParameterType* out) const;
1550
1558 Result describe_parameter(const char* name, ParameterDescriptor& out, char* text,
1559 ::size_t text_len) const;
1560
1568 Result list_parameters(const char* prefix, char* out_names, ::size_t name_stride,
1569 ::size_t max_names, ::size_t& count) const;
1570
1575 Result set_parameters_atomically(const ParameterWrite* writes, ::size_t count);
1576
1589 Result add_on_set_parameters_callback(OnSetParametersCallbackType callback, void* context,
1590 OnSetParametersCallbackToken& out_handle);
1591
1593 Result remove_on_set_parameters_callback(OnSetParametersCallbackToken handle);
1594
1595#ifdef NROS_CPP_STD // hosted-family: parameter-interop
1596 // ---- upstream's value-object parameter surface ---------------------------
1597 //
1598 // Each of these dispatches on a `ParameterValue`'s tag to the typed form
1599 // above, so the store, the declared-parameter contract check and the
1600 // per-node keying are still reached through one implementation. Methods
1601 // only; nothing here is a member.
1602
1607 ParameterValue declare_parameter(const char* name, const ParameterValue& default_value);
1609 ParameterValue declare_parameter(const char* name, const ParameterValue& default_value,
1610 const ParameterDescriptor& descriptor);
1615 template <typename D, typename = decltype(&D::floating_point_range)>
1616 ParameterValue declare_parameter(const char* name, const ParameterValue& default_value,
1617 const D& descriptor);
1619 template <typename T, typename D, typename = decltype(&D::floating_point_range)>
1620 T declare_parameter(const char* name, T default_value, const D& descriptor);
1621 ParameterValue declare_parameter(const ::std::string& name,
1622 const ParameterValue& default_value) {
1623 return this->declare_parameter(name.c_str(), default_value);
1624 }
1625 ParameterValue declare_parameter(const ::std::string& name, const ParameterValue& default_value,
1626 const ParameterDescriptor& descriptor) {
1627 return this->declare_parameter(name.c_str(), default_value, descriptor);
1628 }
1629 template <typename D, typename = decltype(&D::floating_point_range)>
1630 ParameterValue declare_parameter(const ::std::string& name, const ParameterValue& default_value,
1631 const D& descriptor) {
1632 return this->declare_parameter(name.c_str(), default_value, descriptor);
1633 }
1634 template <typename T, typename D, typename = decltype(&D::floating_point_range)>
1635 T declare_parameter(const ::std::string& name, T default_value, const D& descriptor) {
1636 return this->declare_parameter(name.c_str(), default_value, descriptor);
1637 }
1638
1641 Parameter get_parameter(const ::std::string& name) const;
1643 bool get_parameter(const char* name, Parameter& out) const;
1644 bool get_parameter(const ::std::string& name, Parameter& out) const {
1645 return this->get_parameter(name.c_str(), out);
1646 }
1648 ::std::vector<Parameter> get_parameters(const ::std::vector<::std::string>& names) const;
1649
1654 struct SetParametersOutcome {
1655 bool successful;
1656 ::std::string reason;
1657 };
1660 SetParametersOutcome set_parameter(const Parameter& parameter);
1662 ::std::vector<SetParametersOutcome> set_parameters(const ::std::vector<Parameter>& parameters);
1663
1672 template <typename F>
1673 node_interfaces::OnSetParametersCallbackHandle::SharedPtr
1674 add_on_set_parameters_callback(F callback);
1676 void
1677 remove_on_set_parameters_callback(const node_interfaces::OnSetParametersCallbackHandle* handle);
1678
1681 node_interfaces::NodeParametersInterface::SharedPtr get_node_parameters_interface() {
1682 return node_interfaces::NodeParametersInterface(this);
1683 }
1684#endif // NROS_CPP_STD
1685
1686#ifdef NROS_CPP_HAS_STD_STRING // hosted-family: string-interop
1690 template <typename T> T declare_parameter(const ::std::string& name, T default_value = T()) {
1691 return this->template declare_parameter<T>(name.c_str(), default_value);
1692 }
1693 template <typename T> bool get_parameter(const ::std::string& name, T& out) const {
1694 return this->template get_parameter<T>(name.c_str(), out);
1695 }
1696 template <typename T> T get_parameter(const ::std::string& name) const {
1697 return this->template get_parameter<T>(name.c_str());
1698 }
1699 template <typename T> Result set_parameter(const ::std::string& name, T value) {
1700 return this->template set_parameter<T>(name.c_str(), value);
1701 }
1702 bool has_parameter(const ::std::string& name) const {
1703 return this->has_parameter(name.c_str());
1704 }
1705 Result undeclare_parameter(const ::std::string& name) {
1706 return this->undeclare_parameter(name.c_str());
1707 }
1708 template <typename T>
1709 T declare_parameter(const ::std::string& name, T default_value,
1710 const ParameterDescriptor& descriptor) {
1711 return this->template declare_parameter<T>(name.c_str(), default_value, descriptor);
1712 }
1713 template <typename T>
1714 bool get_parameter_or(const ::std::string& name, T& out, T fallback) const {
1715 return this->template get_parameter_or<T>(name.c_str(), out, fallback);
1716 }
1717 ParameterType get_parameter_type(const ::std::string& name) const {
1718 return this->get_parameter_type(name.c_str());
1719 }
1720
1732 template <typename T>
1733 Result declare_parameters(const ::std::string& prefix, const ::std::map<::std::string, T>& m) {
1734 for (typename ::std::map<::std::string, T>::const_iterator it = m.begin(); it != m.end();
1735 ++it) {
1736 const ::std::string full = prefix.empty() ? it->first : (prefix + "." + it->first);
1737 const ::nros_cpp_node_t* h = this->ffi_handle();
1738 Result r = ::rclcpp::detail::node_param_declare(h, full.c_str(), it->second);
1739 if (!r.ok() && r.raw() != RCLC_RET_ALREADY_EXISTS) {
1740 // Returned AND latched, so a caller that drops
1741 // the `Result` still does not boot on the code defaults.
1743 return r;
1744 }
1745 }
1746 return Result(RCL_RET_OK);
1747 }
1748#endif // NROS_CPP_HAS_STD_STRING
1749
1769 static Result create(Node& out, const char* name, const char* ns = nullptr) {
1770 if (!out.executor_handle_) {
1772 }
1773
1774 nros_cpp_ret_t ret = nros_cpp_node_create(out.executor_handle_, name, ns, &out.handle_);
1775
1776 if (ret == 0) {
1777 out.initialized_ = true;
1778 }
1779 return Result(ret);
1780 }
1781
1783 const char* get_name() const {
1784 if (!initialized_) return "";
1785 return nros_cpp_node_get_name(&handle_);
1786 }
1787
1789 const char* get_namespace() const {
1790 if (!initialized_) return "";
1791 return nros_cpp_node_get_namespace(&handle_);
1792 }
1793
1808 Result get_fully_qualified_name(char* buf, size_t buf_len, size_t* out_len = nullptr) const {
1809 if (!initialized_) return Result(::rclcpp::ErrorCode::NotInitialized);
1810 return Result(nros_cpp_node_get_fully_qualified_name(&handle_, buf, buf_len, out_len));
1811 }
1812
1830 const char* serialization_format() const {
1831 if (!initialized_) return nullptr;
1832 return nros_cpp_node_get_serialization_format(&handle_);
1833 }
1834
1847 const char* rmw_implementation_identifier() const {
1848 if (!initialized_) return nullptr;
1849 return nros_cpp_node_get_rmw_implementation_identifier(&handle_);
1850 }
1851
1875 ::rclcpp::Logger get_logger() const {
1876 if (!initialized_) return ::rclcpp::Logger("", nullptr);
1877 return ::rclcpp::Logger(nros_cpp_node_get_name(&handle_),
1878 nros_cpp_node_get_logger(&handle_));
1879 }
1880
1891 Clock* get_clock() { return &clock_; }
1893 const Clock* get_clock() const { return &clock_; }
1894
1902 Time now() const { return clock_.now(); }
1903
1905 bool is_valid() const { return initialized_; }
1906
1919 const nros_cpp_node_t* ffi_handle() const { return initialized_ ? &handle_ : nullptr; }
1920
1931 void set_qos_overrides(const nros_cpp_qos_override_t* overrides, size_t len) {
1932 if (initialized_) {
1933 ::nros_cpp_node_set_qos_overrides(&handle_, overrides, len);
1934 }
1935 }
1936
1943 void* executor_handle() const { return initialized_ ? executor_handle_ : nullptr; }
1944
1952 return Result(nros_cpp_register_parameter_services(executor_handle()));
1953 }
1954
1955 // ---- Graph queries ---------------------------------------
1956 //
1957 // rclcpp puts these on the node. `rclcpp::Executor` owns them here because
1958 // one session per image makes the executor the graph's receiver,
1959 // so each method below FORWARDS to the executor this node was
1960 // opened against and nothing else: no state, no loop, no caching, no name
1961 // construction. The behaviour is Rust's and stays there.
1962 //
1963 // The envelope every one of them shares (ADOPT-BOUNDED): they
1964 // report what has been DISCOVERED and never block, so an empty result
1965 // means "nobody seen yet" and never "nobody exists" — poll rather than
1966 // calling once and concluding. `ErrorCode::Unsupported`, which is what a
1967 // backend with no graph at all returns, is a DIFFERENT answer from an
1968 // empty one and must not be collapsed into zero.
1969
1988 Result get_node_names(nros_cpp_node_visit_fn visit, void* ctx) const {
1989 if (!initialized_) return Result(::rclcpp::ErrorCode::NotInitialized);
1990 return Result(nros_cpp_executor_get_node_names(executor_handle_, visit, ctx));
1991 }
1992
2000 Result get_topic_names_and_types(nros_cpp_names_and_types_visit_fn visit, void* ctx) const {
2001 if (!initialized_) return Result(::rclcpp::ErrorCode::NotInitialized);
2002 return Result(nros_cpp_executor_get_topic_names_and_types(executor_handle_, visit, ctx));
2003 }
2004
2008 Result get_service_names_and_types(nros_cpp_names_and_types_visit_fn visit, void* ctx) const {
2009 if (!initialized_) return Result(::rclcpp::ErrorCode::NotInitialized);
2010 return Result(nros_cpp_executor_get_service_names_and_types(executor_handle_, visit, ctx));
2011 }
2012
2021 Result count_publishers(const char* topic_name, size_t* out_count) const {
2022 if (!initialized_) return Result(::rclcpp::ErrorCode::NotInitialized);
2023 return Result(nros_cpp_executor_count_publishers(executor_handle_, topic_name, out_count));
2024 }
2025
2028 Result count_subscribers(const char* topic_name, size_t* out_count) const {
2029 if (!initialized_) return Result(::rclcpp::ErrorCode::NotInitialized);
2030 return Result(nros_cpp_executor_count_subscribers(executor_handle_, topic_name, out_count));
2031 }
2032
2037 Result count_clients(const char* service_name, size_t* out_count) const {
2038 if (!initialized_) return Result(::rclcpp::ErrorCode::NotInitialized);
2039 return Result(nros_cpp_executor_count_clients(executor_handle_, service_name, out_count));
2040 }
2041
2044 Result count_services(const char* service_name, size_t* out_count) const {
2045 if (!initialized_) return Result(::rclcpp::ErrorCode::NotInitialized);
2046 return Result(nros_cpp_executor_count_services(executor_handle_, service_name, out_count));
2047 }
2048
2052 Result get_publisher_names_and_types_by_node(const char* node_name, const char* node_namespace,
2053 nros_cpp_names_and_types_visit_fn visit,
2054 void* ctx) const {
2055 if (!initialized_) return Result(::rclcpp::ErrorCode::NotInitialized);
2056 return Result(nros_cpp_executor_get_publisher_names_and_types_by_node(
2057 executor_handle_, node_name, node_namespace, visit, ctx));
2058 }
2059
2071 const char* node_namespace,
2072 nros_cpp_names_and_types_visit_fn visit,
2073 void* ctx) const {
2074 if (!initialized_) return Result(::rclcpp::ErrorCode::NotInitialized);
2075 return Result(nros_cpp_executor_get_subscription_names_and_types_by_node(
2076 executor_handle_, node_name, node_namespace, visit, ctx));
2077 }
2078
2082 Result get_service_names_and_types_by_node(const char* node_name, const char* node_namespace,
2083 nros_cpp_names_and_types_visit_fn visit,
2084 void* ctx) const {
2085 if (!initialized_) return Result(::rclcpp::ErrorCode::NotInitialized);
2086 return Result(nros_cpp_executor_get_service_names_and_types_by_node(
2087 executor_handle_, node_name, node_namespace, visit, ctx));
2088 }
2089
2093 Result get_client_names_and_types_by_node(const char* node_name, const char* node_namespace,
2094 nros_cpp_names_and_types_visit_fn visit,
2095 void* ctx) const {
2096 if (!initialized_) return Result(::rclcpp::ErrorCode::NotInitialized);
2097 return Result(nros_cpp_executor_get_client_names_and_types_by_node(
2098 executor_handle_, node_name, node_namespace, visit, ctx));
2099 }
2100
2115 Result get_publishers_info_by_topic(const char* topic_name,
2116 nros_cpp_endpoint_info_visit_fn visit, void* ctx) const {
2117 if (!initialized_) return Result(::rclcpp::ErrorCode::NotInitialized);
2118 return Result(nros_cpp_executor_get_publishers_info_by_topic(executor_handle_, topic_name,
2119 visit, ctx));
2120 }
2121
2130 Result get_publishers_info_by_topic(const char* topic_name,
2131 ::rclcpp::TopicEndpointInfoVisitFn visit, void* ctx) const {
2132 if (!initialized_) return Result(::rclcpp::ErrorCode::NotInitialized);
2133 ::rclcpp::detail::EndpointInfoTrampoline tramp{visit, ctx};
2134 return Result(nros_cpp_executor_get_publishers_info_by_topic(
2135 executor_handle_, topic_name, &::rclcpp::detail::EndpointInfoTrampoline::thunk,
2136 &tramp));
2137 }
2138
2144 nros_cpp_endpoint_info_visit_fn visit, void* ctx) const {
2145 if (!initialized_) return Result(::rclcpp::ErrorCode::NotInitialized);
2146 return Result(nros_cpp_executor_get_subscriptions_info_by_topic(executor_handle_,
2147 topic_name, visit, ctx));
2148 }
2149
2154 ::rclcpp::TopicEndpointInfoVisitFn visit,
2155 void* ctx) const {
2156 if (!initialized_) return Result(::rclcpp::ErrorCode::NotInitialized);
2157 ::rclcpp::detail::EndpointInfoTrampoline tramp{visit, ctx};
2158 return Result(nros_cpp_executor_get_subscriptions_info_by_topic(
2159 executor_handle_, topic_name, &::rclcpp::detail::EndpointInfoTrampoline::thunk,
2160 &tramp));
2161 }
2162
2169 template <typename M>
2171 const ::rclcpp::QoS& qos = ::rclcpp::QoS::default_profile());
2172
2185 template <typename M>
2187 const ::rclcpp::QoS& qos, const ::rclcpp::PublisherOptions& options);
2188
2200 template <typename M>
2202 const ::rclcpp::QoS& qos = ::rclcpp::QoS::default_profile());
2203
2219 template <typename M>
2221 const ::rclcpp::QoS& qos,
2222 const ::rclcpp::SubscriptionOptions& options);
2223
2266 template <
2267 typename M, typename F,
2268 typename = typename std::enable_if<std::is_convertible<F, void (*)(const M&)>::value>::type>
2270 const ::rclcpp::QoS& qos, F callback,
2271 const ::rclcpp::SubscriptionOptions& options = {});
2272
2284 template <typename M, typename F,
2285 typename = typename std::enable_if<
2286 std::is_convertible<F, void (*)(const M&, const uint8_t*, size_t)>::value>::type>
2288 const ::rclcpp::QoS& qos, F callback,
2289 const ::rclcpp::SubscriptionOptions& options = {});
2290
2291#if defined(NROS_SAFETY_E2E)
2310 template <typename M, typename F,
2311 typename = typename std::enable_if<std::is_convertible<
2312 F, void (*)(const M&, const ::nros_cpp_integrity_status_t&)>::value>::type>
2313 Result create_subscription_with_safety(::rclcpp::Subscription<M>& out, const char* topic,
2314 const ::rclcpp::QoS& qos, F callback,
2315 const ::rclcpp::SubscriptionOptions& options = {});
2316#endif // NROS_SAFETY_E2E
2317
2332 template <typename S>
2333 Result create_service(::rclcpp::PollService<S>& out, const char* service_name,
2334 const ::rclcpp::QoS& qos = ::rclcpp::QoS::services());
2335
2349 template <typename S, typename F,
2350 typename = typename std::enable_if<std::is_convertible<
2351 F, void (*)(const typename S::Request&, typename S::Response&)>::value>::type>
2352 Result create_service(::rclcpp::Service<S>& out, const char* service_name, F callback,
2353 const ::rclcpp::QoS& qos = ::rclcpp::QoS::services(),
2354 const ::rclcpp::ServiceOptions& options = {});
2355
2371 template <typename S>
2372 Result create_client(::rclcpp::PollClient<S>& out, const char* service_name,
2373 const ::rclcpp::QoS& qos = ::rclcpp::QoS::services());
2374
2386 template <typename S, typename F,
2387 typename = typename std::enable_if<
2388 std::is_convertible<F, void (*)(const typename S::Response&)>::value>::type>
2389 Result create_client(::rclcpp::Client<S>& out, const char* service_name, F callback,
2390 const ::rclcpp::QoS& qos = ::rclcpp::QoS::services(),
2391 const ::rclcpp::ClientOptions& options = {});
2392
2403 template <typename A>
2404 Result create_action_server(::rclcpp_action::Server<A>& out, const char* action_name,
2405 const ::rclcpp::QoS& qos = ::rclcpp::QoS::services(),
2406 const ::rclcpp::ActionServerOptions& options = {});
2407
2414 template <typename A>
2415 Result create_action_client(::rclcpp_action::Client<A>& out, const char* action_name,
2416 const ::rclcpp::QoS& qos = ::rclcpp::QoS::services());
2417
2421 template <typename A>
2423 const char* action_name);
2424
2426 template <typename A>
2428 const char* action_name);
2429
2435 template <typename M>
2437 const ::rclcpp::QoS& qos = ::rclcpp::QoS::default_profile());
2438
2463 Result create_timer(Timer& out, const Clock& clock, uint64_t period_ms,
2464 nros_cpp_timer_callback_t callback, void* context = nullptr) {
2465 if (!initialized_) return Result(::rclcpp::ErrorCode::NotInitialized);
2466 size_t handle_id = 0;
2467 nros_cpp_ret_t ret = nros_cpp_timer_create_on_clock(
2468 executor_handle_, static_cast<uint8_t>(clock.get_clock_type()), period_ms, callback,
2469 context, &handle_id);
2470 if (ret == 0) {
2471 out.executor_ = executor_handle_;
2472 out.handle_id_ = handle_id;
2473 out.initialized_ = true;
2474 }
2475 return Result(ret);
2476 }
2477
2496 template <typename Cb>
2497 ::rclcpp::TimerHandle create_wall_timer(::rclcpp::Duration period, Cb cb,
2498 const ::rclcpp::CallbackGroup* group = nullptr,
2499 bool autostart = true);
2500
2501#ifdef NROS_CPP_HAS_STD_CHRONO // hosted-family: chrono-interop
2505 template <typename Rep, typename Period, typename Cb>
2506 ::rclcpp::TimerHandle create_wall_timer(::std::chrono::duration<Rep, Period> period, Cb cb,
2507 const ::rclcpp::CallbackGroup* group = nullptr,
2508 bool autostart = true);
2509#endif
2510
2522 Result create_wall_timer(Timer& out, uint64_t period_ms, nros_cpp_timer_callback_t callback,
2523 void* context = nullptr) {
2524 if (!initialized_) return Result(::rclcpp::ErrorCode::NotInitialized);
2525 size_t handle_id = 0;
2526 nros_cpp_ret_t ret =
2527 nros_cpp_timer_create(executor_handle_, period_ms, callback, context, &handle_id);
2528 if (ret == 0) {
2529 out.executor_ = executor_handle_;
2530 out.handle_id_ = handle_id;
2531 out.initialized_ = true;
2532 }
2533 return Result(ret);
2534 }
2535
2536 // ==== member-function binding, on the upstream name ====================
2537 //
2538 // `nros::bind_timer<C, &C::m>(node, out, ms, self)` was a FREE function
2539 // with an invented name doing what `create_wall_timer` does. Folding it in
2540 // removes an invention by reusing an upstream name, which is what clause 2
2541 // asks for — and it is the shape a component actually writes, so the verb a
2542 // reader meets first is the one they need.
2543 //
2544 // NO ALLOCATION and NO `std::function`: the member pointer is a TEMPLATE
2545 // PARAMETER, so the trampoline is a capture-less lambda that converts to
2546 // the executor's raw `void(*)(void*)` and `self` is the context. That is
2547 // why this overload, unlike the `std::chrono` one, reaches every target.
2548 //
2549 // What a registration keeps. Every `create_*timer*` and
2550 // `create_guard_condition` form that takes a `C* self` or a `void* context`
2551 // stores that POINTER in the executor entry and hands it back on every
2552 // dispatch; nothing is copied. So:
2553 // * the object it points to must OUTLIVE the registration: until the
2554 // `Timer` is destroyed or cancelled, or the `GuardCondition` destroyed.
2555 // Holding the `Timer` / `GuardCondition` as a member of that same
2556 // object gives this for free (the handle's destructor runs before the
2557 // object's storage goes);
2558 // * the object must NOT MOVE while registered. Moving it (returning it
2559 // by value, storing it in a growing container, `std::move` into
2560 // another) moves the handle member with it but leaves the entry
2561 // holding the OLD address, and the next tick calls into that. Register
2562 // from the object's final home, or re-register after it moves.
2563 // No debug check stands behind this: a move of the owner is invisible to
2564 // the runtime, which sees only the pointer it was given.
2565
2574 template <class C, void (C::*Method)()>
2575 Result create_wall_timer(Timer& out, uint64_t period_ms, C* self) {
2576 return this->create_wall_timer(
2577 out, period_ms, [](void* ctx) { (static_cast<C*>(ctx)->*Method)(); }, self);
2578 }
2579
2588 template <class C, void (C::*Method)()>
2589 Result create_timer(Timer& out, const Clock& clock, uint64_t period_ms, C* self) {
2590 return this->create_timer(
2591 out, clock, period_ms, [](void* ctx) { (static_cast<C*>(ctx)->*Method)(); }, self);
2592 }
2593
2597 template <class C, void (C::*Method)()>
2598 Result create_timer_in_group(const ::rclcpp::CallbackGroup& group, Timer& out,
2599 uint64_t period_ms, C* self) {
2600 return this->create_timer_in_group(
2601 group, out, period_ms, [](void* ctx) { (static_cast<C*>(ctx)->*Method)(); }, self);
2602 }
2603
2613 Result create_timer_oneshot(Timer& out, uint64_t delay_ms, nros_cpp_timer_callback_t callback,
2614 void* context = nullptr) {
2615 if (!initialized_) return Result(::rclcpp::ErrorCode::NotInitialized);
2616 size_t handle_id = 0;
2617 nros_cpp_ret_t ret = nros_cpp_timer_create_oneshot(executor_handle_, delay_ms, callback,
2618 context, &handle_id);
2619 if (ret == 0) {
2620 out.executor_ = executor_handle_;
2621 out.handle_id_ = handle_id;
2622 out.initialized_ = true;
2623 }
2624 return Result(ret);
2625 }
2626
2627 // -- Callback-group API ------------------------------------
2628
2644 ::rclcpp::CallbackGroup create_callback_group(const char* name) {
2645 if (!::rclcpp::detail::admit_callback_group(name)) {
2646 const ::rclcpp::detail::DeclaredCallbackGroups* g =
2647 ::rclcpp::detail::declared_callback_groups_scope();
2648 const char* list = (g != nullptr) ? g->list : nullptr;
2649 int len = 0;
2650 while (name[len] != '\0')
2651 ++len;
2652 ::rclcpp::detail::report_callback_group_mismatch(this->get_name(), "created", name, len,
2653 list);
2654 this->set_error("create_callback_group: the group is not in this registration's "
2655 "CALLBACK_GROUPS",
2656 ::rclcpp::detail::DECLARED_CALLBACK_GROUP_MISMATCH);
2657 }
2658 return ::rclcpp::CallbackGroup{name};
2659 }
2660
2668 ::rclcpp::CallbackGroup::SharedPtr
2669 create_callback_group(::rclcpp::CallbackGroupType type,
2670 bool automatically_add_to_executor_with_node = true) {
2671 (void)automatically_add_to_executor_with_node;
2672 return ::rclcpp::CallbackGroup::SharedPtr(type);
2673 }
2674
2687 Result create_timer_in_group(const ::rclcpp::CallbackGroup& group, Timer& out,
2688 uint64_t period_ms, nros_cpp_timer_callback_t callback,
2689 void* context = nullptr) {
2690 if (!initialized_) return Result(::rclcpp::ErrorCode::NotInitialized);
2691 size_t handle_id = 0;
2692 nros_cpp_ret_t ret = nros_cpp_timer_create_in_group(
2693 executor_handle_, &handle_, period_ms, callback, context, group.get_name(), &handle_id);
2694 if (ret == 0) {
2695 out.executor_ = executor_handle_;
2696 out.handle_id_ = handle_id;
2697 out.initialized_ = true;
2698 }
2699 return Result(ret);
2700 }
2701
2721 template <
2722 typename M, typename F,
2723 typename = typename std::enable_if<std::is_convertible<F, void (*)(const M&)>::value>::type>
2724 Result create_subscription_in_group(const ::rclcpp::CallbackGroup& group,
2725 ::rclcpp::Subscription<M>& out, const char* topic,
2726 const ::rclcpp::QoS& qos, F callback,
2727 const ::rclcpp::SubscriptionOptions& options = {});
2728
2739 template <typename M>
2740 Result create_publisher_in_group(const ::rclcpp::CallbackGroup& /* group */,
2741 ::rclcpp::Publisher<M>& out, const char* topic,
2742 const ::rclcpp::QoS& qos = ::rclcpp::QoS::default_profile()) {
2743 return create_publisher<M>(out, topic, qos);
2744 }
2745
2757 Result create_guard_condition(::rclcpp::GuardCondition& out, nros_cpp_guard_callback_t callback,
2758 void* context = nullptr) {
2759 if (!initialized_) return Result(::rclcpp::ErrorCode::NotInitialized);
2760 size_t handle_id = 0;
2761 nros_cpp_ret_t ret = nros_cpp_guard_condition_create(executor_handle_, callback, context,
2762 out.storage_, &handle_id);
2763 if (ret == 0) {
2764 out.initialized_ = true;
2765 out.executor_ = executor_handle_;
2766 out.handle_id_ = handle_id;
2767 }
2768 return Result(ret);
2769 }
2770
2771 // ==== the ours-only family, under `_in` names ==========================
2772 //
2773 // These came off `nros::ComponentNode`. Every one of them is spelled with
2774 // an `_in` SUFFIX rather than upstream's bare verb, and the rename is the
2775 // whole point of the item.
2776 //
2777 // `ComponentNode::create_publisher<M>(const char*, const QoS&)` returned by
2778 // value and reported failure through the `ok()` latch; upstream's
2779 // `create_publisher<M>(const std::string&, …)` returns a `shared_ptr` and
2780 // throws. As OVERLOADS on one type those differ only in SIGNATURE, and C++
2781 // resolves a signature-only difference SILENTLY. Measured on the merged
2782 // shape before the rename, with gcc 13:
2783 //
2784 // create_publisher<M>("chatter", 10) -> UPSTREAM (shared_ptr)
2785 // create_publisher<M>("chatter", rclcpp::QoS(10)) -> OURS (by value),
2786 // accepted with only
2787 // a -Wextra-ish note
2788 // that ISO calls it
2789 // ambiguous
2790 //
2791 // So a ported file compiles either way and gets a different type, lifetime
2792 // and failure channel depending on which spelling of the depth it used.
2793 // That is exactly the compile-and-differ the adoption rule forbids, and the merge is
2794 // what would have manufactured it. The fix is a different NAME, not a
2795 // cleverer signature — the third application of that rule in this campaign,
2796 // after the reordered C node initialiser and the clock-taking C timer verb.
2797 //
2798 // `tests/compile/one_node_type_ours_only_names.cpp` pins both halves: that
2799 // the ported spellings reach upstream's overload on the real type, and
2800 // (the negative control) that the pre-rename shape bound the wrong one.
2801
2807 template <typename M>
2809 create_publisher_in(const char* topic,
2810 const ::rclcpp::QoS& qos = ::rclcpp::QoS::default_profile()) {
2812 Result r = this->create_publisher(pub, topic, qos);
2813 if (!r.ok()) {
2814 this->set_error("create_publisher_in", r.raw());
2815 }
2816 return pub;
2817 }
2818
2832 template <typename M, class C, void (C::*Method)(const M& msg)>
2833 void create_subscription_in(const char* topic,
2834 const ::rclcpp::QoS& qos = ::rclcpp::QoS::default_profile());
2835
2838 template <typename M, class C, void (C::*Method)(const M& msg)>
2839 void create_subscription_in_group(const ::rclcpp::CallbackGroup& group, const char* topic,
2840 const ::rclcpp::QoS& qos = ::rclcpp::QoS::default_profile());
2841
2858 bool check_declared_depth(const char* type_name, const char* topic, const ::rclcpp::QoS& qos) {
2859 const int declared = ::rclcpp::declared_depth(type_name, topic);
2860 // Nobody declared this endpoint. Not an error: the image has not opted
2861 // in, and anything sizing from depth refuses rather than defaulting.
2862 if (declared == ::rclcpp::DECLARED_DEPTH_UNDECLARED) {
2863 return true;
2864 }
2865 if (declared == qos.depth()) {
2866 return true;
2867 }
2868 // The two NUMBERS and the TOPIC go out first: `set_error` records one
2869 // `const char*`, which cannot carry them.
2871 qos.depth());
2872 this->set_error(
2873 "create_subscription_in: ::rclcpp::QoS depth disagrees with the depth declared for "
2874 "this topic in the contract sidecar. Depth multiplies the arena, so the "
2875 "declaration and the code must state one number, not two.",
2877 return false;
2878 }
2879
2891 bool check_declared_qos(const char* type_name, const char* topic, const ::rclcpp::QoS& qos) {
2892 if (!this->check_declared_depth(type_name, topic, qos)) {
2893 return false;
2894 }
2895 const int rel = ::rclcpp::declared_reliability(type_name, topic);
2896 if (rel != ::rclcpp::DECLARED_POLICY_UNDECLARED &&
2897 rel != static_cast<int>(qos.reliability())) {
2899 this->get_name(), topic, "reliability",
2902 static_cast<int>(qos.reliability())));
2903 this->set_error("create_subscription_in: ::rclcpp::QoS reliability disagrees with the "
2904 "reliability declared for this topic in the contract sidecar.",
2906 return false;
2907 }
2908 const int dur = ::rclcpp::declared_durability(type_name, topic);
2909 if (dur != ::rclcpp::DECLARED_POLICY_UNDECLARED &&
2910 dur != static_cast<int>(qos.durability())) {
2912 this->get_name(), topic, "durability",
2914 ::rclcpp::detail::declared_durability_spelling(static_cast<int>(qos.durability())));
2915 this->set_error("create_subscription_in: ::rclcpp::QoS durability disagrees with the "
2916 "durability declared for this topic in the contract sidecar.",
2918 return false;
2919 }
2920 return true;
2921 }
2922
2941 bool check_declared_param(const char* name, int passed_type) {
2942 const char* ns = this->get_namespace();
2943 const char* nn = this->get_name();
2944 if (name == nullptr || nn == nullptr) {
2945 return true;
2946 }
2947 const ::rclcpp::declared_params::Node* declaring =
2948 ::rclcpp::declared_param_node((ns != nullptr) ? ns : "", nn);
2949 if (declaring == nullptr || ::rclcpp::declared_param_exempt(name)) {
2950 return true;
2951 }
2952 const int declared = ::rclcpp::declared_param_type(declaring, name);
2953 if (declared == passed_type) {
2954 return true;
2955 }
2956 ::rclcpp::detail::report_declared_param_mismatch(declaring->fqn, name, declaring->contract,
2957 declared, passed_type);
2958 this->set_error("declare_parameter: the code does not declare this parameter the way "
2959 "its contract does (see the line above for the node, the parameter and "
2960 "the contract). The parameter store is sized from the contract's "
2961 "`params:`, so the two must state one name and one type.",
2963 return false;
2964 }
2965
2973 void set_error(const char* what, int32_t code) {
2974 // Relaxed read for the first-failure guard: set_error runs during
2975 // construction, on the constructing thread, never concurrently with a
2976 // reader.
2977 if (!__atomic_load_n(&has_error_, __ATOMIC_RELAXED)) {
2978 error_what_ = what;
2979 error_code_ = code;
2980 // RELEASE publishes the two plain writes above: a reader that
2981 // acquire-observes has_error_ == true is guaranteed to see them.
2982 __atomic_store_n(&has_error_, true, __ATOMIC_RELEASE);
2984 }
2985 }
2986
2995 if (initialized_) {
2996 nros_cpp_node_destroy(&handle_);
2997 initialized_ = false;
2998 }
2999 }
3000
3001 // Move semantics (non-copyable)
3002 Node(Node&& other)
3003 : handle_(other.handle_), initialized_(other.initialized_),
3004 executor_handle_(other.executor_handle_), clock_(other.clock_), options_(other.options_),
3005 // The latch travels with the node: a moved-from node's failure is
3006 // still this node's failure, and the entry checks `ok()` on whichever
3007 // object it ended up holding.
3008 has_error_(other.has_error_), error_what_(other.error_what_),
3009 error_code_(other.error_code_) {
3010 other.initialized_ = false;
3011 other.executor_handle_ = nullptr;
3012 }
3013
3014 Node& operator=(Node&& other) {
3015 if (this != &other) {
3016 if (initialized_) {
3017 nros_cpp_node_destroy(&handle_);
3018 }
3019 handle_ = other.handle_;
3020 initialized_ = other.initialized_;
3021 executor_handle_ = other.executor_handle_;
3022 clock_ = other.clock_;
3023 options_ = other.options_;
3024 has_error_ = other.has_error_;
3025 error_what_ = other.error_what_;
3026 error_code_ = other.error_code_;
3027 other.initialized_ = false;
3028 other.executor_handle_ = nullptr;
3029 }
3030 return *this;
3031 }
3032
3033 private:
3034 Node(const Node&) = delete;
3035 Node& operator=(const Node&) = delete;
3036
3047 template <typename S>
3048 Result register_service_(::rclcpp::Service<S>& out, const char* service_name,
3049 bool (*trampoline)(const uint8_t*, size_t, uint8_t*, size_t, size_t*,
3050 void*),
3051 void* context, const ::rclcpp::QoS& qos,
3052 const ::rclcpp::ServiceOptions& options, const void* capture = nullptr,
3053 size_t capture_len = 0, void (*capture_drop)(void*) = nullptr);
3054
3059 template <typename S>
3060 Result register_service_(::rclcpp::Service<S>& out, const char* service_name,
3061 bool (*trampoline)(const uint8_t*, size_t, ::rmw_request_id_t*,
3062 uint8_t*, size_t, size_t*, void*),
3063 void* context, const ::rclcpp::QoS& qos,
3064 const ::rclcpp::ServiceOptions& options, const void* capture = nullptr,
3065 size_t capture_len = 0, void (*capture_drop)(void*) = nullptr);
3066
3069 template <typename S>
3070 Result finish_register_service_(::rclcpp::Service<S>& out, const char* service_name,
3071 nros_cpp_ret_t ret, size_t handle);
3072
3078 template <typename S, typename F>
3079 Result register_hosted_service_(::rclcpp::Service<S>& out, const char* name, F callback,
3080 const ::rclcpp::QoS& qos,
3081 ::rclcpp::tr::integral_constant<int, 0>);
3082 template <typename S, typename F>
3083 Result register_hosted_service_(::rclcpp::Service<S>& out, const char* name, F callback,
3084 const ::rclcpp::QoS& qos,
3085 ::rclcpp::tr::integral_constant<int, 1>);
3086
3092 void apply_options_(const ::rclcpp::NodeOptions& options) {
3093 options_ = options;
3094 // The per-node opt-out C's `notify_changed_over_dds =
3095 // false` reaches. UNSUPPORTED on a build with no parameter services,
3096 // where no node publishes the topic: nothing to switch off.
3097 if (!options.start_parameter_event_publisher() && initialized_) {
3098 (void)nros_cpp_node_disable_parameter_events(&handle_);
3099 }
3100 Clock chosen(options.clock_type());
3101 if (!chosen.is_valid()) {
3102 this->set_error("NodeOptions::clock_type (not a clock)",
3103 static_cast<int32_t>(::rclcpp::ErrorCode::InvalidArgument));
3104 return;
3105 }
3106 clock_ = chosen;
3107 }
3108
3109 nros_cpp_node_t handle_;
3110 bool initialized_;
3111 void* executor_handle_; // Set by rclcpp::init() via friendship
3112 // The node's own clock, ROS time as in rclcpp. Constructing
3113 // it touches no platform service (only a steady clock records an epoch),
3114 // so a Node in static storage stays as cheap to create as it was.
3115 Clock clock_;
3116 // The options the node was constructed with, for
3117 // `get_node_options()`; `clock_` above is built from `clock_type()`.
3118 // Unconditional (one enum), so the layout stays probe-independent.
3119 ::rclcpp::NodeOptions options_;
3120 // `void* hosted_` and its lazy `hosted()` accessor are gone
3121 // with ~~`detail::NodeHosted`~~ (see there): the block's last member was an
3122 // empty `NodeOptions`. `sizeof(Node)` loses that pointer on EVERY target,
3123 // so the layout stays probe-independent.
3124
3125 // The error latch, 24 UNCONDITIONAL bytes on every node.
3126 //
3127 // These did NOT go behind the old `hosted_` block, and the decision was deliberate rather
3128 // than an oversight the layout rule missed. This is the error channel a
3129 // `-fno-exceptions` target has INSTEAD of a throwing constructor: the
3130 // boot-halt mechanism (`NanoRosEntityInventory.cmake`) is
3131 // exactly what a freestanding image needs, and a latch reachable only on a
3132 // hosted target would leave the firmware case — the one that cannot throw —
3133 // with no channel at all. So every node pays 24 bytes, which is the price
3134 // of one node type whose failure story works on both.
3135 //
3136 // Inverted flag: the HEALTHY value is the zero-init default,
3137 // so a cross-core reader sees "ok" without waiting for any store. Accessed
3138 // via __atomic builtins (release in set_error, acquire in ok()/error_*) —
3139 // NOT `<atomic>`, which the Zephyr `-nostdinc++` minimal libcpp may lack
3140 // (a known class). All three fields are zero-init-safe.
3141 bool has_error_ = false;
3142 const char* error_what_ = nullptr;
3143 int32_t error_code_ = 0;
3144
3145 // The class moved to `rclcpp::` while its friends were still
3146 // `nros::` free functions, so each friend is QUALIFIED. The friends
3147 // are in `rclcpp::` now too; the qualified form still names exactly
3148 // the declarations at the top of this header.
3149 //
3150 // The declarator-id is PARENTHESIZED, and that is not style. A
3151 // nested-name-specifier is parsed greedily, so `friend Result ::rclcpp::init`
3152 // reads as `Result::rclcpp::init` and fails with `'rclcpp' in 'using Result ='
3153 // does not name a type` — a diagnostic that names neither the friend nor
3154 // the namespace. `(::rclcpp::init)` closes the return type first.
3155 friend class ::rclcpp::Executor;
3156 friend class ::rclcpp::NodeBuilder;
3157 friend Result(::rclcpp::init_in)(const char* locator, uint8_t domain_id);
3158 friend Result(::rclcpp::init_in)(const char* locator, uint8_t domain_id,
3159 const char* session_name);
3160 // The namespaced overload. A friend declaration names ONE
3161 // signature, so an overload that reaches `global_storage()` needs its own
3162 // line; without it the new body compiles everywhere the class is not
3163 // instantiated and fails only where a TU actually calls it.
3164 friend Result(::rclcpp::init_in)(const char* locator, uint8_t domain_id,
3165 const char* session_name, const char* node_namespace);
3166 friend Result(::rclcpp::init_with_rmw)(const char* rmw, const char* locator, uint8_t domain_id,
3167 const char* session_name);
3169 friend bool(::rclcpp::ok)();
3170 friend Result(::rclcpp::create_node)(Node& out, const char* name, const char* ns);
3171 friend Result(::rclcpp::create_node_on)(Node& out, void* executor_handle, const char* name,
3172 const char* ns);
3173 friend Result(::rclcpp::spin_once)(int32_t timeout_ms);
3175 friend Result(::rclcpp::spin_in)(uint32_t duration_ms, int32_t poll_ms);
3177
3178 // Global executor inline storage for init/shutdown free functions.
3179 //
3180 // Use a template-static-member trick instead of a function-local static.
3181 // Function-local statics need __cxa_guard_acquire/release on first-call
3182 // initialisation; on NuttX the resulting guard logic returns NULL for
3183 // the storage pointer (observed empirically with LTO on armv7a-nuttx-eabihf,
3184 // even with constant-initialisation `= {}`). A template static member is
3185 // emitted into .bss like a file-scope variable and gets COMDAT-folded by
3186 // the linker, sidestepping the guarded-init path entirely.
3187 template <int = 0> struct GlobalStorageHolder {
3188 alignas(8) static uint8_t storage[NROS_CPP_EXECUTOR_STORAGE_SIZE];
3189 };
3190 static uint8_t* global_storage() { return GlobalStorageHolder<>::storage; }
3191
3211 static bool global_initialized() {
3212 return nros_cpp_context_is_live(GlobalStorageHolder<>::storage);
3213 }
3214};
3215
3216// Out-of-class definitions for Node::GlobalStorageHolder<> — the template
3217// machinery means these get emitted as COMDAT symbols, so multiple TUs
3218// including this header all collapse to a single .bss allocation.
3219template <int N>
3220alignas(8) uint8_t Node::GlobalStorageHolder<N>::storage[NROS_CPP_EXECUTOR_STORAGE_SIZE] = {};
3221
3222} // namespace rclcpp
3223
3224namespace rclcpp {
3225
3226// ==== the timer pool, as a TEMPLATE PARAMETER ===============================
3227//
3228// `ComponentNode` carried `Timer timers_[NROS_COMPONENT_MAX_TIMERS]` — 192
3229// unconditional bytes at the default depth of 8. Merging that onto `Node` would
3230// have charged every node in the tree for a pool most of them never touch, on
3231// targets chosen for having no memory to spare.
3232//
3233// So the depth is a template parameter and the DEFAULT IS ZERO: `Node` itself
3234// carries no pool and is unchanged in size by this half of the merge. A node
3235// that wants the storage-free timer verbs derives `NodeWithTimers<N>` and names
3236// the depth it needs.
3237//
3238// Why a derived template and not `template <size_t N> class Node` — measured,
3239// not preferred. `Node` has to stay ONE non-template type
3240// (`tests/compile/one_node_type.cpp`); 218 in-tree sites spell `Node` with
3241// no argument list, which a class template with a defaulted parameter does not
3242// permit; and every `Node&` parameter in the tree — `create_node(Node&)`,
3243// `Executor`, `spin` — would otherwise accept only ONE depth, so a component
3244// with a pool would not be a node the executor could take. Deriving keeps the
3245// IS-A that `ComponentNode` never had (it WRAPPED a node, which is the reason
3246// this merge exists at all) while keeping the bytes opt-in.
3247//
3248// `NodeWithTimers` is NOT a second node type. It adds storage and two verbs;
3249// it declares no identity, and every one of its instances IS-A `Node`.
3250
3254#ifndef NROS_COMPONENT_MAX_TIMERS
3255#define NROS_COMPONENT_MAX_TIMERS 8
3256#endif
3264#if NROS_COMPONENT_MAX_TIMERS < 1
3265// A zero here sizes a C array to nothing.
3266#error "NROS_COMPONENT_MAX_TIMERS must be >= 1: it sizes a C array"
3267#endif
3268
3288template <::size_t MaxTimers = NROS_COMPONENT_MAX_TIMERS>
3289class NodeWithTimers : public ::rclcpp::Node {
3290 static_assert(MaxTimers >= 1,
3291 "NodeWithTimers<0> has no pool -- derive ::rclcpp::Node directly, or use "
3292 "the out-ref create_wall_timer(Timer&, ...) family");
3293
3294 public:
3295 using ::rclcpp::Node::Node;
3296
3303 template <class C, void (C::*Method)()> void create_wall_timer_in(uint64_t period_ms) {
3304 Timer* slot = this->next_timer_slot("create_wall_timer_in");
3305 if (slot == nullptr) return;
3306 Result r = this->Node::template create_wall_timer<C, Method>(*slot, period_ms,
3307 static_cast<C*>(this));
3308 if (!r.ok()) {
3309 this->set_error("create_wall_timer_in", r.raw());
3310 return;
3311 }
3312 ++timer_count_;
3313 }
3314
3316 void create_wall_timer_in(uint64_t period_ms, nros_cpp_timer_callback_t callback,
3317 void* context = nullptr) {
3318 Timer* slot = this->next_timer_slot("create_wall_timer_in");
3319 if (slot == nullptr) return;
3320 Result r = this->Node::create_wall_timer(*slot, period_ms, callback, context);
3321 if (!r.ok()) {
3322 this->set_error("create_wall_timer_in", r.raw());
3323 return;
3324 }
3325 ++timer_count_;
3326 }
3327
3330 template <class C, void (C::*Method)()>
3331 void create_timer_in_group(const CallbackGroup& group, uint64_t period_ms) {
3332 Timer* slot = this->next_timer_slot("create_timer_in_group");
3333 if (slot == nullptr) return;
3334 Result r = this->Node::template create_timer_in_group<C, Method>(group, *slot, period_ms,
3335 static_cast<C*>(this));
3336 if (!r.ok()) {
3337 this->set_error("create_timer_in_group", r.raw());
3338 return;
3339 }
3340 ++timer_count_;
3341 }
3342
3344 void create_timer_in_group(const CallbackGroup& group, uint64_t period_ms,
3345 nros_cpp_timer_callback_t callback, void* context = nullptr) {
3346 Timer* slot = this->next_timer_slot("create_timer_in_group");
3347 if (slot == nullptr) return;
3348 Result r = this->Node::create_timer_in_group(group, *slot, period_ms, callback, context);
3349 if (!r.ok()) {
3350 this->set_error("create_timer_in_group", r.raw());
3351 return;
3352 }
3353 ++timer_count_;
3354 }
3355
3356 // The out-ref forms on `Node` share these names; bring them in so a derived
3357 // node can still spell `create_timer_in_group(group, my_timer_, 100, cb, ctx)`
3358 // without the pool overloads hiding the base by name lookup.
3361
3362 private:
3365 Timer* next_timer_slot(const char* what) {
3366 if (timer_count_ >= MaxTimers) {
3367 this->set_error(what, -1);
3368 return nullptr;
3369 }
3370 return &timers_[timer_count_];
3371 }
3372
3373 Timer timers_[MaxTimers];
3374 ::size_t timer_count_ = 0;
3375};
3376
3377// -- Free function implementations --
3378
3379inline Result init_in(const char* locator, uint8_t domain_id) {
3380 // Forward RAW to the 3-arg overload, which resolves the whole
3381 // ladder (baked `NROS_ENTRY_LOCATOR`/`NROS_ENTRY_DOMAIN_ID` rungs, hosted
3382 // default, then the env overlay in the Rust resolver behind `nros_cpp_init`).
3383 // This overload previously re-resolved the locator rung itself — a second,
3384 // partial copy of the same ladder (it never applied `NROS_ENTRY_DOMAIN_ID`),
3385 // duplicating what the 3-arg already does. Unified default session
3386 // name "node".
3387 return init_in(locator, domain_id, "node");
3388}
3389
3390inline Result init_in(const char* locator, uint8_t domain_id, const char* session_name) {
3391 // Forward RAW to the 4-arg overload, exactly as the 2-arg
3392 // forwards here: one ladder, one body. `nullptr` is "this
3393 // image declares no namespace", which is what every caller of this
3394 // overload has always meant.
3395 return init_in(locator, domain_id, session_name, nullptr);
3396}
3397
3398inline Result init_in(const char* locator, uint8_t domain_id, const char* session_name,
3399 const char* node_namespace) {
3400 // NROS_CPP_RET_INVALID_ARGUMENT = -3 (defined in nros_cpp_ffi.h
3401 // which isn't included from this header — duplicate the value
3402 // inline; generated header is the source of truth).
3403 if (session_name == nullptr) {
3404 return Result(-3);
3405 }
3406#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0) // hosted-family: hosted-console
3407 // Issue #39 — apply the same `$NROS_LOCATOR` / `$ROS_DOMAIN_ID` env
3408 // fallback as the 2-arg `init()` when `locator` is null / `domain_id` is
3409 // 0. This makes `init_in(argc, argv)` (which delegates here with a
3410 // null locator) honor the env overlay instead of passing a null locator
3411 // to the backend → TransportError / degraded session.
3412 // The hard local default is GONE entirely (it was a zenoh
3413 // fact in an RMW-blind header); the backend now supplies it.
3414 // The env overlay (NROS_LOCATOR / ROS_DOMAIN_ID /
3415 // NROS_NODE_NAME) moved into the shared Rust resolver behind
3416 // nros_cpp_init (precedence model A: hosted env > this baked chain >
3417 // compiled default; malformed or >232 ROS_DOMAIN_ID is an init ERROR,
3418 // never a silent domain 0). This header only assembles the baked rung.
3419#endif
3420 // Compile-time connect defaults, so ONE portable source
3421 // works native + embedded. `NROS_ENTRY_LOCATOR` / `NROS_ENTRY_DOMAIN_ID`
3422 // are target compile definitions the embedded board gate bakes
3423 // (NanoRosEntry.cmake; Kconfig on Zephyr via <rclcpp/detail/main.hpp>), and
3424 // on a `linux` image the stated values; `""` / 0 when nothing
3425 // is stated. Precedence: env (hosted,
3426 // applied in the Rust resolver) > explicit arg > baked macro > default.
3427#ifdef NROS_ENTRY_LOCATOR
3428 if (locator == nullptr) {
3429 locator = NROS_ENTRY_LOCATOR;
3430 }
3431#endif
3432 // `""` is "not stated" (`<rclc/detail/entry_config.h>`
3433 // defines NROS_ENTRY_LOCATOR as `""` when nothing is baked, so it is
3434 // always defined), exactly as `<rclc/detail/baked_rmw.h>` reads it. Passed
3435 // on, it would arrive as a baked `Some("")` and the boot report would name
3436 // an unstated locator `baked`.
3437 if (locator != nullptr && locator[0] == '\0') {
3438 locator = nullptr;
3439 }
3440 // Only the UNSET sentinel (0) folds the baked macro in; an explicit
3441 // argument — including kDomainIdExplicitZero (255) for a literal
3442 // domain 0 — passes through untouched. The `_C_ABI` spelling carries a
3443 // STATED 0 as that explicit zero.
3444#if defined(NROS_ENTRY_DOMAIN_ID_C_ABI)
3445 if (domain_id == 0) {
3446 domain_id = static_cast<uint8_t>(NROS_ENTRY_DOMAIN_ID_C_ABI);
3447 }
3448#elif defined(NROS_ENTRY_DOMAIN_ID)
3449 if (domain_id == 0) {
3450 domain_id = static_cast<uint8_t>(NROS_ENTRY_DOMAIN_ID);
3451 }
3452#endif
3453 // There is deliberately NO hosted "tcp/127.0.0.1:7447"
3454 // fallback here. That value is a *zenoh* fact and this header is
3455 // RMW-blind; a cyclonedds or xrce build must not carry it. A null
3456 // locator flows through `nros_cpp_init` (→ `None` → the boot-config
3457 // resolver's empty bottom rung) to whichever backend is linked, and
3458 // that backend applies its own default (zenoh:
3459 // `nros_rmw_zenoh::DEFAULT_LOCATOR`; xrce: its agent default;
3460 // cyclonedds: ignores the locator). Precedence is otherwise unchanged:
3461 // hosted env > explicit arg > baked macro > backend default.
3462
3463 // RMW-blind init. The selected
3464 // backend registers itself before `main` via its `.init_array` ctor,
3465 // and `nros_cpp_init` additionally calls the weak
3466 // `nros_app_register_backends()` board-override hook for RTOS targets
3467 // where `.init_array` ctors do not run. No `#ifdef NROS_RMW_*` chain
3468 // here, no CMake-driven fan-out — the user's
3469 // `target_link_libraries(... NanoRos::Rmw::<name>)` is the only
3470 // selector.
3471 // The RMW selector's BAKED rung. `NROS_ENTRY_RMW`
3472 // is a target compile definition the entry gate bakes, exactly like
3473 // `NROS_ENTRY_LOCATOR` / `NROS_ENTRY_DOMAIN_ID` above; undefined means the
3474 // image names no backend and the registry must contain exactly one.
3475 //
3476 // This is what the paragraph above could not express. "The user's
3477 // `target_link_libraries(... NanoRos::Rmw::<name>)` is the only selector"
3478 // is true of the LINK and false of the REGISTRY: a hosted archive
3479 // registers whatever it carries, from `.init_array`, before `main`.
3480#ifdef NROS_ENTRY_RMW
3481 const char* rmw = NROS_ENTRY_RMW;
3482#else
3483 const char* rmw = nullptr;
3484#endif
3485 // The namespace travels as the BAKED rung, like `rmw` above
3486 // and `session_name` beside it. `nullptr` reaches `nros_cpp_init_rmw`'s
3487 // own "unset" arm, which is the root; an EMPTY string is normalised here
3488 // rather than there, because a bake macro that did not resolve expands to
3489 // `""` and treating that as "the empty namespace" would be a configured
3490 // value where the image stated nothing (the same reasoning 1050 applied to
3491 // an empty `rmw` selector).
3492 if (node_namespace != nullptr && node_namespace[0] == '\0') {
3493 node_namespace = nullptr;
3494 }
3495 // The one refusal every executor-storage path takes: the
3496 // linked library says whether this TU's `NROS_CPP_EXECUTOR_STORAGE_SIZE`
3497 // (the header it was compiled against — on NuttX the committed snapshot)
3498 // is enough for the executor it builds. Refused rather than overrun.
3499 {
3500 nros_cpp_ret_t chk =
3501 nros_cpp_executor_storage_check(::rclcpp::Node::global_storage(),
3502 sizeof(::rclcpp::Node::GlobalStorageHolder<>::storage));
3503 if (chk != 0) {
3504 return Result(chk);
3505 }
3506 }
3507 nros_cpp_ret_t ret = nros_cpp_init_rmw(rmw, locator, domain_id, session_name, node_namespace,
3508 ::rclcpp::Node::global_storage());
3509 // No flag to set: `nros_cpp_init_rmw` stamps the context tag, and
3510 // `global_initialized()` reads it.
3511 return Result(ret);
3512}
3513
3514inline Result init_with_rmw(const char* rmw, const char* locator, uint8_t domain_id,
3515 const char* session_name) {
3516 // NROS_CPP_RET_INVALID_ARGUMENT = -3; see the 3-arg overload for why the
3517 // value is duplicated here rather than included.
3518 if (session_name == nullptr) {
3519 return Result(-3);
3520 }
3521#ifdef NROS_ENTRY_LOCATOR
3522 if (locator == nullptr) {
3523 locator = NROS_ENTRY_LOCATOR;
3524 }
3525#endif
3526#ifdef NROS_ENTRY_DOMAIN_ID
3527 if (domain_id == 0) {
3528 domain_id = static_cast<uint8_t>(NROS_ENTRY_DOMAIN_ID);
3529 }
3530#endif
3531 // No `NROS_ENTRY_RMW` fallback here: an explicit argument that resolves to
3532 // nullptr is the caller saying "no selector", and quietly substituting the
3533 // bake would make this overload unable to express that.
3534 // The one refusal every executor-storage path takes: the
3535 // linked library says whether this TU's `NROS_CPP_EXECUTOR_STORAGE_SIZE`
3536 // (the header it was compiled against — on NuttX the committed snapshot)
3537 // is enough for the executor it builds. Refused rather than overrun.
3538 {
3539 nros_cpp_ret_t chk =
3540 nros_cpp_executor_storage_check(::rclcpp::Node::global_storage(),
3541 sizeof(::rclcpp::Node::GlobalStorageHolder<>::storage));
3542 if (chk != 0) {
3543 return Result(chk);
3544 }
3545 }
3546 nros_cpp_ret_t ret = nros_cpp_init_rmw(rmw, locator, domain_id, session_name, nullptr,
3547 ::rclcpp::Node::global_storage());
3548 // No flag to set: `nros_cpp_init_rmw` stamps the context tag, and
3549 // `global_initialized()` reads it.
3550 return Result(ret);
3551}
3552
3554 if (!::rclcpp::Node::global_initialized()) {
3555 return Result::success();
3556 }
3557 // No flag to clear: `nros_cpp_fini` unstamps the tag, which is what
3558 // `global_initialized()` reads. One owner of the fact.
3559 return Result(nros_cpp_fini(::rclcpp::Node::global_storage()));
3560}
3561
3562inline void* global_handle() {
3563 if (!::rclcpp::Node::global_initialized()) return nullptr;
3564 return ::rclcpp::Node::global_storage();
3565}
3566
3567namespace detail {
3572inline int32_t apply_ros_args(void* executor, int argc, char const* const* argv) {
3573 // No `--ros-args` scope means nothing for the parser to read; skipping the
3574 // call keeps a plain `main(argc, argv)` off the FFI entirely.
3575 bool scoped = false;
3576 for (int i = 0; argv != nullptr && i < argc && !scoped; ++i) {
3577 const char* a = argv[i];
3578 const char* want = "--ros-args";
3579 while (a != nullptr && *a != '\0' && *a == *want) {
3580 ++a;
3581 ++want;
3582 }
3583 scoped = a != nullptr && *a == '\0' && *want == '\0';
3584 }
3585 // An image that baked arguments of its own has them to
3586 // apply whatever the command line holds (a board's is empty).
3587 if (!scoped && !nros_cpp_baked_ros_args_present()) {
3588 return 0;
3589 }
3590 char why[256] = {0};
3591 const int32_t rc = nros_cpp_install_argv_remaps(executor, argc, argv, why, sizeof(why));
3592 if (rc != 0) {
3593 // Two records through `nros_log`, each short enough for
3594 // its format buffer: the refused token (bounded here), then the fixed
3595 // text, whose length `say_refused` checks at compile time. As one
3596 // `NROS_ERROR` record it was over 870 bytes, which a real sink cannot
3597 // carry: the body is dropped and only an ellipsis is printed.
3598 RCLC_LOG_ERROR(::rclcpp::detail::log_handle(nullptr), "rclcpp::init: refused: %.120s",
3599 why[0] != '\0' ? why : "invalid executor handle or argv");
3600 NROS_RCLCPP_SAY_REFUSED(NROS_RCLCPP_REFUSE_INIT_ARGV);
3601 }
3602 return rc;
3603}
3604
3608inline Result init_honouring_ros_args(int argc, char const* const* argv, const char* name) {
3609 const int32_t checked = apply_ros_args(nullptr, argc, argv);
3610 if (checked != 0) {
3611 return Result(checked);
3612 }
3613 Result r = init_in(nullptr, 0, name);
3614 if (!r.ok()) {
3615 return r;
3616 }
3617 const int32_t installed = apply_ros_args(::rclcpp::global_handle(), argc, argv);
3618 if (installed != 0) {
3619 (void)shutdown_in();
3620 return Result(installed);
3621 }
3622 return r;
3623}
3624} // namespace detail
3625
3626// -- init honouring --ros-args --
3627//
3628// `init_in(argc, argv)` delegates to the 3-arg `init_in`, which reads the
3629// environment. The session name falls back to `"nros_cpp"`.
3630
3631inline Result init_in(int argc, char const* const* argv, const char* session_name) {
3632 const char* name = (session_name != nullptr) ? session_name : "nros_cpp";
3633 return detail::init_honouring_ros_args(argc, argv, name);
3634}
3635
3641inline bool ok() {
3642 return ::rclcpp::Node::global_initialized() && !::nros_cpp_termination_requested();
3643}
3644
3653inline Result create_node(::rclcpp::Node& out, const char* name, const char* ns = nullptr) {
3654 if (!::rclcpp::Node::global_initialized()) {
3656 }
3657 out.executor_handle_ = ::rclcpp::Node::global_storage();
3658 return ::rclcpp::Node::create(out, name, ns);
3659}
3660
3673inline Result create_node_on(::rclcpp::Node& out, void* executor_handle, const char* name,
3674 const char* ns = nullptr) {
3675 if (executor_handle == nullptr) {
3677 }
3678 out.executor_handle_ = executor_handle;
3679 return ::rclcpp::Node::create(out, name, ns);
3680}
3681
3685inline ResultOf<::rclcpp::Node> make_node(const char* name, const char* ns = nullptr) {
3687 Result r = create_node(n, name, ns);
3688 if (!r.ok()) return ResultOf<::rclcpp::Node>::error(r);
3689 return ResultOf<::rclcpp::Node>::ok(::rclcpp::tr::forward_rvalue(n));
3690}
3691
3692// -- Executor::create_node implementation (requires full Node definition) --
3693
3694inline Result Executor::create_node(::rclcpp::Node& out, const char* name, const char* ns) {
3695 if (!initialized_) return Result(ErrorCode::NotInitialized);
3696 out.executor_handle_ = storage_;
3697 return ::rclcpp::Node::create(out, name, ns);
3698}
3699
3700// -- NodeBuilder -----------------------------------------------------
3701//
3702// Mirrors Rust's `Executor::node_builder(name).rmw(...).locator(...).
3703// domain_id(...).namespace(...).sched(...).build()` chain. The C++
3704// wrapper is value-typed and stack-allocated; it accumulates options
3705// into an inline `nros_cpp_node_options_t` and ships it to
3706// `nros_cpp_node_create_ex` on `.build()`.
3707//
3708// Usage:
3709// ```cpp
3710// rclcpp::Node node;
3711// RCLCPP_TRY(executor.node_builder("egress")
3712// .rmw("cyclonedds")
3713// .domain_id(0)
3714// .build(node));
3715// ```
3716
3718 public:
3719 NodeBuilder(void* executor_handle, const char* name)
3720 : executor_handle_(executor_handle), name_(name),
3721 options_(nros_cpp_node_get_default_options()) {}
3722
3727 NodeBuilder& rmw(const char* name) {
3728 copy_bounded(name, options_.rmw_name, &options_.rmw_name_len, NROS_CPP_RMW_NAME_LEN);
3729 return *this;
3730 }
3731
3734 NodeBuilder& locator(const char* loc) {
3735 copy_bounded(loc, options_.locator, &options_.locator_len, NROS_CPP_LOCATOR_LEN);
3736 return *this;
3737 }
3738
3741 NodeBuilder& domain_id(uint32_t id) {
3742 options_.domain_id_override = id;
3743 return *this;
3744 }
3745
3751 NodeBuilder& namespace_(const char* ns) {
3752 copy_bounded(ns, options_.namespace_, &options_.namespace_len, NROS_CPP_NAMESPACE_LEN);
3753 return *this;
3754 }
3755
3758 NodeBuilder& sched(uint8_t sc_id) {
3759 options_.sched_context_id = sc_id;
3760 return *this;
3761 }
3762
3765 if (!executor_handle_) return Result(ErrorCode::NotInitialized);
3766 out.executor_handle_ = executor_handle_;
3767 nros_cpp_ret_t ret =
3768 nros_cpp_node_create_ex(executor_handle_, name_, &options_, &out.handle_);
3769 if (ret == 0) {
3770 out.initialized_ = true;
3771 }
3772 return Result(ret);
3773 }
3774
3775 private:
3776 static void copy_bounded(const char* src, uint8_t* dst, size_t* dst_len, size_t cap) {
3777 size_t n = 0;
3778 if (src != nullptr) {
3779 while (src[n] != '\0' && n < cap) {
3780 dst[n] = static_cast<uint8_t>(src[n]);
3781 ++n;
3782 }
3783 }
3784 // Zero out the tail so stale bytes don't leak across reuses.
3785 for (size_t i = n; i < cap; ++i) {
3786 dst[i] = 0;
3787 }
3788 *dst_len = n;
3789 }
3790
3791 void* executor_handle_;
3792 const char* name_;
3793 nros_cpp_node_options_t options_;
3794};
3795
3796inline NodeBuilder Executor::node_builder(const char* name) {
3797 return NodeBuilder(initialized_ ? handle() : nullptr, name);
3798}
3799
3800namespace detail {
3807 const DeclaredCallbackGroups& groups) {
3808 const char* missing = nullptr;
3809 int len = 0;
3810 if (first_uncreated_callback_group(groups, &missing, &len)) {
3811 report_callback_group_mismatch(node.get_name(), "declared", missing, len, groups.list);
3812 node.set_error("a CALLBACK_GROUPS group was never created",
3813 DECLARED_CALLBACK_GROUP_MISMATCH);
3814 }
3815}
3816} // namespace detail
3817
3818} // namespace rclcpp
3819
3820// The process-level verbs — `rclcpp::init()`, `rclcpp::ok()`,
3821// `rclcpp::shutdown()`, `rclcpp::spin_once()` — are declared in `nros.hpp`,
3822// which is where the free functions they name live. This header carries only
3823// what the node itself needs.
3824
3825#endif // NROS_RCLCPP_NODE_HPP
Definition timer.hpp:225
Definition node.hpp:222
Definition node.hpp:197
Definition rclcpp.hpp:214
Result create_node(::rclcpp::Node &out, const char *name, const char *ns=nullptr)
Definition node.hpp:3694
NodeBuilder node_builder(const char *name)
Definition node.hpp:3796
Definition node.hpp:3717
NodeBuilder & locator(const char *loc)
Definition node.hpp:3734
NodeBuilder & sched(uint8_t sc_id)
Definition node.hpp:3758
Result build(::rclcpp::Node &out) const
Materialize the Node.
Definition node.hpp:3764
NodeBuilder(void *executor_handle, const char *name)
Definition node.hpp:3719
NodeBuilder & rmw(const char *name)
Definition node.hpp:3727
NodeBuilder & domain_id(uint32_t id)
Definition node.hpp:3741
NodeBuilder & namespace_(const char *ns)
Definition node.hpp:3751
Definition node.hpp:3289
::rclcpp::TimerHandle create_wall_timer(::rclcpp::Duration period, Cb cb, const ::rclcpp::CallbackGroup *group=nullptr, bool autostart=true)
void create_timer_in_group(const CallbackGroup &group, uint64_t period_ms)
Definition node.hpp:3331
void create_timer_in_group(const CallbackGroup &group, uint64_t period_ms, nros_cpp_timer_callback_t callback, void *context=nullptr)
The plain C callback + ctx form, in a group, parked in the pool.
Definition node.hpp:3344
void create_wall_timer_in(uint64_t period_ms)
Definition node.hpp:3303
void create_wall_timer_in(uint64_t period_ms, nros_cpp_timer_callback_t callback, void *context=nullptr)
The plain C callback + ctx escape hatch, parked in the pool.
Definition node.hpp:3316
Definition node.hpp:874
Node & operator=(Node &&other)
Definition node.hpp:3014
bool check_declared_depth(const char *type_name, const char *topic, const ::rclcpp::QoS &qos)
Definition node.hpp:2858
Result create_subscription(::rclcpp::PollSubscription< M > &out, const char *topic, const ::rclcpp::QoS &qos, const ::rclcpp::SubscriptionOptions &options)
Result create_client(::rclcpp::PollClient< S > &out, const char *service_name, const ::rclcpp::QoS &qos=::rclcpp::QoS::services())
void create_subscription_in(const char *topic, const ::rclcpp::QoS &qos=::rclcpp::QoS::default_profile())
Result create_timer(Timer &out, const Clock &clock, uint64_t period_ms, C *self)
Definition node.hpp:2589
Result create_subscription_in_group(const ::rclcpp::CallbackGroup &group, ::rclcpp::Subscription< M > &out, const char *topic, const ::rclcpp::QoS &qos, F callback, const ::rclcpp::SubscriptionOptions &options={})
const nros_cpp_node_t * ffi_handle() const
Definition node.hpp:1919
Result count_subscribers(const char *topic_name, size_t *out_count) const
Definition node.hpp:2028
SharedPtr shared_from_this()
Definition node.hpp:1100
Result create_timer(Timer &out, const Clock &clock, uint64_t period_ms, nros_cpp_timer_callback_t callback, void *context=nullptr)
Definition node.hpp:2463
Time now() const
Definition node.hpp:1902
Result create_subscription(::rclcpp::PollSubscription< M > &out, const char *topic, const ::rclcpp::QoS &qos=::rclcpp::QoS::default_profile())
Result create_service(::rclcpp::Service< S > &out, const char *service_name, F callback, const ::rclcpp::QoS &qos=::rclcpp::QoS::services(), const ::rclcpp::ServiceOptions &options={})
const char * error_what() const
Definition node.hpp:1002
Result get_parameter_types(const char *const *names, ::size_t count, ParameterType *out) const
Definition rclcpp.hpp:2051
Result create_publisher(::rclcpp::Publisher< M > &out, const char *topic, const ::rclcpp::QoS &qos=::rclcpp::QoS::default_profile())
typename::rclcpp::Service< S >::SharedPtr create_service(const char *, F, const ::rclcpp::QoS &=::rclcpp::QoS::services())
Result create_polling_action_client(::rclcpp::PollingActionClient< A > &out, const char *action_name)
Create an L1 polling-mode action client.
typename::rclcpp::Subscription< M >::SharedPtr create_subscription(const char *topic, ::size_t depth, Cb cb)
create_subscription<M>(topic, depth, callback).
::rclcpp::Handle< const Node > ConstWeakPtr
Const spelling of WeakPtr.
Definition node.hpp:1087
Result add_on_set_parameters_callback(OnSetParametersCallbackType callback, void *context, OnSetParametersCallbackToken &out_handle)
Definition rclcpp.hpp:2110
::rclcpp::Handle< const Node > ConstSharedPtr
rclcpp::Node::ConstSharedPtr.
Definition node.hpp:1082
Result create_timer_in_group(const ::rclcpp::CallbackGroup &group, Timer &out, uint64_t period_ms, C *self)
Definition node.hpp:2598
Node(const char *name, const char *ns, const ::rclcpp::NodeOptions &options)
Definition node.hpp:1044
Result create_client(::rclcpp::Client< S > &out, const char *service_name, F callback, const ::rclcpp::QoS &qos=::rclcpp::QoS::services(), const ::rclcpp::ClientOptions &options={})
::rclcpp::Logger get_logger() const
Definition node.hpp:1875
Result create_service(::rclcpp::PollService< S > &out, const char *service_name, const ::rclcpp::QoS &qos=::rclcpp::QoS::services())
typename::rclcpp::Subscription< M >::SharedPtr create_subscription(const char *topic, const ::rclcpp::QoS &qos, Cb cb, const ::rclcpp::SubscriptionOptions &options)
typename::rclcpp::Subscription< M >::SharedPtr create_subscription(const char *topic, ::size_t depth, Cb cb, const ::rclcpp::SubscriptionOptions &options)
create_subscription<M>(topic, depth, callback, options).
::rclcpp::Handle< Node > WeakPtr
Definition node.hpp:1085
Result create_subscription(::rclcpp::Subscription< M > &out, const char *topic, const ::rclcpp::QoS &qos, F callback, const ::rclcpp::SubscriptionOptions &options={})
::rclcpp::Owned<::rclcpp::PollService< S > > create_service(const char *name, const ::rclcpp::QoS &qos=::rclcpp::QoS::services())
Result create_subscription_with_info(::rclcpp::Subscription< M > &out, const char *topic, const ::rclcpp::QoS &qos, F callback, const ::rclcpp::SubscriptionOptions &options={})
bool get_parameter(const char *name, T &out) const
Definition rclcpp.hpp:1970
typename::rclcpp::Subscription< M >::SharedPtr create_subscription(const char *topic, const ::rclcpp::QoS &qos, Cb cb)
void create_generic_publisher(const A &topic, const B &type, const ::rclcpp::QoS &qos, const R &...)
Definition node.hpp:1384
Result count_clients(const char *service_name, size_t *out_count) const
Definition node.hpp:2037
Result create_wall_timer(Timer &out, uint64_t period_ms, C *self)
Definition node.hpp:2575
Result get_node_names(nros_cpp_node_visit_fn visit, void *ctx) const
Definition node.hpp:1988
Result init(const char *name, const char *ns=nullptr)
Definition node.hpp:913
::rclcpp::node_interfaces::NodeWaitablesInterface::SharedPtr get_node_waitables_interface()
See get_node_base_interface.
Definition node.hpp:1124
typename::rclcpp::Publisher< M >::SharedPtr create_publisher(const char *topic, const ::rclcpp::QoS &qos=::rclcpp::QoS::default_profile())
create_publisher<M>(topic, qos) — available on every target.
::rclcpp::TimerHandle create_wall_timer(::rclcpp::Duration period, Cb cb, const ::rclcpp::CallbackGroup *group=nullptr, bool autostart=true)
bool check_declared_param(const char *name, int passed_type)
Definition node.hpp:2941
Result describe_parameter(const char *name, ParameterDescriptor &out, char *text, ::size_t text_len) const
Definition rclcpp.hpp:2062
T declare_parameter(const char *name, T default_value=T())
rclcpp::Node::declare_parameter<T>(name, default).
Definition rclcpp.hpp:1941
Result remove_on_set_parameters_callback(OnSetParametersCallbackToken handle)
rclcpp::Node::remove_on_set_parameters_callback(handle).
Definition rclcpp.hpp:2117
const char * serialization_format() const
Definition node.hpp:1830
~Node()
Definition node.hpp:2994
static Result create(Node &out, const char *name, const char *ns=nullptr)
Definition node.hpp:1769
bool get_parameter_or(const char *name, T &out, T fallback) const
Definition rclcpp.hpp:2031
typename::rclcpp::Service< S >::SharedPtr create_service(const char *name, F callback, const ::rclcpp::QoS &qos, const ::rclcpp::CallbackGroup *group)
ParameterType get_parameter_type(const char *name) const
Definition rclcpp.hpp:2043
bool ok() const
Definition node.hpp:998
bool has_parameter(const char *name) const
rclcpp::Node::has_parameter(name).
Definition rclcpp.hpp:2002
::rclcpp::CallbackGroup::SharedPtr create_callback_group(::rclcpp::CallbackGroupType type, bool automatically_add_to_executor_with_node=true)
Definition node.hpp:2669
Result count_services(const char *service_name, size_t *out_count) const
Definition node.hpp:2044
void * executor_handle() const
Definition node.hpp:1943
Result list_parameters(const char *prefix, char *out_names, ::size_t name_stride, ::size_t max_names, ::size_t &count) const
Definition rclcpp.hpp:2100
::rclcpp::Publisher< M > create_publisher_in(const char *topic, const ::rclcpp::QoS &qos=::rclcpp::QoS::default_profile())
Definition node.hpp:2809
Result get_publishers_info_by_topic(const char *topic_name, ::rclcpp::TopicEndpointInfoVisitFn visit, void *ctx) const
Definition node.hpp:2130
::rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr get_node_logging_interface()
See get_node_base_interface.
Definition node.hpp:1120
::rclcpp::Handle< Node > SharedPtr
Definition node.hpp:1080
typename::rclcpp::Service< S >::SharedPtr create_service(const char *name, F callback, const ::rclcpp::QoS &qos=::rclcpp::QoS::services())
Callback-style service server (void(const S::Request&, S::Response&)).
Node(Node &&other)
Definition node.hpp:3002
Node(const char *name, const ::rclcpp::NodeOptions &options)
Definition node.hpp:1037
const char * rmw_implementation_identifier() const
Definition node.hpp:1847
Result create_guard_condition(::rclcpp::GuardCondition &out, nros_cpp_guard_callback_t callback, void *context=nullptr)
Definition node.hpp:2757
const char * get_namespace() const
Get the node namespace.
Definition node.hpp:1789
bool initialized() const
Definition node.hpp:1156
void set_error(const char *what, int32_t code)
Definition node.hpp:2973
Node & nros_node()
Definition node.hpp:1160
Result get_client_names_and_types_by_node(const char *node_name, const char *node_namespace, nros_cpp_names_and_types_visit_fn visit, void *ctx) const
Definition node.hpp:2093
Result count_publishers(const char *topic_name, size_t *out_count) const
Definition node.hpp:2021
Result start_parameter_services()
Definition node.hpp:1951
int32_t error_code() const
The raw error code of the first latched failure, or 0.
Definition node.hpp:1009
const char * get_name() const
Get the node name.
Definition node.hpp:1783
bool is_valid() const
Check if the node is initialized and valid.
Definition node.hpp:1905
::rclcpp::node_interfaces::NodeGraphInterface::SharedPtr get_node_graph_interface()
See get_node_base_interface.
Definition node.hpp:1116
Result create_wall_timer(Timer &out, uint64_t period_ms, nros_cpp_timer_callback_t callback, void *context=nullptr)
Definition node.hpp:2522
Result create_timer_in_group(const ::rclcpp::CallbackGroup &group, Timer &out, uint64_t period_ms, nros_cpp_timer_callback_t callback, void *context=nullptr)
Definition node.hpp:2687
::rclcpp::CallbackGroup create_callback_group(const char *name)
Definition node.hpp:2644
Node(::rclcpp::NodeHandle handle, const char *name, const char *ns=nullptr)
Definition node.hpp:958
Node(const char *name, const char *ns=nullptr)
Definition node.hpp:895
Result set_parameters_atomically(const ParameterWrite *writes, ::size_t count)
Definition rclcpp.hpp:2106
::rclcpp::Owned<::rclcpp::PollClient< S > > create_client(const char *name, const ::rclcpp::QoS &qos=::rclcpp::QoS::services())
::rclcpp::SubscriptionHandle<::rclcpp::GenericSubscription > create_generic_subscription(const char *topic, const char *type, const char *type_hash, const ::rclcpp::QoS &qos, Cb callback)
typename::rclcpp::Publisher< M >::SharedPtr create_publisher(const char *topic, ::size_t depth)
create_publisher<M>(topic, depth) — the integer-depth spelling.
Result get_subscription_names_and_types_by_node(const char *node_name, const char *node_namespace, nros_cpp_names_and_types_visit_fn visit, void *ctx) const
Definition node.hpp:2070
bool check_declared_qos(const char *type_name, const char *topic, const ::rclcpp::QoS &qos)
Definition node.hpp:2891
Result create_timer_oneshot(Timer &out, uint64_t delay_ms, nros_cpp_timer_callback_t callback, void *context=nullptr)
Definition node.hpp:2613
Result get_service_names_and_types(nros_cpp_names_and_types_visit_fn visit, void *ctx) const
Definition node.hpp:2008
Result get_topic_names_and_types(nros_cpp_names_and_types_visit_fn visit, void *ctx) const
Definition node.hpp:2000
Result set_parameter(const char *name, T value)
Definition rclcpp.hpp:1994
const Clock * get_clock() const
Const overload of get_clock().
Definition node.hpp:1893
Result get_fully_qualified_name(char *buf, size_t buf_len, size_t *out_len=nullptr) const
Definition node.hpp:1808
Result get_subscriptions_info_by_topic(const char *topic_name, ::rclcpp::TopicEndpointInfoVisitFn visit, void *ctx) const
Definition node.hpp:2153
typename::rclcpp::Client< S >::SharedPtr create_client(const char *, F, const ::rclcpp::QoS &=::rclcpp::QoS::services())
REFUSED — upstream's shared_ptr handler shape.
Result create_polling_action_server(::rclcpp::PollingActionServer< A > &out, const char *action_name)
Clock * get_clock()
Definition node.hpp:1891
void create_generic_subscription(const A &topic, const B &type, const ::rclcpp::QoS &qos, Cb &&callback, const R &...)
Definition node.hpp:1395
const Node & nros_node() const
Const overload of [nros_node].
Definition node.hpp:1162
Result get_publisher_names_and_types_by_node(const char *node_name, const char *node_namespace, nros_cpp_names_and_types_visit_fn visit, void *ctx) const
Definition node.hpp:2052
Result get_publishers_info_by_topic(const char *topic_name, nros_cpp_endpoint_info_visit_fn visit, void *ctx) const
Definition node.hpp:2115
void create_subscription_in_group(const ::rclcpp::CallbackGroup &group, const char *topic, const ::rclcpp::QoS &qos=::rclcpp::QoS::default_profile())
::rclcpp::node_interfaces::NodeBaseInterface::SharedPtr get_node_base_interface()
Definition node.hpp:1108
Node()
Definition node.hpp:878
Result create_publisher_in_group(const ::rclcpp::CallbackGroup &, ::rclcpp::Publisher< M > &out, const char *topic, const ::rclcpp::QoS &qos=::rclcpp::QoS::default_profile())
Definition node.hpp:2740
Result undeclare_parameter(const char *name)
Definition rclcpp.hpp:2039
const ::rclcpp::NodeOptions & get_node_options() const
Definition node.hpp:1051
::rclcpp::node_interfaces::NodeClockInterface::SharedPtr get_node_clock_interface()
See get_node_base_interface.
Definition node.hpp:1112
Result create_publisher(::rclcpp::Publisher< M > &out, const char *topic, const ::rclcpp::QoS &qos, const ::rclcpp::PublisherOptions &options)
Result create_polling_subscription(::rclcpp::PollingSubscription< M > &out, const char *topic, const ::rclcpp::QoS &qos=::rclcpp::QoS::default_profile())
ConstSharedPtr shared_from_this() const
Const overload of [shared_from_this].
Definition node.hpp:1102
void set_qos_overrides(const nros_cpp_qos_override_t *overrides, size_t len)
Definition node.hpp:1931
Result init_on(void *executor_handle, const char *name, const char *ns=nullptr)
Definition node.hpp:924
Result get_subscriptions_info_by_topic(const char *topic_name, nros_cpp_endpoint_info_visit_fn visit, void *ctx) const
Definition node.hpp:2143
::rclcpp::Owned<::rclcpp::GenericPublisher > create_generic_publisher(const char *topic, const char *type, const char *type_hash, const ::rclcpp::QoS &qos=::rclcpp::QoS::default_profile())
Definition rclcpp.hpp:1403
Result get_service_names_and_types_by_node(const char *node_name, const char *node_namespace, nros_cpp_names_and_types_visit_fn visit, void *ctx) const
Definition node.hpp:2082
typename::rclcpp::Client< S >::SharedPtr create_client(const char *name, F callback, const ::rclcpp::QoS &qos=::rclcpp::QoS::services())
Callback-style service client (void(const S::Response&)).
Definition node.hpp:221
Definition node.hpp:217
Definition node.hpp:214
Definition node.hpp:212
Definition node.hpp:211
Definition node.hpp:215
Definition publisher.hpp:179
static constexpr QoS services()
Services profile: RELIABLE + VOLATILE + KEEP_LAST(10).
Definition qos.hpp:805
static constexpr QoS default_profile()
Default profile: RELIABLE + VOLATILE + KEEP_LAST(10).
Definition qos.hpp:799
int32_t raw() const
Get the raw integer code (for FFI interop).
Definition result.hpp:236
bool ok() const
Returns true if the operation succeeded.
Definition result.hpp:227
static constexpr ResultOf success()
Named constructors.
Definition result.hpp:239
Definition result.hpp:332
static ResultOf ok(T value)
Definition result.hpp:334
static ResultOf error(ErrorCode code)
Definition result.hpp:340
Definition service.hpp:146
Definition node.hpp:200
Definition subscription.hpp:197
Definition timer.hpp:153
static const bool value
Definition qos.hpp:889
One slice's handle; Tag only keeps the five spellings distinct types.
Definition node.hpp:247
Node * node() const
Definition node.hpp:254
Context get_context() const
Definition rclcpp.hpp:337
const NodeInterfaceHandle * operator->() const
Definition node.hpp:258
NodeInterfaceHandle()
Definition node.hpp:251
NodeInterfaceHandle SharedPtr
Upstream's Node*InterfaceSharedPtr — the handle itself (no allocator).
Definition node.hpp:250
NodeInterfaceHandle(Node *node)
Definition node.hpp:252
Definition client.hpp:256
Definition server.hpp:350
rclcpp::Executor — drives transport I/O and dispatches callbacks.
int nros_cpp_ret_t
Definition future.hpp:25
rclcpp::GuardCondition — cross-thread wake source.
Definition rclcpp.hpp:437
void report_declared_depth_mismatch(const char *node_name, const char *topic, int declared, int passed)
Definition node.hpp:516
const char * declared_reliability_spelling(int ordinal)
The contract spelling of a reliability ordinal, for the report above.
Definition node.hpp:611
constexpr const char * PARAM_VALUE_TYPE_MISMATCH_WHAT
The set_error text for a declaration whose value in effect has another type.
Definition node.hpp:683
void report_declared_policy_mismatch(const char *node_name, const char *topic, const char *policy, const char *declared, const char *passed)
Definition node.hpp:587
void report_component_failure(const char *node_name, const char *what, int32_t code)
Definition node.hpp:487
constexpr const char * PARAM_STORE_FULL_WHAT
Definition node.hpp:674
void refuse_param_declare(Node &node, int32_t code)
Definition rclcpp.hpp:1886
constexpr int32_t PARAM_VALUE_TYPE_MISMATCH
Definition node.hpp:669
constexpr int32_t DECLARED_PARAM_MISMATCH
Definition node.hpp:628
int32_t apply_ros_args(void *executor, int argc, char const *const *argv)
Definition node.hpp:3572
Result init_honouring_ros_args(int argc, char const *const *argv, const char *name)
Definition node.hpp:3608
const char * declared_durability_spelling(int ordinal)
The contract spelling of a durability ordinal, for the report above.
Definition node.hpp:619
constexpr int32_t DECLARED_DEPTH_MISMATCH
Definition node.hpp:511
void finish_declared_callback_groups(::rclcpp::Node &node, const DeclaredCallbackGroups &groups)
Definition node.hpp:3806
void report_callback_group_mismatch(const char *node_name, const char *how, const char *name, int len, const char *list)
Definition node.hpp:545
constexpr const char * PARAM_DECLARE_REFUSED_WHAT
The set_error text for any other refusal of a declaration.
Definition node.hpp:679
void report_declared_param_mismatch(const char *fqn, const char *param, const char *contract, int declared, int passed)
Definition node.hpp:634
constexpr int32_t DECLARED_QOS_MISMATCH
Definition node.hpp:582
Definition rclcpp.hpp:336
NodeInterfaceHandle< 3 > NodeLoggingInterface
Definition node.hpp:271
NodeInterfaceHandle< 0 > NodeBaseInterface
Definition node.hpp:268
NodeInterfaceHandle< 1 > NodeClockInterface
Definition node.hpp:269
NodeInterfaceHandle< 2 > NodeGraphInterface
Definition node.hpp:270
NodeInterfaceHandle< 4 > NodeWaitablesInterface
Definition node.hpp:272
Definition node.hpp:203
Client & operator=(Client &&other)
Definition client.hpp:1000
Definition rclcpp.hpp:75
constexpr uint8_t kDomainIdExplicitZero
Definition node.hpp:473
Result shutdown_in()
Definition node.hpp:3553
Result create_node(::rclcpp::Node &out, const char *name, const char *ns)
Definition node.hpp:3653
@ Reliable
Definition qos.hpp:149
@ BestEffort
Definition qos.hpp:150
Result init_in(const char *locator=nullptr, uint8_t domain_id=0)
Definition node.hpp:3379
Result spin_once(int32_t timeout_ms=10)
Definition rclcpp.hpp:97
void init()
rclcpp::init() — the zero-argument form. ADOPT.
Definition rclcpp.hpp:561
bool ok()
Definition node.hpp:3641
Result spin_in()
Definition rclcpp.hpp:350
Result create_node_on(::rclcpp::Node &out, void *executor_handle, const char *name, const char *ns)
Definition node.hpp:3673
ResultOf<::rclcpp::Node > make_node(const char *name, const char *ns=nullptr)
Definition node.hpp:3685
ResultOf< Publisher< M > > create_publisher(::rclcpp::Node &node, const char *topic, const QoS &qos=QoS::default_profile())
Definition publisher.hpp:705
void * global_handle()
Definition node.hpp:3562
@ InvalidArgument
Null pointer, empty topic name, or out-of-range value.
Definition result.hpp:122
@ AlreadyExists
Already exists (duplicate declare/register).
Definition result.hpp:126
@ NotInitialized
Definition result.hpp:131
Result init_with_rmw(const char *rmw, const char *locator=nullptr, uint8_t domain_id=0, const char *session_name="node")
Definition node.hpp:3514
@ Volatile
Definition qos.hpp:164
@ TransientLocal
Definition qos.hpp:165
ResultOf< void > Result
Definition result.hpp:247
rclcpp::QoS — full DDS-shaped QoS settings.
**auto handle
Definition client.hpp:127
::rclcpp::Owned< Client > SharedPtr
Definition client.hpp:496
rclcpp::Result, rclcpp::ErrorCode, and the RCLCPP_TRY macro.
Definition node.hpp:407
constexpr const char * resolve_namespace(const char *fallback) const
The launch namespace if one was declared, else fallback.
Definition node.hpp:455
constexpr bool valid() const
Definition node.hpp:447
constexpr NodeHandle()
Definition node.hpp:429
const char * launch_name
Definition node.hpp:412
void * executor
Definition node.hpp:408
constexpr NodeHandle(void *exec)
Definition node.hpp:432
const char * launch_namespace
Launch-declared namespace, same contract.
Definition node.hpp:414
const nros_cpp_qos_override_t * qos_overrides
Definition node.hpp:425
constexpr const char * resolve_name(const char *fallback) const
Definition node.hpp:451
constexpr NodeHandle(void *exec, const char *name, const char *ns, const nros_cpp_qos_override_t *overrides, size_t override_count)
Definition node.hpp:443
constexpr NodeHandle(void *exec, const char *name, const char *ns)
Definition node.hpp:437
size_t qos_override_count
Entries in qos_overrides; 0 = none.
Definition node.hpp:427
rclcpp::Timer — periodic callback driven by the executor.