nros C++ API
Lightweight ROS 2 client for embedded real-time systems (C++ headers)
Loading...
Searching...
No Matches
rclcpp.hpp
Go to the documentation of this file.
1// nros-cpp: Umbrella header
2// Include this single header to get the full nros C++ API.
3//
4// Freestanding C++ compatible — no STL, no exceptions, no RTTI required.
5
11
12#ifndef NROS_RCLCPP_RCLCPP_HPP
13#define NROS_RCLCPP_RCLCPP_HPP
14
15// Pull cbindgen-generated FFI before any wrapper hpp so
16// `rclcpp/qos.hpp`'s `#ifndef NROS_CPP_FFI_H` guard skips its local
17// fallback definitions in favor of the canonical types.
18#include "rclcpp/detail/nros_cpp_ffi.h"
19
20#include "rclcpp/detail/traits.hpp"
21#include "rclcpp/logging.hpp"
22#include "rclcpp/result.hpp"
23// The clock / time / duration surface. `node.now()` and
24// `node.get_clock()->now()` are what a ported rclcpp publisher calls to
25// stamp a header, so the umbrella carries all three. A later change moved
26// `duration.hpp` ABOVE `qos.hpp`: the QoS deadline / lifespan / lease
27// accessors take and return `rclcpp::Duration`. `qos.hpp` also includes it
28// directly, so this order is legibility rather than load-bearing.
29#include "rclcpp/duration.hpp"
30#include "rclcpp/time.hpp"
31#include "rclcpp/clock.hpp"
32#include "rclcpp/qos.hpp"
33#include "rclcpp/options.hpp"
34#include "rclcpp/future.hpp"
35#include "rclcpp/stream.hpp"
36// rclcpp::SerializationFormat / format_of<M> / linked_format().
38// node.hpp no longer pulls in the heavy entity headers —
39// each entity header carries its own out-of-line `Node::create_X<>()`
40// template definition. The umbrella pulls in every entity explicitly so
41// `#include <rclcpp/rclcpp.hpp>` still yields the full API.
42#include "rclcpp/node.hpp"
43#include "rclcpp/publisher.hpp"
45#include "rclcpp/generic.hpp"
46#include "rclcpp/service.hpp"
47#include "rclcpp/client.hpp"
50#include "rclcpp/polling_action_server.hpp"
51#include "rclcpp/polling_action_client.hpp"
52#include "rclcpp/polling_client.hpp"
53#include "rclcpp/polling_service.hpp"
54#include "rclcpp/polling_subscription.hpp"
55#include "rclcpp/parameter.hpp"
56// The ONE parameter facade. Forwards a node's
57// declare/get/set/has onto the executor's store across the FFI, so a parameter
58// means the same thing wherever it is declared. There is now one node type to
59// wear it, which is the other half of that guarantee.
60// Freestanding: `<string>`/`<vector>` behind `NROS_CPP_STD`.
61#include "rclcpp/node_parameters.hpp"
62#include "rclcpp_lifecycle/lifecycle_node.hpp"
63#include "rclcpp/rosout.hpp" // `/rosout` from C++
64// `nros/component_node.hpp` IS GONE. `nros::ComponentNode` was a
65// type that WRAPPED a node ("wrap, not derive"), so a component
66// was not a `Node` and every verb had to be forwarded. Its members are on
67// `rclcpp::Node` now, its pool is the opt-in `rclcpp::NodeWithTimers<N>`, and its
68// macros are in `component.hpp` below. The rclcpp-shaped, value-returning
69// parameter facade once pulled in here for is `Node`'s own.
70// `rclcpp::create_subscription_raw`, the
71// arena-registration entry point `rclcpp::Node::create_subscription`
72// below uses so it has no dispatch of its own.
73#include "rclcpp/detail/component.hpp"
74
75namespace rclcpp {
76
88inline void* global_handle();
89
97inline Result spin_once(int32_t timeout_ms = 10) {
98 if (!::rclcpp::Node::global_initialized()) {
100 }
101 return Result(nros_cpp_spin_once(::rclcpp::Node::global_storage(), timeout_ms));
102}
103
113inline void arm_monitors() {
114 nros_cpp_monitors_arm();
115}
116
118constexpr uint32_t kTraceAppMarkerFirst = 1;
121constexpr uint32_t kTraceAppMarkerLast = 15;
122
132inline Result trace_marker(uint32_t id, uint32_t arg) {
133 return Result(nros_cpp_trace_marker(id, arg));
134}
135
156inline Result pre_shutdown(ShutdownCallback callback, void* context = nullptr,
157 PreShutdownCallbackHandle* out = nullptr) {
158 void* executor = global_handle();
159 if (executor == nullptr) {
161 }
162 nros_cpp_shutdown_callback_handle_t raw = NROS_CPP_SHUTDOWN_CALLBACK_HANDLE_INVALID;
163 nros_cpp_ret_t ret = nros_cpp_add_pre_shutdown_callback(executor, callback, context, &raw);
164 if (out != nullptr) *out = PreShutdownCallbackHandle(raw);
165 return Result(ret);
166}
167
175inline Result on_shutdown(ShutdownCallback callback, void* context = nullptr,
176 OnShutdownCallbackHandle* out = nullptr) {
177 void* executor = global_handle();
178 if (executor == nullptr) {
180 }
181 nros_cpp_shutdown_callback_handle_t raw = NROS_CPP_SHUTDOWN_CALLBACK_HANDLE_INVALID;
182 nros_cpp_ret_t ret = nros_cpp_add_on_shutdown_callback(executor, callback, context, &raw);
183 if (out != nullptr) *out = OnShutdownCallbackHandle(raw);
184 return Result(ret);
185}
186
190 void* executor = global_handle();
191 if (executor == nullptr) return false;
192 return nros_cpp_remove_pre_shutdown_callback(executor, handle.value()) == 0;
193}
194
198 void* executor = global_handle();
199 if (executor == nullptr) return false;
200 return nros_cpp_remove_on_shutdown_callback(executor, handle.value()) == 0;
201}
202
214class Context {
215 public:
217 Context() : executor_(nullptr) {}
218 explicit Context(void* executor) : executor_(executor) {}
219 Context* operator->() { return this; }
220 const Context* operator->() const { return this; }
222 void* executor_handle() const { return executor_; }
224 bool is_valid() const { return executor_ != nullptr && ::rclcpp::ok(); }
225
228 PreShutdownCallbackHandle* out = nullptr) {
229 if (executor_ == nullptr) return Result(ErrorCode::NotInitialized);
230 nros_cpp_shutdown_callback_handle_t raw = NROS_CPP_SHUTDOWN_CALLBACK_HANDLE_INVALID;
231 nros_cpp_ret_t ret = nros_cpp_add_pre_shutdown_callback(executor_, callback, context, &raw);
232 if (out != nullptr) *out = PreShutdownCallbackHandle(raw);
233 return Result(ret);
234 }
235
237 OnShutdownCallbackHandle* out = nullptr) {
238 if (executor_ == nullptr) return Result(ErrorCode::NotInitialized);
239 nros_cpp_shutdown_callback_handle_t raw = NROS_CPP_SHUTDOWN_CALLBACK_HANDLE_INVALID;
240 nros_cpp_ret_t ret = nros_cpp_add_on_shutdown_callback(executor_, callback, context, &raw);
241 if (out != nullptr) *out = OnShutdownCallbackHandle(raw);
242 return Result(ret);
243 }
244
246 if (executor_ == nullptr) return false;
247 const bool removed = nros_cpp_remove_pre_shutdown_callback(executor_, handle.value()) == 0;
248#if defined(NROS_CPP_STD) // hosted-family: shutdown-interop
249 if (removed) release_closure(handle.value());
250#endif
251 return removed;
252 }
253
255 if (executor_ == nullptr) return false;
256 const bool removed = nros_cpp_remove_on_shutdown_callback(executor_, handle.value()) == 0;
257#if defined(NROS_CPP_STD) // hosted-family: shutdown-interop
258 if (removed) release_closure(handle.value());
259#endif
260 return removed;
261 }
262
263#if defined(NROS_CPP_STD) // hosted-family: shutdown-interop
266 PreShutdownCallbackHandle add_pre_shutdown_callback(::std::function<void()> callback) {
267 PreShutdownCallbackHandle h(NROS_CPP_SHUTDOWN_CALLBACK_HANDLE_INVALID);
268 auto* fn = new ::std::function<void()>(static_cast<::std::function<void()>&&>(callback));
269 if (!add_pre_shutdown_callback(&Context::run_closure, fn, &h).ok()) {
270 delete fn;
271 return PreShutdownCallbackHandle(NROS_CPP_SHUTDOWN_CALLBACK_HANDLE_INVALID);
272 }
273 closures()[h.value()].reset(fn);
274 return h;
275 }
277 OnShutdownCallbackHandle add_on_shutdown_callback(::std::function<void()> callback) {
278 OnShutdownCallbackHandle h(NROS_CPP_SHUTDOWN_CALLBACK_HANDLE_INVALID);
279 auto* fn = new ::std::function<void()>(static_cast<::std::function<void()>&&>(callback));
280 if (!add_on_shutdown_callback(&Context::run_closure, fn, &h).ok()) {
281 delete fn;
282 return OnShutdownCallbackHandle(NROS_CPP_SHUTDOWN_CALLBACK_HANDLE_INVALID);
283 }
284 closures()[h.value()].reset(fn);
285 return h;
286 }
287
288 private:
289 static void run_closure(void* fn) {
290 if (fn != nullptr) (*static_cast<::std::function<void()>*>(fn))();
291 }
292 using ClosureMap =
293 ::std::map<nros_cpp_shutdown_callback_handle_t, ::std::unique_ptr<::std::function<void()>>>;
294 static ClosureMap& closures() {
295 static ClosureMap m;
296 return m;
297 }
298 static void release_closure(nros_cpp_shutdown_callback_handle_t h) { closures().erase(h); }
299#else
300 private:
301#endif
302 void* executor_;
303};
304
305namespace contexts {
311} // namespace contexts
312
313// --- Clock::sleep_until / sleep_for ---------------------------
314//
315// One call into `nros_cpp_spin_until_clock`, which owns the loop Rust-side, as
316// `Rate::sleep` makes one call into `nros_cpp_spin_for`: a wrapper that looped
317// over `spin_once` here would be thin-wrapper violation class 2.
318inline bool Clock::sleep_until(Time until, Context context) {
319 if (until.get_clock_type() != get_clock_type()) return false;
320 void* executor = context.executor_handle();
321 if (executor == nullptr || !::rclcpp::ok()) return false;
322 const nros_cpp_ret_t ret =
323 nros_cpp_spin_until_clock(executor, &clock_, until.nanoseconds(), 10);
324 return ret == NROS_CPP_RET_OK && now() >= until;
325}
326inline bool Clock::sleep_until(Time until) {
327 return sleep_until(until, contexts::get_global_default_context());
328}
329inline bool Clock::sleep_for(Duration rel_time, Context context) {
330 return sleep_until(now() + rel_time, context);
331}
332inline bool Clock::sleep_for(Duration rel_time) {
333 return sleep_for(rel_time, contexts::get_global_default_context());
334}
335
337template <int Tag> inline Context NodeInterfaceHandle<Tag>::get_context() const {
338 return Context(node_ != nullptr ? node_->executor_handle() : nullptr);
339}
340} // namespace node_interfaces
341
350inline Result spin_in() {
351 if (!::rclcpp::Node::global_initialized()) {
353 }
354 Result last = Result::success();
355 while (ok()) {
356 // The executor's entry budget, not a fixed 10 ms.
357 void* storage = ::rclcpp::Node::global_storage();
358 last = Result(nros_cpp_spin_once(storage, nros_cpp_entry_spin_budget_ms(storage)));
359 if (!last.ok()) return last;
360 }
361 return last;
362}
363
372inline Result spin_in(uint32_t duration_ms, int32_t poll_ms = 10) {
373 if (!::rclcpp::Node::global_initialized()) {
375 }
376 // Forward to the single budgeted-spin CFFI entry point. This
377 // loop previously budgeted by ITERATION count (`elapsed += timeout`), which
378 // collapsed to milliseconds when `spin_once` returned early on a signaled
379 // wake — the exact bug `Executor::spin` fixed. The correct
380 // wall-clock budget now lives once, Rust-side, in `nros_cpp_spin_for`.
381 return Result(nros_cpp_spin_for(::rclcpp::Node::global_storage(), duration_ms, poll_ms));
382}
383
384} // namespace rclcpp
385
386// ============================================================================
387// rclcpp:: — the process-level surface
388// ============================================================================
389//
390// `rclcpp::init` / `shutdown` / `ok` / `Node` / `spin` / `spin_some` / `Rate` /
391// `spin_until_future_complete` used to live in `nros/rclcpp_compat.hpp`, a
392// separate header a ported file had to be force-included with. The adoption
393// rule (replace, with an alias as the migration step) makes the ROS 2 spelling
394// a FIRST-CLASS name declared by the API headers themselves; "no compat
395// layer survives" is what follows from it — with one spelling per
396// concept there is nothing left for a shim to bridge, so it dissolves by
397// construction rather than having to be argued away. The in-tree
398// `nros::` spelling is retired: `rclcpp::` is now the only
399// namespace.
400//
401// They land HERE, in the umbrella, and not in `node.hpp`, because that is where
402// their dependencies are. `rclcpp::Node` reaches `rclcpp::create_subscription_raw`
403// (`component.hpp`), `rclcpp::Timer`, `rclcpp::Service` and `rclcpp::Client`,
404// every one of which includes `node.hpp` itself; `Rate::sleep` and
405// `spin_until_future_complete` drive the `rclcpp::spin` / `rclcpp::spin_once`
406// free functions defined a few lines above. This IS the header they were
407// shimming: the process-level verbs — `rclcpp::init`, `rclcpp::spin`,
408// `rclcpp::spin_once`, `rclcpp::on_shutdown` — are all reached through
409// `<rclcpp/rclcpp.hpp>`.
410//
411// FREESTANDING. Unlike the shim it replaces, this is not hosted-STL by
412// construction. `init` / `shutdown` / `ok` and the `--ros-args` predicate need
413// nothing but `<cstdlib>`, so they reach a `no_std` C++ build. `Node`, the spin
414// forwarders and `Rate` are gated on the standard-library pieces their
415// signatures are spelled in (`__has_include`, never `__STDC_HOSTED__` — issue
416// 0112, rationale in `publisher.hpp`), so on a minimal libcpp they are absent
417// rather than a parse error.
418
419#include <cstdlib> // std::abort -- the runtime half of REFUSE-LOUD
420#include <type_traits> // the SFINAE guards on create_service / create_client
421
422namespace rclcpp {
423
424// --- Process-level lifecycle -------------------------------------------------
425//
426// `rclcpp::init()` / `rclcpp::shutdown()` / `rclcpp::ok()` are the
427// process-level handshake (nros tracks the shutdown flag).
428//
429// The TWO-ARGUMENT form is REFUSE-LOUD. It used to forward to
430// the one-argument `init()` and discard `argv`, so `--ros-args -r
431// chatter:=/other` — the single most common thing a ported `main` passes —
432// silently became a wrong-topic bug at runtime. Honouring it is remap
433// resolution, thin-wrapper violation class 4, and belongs beside
434// `rclcpp::resolve_name` rather than here; until it lands, the honest answer is a
435// loud abort carrying the migration.
436
437namespace detail {
444constexpr bool is_ros_args_flag(char const* s, int i = 0) {
445 return s == nullptr ? false
446 : "--ros-args"[i] == '\0' ? s[i] == '\0'
447 : s[i] != "--ros-args"[i] ? false
448 : is_ros_args_flag(s, i + 1);
449}
450
451constexpr bool argv_has_ros_args(int argc, char const* const* argv, int i = 0) {
452 return i >= argc ? false
453 : argv == nullptr ? false
454 : is_ros_args_flag(argv[i]) ? true
455 : argv_has_ros_args(argc, argv, i + 1);
456}
457
497[[noreturn]] inline void abort_failed_create(const char* verb, const char* name, int32_t code) {
498 // Two records through `nros_log`, each short enough for its
499 // format buffer: the call (the name bounded here), then the fixed text,
500 // whose length `say_refused` checks at compile time. As one `NROS_ERROR`
501 // record it was over 1180 bytes, which a real sink cannot carry: the body
502 // is dropped and only an ellipsis is printed, so the process aborted
503 // without saying why.
504 RCLC_LOG_ERROR(log_handle(nullptr), "rclcpp::Node::%s(\"%.64s\") failed: rclcpp::ErrorCode %d",
505 verb, name != nullptr ? name : "", static_cast<int>(code));
506 NROS_RCLCPP_SAY_REFUSED(NROS_RCLCPP_ABORT_FAILED_CREATE);
507 ::std::abort();
508}
509
512inline void require_created(::rclcpp::Result r, const char* verb, const char* name) {
513 if (!r.ok()) {
514 abort_failed_create(verb, name, r.raw());
515 }
516}
517} // namespace detail
518
544inline void init(int argc, char const* const* argv) {
545 // The image's baked `ros_args` / `params_files` apply too,
546 // with or without a `--ros-args` on the command line.
547 const bool any = detail::argv_has_ros_args(argc, argv) || ::nros_cpp_baked_ros_args_present();
548 if (any && ::rclcpp::detail::apply_ros_args(nullptr, argc, argv) != 0) {
549 ::std::abort();
550 }
551 (void)::rclcpp::init_in();
552 // An init that failed leaves no executor to install into; nothing here is
553 // dropped that the failed init did not already drop with the session.
554 void* const executor = ::rclcpp::global_handle();
555 if (any && executor != nullptr && ::rclcpp::detail::apply_ros_args(executor, argc, argv) != 0) {
556 ::std::abort();
557 }
558}
559
561inline void init() {
562 (void)::rclcpp::init_in();
563}
564
578inline bool shutdown() {
579 return ::rclcpp::shutdown_in().ok();
580}
581
596using ::rclcpp::spin_once;
597
615
616} // namespace rclcpp
617
618// -- the ported publisher line, UNGATED ---------------------------------------
619//
620// `auto pub = node->create_publisher<M>("chatter", 10);` compiles on every
621// target now, including `-ffreestanding -nostdinc++` against Zephyr's and
622// ThreadX's minimal libcpp. It returns `Publisher<M>::SharedPtr`, which is
623// `rclcpp::Owned<Publisher<M>>` — the publisher by value, `operator->` for
624// `pub->publish(m)`, no allocator, no control block, no `<memory>`.
625//
626// WHAT THE NODE STOPPED DOING, stated because it is a behaviour change.
627// The hosted body used to `make_shared` the publisher and push a second
628// reference into `hosted().owned_entities`, so the node co-owned it and a
629// ported body could drop the returned pointer mid-expression
630// (`node->create_publisher<M>(…)->publish(m);`) and still have a live
631// publisher afterwards. `Owned<T>` is SOLE ownership, so there is no second
632// reference to keep: the entity is destroyed when the holder is. For the
633// expression above that is still correct — the temporary outlives the
634// full-expression — and for the member pattern the corpus actually uses
635// (`publisher_ = this->create_publisher<M>(…)`) it is identical to upstream,
636// where the node is the last owner. What is gone is a publisher that survives
637// its own handle, which upstream does not give either once the node drops it.
638//
639// A measurement showed that the node was never an ARENA owner here: nothing
640// registers a publisher and `EntryKind` has no publisher kind, so the retention
641// was retention and nothing more. The comment that used to sit on it claimed
642// the arena stored `&entity`, which was false in both halves and is the kind of
643// copied rationale that teaches the next reader the wrong model.
644namespace rclcpp {
645template <typename M>
646inline typename Publisher<M>::SharedPtr Node::create_publisher(const char* topic,
647 const ::rclcpp::QoS& qos) {
648 Publisher<M> p;
649 ::rclcpp::detail::require_created(this->create_publisher<M>(p, topic, qos), "create_publisher",
650 topic);
651 return typename Publisher<M>::SharedPtr(::rclcpp::tr::forward_rvalue(p));
652}
653
654template <typename M>
655inline typename Publisher<M>::SharedPtr Node::create_publisher(const char* topic, ::size_t depth) {
656 return this->create_publisher<M>(topic, ::rclcpp::QoS(static_cast<uint32_t>(depth)));
657}
658} // namespace rclcpp
659
660// The `std::string`-keyed forwarders, then the `Node::SharedPtr`-taking
661// verbs. A change split what was one block behind all four capability
662// probes: each half now names the one capability its signatures use. Every
663// verb here forwards to (or refuses in place of) a freestanding form defined
664// after these blocks.
665#if defined(NROS_CPP_HAS_STD_STRING) // hosted-family: string-interop
666
667namespace rclcpp {
668
669namespace detail {
670
671// ~~`adopt_executor_param_seed`~~ IS GONE, along with the store it
672// existed to reconcile.
673//
674// It re-read every launch-seeded parameter out of the EXECUTOR's store and
675// copied it over the code default, because `rclcpp::Node`'s own
676// `nros::ParameterServer` was a DIFFERENT object and would otherwise have
677// answered 0.15 while launch said 0.03. `nros::ComponentNode`
678// carried the same dispatch written a second time, in C++17 `if constexpr`,
679// and both headers flagged the duplication against themselves.
680//
681// With one store there is nothing to reconcile: `declare_parameter` declares
682// into the store the seed was written to, finds the name already present, and
683// reads back the seeded value. The adoption is the FFI's ALREADY_EXISTS
684// path, not a helper — and it is now one path rather than two that could
685// disagree.
686
687} // namespace detail
688
689// --- Node ---------------------------------------------------------------------
690//
691// THE NODE TYPES ARE MERGED. `rclcpp::Node` stopped being a
692// separate adapter class here (it became an alias for `nros::Node`, and now
693// it IS the one class), and the hosted call shape that adapter
694// carried is now a set of overloads on that one type (declared in `node.hpp`,
695// defined below).
696//
697// What that closes, in order of how much it cost:
698//
699// * THE DUPLICATE PARAMETER FACADE. `nros.hpp` said so about itself ("KNOWN
700// DUPLICATION... There should be ONE helper"): the same rclcpp-shaped
701// `declare_parameter<T>` existed twice, once in C++14 here and once in
702// C++17 `if constexpr` on `ComponentNode`. One node type is what makes one
703// facade possible.
704// * THE `get_logger()` COLLISION. Two accessors with identical signatures
705// and different observable behaviour — a real node logger and the
706// hardcoded `"nros.compat"` sentinel. One type can hold only one, so the
707// merge forced the decision W5 records.
708// * THE TWO-VOCABULARY SPLIT. A ported file wrote `rclcpp::Node` and got a
709// type with no graph queries, no lifecycle, no callback groups, no action
710// entities and no out-ref creators; a native file wrote `nros::Node` and
711// got no `shared_ptr` creators and no parameters. Neither list was a
712// design; both were what the other file happened to have.
713//
714// The class holds no dispatch state and runs no loop — every entity it creates
715// is registered on the executor arena `rclcpp::init()` opened (one
716// session per image), which is all the thin-wrapper discipline permits a wrapper to be.
717//
718// Threading: callbacks fire on whatever thread services a spin verb, mirroring
719// the rclcpp default. A node cannot move between executors (one
720// executor per RTOS task), which is why the executor is decided at construction
721// and never afterwards.
722
723} // namespace rclcpp
724
725namespace rclcpp {
726
727// The HOSTED half of `rclcpp::Node`, defined here rather than in `node.hpp`
728// because every body below needs a complete entity type (`Publisher<M>`,
729// `Subscription<M>`, `Service<S>`, `Client<S>`) or a helper the umbrella pulls
730// in (`create_subscription_raw` from `component.hpp`, the callback cells from
731// `subscription.hpp` / `timer.hpp`). That is the same split every entity already
732// uses for the out-ref `Node::create_X<>` templates, which live in the header
733// that owns each entity.
734//
735// The declarations — with the default arguments — are in `node.hpp` under
736// `NROS_CPP_HAS_STD_STRING`, the one predicate both files share.
737
738// -- publishers ---------------------------------------------------------------
739
740} // namespace rclcpp
741
742namespace rclcpp {
743template <typename M>
744inline typename Publisher<M>::SharedPtr Node::create_publisher(const ::std::string& topic,
745 const ::rclcpp::QoS& qos) {
746 return this->create_publisher<M>(topic.c_str(), qos);
747}
748} // namespace rclcpp
749
750namespace rclcpp {} // namespace rclcpp
751
752namespace rclcpp {
753template <typename M>
754inline typename Publisher<M>::SharedPtr Node::create_publisher(const ::std::string& topic,
755 ::size_t depth) {
756 return this->create_publisher<M>(topic.c_str(), ::rclcpp::QoS(static_cast<uint32_t>(depth)));
757}
758} // namespace rclcpp
759
760namespace rclcpp {
761
762// -- subscriptions ------------------------------------------------------------
763//
764// ONE DISPATCH PATH. This ARENA-REGISTERS the subscription through
765// `rclcpp::create_subscription_raw` (`component.hpp`), the same
766// `nros_cpp_subscription_register` call the native callback-style
767// `create_subscription` makes, so the executor owns the subscriber and
768// dispatches the callback during `spin_once` — whichever spin verb the caller
769// drives. It used to create a POLL-mode subscription and drain it from a
770// node-local `pump()`, which only `rclcpp::spin` / `spin_some` called: a file
771// that spun `rclcpp::spin_once()` instead got zero callbacks and no diagnostic.
772//
773// Why not the out-ref `create_subscription(sub, topic, qos, cb)` overload: that
774// one is SFINAE-restricted to `void(*)(const M&)` — a plain function pointer
775// with NO context slot — and every ported rclcpp callback captures.
776//
777// The receive-buffer hint is `rx_buffer_capacity<M>` — the same number the poll
778// path's `take()` stacks — and NOT the strict `rx_size_bound<M>`, whose
779// unbounded-type arm is a deliberate compile error. A ported file
780// must not stop compiling because its message has an unbounded string.
781//
782// ONE THING THIS LOSES, stated rather than left silent:
783// `create_subscription_raw` hardcodes an EMPTY type hash (it takes no such
784// parameter), which `normalize_type_hash` turns into `"TypeHashNotSupported"`.
785// It does not affect DELIVERY — a subscriber's data keyexpr puts `*` in the
786// hash slot — but under `ros-iron` / `ros-jazzy` the subscription's LIVELINESS
787// token advertises the placeholder instead of the real hash, so
788// `ros2 topic info --verbose` reads differently.
789//
790// WHAT THE RETURNED HANDLE IS: a keep-alive, which is all upstream source does
791// with it (`rclcpp::Subscription<M>::SharedPtr sub_;`). The executor owns the
792// real subscriber. This comment used to say `sub->take(msg)` on it "answers
793// `NotInitialized`"; it did not — `initialized_` was true and the call reached
794// `&mut *(storage as *mut RmwSubscriber)` over bytes the arena never filled.
795// The handle is now a type with no `operator->`, and a later change moved the
796// taking API to `rclcpp::PollSubscription<M>`, so neither half of that sentence
797// has a subject any more.
798} // namespace rclcpp
799
800namespace rclcpp {
801template <typename M, typename Cb>
802inline typename Subscription<M>::SharedPtr
803Node::create_subscription(const ::std::string& topic, const ::rclcpp::QoS& qos, Cb cb) {
804 // Forwards to the freestanding `const char*` overload.
805 return this->create_subscription<M>(topic.c_str(), qos, ::rclcpp::tr::forward_rvalue(cb));
806}
807} // namespace rclcpp
808
809namespace rclcpp {} // namespace rclcpp
810
811namespace rclcpp {
812template <typename M, typename Cb>
813inline typename Subscription<M>::SharedPtr Node::create_subscription(const ::std::string& topic,
814 ::size_t depth, Cb cb) {
815 return this->create_subscription<M>(topic.c_str(), depth, ::rclcpp::tr::forward_rvalue(cb));
816}
817} // namespace rclcpp
818
819namespace rclcpp {
820
821// -- wall timer ---------------------------------------------------------------
822
823// `create_wall_timer` is defined after the hosted block now
824// (`-- timers --`): it returns a `TimerHandle` and allocates nothing, so it is
825// not a hosted capability.
826
827// -- parameters ---------------------------------------------------------------
828//
829// MOVED OUT OF THIS BLOCK. The definitions are below, after
830// `#endif // NROS_CPP_HAS_SHARED_PTR && ...`, because a node's parameters are
831// not a hosted capability: the scalar FFI is `<cstdint>` and a `const char*`,
832// and `rclcpp::Seq<T, N>` carries arrays with no STL either. Only the
833// `std::string`-KEYED overloads (declared on the class in `node.hpp`) need the
834// STL, and only those keep the gate.
835//
836// `parameters()` IS GONE. It handed out a reference to the node's
837// own `nros::ParameterServer`, described as the escape hatch for "the C-API
838// helpers that take an `rclc_parameter_server_t*`" - and no such helper
839// existed: ~~`nros_executor_register_parameter_services`~~ takes the executor,
840// never a standalone store. That class is deleted now too, so there is nothing
841// to return and nothing that took it. A node's parameters are reached through
842// `declare_parameter` / `get_parameter` / `set_parameter`, which name the store
843// the services actually read.
844
845// -- services and clients -----------------------------------------------------
846//
847// A callback of upstream's `shared_ptr<Request>, shared_ptr<Response>` shape is
848// REFUSE-LOUD rather than "no matching function": that signature needs a
849// per-request heap allocation on the delivery path, which is a second delivery
850// path, not a spelling.
851
852} // namespace rclcpp
853
854namespace rclcpp {
855template <typename S>
856inline ::rclcpp::Owned<::rclcpp::PollService<S>> Node::create_service(const ::std::string& name,
857 const ::rclcpp::QoS& qos) {
858 // Forwards to the freestanding `const char*` overload.
859 return this->template create_service<S>(name.c_str(), qos);
860}
861} // namespace rclcpp
862
863namespace rclcpp {} // namespace rclcpp
864
865namespace rclcpp {
866template <typename S, typename F, typename>
867inline typename Service<S>::SharedPtr Node::create_service(const ::std::string& name, F callback,
868 const ::rclcpp::QoS& qos) {
869 return this->template create_service<S>(name.c_str(), callback, qos);
870}
871} // namespace rclcpp
872
873namespace rclcpp {} // namespace rclcpp
874
875namespace rclcpp {
876template <typename S, typename F, typename, typename>
877inline typename Service<S>::SharedPtr Node::create_service(const ::std::string& name, F callback,
878 const ::rclcpp::QoS& qos) {
879 // The `const char*` overload decides: it takes upstream's
880 // shared_ptr handler and refuses the rest.
881 return this->template create_service<S>(name.c_str(), callback, qos);
882}
883} // namespace rclcpp
884
885namespace rclcpp {} // namespace rclcpp
886
887namespace rclcpp {
888template <typename S>
889inline ::rclcpp::Owned<::rclcpp::PollClient<S>> Node::create_client(const ::std::string& name,
890 const ::rclcpp::QoS& qos) {
891 // Forwards to the freestanding `const char*` overload.
892 return this->template create_client<S>(name.c_str(), qos);
893}
894} // namespace rclcpp
895
896namespace rclcpp {} // namespace rclcpp
897
898namespace rclcpp {
899template <typename S, typename F, typename>
900inline typename Client<S>::SharedPtr Node::create_client(const ::std::string& name, F callback,
901 const ::rclcpp::QoS& qos) {
902 return this->template create_client<S>(name.c_str(), callback, qos);
903}
904} // namespace rclcpp
905
906namespace rclcpp {} // namespace rclcpp
907
908namespace rclcpp {
909template <typename S, typename F, typename, typename>
910inline typename Client<S>::SharedPtr Node::create_client(const ::std::string&, F,
911 const ::rclcpp::QoS&) {
912 static_assert(::rclcpp::detail::refuse<F>::value,
913 NROS_RCLCPP_REFUSE_SHARED_PTR_SERVICE_CALLBACK);
914 return typename Client<S>::SharedPtr();
915}
916} // namespace rclcpp
917
918namespace rclcpp {} // namespace rclcpp
919
920#endif // NROS_CPP_HAS_STD_STRING
921
922#if defined(NROS_CPP_HAS_SHARED_PTR) // hosted-family: shared-ptr-interop
923namespace rclcpp {
924
925// `rclcpp::Node` is defined in `node.hpp`, UNCONDITIONALLY, not here, because
926// a freestanding target gets the class and must get its ROS 2 spelling with it.
927//
928// `pump()` IS GONE and does not come back. It ran a node's wall
929// timers and drained its polling subscriptions, and only `rclcpp::spin` /
930// `spin_some` called it, so a node driven by any other spin verb dispatched
931// nothing. Every entity a node creates is registered on the executor arena, so
932// there is nothing left for a node-local sweep to do and mixing spin spellings
933// is harmless. A second dispatch path here is the thin-wrapper violation the whole
934// item was about, and it cannot be made visible by a diagnostic.
935
936// --- rclcpp::create_timer -------------------------------------
937//
938// Humble has NO `Node::create_timer` member — the clock-taking verb is a FREE
939// function, `rclcpp::create_timer(node, clock, period, callback[, group])`, and
940// that is the only form a Humble-era file can be written in. Ours takes the
941// same arguments in the same order and returns the same cell
942// `create_wall_timer` returns.
943//
944// The clock is `rclcpp::Clock*`, which is exactly what `node->get_clock()` hands
945// back, so the ported line binds with no conversion. Upstream's parameter is
946// `rclcpp::Clock::SharedPtr`; there is no allocator here and the
947// clock is a member of the node, so the pointer is the counterpart — the same
948// ADOPT-BOUNDED trade `get_clock()` itself makes.
949//
950// WHAT THE CLOCK DOES, and it is the whole point of the verb: a
951// `RCL_ROS_TIME` clock follows `/clock`, so the timer stops when a bag
952// stops and re-times when the bag is replayed at another rate; a
953// `RCL_STEADY_TIME` one does not. `create_wall_timer` is the steady
954// verb and is unaffected by simulated time. Upstream distinguishes the two
955// cases by TYPE (`WallTimer` vs `GenericTimer<ClockT>`) *and* by VERB; the type
956// distinction is unportable here (the clock is a runtime field on one flat
957// `Timer`), the verb
958// distinction is portable and is what ported code writes, so that is what we
959// take.
960//
961// NOT ADDED: a clock-less `Node::create_timer(period, callback)`. That member
962// arrives in Iron, and the captured surface here is Humble; adding it now would
963// claim a spelling the recorded upstream does not have.
964
965namespace detail {
966
972template <typename N, typename ::rclcpp::tr::enable_if<
973 ::rclcpp::tr::is_convertible<N*, ::rclcpp::Node*>::value, int>::type = 0>
974inline ::rclcpp::Node& as_node_ref(const ::std::shared_ptr<N>& n) {
975 return *n;
976}
977
978} // namespace detail
979
980// `rclcpp::create_timer` moved after this block (`-- timers --`).
981
982// --- spin / spin_some --------------------------------------------------------
983//
984// FORWARDERS, and nothing else. `rclcpp::spin(node)` is
985// `rclcpp::spin()` (block until `ok()` goes false) and `rclcpp::spin_some(node)`
986// is the process executor's `spin_some` drain (it was one 0-timeout
987// `rclcpp::spin_once`). Both used to call a node-local `pump()`
988// first, which was the ONLY thing that ran a ported node's timers and
989// subscriptions; now those live on the executor, so these two dispatch nothing
990// of their own and a file that reaches for `rclcpp::spin_once()` or drives an
991// `rclcpp::Executor` gets exactly the same callbacks. That equivalence is the
992// structural prerequisite for step B: after it both node types share a name,
993// and a mismatch would be invisible.
994//
995// One behaviour change for an existing caller: `rclcpp::spin()` RETURNS on the
996// first failing `spin_once`, where this loop used to discard the result and
997// keep going. A dead session now ends the spin instead of looking alive
998// forever, which is what `rclcpp::spin()` and `Executor::spin` already promise.
999//
1000// The `node` argument is still checked, and still otherwise unused: there is
1001// one session per image, so every `rclcpp::Node` is on the global
1002// executor these verbs drive. Upstream takes the node for the same reason and
1003// spins the executor it belongs to.
1004
1005} // namespace rclcpp
1006
1007#endif // NROS_CPP_HAS_SHARED_PTR
1008
1009// --- spin verbs, freestanding ----------------------------------
1010//
1011// They take `Node::SharedPtr`, which is `rclcpp::Handle<Node>` on every target
1012// now, so they left the `shared_ptr` block: a freestanding port's
1013// `main` spells `rclcpp::spin(node)` exactly as a hosted one does.
1014namespace rclcpp {
1015
1016inline void spin(const Node::SharedPtr& node) {
1017 if (!node || !node->initialized()) {
1018 return;
1019 }
1020 (void)::rclcpp::spin_in();
1021}
1022
1026 spin(Node::SharedPtr(base.node()));
1027}
1028
1029inline void spin_some(const Node::SharedPtr& node) {
1030 if (!node || !node->initialized()) {
1031 return;
1032 }
1033 // The process executor's `spin_some`, the same drain as
1034 // `Executor::spin_some` and Rust's (`nros_cpp_spin_some`). It was one
1035 // `spin_once(0)` pass, which leaves work a callback made ready for the
1036 // next call.
1037 void* const executor = ::rclcpp::global_handle();
1038 if (executor == nullptr) return;
1039 (void)nros_cpp_spin_some(executor, 0);
1040}
1041
1045}
1046
1047// Future type is templated rather than `const auto& future` so the header
1048// stays parseable under `-std=c++14` (the C++20 abbreviated-function-template
1049// syntax breaks `just check cpp`'s freestanding probe).
1050//
1051// The bounded branch used to call `Executor::spin(timeout_ms)`
1052// and never consult the future, so it BURNED THE WHOLE TIMEOUT even when the
1053// future completed on the first spin: a `wait_for_service` / `send_request`
1054// sequence ported from rclcpp paid the full timeout on every SUCCESSFUL call.
1055// The unbounded branch directly below already had the right shape; both now
1056// share it, differing only in whether a deadline exists.
1071namespace detail {
1077template <typename F> inline bool future_is_ready(F& f) {
1078 return f.is_ready();
1079}
1080#if defined(NROS_CPP_HAS_STD_FUTURE) // hosted-family: future-interop
1081template <typename T> inline bool future_is_ready(const ::std::shared_future<T>& f) {
1082 return f.valid() && f.wait_for(::std::chrono::seconds(0)) == ::std::future_status::ready;
1083}
1084template <typename T> inline bool future_is_ready(::std::shared_future<T>& f) {
1085 return f.valid() && f.wait_for(::std::chrono::seconds(0)) == ::std::future_status::ready;
1086}
1087template <typename T> inline bool future_is_ready(::std::future<T>& f) {
1088 return f.valid() && f.wait_for(::std::chrono::seconds(0)) == ::std::future_status::ready;
1089}
1090#endif
1091} // namespace detail
1092
1093template <typename Future>
1095 int32_t timeout_ms = -1) {
1096 if (!node || !node->initialized()) {
1098 }
1099 // Poll slice: same 10 ms the unbounded loop always used.
1100 constexpr int32_t kPollMs = 10;
1101 const bool bounded = timeout_ms >= 0;
1102 const uint64_t start_ns = nros_cpp_time_ns();
1103 const uint64_t budget_ns = bounded ? static_cast<uint64_t>(timeout_ms) * 1000000ull : 0ull;
1104
1105 while (::rclcpp::ok()) {
1108 }
1109 (void)::rclcpp::spin_once(kPollMs);
1110 // Re-check before the deadline test: a future that became ready on the
1111 // spin just above must report SUCCESS even if the budget expired in
1112 // the same slice.
1115 }
1116 if (bounded && nros_cpp_time_ns() - start_ns >= budget_ns) {
1118 }
1119 }
1121}
1122
1123namespace detail {
1131template <typename Future>
1133 int32_t timeout_ms, bool process) {
1134 if (executor == nullptr) return FutureReturnCode::INTERRUPTED;
1135 constexpr int32_t kPollMs = 10;
1136 const bool bounded = timeout_ms >= 0;
1137 const uint64_t start_ns = nros_cpp_time_ns();
1138 const uint64_t budget_ns = bounded ? static_cast<uint64_t>(timeout_ms) * 1000000ull : 0ull;
1139 while (process ? ::rclcpp::ok() : !::nros_cpp_termination_requested()) {
1141 (void)nros_cpp_spin_once(executor, kPollMs);
1143 if (bounded && nros_cpp_time_ns() - start_ns >= budget_ns) return FutureReturnCode::TIMEOUT;
1144 }
1146}
1147
1149template <typename NodePtr>
1150inline void check_node_on_executor(const NodePtr& node, void* executor, bool process) {
1151 const bool live = node && node->initialized();
1152 const char* name = live ? node->get_name() : "";
1153 if (!live) {
1155 static_cast<int32_t>(ErrorCode::NotInitialized));
1156 }
1157 if (node->executor_handle() != executor) {
1158 // `say_refused` takes a LITERAL (its length is checked against the
1159 // log buffer), so the two refusals are spelled out, not passed in.
1160 if (process) {
1161 NROS_RCLCPP_SAY_REFUSED(NROS_RCLCPP_REFUSE_FOREIGN_EXECUTOR_NODE);
1162 } else {
1163 NROS_RCLCPP_SAY_REFUSED(NROS_RCLCPP_REFUSE_FOREIGN_NODE);
1164 }
1166 static_cast<int32_t>(ErrorCode::Unsupported));
1167 }
1168}
1169} // namespace detail
1170
1171template <typename Future>
1173 if (!initialized_) return FutureReturnCode::INTERRUPTED;
1174 return ::rclcpp::detail::spin_executor_until_future_complete(storage_, future, timeout_ms,
1175 false);
1176}
1177
1178template <typename NodePtr> inline void Executor::add_node(const NodePtr& node, bool notify) {
1179 (void)notify;
1180 ::rclcpp::detail::check_node_on_executor(node, static_cast<void*>(storage_), false);
1181}
1182
1183// --- rclcpp::executors --------------------------------------------
1184namespace executors {
1185
1206 public:
1208
1211 void add_node(const ::rclcpp::Node::SharedPtr& node, bool notify = true) {
1212 (void)notify;
1214 }
1215
1217 template <typename NodePtr, typename T = void>
1218 void remove_node(const NodePtr& node, bool notify = true) {
1219 (void)node;
1220 (void)notify;
1221 static_assert(::rclcpp::detail::refuse<T>::value, NROS_RCLCPP_REFUSE_REMOVE_NODE);
1222 }
1223
1227 template <typename Future>
1228 FutureReturnCode spin_until_future_complete(Future&& future, int32_t timeout_ms = -1) {
1229 return ::rclcpp::detail::spin_executor_until_future_complete(::rclcpp::global_handle(),
1230 future, timeout_ms, true);
1231 }
1232
1235 void spin_all(uint32_t max_duration_ms) {
1236 if (max_duration_ms == 0) {
1237 NROS_RCLCPP_SAY_REFUSED("spin_all(0) REFUSED: max_duration must be positive, as in "
1238 "rclcpp.");
1239 return;
1240 }
1241 spin_some(max_duration_ms);
1242 }
1243
1246 void spin_node_some(const ::rclcpp::Node::SharedPtr& node) {
1247 add_node(node);
1248 spin_some();
1249 }
1250
1254 void spin_node_once(const ::rclcpp::Node::SharedPtr& node, int32_t timeout_ms) {
1255 add_node(node);
1256 (void)::rclcpp::spin_once(timeout_ms);
1257 }
1258
1260 void spin() { (void)::rclcpp::spin_in(); }
1261
1264 void spin_some(uint32_t max_ms = 0) {
1265 void* const executor = ::rclcpp::global_handle();
1266 if (executor == nullptr) return;
1267 (void)nros_cpp_spin_some(executor, max_ms);
1268 }
1269};
1270
1272template <typename T = void> class MultiThreadedExecutorRefused {
1273 public:
1274 template <typename... Args> explicit MultiThreadedExecutorRefused(Args&&...) {
1275 static_assert(::rclcpp::detail::refuse<T>::value,
1276 NROS_RCLCPP_REFUSE_MULTI_THREADED_EXECUTOR);
1277 }
1278};
1279
1289
1290} // namespace executors
1291
1292} // namespace rclcpp
1293
1294#if defined(NROS_CPP_HAS_SHARED_PTR) // hosted-family: shared-ptr-interop
1295namespace rclcpp {
1296
1297// The upstream `main` is `rclcpp::spin(std::make_shared<MyNode>())`,
1298// a TEMPORARY `shared_ptr`. Binding it to a function parameter is safe (it lives
1299// for the call), but converting it to a `Node::SharedPtr` handle is refused
1300// because a STORED handle would dangle. These overloads take the `shared_ptr` by
1301// reference instead, so that line compiles unchanged and owns the node for
1302// exactly as long as the spin runs.
1303template <typename N, typename ::rclcpp::tr::enable_if<
1304 ::rclcpp::tr::is_convertible<N*, Node*>::value, int>::type = 0>
1305inline void spin(const ::std::shared_ptr<N>& node) {
1306 spin(Node::SharedPtr(node));
1307}
1308
1309template <typename N, typename ::rclcpp::tr::enable_if<
1310 ::rclcpp::tr::is_convertible<N*, Node*>::value, int>::type = 0>
1311inline void spin_some(const ::std::shared_ptr<N>& node) {
1313}
1314
1315template <
1316 typename N, typename Future,
1317 typename ::rclcpp::tr::enable_if<::rclcpp::tr::is_convertible<N*, Node*>::value, int>::type = 0>
1318inline FutureReturnCode spin_until_future_complete(const ::std::shared_ptr<N>& node,
1319 Future&& future, int32_t timeout_ms = -1) {
1320 return spin_until_future_complete(Node::SharedPtr(node), future, timeout_ms);
1321}
1322
1323} // namespace rclcpp
1324#endif // NROS_CPP_HAS_SHARED_PTR
1325
1326// -- dispatch verbs, freestanding -------------------------------
1327//
1328// The `const char*` overloads of `create_subscription` / `create_service` /
1329// `create_client`. Each result is a handle or an owned poll object, none of them
1330// allocates, and their bodies are the ones the hosted `std::string` overloads
1331// used to carry; those overloads now forward here.
1332
1333namespace rclcpp {
1334
1335namespace detail {
1336
1338template <typename M, typename Cb>
1339inline typename Subscription<M>::SharedPtr
1340create_subscription_dispatch(::rclcpp::Node& node, const char* topic, const ::rclcpp::QoS& qos,
1341 Cb cb, ::rclcpp::tr::false_type /* takes MessageInfo */) {
1342 // The arena owns everything, so this allocates nothing.
1343 //
1344 // This used to `make_shared` a `detail::SubscriptionCallback<M>` cell whose
1345 // only job was to give a capturing lambda a stable address, push it into
1346 // ~~`owned_entities`~~ to keep it alive, and hand back a `shared_ptr` aliasing
1347 // into it. W1 put the capture in the arena entry, so the cell has nothing
1348 // left to hold; W2 stops pretending the result is a pointer to an object.
1349 //
1350 // The callback's SHAPE decides what the arena holds: a
1351 // `const M&` callable as-is, or (hosted only) an adapter that hands a
1352 // pointer-shaped callback a heap copy of each message. Anything else is
1353 // refused here, naming the shapes, rather than as an `InplaceFn` conversion.
1355 static_assert(shape != ::rclcpp::detail::SUB_SHAPE_NONE || ::rclcpp::detail::refuse<Cb>::value,
1356 NROS_RCLCPP_REFUSE_SUBSCRIPTION_CALLBACK_SHAPE);
1357 using Capture = ::rclcpp::InplaceFn<void(const M&)>;
1359 ::rclcpp::tr::forward_rvalue(cb)));
1360 ::size_t handle_id = 0;
1362 node, topic, qos, captured, &handle_id);
1363 // The arena's copy owns the callable now and destroys it on
1364 // release; ours must not destroy it too.
1365 if (r.ok()) {
1366 captured.relinquish();
1367 }
1368 ::rclcpp::detail::require_created(r, "create_subscription", topic);
1369 return typename Subscription<M>::SharedPtr(node.executor_handle(), handle_id);
1370}
1371
1377template <typename M, typename Cb>
1378inline typename Subscription<M>::SharedPtr
1379create_subscription_dispatch(::rclcpp::Node& node, const char* topic, const ::rclcpp::QoS& qos,
1380 Cb cb, ::rclcpp::tr::true_type /* takes MessageInfo */) {
1382 static_assert(shape != ::rclcpp::detail::SUB_SHAPE_NONE || ::rclcpp::detail::refuse<Cb>::value,
1383 NROS_RCLCPP_REFUSE_SUBSCRIPTION_CALLBACK_SHAPE);
1384 using Capture = ::rclcpp::InplaceFn<void(const M&, const ::rclcpp::MessageInfo&)>;
1386 ::rclcpp::tr::forward_rvalue(cb)));
1387 ::size_t handle_id = 0;
1389 node, topic, qos, captured, &handle_id);
1390 // The arena's copy owns the callable now and destroys it on
1391 // release; ours must not destroy it too.
1392 if (r.ok()) {
1393 captured.relinquish();
1394 }
1395 ::rclcpp::detail::require_created(r, "create_subscription", topic);
1396 return typename Subscription<M>::SharedPtr(node.executor_handle(), handle_id);
1397}
1398
1399} // namespace detail
1400
1401// The hash-taking generic verbs.
1402inline ::rclcpp::Owned<::rclcpp::GenericPublisher>
1403Node::create_generic_publisher(const char* topic, const char* type, const char* type_hash,
1404 const ::rclcpp::QoS& qos) {
1405 ::rclcpp::GenericPublisher p;
1406 ::rclcpp::detail::require_created(::rclcpp::detail::create_generic_publisher(
1407 this->ffi_handle(), p, topic, type, type_hash, qos),
1408 "create_generic_publisher", topic);
1409 return ::rclcpp::Owned<::rclcpp::GenericPublisher>(::rclcpp::tr::forward_rvalue(p));
1410}
1411
1412template <typename Cb>
1413inline ::rclcpp::SubscriptionHandle<::rclcpp::GenericSubscription>
1414Node::create_generic_subscription(const char* topic, const char* type, const char* type_hash,
1415 const ::rclcpp::QoS& qos, Cb callback) {
1416 ::rclcpp::GenericSubscription::Callback fn(::rclcpp::tr::forward_rvalue(callback));
1417 ::size_t handle_id = 0;
1419 ::rclcpp::detail::register_generic_subscription(this->ffi_handle(), topic, type, type_hash,
1420 qos, fn, &handle_id),
1421 "create_generic_subscription", topic);
1422 return ::rclcpp::SubscriptionHandle<::rclcpp::GenericSubscription>(this->executor_handle(),
1423 handle_id);
1424}
1425
1426template <typename M, typename Cb>
1427inline typename Subscription<M>::SharedPtr
1428Node::create_subscription(const char* topic, const ::rclcpp::QoS& qos, Cb cb) {
1429 // A callback that takes no one-argument shape but does take
1430 // `(message, const MessageInfo&)` goes down the metadata path; every other
1431 // callback (including one that would take both) keeps the one-argument path.
1436 return ::rclcpp::detail::create_subscription_dispatch<M>(
1437 *this, topic, qos, ::rclcpp::tr::forward_rvalue(cb),
1438 ::rclcpp::tr::integral_constant<bool, takes_info>());
1439}
1440
1441template <typename M, typename Cb>
1443 ::size_t depth, Cb cb) {
1444 return this->create_subscription<M>(topic, ::rclcpp::QoS(static_cast<uint32_t>(depth)),
1445 ::rclcpp::tr::forward_rvalue(cb));
1446}
1447
1448template <typename M, typename Cb>
1449inline typename Subscription<M>::SharedPtr
1450Node::create_subscription(const char* topic, const ::rclcpp::QoS& qos, Cb cb,
1451 const ::rclcpp::SubscriptionOptions& options) {
1452 // `options.callback_group` is upstream's anonymous group, which
1453 // selects the node default (`rclcpp::CallbackGroupToken`), so it needs no
1454 // handling here. A scheduling context is a different matter: this overload
1455 // cannot bind one, and dropping it would schedule the callback somewhere
1456 // the caller did not ask for.
1457 if (options.sched_context != ::rclcpp::SCHED_CONTEXT_UNSET) {
1459 "create_subscription(..., options.sched_context)", topic);
1460 }
1461 // Metadata delivery is chosen by the CALLBACK, as upstream
1462 // chooses it: a callback taking `const rclcpp::MessageInfo&` gets it.
1463 // `options.message_info = true` with a callback that cannot receive it
1464 // would configure nothing, so it is refused rather than ignored.
1465 constexpr bool cb_takes_info =
1470 if (options.message_info && !cb_takes_info) {
1473 "create_subscription(..., options.message_info) with a callback taking no "
1474 "rclcpp::MessageInfo",
1475 topic);
1476 }
1477 return this->create_subscription<M>(topic, qos, ::rclcpp::tr::forward_rvalue(cb));
1478}
1479
1480template <typename M, typename Cb>
1481inline typename Subscription<M>::SharedPtr
1482Node::create_subscription(const char* topic, ::size_t depth, Cb cb,
1483 const ::rclcpp::SubscriptionOptions& options) {
1484 return this->create_subscription<M>(topic, ::rclcpp::QoS(static_cast<uint32_t>(depth)),
1485 ::rclcpp::tr::forward_rvalue(cb), options);
1486}
1487
1488template <typename S>
1489inline ::rclcpp::Owned<::rclcpp::PollService<S>> Node::create_service(const char* name,
1490 const ::rclcpp::QoS& qos) {
1491 // The POLL server, by value. `Service<S>::SharedPtr` is a
1492 // dispatch handle now, and this factory exists precisely to be
1493 // `->take_request()`'d, so it must hand back something dereferenceable.
1494 // `Owned<PollService<S>>` is that and costs no allocator; the node keeps no
1495 // second reference because there is no second reference to keep.
1497 ::rclcpp::detail::require_created(this->template create_service<S>(s, name, qos),
1498 "create_service", name);
1499 return ::rclcpp::Owned<::rclcpp::PollService<S>>(::rclcpp::tr::forward_rvalue(s));
1500}
1501
1502template <typename S, typename F, typename>
1503inline typename Service<S>::SharedPtr Node::create_service(const char* name, F callback,
1504 const ::rclcpp::QoS& qos) {
1505 // The arena owns the server and (W3) the handler, so this
1506 // allocates nothing and there is no cell to retain. The ~~`owned_entities`~~
1507 // push that used to stand here was LOAD-BEARING while the arena held
1508 // `&*s` — dropping the caller's pointer would have dangled it — and became
1509 // pure retention when W3 moved the context to the handler.
1510 Service<S> s;
1511 ::rclcpp::detail::require_created(this->template create_service<S>(s, name, callback, qos),
1512 "create_service", name);
1513 return typename Service<S>::SharedPtr(this->executor_handle(), s.handle_id());
1514}
1515
1516template <typename S, typename F, typename, typename>
1517inline typename Service<S>::SharedPtr Node::create_service(const char* name, F callback,
1518 const ::rclcpp::QoS& qos) {
1519#if defined(NROS_CPP_HAS_SHARED_PTR) // hosted-family: shared-ptr-interop
1520 // Upstream's `shared_ptr` handler, lent from the dispatch frame
1521 // (`detail::shared_ptr_service_trampoline`, no heap), when it converts to a
1522 // function pointer. A handler with STATE — `std::bind(&X::on_req, this, _1,
1523 // _2)`, a capturing lambda — is copied into the service's arena entry
1524 // instead (`detail::stateful_service_trampoline`), in any of the three
1525 // shapes. Anything invocable as none of them is refused, naming them.
1526 constexpr int shape = ::rclcpp::detail::service_ptr_shape<S, F>::value;
1527 constexpr int stateful = ::rclcpp::detail::stateful_service_shape<S, F>::value;
1528 static_assert(shape != 0 || stateful != 0 || ::rclcpp::detail::refuse<F>::value,
1529 NROS_RCLCPP_REFUSE_SERVICE_CALLBACK_SHAPE);
1530 Service<S> s;
1532 this->template register_hosted_service_<S>(
1533 s, name, ::rclcpp::tr::forward_rvalue(callback), qos,
1534 ::rclcpp::tr::integral_constant<int, (shape != 0 ? 0 : 1)>()),
1535 "create_service", name);
1536 return typename Service<S>::SharedPtr(this->executor_handle(), s.handle_id());
1537#else
1538 (void)name;
1539 (void)callback;
1540 (void)qos;
1541 static_assert(::rclcpp::detail::refuse<F>::value, NROS_RCLCPP_REFUSE_SERVICE_CALLBACK_SHAPE);
1542 return typename Service<S>::SharedPtr();
1543#endif // NROS_CPP_HAS_SHARED_PTR
1544}
1545
1546#if defined(NROS_CPP_HAS_SHARED_PTR) // hosted-family: shared-ptr-interop
1547template <typename S, typename F>
1548inline Result Node::register_hosted_service_(Service<S>& out, const char* name, F callback,
1549 const ::rclcpp::QoS& qos,
1550 ::rclcpp::tr::integral_constant<int, 0>) {
1551 constexpr int shape = ::rclcpp::detail::service_ptr_shape<S, F>::value;
1552 return this->template register_service_<S>(
1553 out, name, &::rclcpp::detail::shared_ptr_service_trampoline<S, shape>::call,
1554 ::rclcpp::detail::shared_ptr_service_context<S>(
1555 callback, ::rclcpp::tr::integral_constant<int, (shape == 3 ? 3 : 2)>()),
1556 qos, ::rclcpp::ServiceOptions());
1557}
1558
1559template <typename S, typename F>
1560inline Result Node::register_hosted_service_(Service<S>& out, const char* name, F callback,
1561 const ::rclcpp::QoS& qos,
1562 ::rclcpp::tr::integral_constant<int, 1>) {
1563 constexpr int stateful = ::rclcpp::detail::stateful_service_shape<S, F>::value;
1564 using Fn = ::rclcpp::detail::StatefulServiceFn<S>;
1565 Fn captured(::rclcpp::detail::stateful_service_adapter<S, (stateful != 0 ? stateful : 1)>::wrap(
1566 ::rclcpp::tr::forward_rvalue(callback)));
1567 const Result r = this->template register_service_<S>(
1568 out, name, &::rclcpp::detail::stateful_service_trampoline<S>::call, nullptr, qos,
1569 ::rclcpp::ServiceOptions(), &captured, sizeof(Fn),
1570 &::rclcpp::detail::stateful_service_trampoline<S>::destroy);
1571 // The arena's copy owns the callable now and destroys it on release.
1572 if (r.ok()) {
1573 captured.relinquish();
1574 }
1575 return r;
1576}
1577#endif // NROS_CPP_HAS_SHARED_PTR
1578
1579template <typename S, typename F>
1580inline typename Service<S>::SharedPtr Node::create_service(const char* name, F callback,
1581 const ::rclcpp::QoS& qos,
1582 const ::rclcpp::CallbackGroup* group) {
1583 // See the declaration: an anonymous group is null here.
1584 if (group != nullptr && group->get_name() != nullptr) {
1586 "create_service(..., named callback group)", name);
1587 }
1588 return this->template create_service<S>(name, ::rclcpp::tr::forward_rvalue(callback), qos);
1589}
1590
1591template <typename S>
1592inline ::rclcpp::Owned<::rclcpp::PollClient<S>> Node::create_client(const char* name,
1593 const ::rclcpp::QoS& qos) {
1594 // The FUTURE-style client, by value. `Client<S>::SharedPtr`
1595 // is a dispatch handle now, and this factory exists precisely to be
1596 // `->send_request()`'d, so it must hand back something dereferenceable.
1597 // `Owned<PollClient<S>>` is that and costs no allocator; the node keeps no
1598 // second reference because there is no second reference to keep.
1600 ::rclcpp::detail::require_created(this->template create_client<S>(c, name, qos),
1601 "create_client", name);
1602 return ::rclcpp::Owned<::rclcpp::PollClient<S>>(::rclcpp::tr::forward_rvalue(c));
1603}
1604
1605template <typename S, typename F, typename>
1606inline typename Client<S>::SharedPtr Node::create_client(const char* name, F callback,
1607 const ::rclcpp::QoS& qos) {
1608 // The arena owns the client and (W3) the handler, so this
1609 // allocates nothing and there is no cell to retain. The ~~`owned_entities`~~
1610 // push that used to stand here was LOAD-BEARING while the arena held
1611 // `&*c` — dropping the caller's pointer would have dangled it — and became
1612 // pure retention when W3 moved the context to the handler. Same removal W5
1613 // made one entity over.
1614 Client<S> c;
1615 ::rclcpp::detail::require_created(this->template create_client<S>(c, name, callback, qos),
1616 "create_client", name);
1617 return typename Client<S>::SharedPtr(this->executor_handle(), c.handle_id());
1618}
1619
1620template <typename S, typename F, typename, typename>
1621inline typename Client<S>::SharedPtr Node::create_client(const char*, F, const ::rclcpp::QoS&) {
1622 static_assert(::rclcpp::detail::refuse<F>::value,
1623 NROS_RCLCPP_REFUSE_SHARED_PTR_SERVICE_CALLBACK);
1624 return typename Client<S>::SharedPtr();
1625}
1626
1627} // namespace rclcpp
1628
1629// -- timers -------------------------------------------------------------------
1630//
1631// FREESTANDING. The callable is copied into the executor arena
1632// (`nros_cpp_timer_create_capturing`), which destroys it when the timer is
1633// released, so these allocate nothing and return a two-word `TimerHandle`.
1634// Defined after the hosted block so that, on a hosted target, the
1635// `shared_ptr` member of `as_node_ref`'s overload set is already declared when
1636// `rclcpp::create_timer`'s body names it.
1637
1638namespace rclcpp {
1639namespace detail {
1640
1644template <typename F> class timer_takes_info {
1645 typedef char yes_t[1];
1646 typedef char no_t[2];
1647 template <typename G>
1648 static yes_t& probe(G* g, decltype((*g)(*static_cast<const TimerInfo*>(nullptr)), 0));
1649 template <typename G> static no_t& probe(...);
1650
1651 public:
1652 static const bool value = sizeof(probe<F>(nullptr, 0)) == sizeof(yes_t);
1653};
1654
1658template <typename F, bool TakesInfo = timer_takes_info<F>::value> struct TimerAdapter {
1659 F f;
1660 void operator()(const nros_cpp_timer_call_info_t& raw) {
1661 const rcl_clock_type_t clock = static_cast<rcl_clock_type_t>(raw.clock_type);
1662 const TimerInfo info{Time(raw.expected_call_time, clock),
1663 Time(raw.actual_call_time, clock)};
1664 f(info);
1665 }
1666};
1667template <typename F> struct TimerAdapter<F, false> {
1668 F f;
1669 void operator()(const nros_cpp_timer_call_info_t&) { f(); }
1670};
1671
1677template <typename F> struct timer_capture_capacity {
1678 static constexpr tr::size_type value = NROS_CPP_CALLBACK_CAPACITY;
1679};
1680template <typename Sig, tr::size_type Cap> struct timer_capture_capacity<InplaceFn<Sig, Cap>> {
1681 static constexpr tr::size_type value = sizeof(TimerAdapter<InplaceFn<Sig, Cap>>);
1682};
1683
1699template <typename Cb>
1700inline TimerHandle register_timer_capturing(::rclcpp::Node& node, rcl_clock_type_t clock_type,
1701 Duration period, Cb&& cb, const char* verb,
1702 const CallbackGroup* group = nullptr,
1703 bool autostart = true) {
1704 using F = typename tr::decay<Cb>::type;
1705 using Adapter = TimerAdapter<F>;
1706 using Capture =
1707 InplaceFn<void(const nros_cpp_timer_call_info_t&), timer_capture_capacity<F>::value>;
1708 Capture captured(Adapter{tr::relay<Cb>(cb)});
1709 // Non-capturing lambdas, so each decays to the plain function pointer the
1710 // arena stores. `ctx` is the ARENA's copy of `captured`, never ours.
1711 nros_cpp_timer_info_callback_t invoke = [](const nros_cpp_timer_call_info_t* info, void* ctx) {
1712 (*static_cast<Capture*>(ctx))(*info);
1713 };
1714 nros_cpp_timer_callback_t destroy = [](void* ctx) { static_cast<Capture*>(ctx)->clear(); };
1715 const int64_t ns = period.nanoseconds();
1716 const uint64_t ms = ns > 0 ? static_cast<uint64_t>(ns / 1000000) : uint64_t(0);
1717 size_t handle_id = 0;
1718 const nros_cpp_node_t* h = node.ffi_handle();
1719 const char* group_name = group != nullptr ? group->get_name() : nullptr;
1720 Result r = h == nullptr ? Result(ErrorCode::NotInitialized)
1721 : Result(nros_cpp_timer_create_capturing_with_info(
1722 h, static_cast<uint8_t>(clock_type), ms, invoke,
1723 reinterpret_cast<const uint8_t*>(&captured), sizeof(Capture),
1724 destroy, group_name, autostart, &handle_id));
1725 if (r.ok()) {
1726 captured.relinquish();
1727 }
1728 // A null return would be silent HERE above all: a ported node stores the
1729 // timer handle and never dereferences it, so a dead timer would simply
1730 // never fire.
1732 return TimerHandle(node.executor_handle(), handle_id);
1733}
1734
1735} // namespace detail
1736} // namespace rclcpp
1737
1738namespace rclcpp {
1739
1740template <typename Cb>
1741inline ::rclcpp::TimerHandle Node::create_wall_timer(::rclcpp::Duration period, Cb cb,
1742 const ::rclcpp::CallbackGroup* group,
1743 bool autostart) {
1744 return ::rclcpp::detail::register_timer_capturing(*this, RCL_STEADY_TIME, period,
1745 ::rclcpp::tr::forward_rvalue(cb),
1746 "create_wall_timer", group, autostart);
1747}
1748
1749#ifdef NROS_CPP_HAS_STD_CHRONO // hosted-family: chrono-interop
1750template <typename Rep, typename Period, typename Cb>
1751inline ::rclcpp::TimerHandle Node::create_wall_timer(::std::chrono::duration<Rep, Period> period,
1752 Cb cb, const ::rclcpp::CallbackGroup* group,
1753 bool autostart) {
1754 const auto ns = ::std::chrono::duration_cast<::std::chrono::nanoseconds>(period).count();
1755 return this->create_wall_timer(::rclcpp::Duration::from_nanoseconds(static_cast<int64_t>(ns)),
1756 ::rclcpp::tr::forward_rvalue(cb), group, autostart);
1757}
1758#endif // NROS_CPP_HAS_STD_CHRONO
1759
1760namespace detail {
1765inline ::rclcpp::Node& as_node_ref(const ::rclcpp::Node::SharedPtr& n) {
1766 return *n;
1767}
1768inline ::rclcpp::Node& as_node_ref(::rclcpp::Node& n) {
1769 return n;
1770}
1771inline ::rclcpp::Node& as_node_ref(::rclcpp::Node* n) {
1772 return *n;
1773}
1774} // namespace detail
1775
1789template <typename NodeT, typename CallbackT>
1790inline ::rclcpp::TimerHandle
1791create_timer(NodeT&& node, ::rclcpp::Clock* clock, ::rclcpp::Duration period, CallbackT&& callback,
1792 const ::rclcpp::CallbackGroup* group = nullptr, bool autostart = true) {
1794 const rcl_clock_type_t type =
1795 clock != nullptr ? clock->get_clock_type() : n.get_clock()->get_clock_type();
1796 return ::rclcpp::detail::register_timer_capturing(n, type, period,
1797 ::rclcpp::tr::relay<CallbackT>(callback),
1798 "create_timer", group, autostart);
1799}
1800
1801#ifdef NROS_CPP_HAS_STD_CHRONO // hosted-family: chrono-interop
1807template <typename NodeT, typename Rep, typename Period, typename CallbackT>
1808inline ::rclcpp::TimerHandle
1809create_timer(NodeT&& node, ::rclcpp::Clock* clock, ::std::chrono::duration<Rep, Period> period,
1810 CallbackT&& callback, const ::rclcpp::CallbackGroup* group = nullptr,
1811 bool autostart = true) {
1812 const auto ns = ::std::chrono::duration_cast<::std::chrono::nanoseconds>(period).count();
1813 return create_timer(::rclcpp::tr::relay<NodeT>(node), clock,
1814 ::rclcpp::Duration::from_nanoseconds(static_cast<int64_t>(ns)),
1815 ::rclcpp::tr::relay<CallbackT>(callback), group, autostart);
1816}
1817#endif // NROS_CPP_HAS_STD_CHRONO
1818
1819} // namespace rclcpp
1820
1821// --- node parameters ---------------------------------------------------------
1822//
1823// Out here rather than in the hosted block above: see the note at the
1824// `-- parameters --` marker there, and `node.hpp` for why the gate moved to
1825// the `std::string`-keyed overloads alone.
1826
1827// -- parameters ---------------------------------------------------------------
1828//
1829// Forwarders onto THE parameter store — the `nros_params::ParameterServer` the
1830// EXECUTOR owns, reached through `rclcpp/node_parameters.hpp`. There is no other
1831// one any more.
1832//
1833// What changed, and why it is not a detail: these used to
1834// forward to an inline `nros::ParameterServer<NROS_RCLCPP_MAX_PARAMS>` member
1835// on the hosted block — a second store, node-local, which the six
1836// `rcl_interfaces/srv/*` servers could not read. So a parameter declared here
1837// was invisible to `ros2 param get`, a sibling node did not share it, and the
1838// launch seed had to be copied across by a helper because the two stores could
1839// not be the same object. The member is deleted; the seam is one FFI call;
1840// `ros2 param get <node> <name>` sees what `declare_parameter` wrote.
1841//
1842//
1843// ADOPT-BOUNDED still, and the envelope is now about TYPES rather than scope:
1844// bool / int / int64_t / double reach the store, `std::string` and
1845// `std::vector<T>` do under `NROS_CPP_STD`, and rclcpp's `ParameterDescriptor`
1846// / `ignore_override` / callback arguments remain absent (the
1847// compile-time-options rule). The WIRE half of the acceptance — that the six
1848// services answer per node FQN — is tested on the wire.
1849//
1850// Where the image declares no `param_services` capability there is no store at
1851// all, and every call answers `ErrorCode::Unsupported`. This facade wears
1852// upstream's value-returning signature, which has nowhere to report that, so
1853// `declare_parameter` returns the code default. The loud half USED to be
1854// `nros::ComponentNode`, whose own facade recorded the failure on an `ok()`
1855// flag and made it boot-fatal; that type is deleted, so no C++ path
1856// is boot-fatal on a missing store any more.
1857//
1858// A store that EXISTS and refuses is another matter: a full
1859// store used to take this same silent `return default_value`, so a launch
1860// override was lost and a controller ran on its compiled gains. That refusal
1861// now goes through `rclcpp::Node`'s `set_error` latch, as upstream's
1862// exception would end the node; only `Unsupported` keeps the default.
1863
1883
1884namespace rclcpp {
1885namespace detail {
1886inline void refuse_param_declare(Node& node, int32_t code) {
1887 if (code == NROS_CPP_RET_UNSUPPORTED) {
1888 return;
1889 }
1890 // The runtime printed the line naming the node, the parameter and the
1891 // store's capacity (`Executor::report_parameter_refused`).
1892 node.set_error(code == NROS_CPP_RET_FULL ? PARAM_STORE_FULL_WHAT : PARAM_DECLARE_REFUSED_WHAT,
1893 code);
1894}
1895
1900template <typename T>
1901inline void report_param_value_type_mismatch(const ::nros_cpp_node_t* h, const char* node,
1902 const char* param) {
1903 const char* n = (node != nullptr) ? node : "?";
1904 const char* p = (param != nullptr) ? param : "?";
1905 const int declared = node_param_type<T>::value;
1906 const char* want = ::rclcpp::declared_param_type_name(declared);
1907 int64_t i = 0;
1908 double d = 0.0;
1909 bool b = false;
1910 char str[64];
1911 if (node_param_get(h, param, i).ok()) {
1912 if (declared == ::rclcpp::param_type::DOUBLE) {
1913 NROS_ERROR("node \"%s\": parameter \"%s\" is declared double but the launch value is "
1914 "the integer %lld; write %lld.0 in the YAML.",
1915 n, p, static_cast<long long>(i), static_cast<long long>(i));
1916 } else {
1917 NROS_ERROR("node \"%s\": parameter \"%s\" is declared %s but the launch value is the "
1918 "integer %lld; write a %s value in the YAML.",
1919 n, p, want, static_cast<long long>(i), want);
1920 }
1921 } else if (node_param_get(h, param, d).ok()) {
1922 NROS_ERROR("node \"%s\": parameter \"%s\" is declared %s but the launch value is the "
1923 "double %g; write a %s value in the YAML.",
1924 n, p, want, d, want);
1925 } else if (node_param_get(h, param, b).ok()) {
1926 NROS_ERROR("node \"%s\": parameter \"%s\" is declared %s but the launch value is the "
1927 "bool %s; write a %s value in the YAML.",
1928 n, p, want, b ? "true" : "false", want);
1929 } else if (node_param_get(h, param, str, sizeof(str)).ok()) {
1930 NROS_ERROR("node \"%s\": parameter \"%s\" is declared %s but the launch value is the "
1931 "string \"%s\"; write a %s value in the YAML.",
1932 n, p, want, str, want);
1933 } else {
1934 NROS_ERROR("node \"%s\": parameter \"%s\" is declared %s but the launch value has "
1935 "another type; write a %s value in the YAML.",
1936 n, p, want, want);
1937 }
1938}
1939} // namespace detail
1940
1941template <typename T> inline T Node::declare_parameter(const char* name, T default_value) {
1942 // A declaration the contract's `params:` does not make, or
1943 // makes with another type, refuses the boot through `set_error` before
1944 // anything reaches the store (see `Node::check_declared_param`).
1945 if (!this->check_declared_param(name, ::rclcpp::detail::node_param_type<T>::value)) {
1946 return default_value;
1947 }
1948 const ::nros_cpp_node_t* h = this->ffi_handle();
1949 Result r = ::rclcpp::detail::node_param_declare(h, name, default_value);
1950 if (!r.ok() && r.raw() != RCLC_RET_ALREADY_EXISTS) {
1952 return default_value;
1953 }
1954 T out = T();
1955 if (!::rclcpp::detail::node_param_get(h, name, out).ok()) {
1956 if (r.raw() == RCLC_RET_ALREADY_EXISTS) {
1960 }
1961 return default_value;
1962 }
1963 return out;
1964}
1965} // namespace rclcpp
1966
1967namespace rclcpp {} // namespace rclcpp
1968
1969namespace rclcpp {
1970template <typename T> inline bool Node::get_parameter(const char* name, T& out) const {
1971 return ::rclcpp::detail::node_param_get(this->ffi_handle(), name, out).ok();
1972}
1973} // namespace rclcpp
1974
1975namespace rclcpp {} // namespace rclcpp
1976
1977namespace rclcpp {
1978template <typename T> inline T Node::get_parameter(const char* name) const {
1979 T out = T();
1980 (void)::rclcpp::detail::node_param_get(this->ffi_handle(), name, out);
1981 return out;
1982}
1983} // namespace rclcpp
1984
1985namespace rclcpp {
1986
1991} // namespace rclcpp
1992
1993namespace rclcpp {
1994template <typename T> inline Result Node::set_parameter(const char* name, T value) {
1995 return ::rclcpp::detail::node_param_set(this->ffi_handle(), name, value);
1996}
1997} // namespace rclcpp
1998
1999namespace rclcpp {} // namespace rclcpp
2000
2001namespace rclcpp {
2002inline bool Node::has_parameter(const char* name) const {
2003 return ::rclcpp::detail::node_param_has(this->ffi_handle(), name);
2004}
2005} // namespace rclcpp
2006
2007// --- the rest of rclcpp's parameter surface -----------------
2008//
2009// Every one of these is a forwarder onto the executor's ONE store through
2010// `rclcpp/node_parameters.hpp`. None of them holds state; a wrapper that did
2011// would be the second store that was removed, in a smaller spelling.
2012
2013namespace rclcpp {
2014
2015template <typename T>
2016inline T Node::declare_parameter(const char* name, T default_value,
2017 const ParameterDescriptor& descriptor) {
2018 T in_effect = this->template declare_parameter<T>(name, default_value);
2019 // The descriptor is attached AFTER the declaration, which is the store's
2020 // own shape (rclc's `rclc_add_parameter_description` & co.). A failure
2021 // here leaves the parameter declared with its value, which is what
2022 // upstream does when the descriptor is consistent with the default — and
2023 // when it is not, the attach refuses rather than advertising a bound the
2024 // value breaks.
2025 (void)::rclcpp::detail::node_param_apply_descriptor(
2026 this->ffi_handle(), name, descriptor, ::rclcpp::detail::node_param_type<T>::value);
2027 return in_effect;
2028}
2029
2030template <typename T>
2031inline bool Node::get_parameter_or(const char* name, T& out, T fallback) const {
2032 if (::rclcpp::detail::node_param_get(this->ffi_handle(), name, out).ok()) {
2033 return true;
2034 }
2035 out = fallback;
2036 return false;
2037}
2038
2039inline Result Node::undeclare_parameter(const char* name) {
2040 return ::rclcpp::detail::node_param_undeclare(this->ffi_handle(), name);
2041}
2042
2043inline ParameterType Node::get_parameter_type(const char* name) const {
2044 int32_t code = 0;
2045 if (!::rclcpp::detail::node_param_get_type(this->ffi_handle(), name, code).ok()) {
2046 return PARAMETER_NOT_SET;
2047 }
2048 return static_cast<ParameterType>(code);
2049}
2050
2051inline Result Node::get_parameter_types(const char* const* names, ::size_t count,
2052 ParameterType* out) const {
2053 if ((names == nullptr || out == nullptr) && count != 0) {
2054 return Result(RCL_RET_INVALID_ARGUMENT);
2055 }
2056 for (::size_t i = 0; i < count; ++i) {
2057 out[i] = this->get_parameter_type(names[i]);
2058 }
2059 return Result(RCL_RET_OK);
2060}
2061
2062inline Result Node::describe_parameter(const char* name, ParameterDescriptor& out, char* text,
2063 ::size_t text_len) const {
2064 out = parameter_descriptor();
2065 // The buffer is split in half, one NUL-terminated string in each, so ONE
2066 // caller buffer serves both texts and neither can run into the other.
2067 char* description = nullptr;
2068 char* constraints = nullptr;
2069 ::size_t half = 0;
2070 if (text != nullptr && text_len >= 2) {
2071 half = text_len / 2;
2072 description = text;
2073 constraints = text + half;
2074 }
2075 int32_t type = 0;
2076 Result r = ::rclcpp::detail::node_param_describe(this->ffi_handle(), name, description, half,
2077 constraints, half, &out.read_only, &type);
2078 if (r.raw() == RCLC_RET_NOT_FOUND) {
2079 return r;
2080 }
2081 out.description = description;
2082 out.additional_constraints = constraints;
2083
2084 // The range, read through whichever accessor the TYPE picks. NOT_FOUND
2085 // from it means "no range", which is not a failure of `describe`.
2086 if (type == ::rclcpp::param_type::INTEGER) {
2087 out.has_range =
2088 ::rclcpp::detail::node_param_get_range(this->ffi_handle(), name, &out.integer_from,
2089 &out.integer_to, &out.integer_step)
2090 .ok();
2091 } else if (type == ::rclcpp::param_type::DOUBLE) {
2092 out.has_range =
2093 ::rclcpp::detail::node_param_get_range(this->ffi_handle(), name, &out.double_from,
2094 &out.double_to, &out.double_step)
2095 .ok();
2096 }
2097 return r;
2098}
2099
2100inline Result Node::list_parameters(const char* prefix, char* out_names, ::size_t name_stride,
2101 ::size_t max_names, ::size_t& count) const {
2102 return ::rclcpp::detail::node_param_list(this->ffi_handle(), prefix, out_names, name_stride,
2103 max_names, &count);
2104}
2105
2106inline Result Node::set_parameters_atomically(const ParameterWrite* writes, ::size_t count) {
2107 return ::rclcpp::detail::node_params_set_atomically(this->ffi_handle(), writes, count);
2108}
2109
2110inline Result Node::add_on_set_parameters_callback(OnSetParametersCallbackType callback,
2111 void* context,
2112 OnSetParametersCallbackToken& out_handle) {
2113 return ::rclcpp::detail::node_param_add_on_set_callback(this->ffi_handle(), callback, context,
2114 &out_handle);
2115}
2116
2117inline Result Node::remove_on_set_parameters_callback(OnSetParametersCallbackToken handle) {
2118 return ::rclcpp::detail::node_param_remove_on_set_callback(this->ffi_handle(), handle);
2119}
2120
2121} // namespace rclcpp
2122
2123// --- the value-object parameter surface (hosted) ----------------------------
2124//
2125// Dispatchers from `ParameterValue` / `Parameter` onto the typed methods
2126// above. No state: a `Parameter` read here is built from the store each time.
2127
2128#ifdef NROS_CPP_STD // hosted-family: parameter-interop
2129namespace rclcpp {
2130namespace detail {
2131
2132template <typename T>
2133inline T node_declare_typed(Node& n, const char* name, T v, const ParameterDescriptor* d) {
2134 return d != nullptr ? n.template declare_parameter<T>(name, v, *d)
2135 : n.template declare_parameter<T>(name, v);
2136}
2137
2138inline ParameterValue node_declare_value(Node& n, const char* name, const ParameterValue& v,
2139 const ParameterDescriptor* d) {
2140 switch (v.get_type()) {
2141 case PARAMETER_BOOL:
2142 return ParameterValue(node_declare_typed<bool>(n, name, v.as_bool(), d));
2143 case PARAMETER_INTEGER:
2144 return ParameterValue(
2145 static_cast<long long>(node_declare_typed<int64_t>(n, name, v.as_int(), d)));
2146 case PARAMETER_DOUBLE:
2147 return ParameterValue(node_declare_typed<double>(n, name, v.as_double(), d));
2148 case PARAMETER_STRING:
2149 return ParameterValue(node_declare_typed<::std::string>(n, name, v.as_string(), d));
2150 case PARAMETER_BOOL_ARRAY:
2151 return ParameterValue(
2152 node_declare_typed<::std::vector<bool>>(n, name, v.as_bool_array(), d));
2153 case PARAMETER_INTEGER_ARRAY:
2154 return ParameterValue(
2155 node_declare_typed<::std::vector<int64_t>>(n, name, v.as_integer_array(), d));
2156 case PARAMETER_DOUBLE_ARRAY:
2157 return ParameterValue(
2158 node_declare_typed<::std::vector<double>>(n, name, v.as_double_array(), d));
2159 default:
2160 // NOT_SET, a byte array or a string array: no store form.
2161 return ParameterValue();
2162 }
2163}
2164
2168template <typename D> inline ParameterDescriptor descriptor_from_message(const D& m) {
2169 ParameterDescriptor d = ::rclcpp::parameter_descriptor();
2170 d.description = m.description.c_str();
2171 d.additional_constraints = m.additional_constraints.c_str();
2172 d.read_only = m.read_only;
2173 for (const auto& r : m.floating_point_range) {
2174 d.has_range = true;
2175 d.double_from = r.from_value;
2176 d.double_to = r.to_value;
2177 d.double_step = r.step;
2178 break;
2179 }
2180 for (const auto& r : m.integer_range) {
2181 d.has_range = true;
2182 d.integer_from = r.from_value;
2183 d.integer_to = r.to_value;
2184 d.integer_step = static_cast<int64_t>(r.step);
2185 break;
2186 }
2187 return d;
2188}
2189
2190inline Node::SetParametersOutcome node_set_outcome(Result r) {
2191 Node::SetParametersOutcome o;
2192 o.successful = r.ok();
2193 if (!o.successful) {
2194 o.reason = "set_parameter refused (nano-ros code " + ::std::to_string(r.raw()) + ")";
2195 }
2196 return o;
2197}
2198
2199} // namespace detail
2200
2201inline ParameterValue Node::declare_parameter(const char* name,
2202 const ParameterValue& default_value) {
2203 return ::rclcpp::detail::node_declare_value(*this, name, default_value, nullptr);
2204}
2205
2206inline ParameterValue Node::declare_parameter(const char* name, const ParameterValue& default_value,
2207 const ParameterDescriptor& descriptor) {
2208 return ::rclcpp::detail::node_declare_value(*this, name, default_value, &descriptor);
2209}
2210
2211template <typename D, typename>
2212inline ParameterValue Node::declare_parameter(const char* name, const ParameterValue& default_value,
2213 const D& descriptor) {
2214 const ParameterDescriptor d = ::rclcpp::detail::descriptor_from_message(descriptor);
2215 return ::rclcpp::detail::node_declare_value(*this, name, default_value, &d);
2216}
2217
2218template <typename T, typename D, typename>
2219inline T Node::declare_parameter(const char* name, T default_value, const D& descriptor) {
2220 const ParameterDescriptor d = ::rclcpp::detail::descriptor_from_message(descriptor);
2221 return this->template declare_parameter<T>(name, default_value, d);
2222}
2223
2224inline bool Node::get_parameter(const char* name, Parameter& out) const {
2225 ParameterValue v;
2226 switch (this->get_parameter_type(name)) {
2227 case PARAMETER_BOOL: {
2228 bool x = false;
2229 if (!this->template get_parameter<bool>(name, x)) return false;
2230 v = ParameterValue(x);
2231 break;
2232 }
2233 case PARAMETER_INTEGER: {
2234 int64_t x = 0;
2235 if (!this->template get_parameter<int64_t>(name, x)) return false;
2236 v = ParameterValue(static_cast<long long>(x));
2237 break;
2238 }
2239 case PARAMETER_DOUBLE: {
2240 double x = 0.0;
2241 if (!this->template get_parameter<double>(name, x)) return false;
2242 v = ParameterValue(x);
2243 break;
2244 }
2245 case PARAMETER_STRING: {
2246 ::std::string x;
2247 if (!this->template get_parameter<::std::string>(name, x)) return false;
2248 v = ParameterValue(x);
2249 break;
2250 }
2251 case PARAMETER_BOOL_ARRAY: {
2252 ::std::vector<bool> x;
2253 if (!this->template get_parameter<::std::vector<bool>>(name, x)) return false;
2254 v = ParameterValue(x);
2255 break;
2256 }
2257 case PARAMETER_INTEGER_ARRAY: {
2258 ::std::vector<int64_t> x;
2259 if (!this->template get_parameter<::std::vector<int64_t>>(name, x)) return false;
2260 v = ParameterValue(x);
2261 break;
2262 }
2263 case PARAMETER_DOUBLE_ARRAY: {
2264 ::std::vector<double> x;
2265 if (!this->template get_parameter<::std::vector<double>>(name, x)) return false;
2266 v = ParameterValue(x);
2267 break;
2268 }
2269 default:
2270 return false;
2271 }
2272 out = Parameter(::std::string(name), v);
2273 return true;
2274}
2275
2276inline Parameter Node::get_parameter(const ::std::string& name) const {
2277 Parameter p(name);
2278 (void)this->get_parameter(name.c_str(), p);
2279 return p;
2280}
2281
2282inline ::std::vector<Parameter>
2283Node::get_parameters(const ::std::vector<::std::string>& names) const {
2284 ::std::vector<Parameter> out;
2285 out.reserve(names.size());
2286 for (const auto& n : names) {
2287 out.push_back(this->get_parameter(n));
2288 }
2289 return out;
2290}
2291
2292inline Node::SetParametersOutcome Node::set_parameter(const Parameter& p) {
2293 const char* name = p.get_name().c_str();
2294 Result r(NROS_CPP_RET_UNSUPPORTED);
2295 switch (p.get_type()) {
2296 case PARAMETER_BOOL:
2297 r = this->template set_parameter<bool>(name, p.as_bool());
2298 break;
2299 case PARAMETER_INTEGER:
2300 r = this->template set_parameter<int64_t>(name, p.as_int());
2301 break;
2302 case PARAMETER_DOUBLE:
2303 r = this->template set_parameter<double>(name, p.as_double());
2304 break;
2305 case PARAMETER_STRING:
2306 r = this->template set_parameter<::std::string>(name, p.as_string());
2307 break;
2308 case PARAMETER_BOOL_ARRAY:
2309 r = this->template set_parameter<::std::vector<bool>>(name, p.as_bool_array());
2310 break;
2311 case PARAMETER_INTEGER_ARRAY:
2312 r = this->template set_parameter<::std::vector<int64_t>>(name, p.as_integer_array());
2313 break;
2314 case PARAMETER_DOUBLE_ARRAY:
2315 r = this->template set_parameter<::std::vector<double>>(name, p.as_double_array());
2316 break;
2317 default:
2318 break;
2319 }
2320 return ::rclcpp::detail::node_set_outcome(r);
2321}
2322
2323inline ::std::vector<Node::SetParametersOutcome>
2324Node::set_parameters(const ::std::vector<Parameter>& parameters) {
2325 ::std::vector<SetParametersOutcome> out;
2326 out.reserve(parameters.size());
2327 for (const auto& p : parameters) {
2328 out.push_back(this->set_parameter(p));
2329 }
2330 return out;
2331}
2332
2333template <typename F>
2334inline node_interfaces::OnSetParametersCallbackHandle::SharedPtr
2335Node::add_on_set_parameters_callback(F callback) {
2336 using Handle = node_interfaces::OnSetParametersCallbackHandle;
2337 auto handle = ::std::make_shared<Handle>();
2338 handle->callback = [callback](const ::std::vector<Parameter>& params) mutable -> bool {
2339 return static_cast<bool>(callback(params).successful);
2340 };
2341 handle->node = this->ffi_handle();
2342 Result r = ::rclcpp::detail::node_param_add_on_set_callback(handle->node, &Handle::trampoline,
2343 handle.get(), &handle->token);
2344 if (!r.ok()) {
2345 return nullptr;
2346 }
2347 handle->registered = true;
2348 return handle;
2349}
2350
2351inline void Node::remove_on_set_parameters_callback(
2352 const node_interfaces::OnSetParametersCallbackHandle* handle) {
2353 if (handle != nullptr) {
2354 const_cast<node_interfaces::OnSetParametersCallbackHandle*>(handle)->unregister();
2355 }
2356}
2357
2358namespace node_interfaces {
2359inline bool NodeParametersInterface::has_parameter(const ::std::string& name) const {
2360 return node_ != nullptr && node_->has_parameter(name);
2361}
2362inline ParameterValue NodeParametersInterface::declare_parameter(const ::std::string& name,
2363 const ParameterValue& v) {
2364 return node_ == nullptr ? ParameterValue() : node_->declare_parameter(name, v);
2365}
2366template <typename D>
2367inline ParameterValue NodeParametersInterface::declare_parameter(const ::std::string& name,
2368 const ParameterValue& v,
2369 const D& descriptor) {
2370 return node_ == nullptr ? ParameterValue() : node_->declare_parameter(name, v, descriptor);
2371}
2372inline bool NodeParametersInterface::get_parameter(const ::std::string& name,
2373 Parameter& out) const {
2374 return node_ != nullptr && node_->get_parameter(name, out);
2375}
2376inline Parameter NodeParametersInterface::get_parameter(const ::std::string& name) const {
2377 return node_ == nullptr ? Parameter(name) : node_->get_parameter(name);
2378}
2379inline const ::std::map<::std::string, ParameterValue>&
2380NodeParametersInterface::get_parameter_overrides() const {
2381 using Map = ::std::map<::std::string, ParameterValue>;
2382 // One copy per node, keyed by its FFI handle, so every call (and every
2383 // view of the node) returns the same map. The executor dispatches on one
2384 // task, which is what makes a plain static safe here.
2385 static ::std::map<const void*, Map> copies;
2386 static Map none;
2387 if (node_ == nullptr || node_->ffi_handle() == nullptr) {
2388 return none;
2389 }
2390 struct Sink {
2391 static bool add(const ParameterWrite* write, void* context) {
2392 if (write != nullptr && write->name != nullptr) {
2393 (*static_cast<Map*>(context))[write->name] =
2394 Parameter::from_write(*write).get_parameter_value();
2395 }
2396 return true;
2397 }
2398 };
2399 Map now;
2400 (void)::rclcpp::detail::node_param_list_overrides(node_->ffi_handle(), &Sink::add, &now,
2401 nullptr);
2402 Map& kept = copies[node_->ffi_handle()];
2403 if (kept != now) {
2404 kept = static_cast<Map&&>(now);
2405 }
2406 return kept;
2407}
2408} // namespace node_interfaces
2409
2410} // namespace rclcpp
2411#endif // NROS_CPP_STD
2412
2413// --- Rate / WallRate ----------------------------------------
2414//
2415// A FORWARDER onto `rclcpp::spin(remaining_ms, poll_ms)`, which budgets by wall
2416// clock inside `nros_cpp_spin_for` — Rust-side, once.
2417//
2418// The obvious fifteen-line class with its own sleep loop is NOT admissible
2419// here, and the distinction is the whole point of this item: a loop in the
2420// wrapper that spins the executor is thin-wrapper violation class 2, and a wrapper
2421// that BLOCKS without spinning is what the blocking-API rule forbids. Same capability, and
2422// only one of the two shapes is allowed. So `sleep()` computes a deadline and
2423// makes exactly one call into the entry point that already exists.
2424//
2425// ADOPT-BOUNDED, and the envelope is load-bearing enough that a ported loop
2426// behaves DIFFERENTLY here even though it compiles unchanged:
2427//
2428// * **Your callbacks RUN during the sleep.** `rclcpp::spin` drives the
2429// executor, so subscriptions and timers registered on the arena fire while
2430// `rate.sleep()` is blocked. Under a single-threaded rclcpp executor they
2431// do not — `Rate::sleep()` there is a pure `sleep_for`, and callbacks only
2432// run when you call `spin_some`. The nano-ros behaviour is the one a
2433// `while (ok()) { work(); rate.sleep(); }` loop usually WANTS (it is why
2434// that loop needs a second thread upstream), but it is not the same
2435// contract, and a callback that races your loop body is the way it shows.
2436// That includes a `rclcpp::Node`'s OWN timers and
2437// subscriptions: they are executor entities now, so `rate.sleep()` runs
2438// them.
2439// * `Rate` and `WallRate` are the SAME clock. Upstream's `Rate` measures ROS
2440// time and `WallRate` steady time; both here read the monotonic
2441// `nros_cpp_time_ns()`, so a `Rate` does not slow down under a sim clock.
2442// `WallRate` is faithful; `Rate` is `WallRate` under a second name.
2443// * Resolution is ONE MILLISECOND — the FFI budget is `uint32_t` ms — and the
2444// remaining time is rounded UP, so a period below 1 ms cannot be met and a
2445// rate faster than 1 kHz is not expressible.
2446// * Before `rclcpp::init()` there is no executor to spin, so `sleep()` returns
2447// immediately rather than blocking. A rate loop that runs before init busy
2448// spins; upstream would have slept.
2449//
2450// Gated on `<chrono>` alone: the duration constructor and `period()` are spelled
2451// in `std::chrono`, and everything else it touches is an integer.
2452// `Rate` EXISTS ON EVERY TARGET.
2453//
2454// It used to sit inside `#ifdef NROS_CPP_HAS_STD_CHRONO`, which made the whole
2455// type a property of the toolchain: a node written against `rclcpp::Rate`
2456// compiled on a host and vanished on ThreadX. Measured, the gate was paying for
2457// two members out of five — `Rate(double)`, `sleep()` and `reset()` are integer
2458// arithmetic over `nros_cpp_time_ns()` and never needed `<chrono>` at all.
2459//
2460// The two that did are handled differently, and the difference is the rule
2461// of one API everywhere. `period()` returns `rclcpp::Duration`, which is ours and
2462// exists everywhere, so the type's SHAPE no longer follows a probe. The
2463// `std::chrono` CONSTRUCTOR stays behind the capability macro, which is a gate
2464// on a METHOD — permitted, since `sizeof(Rate)` is `int64_t` + `uint64_t` in
2465// every configuration and two translation units cannot disagree about it.
2466//
2467// That constructor is the one thing here W8 still has to resolve: its parameter
2468// names `std::chrono::duration`, and W8's acceptance is zero `NROS_CPP_HAS_*` in
2469// the tree. Recorded rather than quietly left, because a gated method is exactly
2470// the kind of residue that reads as finished work.
2471
2472namespace rclcpp {
2473
2476class Rate {
2477 public:
2480 explicit Rate(double frequency_hz)
2481 : period_ns_(frequency_hz > 0.0 ? static_cast<int64_t>(1000000000.0 / frequency_hz) : 0) {
2482 reset();
2483 }
2484
2487 explicit Rate(::rclcpp::Duration period) : period_ns_(period.nanoseconds()) {
2488 if (period_ns_ < 0) period_ns_ = 0;
2489 reset();
2490 }
2491
2492#ifdef NROS_CPP_HAS_STD_CHRONO // hosted-family: chrono-interop
2498 template <typename Rep, typename Period>
2499 explicit Rate(std::chrono::duration<Rep, Period> period)
2500 : period_ns_(std::chrono::duration_cast<std::chrono::nanoseconds>(period).count()) {
2501 if (period_ns_ < 0) period_ns_ = 0;
2502 reset();
2503 }
2504#endif
2505
2511 bool sleep() {
2512 if (period_ns_ <= 0) {
2513 return false;
2514 }
2515 const uint64_t now_ns = nros_cpp_time_ns();
2516 if (now_ns >= next_tick_ns_) {
2517 // Overran. Re-anchor on now rather than firing a burst to catch up
2518 // — upstream's `Rate` contract, and the choice the retired
2519 // node-local `pump()` used to make for wall timers before they
2520 // became executor timers (which catch up instead; see the envelope
2521 // on `rclcpp::Timer`).
2522 next_tick_ns_ = now_ns + static_cast<uint64_t>(period_ns_);
2523 return false;
2524 }
2525 const uint64_t remaining_ns = next_tick_ns_ - now_ns;
2526 // Round UP: truncating a 0.4 ms remainder to 0 would turn `sleep()`
2527 // into a busy loop.
2528 uint32_t remaining_ms = static_cast<uint32_t>((remaining_ns + 999999ull) / 1000000ull);
2529 if (remaining_ms == 0) remaining_ms = 1;
2530 next_tick_ns_ += static_cast<uint64_t>(period_ns_);
2531 const int32_t poll_ms = remaining_ms < 10u ? static_cast<int32_t>(remaining_ms) : 10;
2532 (void)::rclcpp::spin_in(remaining_ms, poll_ms);
2533 return true;
2534 }
2535
2537 void reset() { next_tick_ns_ = nros_cpp_time_ns() + static_cast<uint64_t>(period_ns_); }
2538
2545 ::rclcpp::Duration period() const { return ::rclcpp::Duration::from_nanoseconds(period_ns_); }
2546
2547 private:
2548 int64_t period_ns_;
2549 uint64_t next_tick_ns_;
2550};
2551
2555
2556} // namespace rclcpp
2557
2558// `rclcpp_action::create_client` / `create_server`, at upstream's
2559// paths. Included LAST because they build on everything above
2560// (`detail::require_created`); the umbrella reaches them as it reaches
2561// `rclcpp_action::Client` / `Server`, so `#include <rclcpp/rclcpp.hpp>` alone
2562// is enough for a ported action node, as upstream's transitive includes are.
2563#include "rclcpp_action/create_client.hpp"
2564#include "rclcpp_action/create_server.hpp"
2565// `rclcpp::ParameterEventHandler`, at upstream's umbrella. LAST for
2566// the same reason: it builds on `Node::create_subscription`.
2567#include "rclcpp/parameter_event_handler.hpp"
2568
2569#endif // NROS_RCLCPP_RCLCPP_HPP
::rclcpp::ClientHandle< S > SharedPtr
Definition client.hpp:142
Definition node.hpp:197
Definition rclcpp.hpp:214
Context()
Definition rclcpp.hpp:217
Context(void *executor)
Definition rclcpp.hpp:218
Context SharedPtr
Definition rclcpp.hpp:216
Result add_pre_shutdown_callback(ShutdownCallback callback, void *context, PreShutdownCallbackHandle *out=nullptr)
The C-callback forms, on every target. See rclcpp::pre_shutdown.
Definition rclcpp.hpp:227
bool remove_pre_shutdown_callback(const PreShutdownCallbackHandle &handle)
true when handle named a live callback.
Definition rclcpp.hpp:245
Context * operator->()
Definition rclcpp.hpp:219
void * executor_handle() const
The executor handle this context names; null for an empty one.
Definition rclcpp.hpp:222
const Context * operator->() const
Definition rclcpp.hpp:220
bool remove_on_shutdown_callback(const OnShutdownCallbackHandle &handle)
Definition rclcpp.hpp:254
bool is_valid() const
Context::is_valid() — named, and not yet shut down.
Definition rclcpp.hpp:224
Result add_on_shutdown_callback(ShutdownCallback callback, void *context, OnShutdownCallbackHandle *out=nullptr)
Definition rclcpp.hpp:236
void add_node(const NodePtr &node, bool notify=true)
Definition rclcpp.hpp:1178
FutureReturnCode spin_until_future_complete(Future &&future, int32_t timeout_ms=-1)
Definition rclcpp.hpp:1172
Definition future.hpp:337
Definition node.hpp:874
const nros_cpp_node_t * ffi_handle() const
Definition node.hpp:1919
Result get_parameter_types(const char *const *names, ::size_t count, ParameterType *out) const
Definition rclcpp.hpp:2051
Result add_on_set_parameters_callback(OnSetParametersCallbackType callback, void *context, OnSetParametersCallbackToken &out_handle)
Definition rclcpp.hpp:2110
::rclcpp::Owned<::rclcpp::PollService< S > > create_service(const char *name, const ::rclcpp::QoS &qos=::rclcpp::QoS::services())
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)
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
bool get_parameter_or(const char *name, T &out, T fallback) const
Definition rclcpp.hpp:2031
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
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::Handle< Node > SharedPtr
Definition node.hpp:1080
void set_error(const char *what, int32_t code)
Definition node.hpp:2973
const char * get_name() const
Get the node name.
Definition node.hpp:1783
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)
Result set_parameter(const char *name, T value)
Definition rclcpp.hpp:1994
Clock * get_clock()
Definition node.hpp:1891
Result undeclare_parameter(const char *name)
Definition rclcpp.hpp:2039
::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
Definition executor.hpp:91
Definition node.hpp:221
Definition node.hpp:217
Definition executor.hpp:84
Definition publisher.hpp:179
::rclcpp::Owned< Publisher< M > > SharedPtr
Definition publisher.hpp:203
Definition qos.hpp:276
Definition rclcpp.hpp:2476
bool sleep()
Definition rclcpp.hpp:2511
Rate(::rclcpp::Duration period)
Definition rclcpp.hpp:2487
Rate(double frequency_hz)
Definition rclcpp.hpp:2480
void reset()
rclcpp::Rate::reset() — anchor the next tick one period from now.
Definition rclcpp.hpp:2537
::rclcpp::Duration period() const
Definition rclcpp.hpp:2545
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 service.hpp:146
size_t handle_id() const
Executor arena slot for the registration; SIZE_MAX until registered.
Definition service.hpp:282
::rclcpp::ServiceHandle< S > SharedPtr
Definition service.hpp:158
::rclcpp::SubscriptionHandle< M > SharedPtr
Definition subscription.hpp:220
Definition timer.hpp:153
Definition rclcpp.hpp:1644
static const bool value
Definition rclcpp.hpp:1652
The refusal behind MultiThreadedExecutor; see that alias.
Definition rclcpp.hpp:1272
MultiThreadedExecutorRefused(Args &&...)
Definition rclcpp.hpp:1274
void spin_some(uint32_t max_ms=0)
Definition rclcpp.hpp:1264
void spin()
Block until rclcpp::ok() goes false — rclcpp::spin_in().
Definition rclcpp.hpp:1260
void remove_node(const NodePtr &node, bool notify=true)
REFUSED — remove_node; see rclcpp::Executor::remove_node.
Definition rclcpp.hpp:1218
FutureReturnCode spin_until_future_complete(Future &&future, int32_t timeout_ms=-1)
Definition rclcpp.hpp:1228
SingleThreadedExecutor()
Definition rclcpp.hpp:1207
void spin_node_once(const ::rclcpp::Node::SharedPtr &node, int32_t timeout_ms)
Definition rclcpp.hpp:1254
void spin_all(uint32_t max_duration_ms)
Definition rclcpp.hpp:1235
void add_node(const ::rclcpp::Node::SharedPtr &node, bool notify=true)
Definition rclcpp.hpp:1211
void spin_node_some(const ::rclcpp::Node::SharedPtr &node)
Definition rclcpp.hpp:1246
Node * node() const
The node this handle names (null for a default-constructed one).
Definition node.hpp:254
Context get_context() const
Definition rclcpp.hpp:337
rclcpp::Future<T> — single-shot deferred result.
int nros_cpp_ret_t
Definition future.hpp:25
nros_cpp_ret_t nros_cpp_spin_once(void *handle, int32_t timeout_ms)
uint64_t nros_cpp_time_ns(void)
Definition rclcpp.hpp:305
Context get_global_default_context()
Definition rclcpp.hpp:308
Definition rclcpp.hpp:437
void check_node_on_executor(const NodePtr &node, void *executor, bool process)
The add_node check, against one executor handle.
Definition rclcpp.hpp:1150
Subscription< M >::SharedPtr create_subscription_dispatch(::rclcpp::Node &node, const char *topic, const ::rclcpp::QoS &qos, Cb cb, ::rclcpp::tr::false_type)
The one-argument callback path (void(const M&), or a hosted pointer shape).
Definition rclcpp.hpp:1340
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 abort_failed_create(const char *verb, const char *name, int32_t code)
Definition rclcpp.hpp:497
@ SUB_SHAPE_NONE
Definition subscription.hpp:719
void require_created(::rclcpp::Result r, const char *verb, const char *name)
Definition rclcpp.hpp:512
void report_param_value_type_mismatch(const ::nros_cpp_node_t *h, const char *node, const char *param)
Definition rclcpp.hpp:1901
TimerHandle register_timer_capturing(::rclcpp::Node &node, rcl_clock_type_t clock_type, Duration period, Cb &&cb, const char *verb, const CallbackGroup *group=nullptr, bool autostart=true)
Definition rclcpp.hpp:1700
constexpr bool is_ros_args_flag(char const *s, int i=0)
Definition rclcpp.hpp:444
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
int32_t apply_ros_args(void *executor, int argc, char const *const *argv)
Definition node.hpp:3572
Result register_subscription_capturing_message_info(::rclcpp::Node &node, const char *topic, const QoS &qos, const Fn &fn, size_t *out_handle_id)
Definition subscription.hpp:900
inline ::rclcpp::Node & as_node_ref(const ::rclcpp::Node::SharedPtr &n)
Definition rclcpp.hpp:1765
Result register_subscription_capturing(::rclcpp::Node &node, const char *topic, const QoS &qos, const Fn &fn, size_t *out_handle_id)
Definition subscription.hpp:935
FutureReturnCode spin_executor_until_future_complete(void *executor, Future &future, int32_t timeout_ms, bool process)
Definition rclcpp.hpp:1132
constexpr const char * PARAM_DECLARE_REFUSED_WHAT
The set_error text for any other refusal of a declaration.
Definition node.hpp:679
bool future_is_ready(F &f)
Definition rclcpp.hpp:1077
constexpr bool argv_has_ros_args(int argc, char const *const *argv, int i=0)
Definition rclcpp.hpp:451
Definition rclcpp.hpp:1184
MultiThreadedExecutorRefused<> MultiThreadedExecutor
Definition rclcpp.hpp:1288
Definition rclcpp.hpp:336
NodeInterfaceHandle< 0 > NodeBaseInterface
Definition node.hpp:268
Definition rclcpp.hpp:75
constexpr uint32_t kTraceAppMarkerFirst
First application trace marker id (see trace_marker).
Definition rclcpp.hpp:118
Rate WallRate
Definition rclcpp.hpp:2554
void(*)(void *context) ShutdownCallback
Definition executor.hpp:47
void spin(const Node::SharedPtr &node)
Definition rclcpp.hpp:1016
void spin_some(const Node::SharedPtr &node)
Definition rclcpp.hpp:1029
inline ::rclcpp::TimerHandle create_timer(NodeT &&node, ::rclcpp::Clock *clock, ::rclcpp::Duration period, CallbackT &&callback, const ::rclcpp::CallbackGroup *group=nullptr, bool autostart=true)
Definition rclcpp.hpp:1791
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
FutureReturnCode
Definition rclcpp.hpp:608
@ TIMEOUT
The deadline passed with the future still pending.
Definition rclcpp.hpp:611
@ INTERRUPTED
rclcpp::ok() went false (shutdown) before the future was ready.
Definition rclcpp.hpp:613
@ SUCCESS
Definition rclcpp.hpp:609
void init()
rclcpp::init() — the zero-argument form. ADOPT.
Definition rclcpp.hpp:561
FutureReturnCode spin_until_future_complete(const Node::SharedPtr &node, Future &&future, int32_t timeout_ms=-1)
Definition rclcpp.hpp:1094
bool remove_on_shutdown_callback(OnShutdownCallbackHandle handle)
Definition rclcpp.hpp:197
bool ok()
Definition node.hpp:3641
Result spin_in()
Definition rclcpp.hpp:350
Result trace_marker(uint32_t id, uint32_t arg)
Definition rclcpp.hpp:132
void * global_handle()
Definition node.hpp:3562
Result on_shutdown(ShutdownCallback callback, void *context=nullptr, OnShutdownCallbackHandle *out=nullptr)
Definition rclcpp.hpp:175
bool shutdown()
Definition rclcpp.hpp:578
constexpr uint32_t kTraceAppMarkerLast
Definition rclcpp.hpp:121
bool remove_pre_shutdown_callback(PreShutdownCallbackHandle handle)
Definition rclcpp.hpp:189
void arm_monitors()
Definition rclcpp.hpp:113
@ NotInitialized
Definition result.hpp:131
@ Unsupported
Operation not implemented by the active backend.
Definition result.hpp:152
Result pre_shutdown(ShutdownCallback callback, void *context=nullptr, PreShutdownCallbackHandle *out=nullptr)
Definition rclcpp.hpp:156
ResultOf< void > Result
Definition result.hpp:247
rclcpp::Node and global session helpers.
rclcpp::Publisher<M> — typed topic publisher.
rclcpp::QoS — full DDS-shaped QoS settings.
rclcpp::Client<S> — the arena-registered (callback-style) service client, and Client<S>::SharedPtr = ...
**auto handle
Definition client.hpp:127
rclcpp::Result, rclcpp::ErrorCode, and the RCLCPP_TRY macro.
rclcpp::format_of<M> — a message type's serialization format; rclcpp::linked_format() — the linked ba...
rclcpp::Service<S> — the arena-registered (callback-style) service server, and Service<S>::SharedPtr ...
rclcpp::Stream<T> — multi-shot message receiver.
Definition timer.hpp:550
void operator()(const nros_cpp_timer_call_info_t &)
Definition rclcpp.hpp:1669
F f
Definition rclcpp.hpp:1668
Definition rclcpp.hpp:1658
F f
Definition rclcpp.hpp:1659
void operator()(const nros_cpp_timer_call_info_t &raw)
Definition rclcpp.hpp:1660
Definition subscription.hpp:767
Which SubscriptionCallbackShape the callable F is, for message M.
Definition subscription.hpp:761
Definition subscription.hpp:874
static constexpr tr::size_type value
Definition rclcpp.hpp:1681
Definition rclcpp.hpp:1677
static constexpr tr::size_type value
Definition rclcpp.hpp:1678
rclcpp::Subscription<M> — the typed DISPATCH subscriber: the arena owns it and the executor calls you...