10#ifndef NROS_RCLCPP_NODE_HPP
11#define NROS_RCLCPP_NODE_HPP
16#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0)
18#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0)
50#if defined(NROS_CPP_STD)
57#include "rclcpp/detail/nros_cpp_ffi.h"
59#include "rclcpp/detail/traits.hpp"
60#include "rclcpp/handle.hpp"
62#include "rclcpp/owned.hpp"
63#include "rclcpp/detail/hosted_block.hpp"
64#include "rclcpp/detail/nros_cpp_config_generated.h"
74#include "rclc/detail/entry_config.h"
79#include "rclcpp/options.hpp"
93#include "rclcpp/clock.hpp"
104#include "rclcpp/detail/declared_qos.hpp"
105#include "rclcpp/detail/declared_params.hpp"
111#include "rclcpp/node_parameters.hpp"
115#include "rclcpp/parameter_value.hpp"
116#include "rclcpp/logging.hpp"
121#include "rclcpp/graph.hpp"
123#include "rclcpp/callback_group.hpp"
132#include "rclcpp/parameter.hpp"
137#include "rclcpp/detail/std_detect.hpp"
142struct rmw_request_id_t;
172static_assert(NROS_CPP_RET_NOT_FOUND == -4 && NROS_CPP_RET_ALREADY_EXISTS == -5 &&
173 NROS_CPP_RET_FULL == -6 && NROS_CPP_RET_NOT_INIT == -7 &&
174 NROS_CPP_RET_TRY_AGAIN == -14 && NROS_CPP_RET_REENTRANT == -15 &&
175 NROS_CPP_RET_UNSUPPORTED == -16,
176 "nros_cpp_ret_t diverged from the shared numbering: NROS_CPP_RET_* must "
177 "keep the rcl_ret_t values");
196template <
typename S>
class Service;
198class GenericPublisher;
199class GenericSubscription;
204template <
typename A>
class Server;
205template <
typename A>
class Client;
255 explicit operator bool()
const {
return node_ !=
nullptr; }
293class NodeParametersInterface {
295 using SharedPtr = NodeParametersInterface;
296 NodeParametersInterface() : node_(nullptr) {}
297 explicit NodeParametersInterface(
Node* node) : node_(node) {}
298 NodeParametersInterface* operator->() {
return this; }
299 const NodeParametersInterface* operator->()
const {
return this; }
300 explicit operator bool()
const {
return node_ !=
nullptr; }
301 Node* node()
const {
return node_; }
303 inline bool has_parameter(const ::std::string& name)
const;
304 inline ParameterValue declare_parameter(const ::std::string& name,
305 const ParameterValue& default_value);
306 template <
typename D>
307 inline ParameterValue declare_parameter(const ::std::string& name,
308 const ParameterValue& default_value,
309 const D& descriptor);
310 inline bool get_parameter(const ::std::string& name, Parameter& out)
const;
311 inline Parameter get_parameter(const ::std::string& name)
const;
312 inline const ::std::map<::std::string, ParameterValue>& get_parameter_overrides()
const;
327struct OnSetParametersCallbackHandle {
328 using SharedPtr = ::std::shared_ptr<OnSetParametersCallbackHandle>;
329 using WeakPtr = ::std::weak_ptr<OnSetParametersCallbackHandle>;
333 using OnParametersSetCallbackType = ::std::function<bool(const ::std::vector<Parameter>&)>;
335 OnSetParametersCallbackHandle() : node(nullptr), token(0), registered(false) {}
336 OnSetParametersCallbackHandle(
const OnSetParametersCallbackHandle&) =
delete;
337 OnSetParametersCallbackHandle&
operator=(
const OnSetParametersCallbackHandle&) =
delete;
338 ~OnSetParametersCallbackHandle() { unregister(); }
343 (void)::rclcpp::detail::node_param_remove_on_set_callback(node, token);
349 static bool trampoline(
const ParameterWrite* write,
void* context) {
350 auto* self =
static_cast<OnSetParametersCallbackHandle*
>(context);
351 if (write ==
nullptr || self ==
nullptr || !self->callback) {
354 ::std::vector<Parameter> params;
355 params.push_back(Parameter::from_write(*write));
356 return self->callback(params);
359 OnParametersSetCallbackType callback;
360 const nros_cpp_node_t* node;
361 OnSetParametersCallbackToken token;
437 constexpr NodeHandle(
void* exec,
const char* name,
const char* ns)
443 constexpr NodeHandle(
void* exec,
const char* name,
const char* ns,
444 const nros_cpp_qos_override_t* overrides,
size_t override_count)
495 NROS_ERROR(
"node \"%s\": FAILED at %s (code=%d)", (node_name !=
nullptr) ? node_name :
"?",
496 (what !=
nullptr) ? what :
"?",
static_cast<int>(code));
497#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0)
498 ::fprintf(stderr,
"[nros] FATAL: node \"%s\" failed to construct at %s (code=%d)\n",
499 (node_name !=
nullptr) ? node_name :
"?", (what !=
nullptr) ? what :
"?",
500 static_cast<int>(code));
518 NROS_ERROR(
"node \"%s\": topic \"%s\" DECLARED depth %d but the QoS "
519 "passed states %d. Depth multiplies the executor arena, so they must agree.",
520 (node_name !=
nullptr) ? node_name :
"?", (topic !=
nullptr) ? topic :
"?", declared,
522#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0)
524 "[nros] FATAL: node \"%s\": topic \"%s\" was DECLARED depth %d in "
525 "the contract sidecar (<stem>.contract.yaml) but the QoS passed to "
526 "create_subscription_in states depth %d. Depth multiplies the executor "
527 "arena (cost is (depth+1)*bound per subscription), so the two must agree. "
528 "Fix the contract row or the call site.\n",
529 (node_name !=
nullptr) ? node_name :
"?", (topic !=
nullptr) ? topic :
"?", declared,
546 int len,
const char* list) {
547 const char* node = (node_name !=
nullptr) ? node_name :
"?";
548 const char* group = (name !=
nullptr) ? name :
"?";
549 const char* declared = (list !=
nullptr) ? list :
"";
552 const bool created = (how !=
nullptr && how[0] ==
'c');
554 NROS_ERROR(
"node \"%s\": created callback group \"%.*s\", not in CALLBACK_GROUPS \"%s\"",
555 node, len, group, declared);
557 NROS_ERROR(
"node \"%s\": CALLBACK_GROUPS \"%s\" declares \"%.*s\", never created", node,
558 declared, len, group);
560#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0)
562 created ?
"[nros] FATAL: node \"%s\" created callback group \"%.*s\", which its "
563 "registration's CALLBACK_GROUPS \"%s\" does not declare.\n"
564 :
"[nros] FATAL: node \"%s\" never created callback group \"%.*s\", which "
565 "its registration's CALLBACK_GROUPS \"%s\" declares.\n",
566 node, len, group, declared);
569 " The sched task derivation ranks the declared list and the executor binds what the "
570 "code creates, so the two must name the same groups (ONE declared group and none "
571 "created is node-level placement, and is allowed). Fix the "
572 "nano_ros_node_register(... CALLBACK_GROUPS ...) line or the create_callback_group "
588 const char* policy,
const char* declared,
589 const char* passed) {
590 NROS_ERROR(
"node \"%s\": topic \"%s\" DECLARED %s %s but the QoS passed states %s. An "
591 "incompatible-QoS match never delivers, so they must agree.",
592 (node_name !=
nullptr) ? node_name :
"?", (topic !=
nullptr) ? topic :
"?", policy,
594#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0)
596 "[nros] FATAL: node \"%s\": topic \"%s\" was DECLARED %s %s in the contract "
597 "sidecar (<stem>.contract.yaml) but the QoS passed to create_subscription_in "
598 "states %s. Fix the contract row or the call site.\n",
599 (node_name !=
nullptr) ? node_name :
"?", (topic !=
nullptr) ? topic :
"?", policy,
635 int declared,
int passed) {
636 const char* f = (fqn !=
nullptr) ? fqn :
"?";
637 const char* p = (param !=
nullptr) ? param :
"?";
638 const char* c = (contract !=
nullptr) ? contract :
"?";
639 if (declared == ::rclcpp::DECLARED_PARAM_UNDECLARED) {
640 NROS_ERROR(
"node \"%s\": parameter \"%s\" is not declared in its contract (%s).", f, p, c);
642 NROS_ERROR(
"node \"%s\": parameter \"%s\" is declared %s in its contract (%s) but the "
643 "code declares it as %s.",
644 f, p, ::rclcpp::declared_param_type_name(declared), c,
645 ::rclcpp::declared_param_type_name(passed));
647#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0)
648 if (declared == ::rclcpp::DECLARED_PARAM_UNDECLARED) {
650 "[nros] FATAL: node \"%s\": parameter \"%s\" is not declared in its "
651 "contract (%s, `params:`). The parameter store is sized from that "
652 "declaration, so a parameter it does not name has no slot. Declare it "
653 "there with its type, or stop declaring it in the code.\n",
657 "[nros] FATAL: node \"%s\": parameter \"%s\" is declared `%s` in its "
658 "contract (%s) but the code declares it as `%s`. Fix the contract or "
659 "the code so they state one type.\n",
660 f, p, ::rclcpp::declared_param_type_name(declared), c,
661 ::rclcpp::declared_param_type_name(passed));
675 "declare_parameter: parameter store full; raise `max_parameters` under [knobs.params] "
676 "(NROS_PARAMS_MAX_PARAMETERS / CONFIG_NROS_PARAMS_MAX_PARAMETERS)";
680 "declare_parameter: the parameter store refused it, so its launch/YAML value is not applied";
684 "declare_parameter: its launch/YAML value has another type than the code declares (the "
685 "line above says what to write)";
707inline Result init_in(
const char* locator =
nullptr, uint8_t domain_id = 0);
728inline Result init_in(
const char* locator, uint8_t domain_id,
const char* session_name);
748inline Result init_in(
const char* locator, uint8_t domain_id,
const char* session_name,
749 const char* node_namespace);
768inline Result init_with_rmw(
const char* rmw,
const char* locator =
nullptr, uint8_t domain_id = 0,
769 const char* session_name =
"node");
793inline Result init_in(
int argc,
char const*
const* argv,
const char* session_name =
nullptr);
878 Node() : handle_(), initialized_(false), executor_handle_(nullptr), clock_(RCL_ROS_TIME) {}
895 explicit Node(
const char* name,
const char* ns =
nullptr)
896 : handle_(), initialized_(false), executor_handle_(nullptr), clock_(RCL_ROS_TIME) {
897 (void)this->
init(name, ns);
898#if defined(NROS_AMENT_START_PARAMETER_SERVICES)
916 executor_handle_ = Node::global_storage();
959 : handle_(), initialized_(false), executor_handle_(nullptr), clock_(RCL_ROS_TIME) {
961 this->set_error(
"ctor (null executor handle)", -1);
965 this->init_on(
handle.executor,
handle.resolve_name(name),
handle.resolve_namespace(ns));
967 this->set_error(
"node create", r.raw());
974 if (
handle.qos_overrides !=
nullptr &&
handle.qos_override_count != 0) {
975 nros_cpp_ret_t qrc = ::nros_cpp_node_set_qos_overrides(&handle_, handle.qos_overrides,
976 handle.qos_override_count);
977 if (qrc != NROS_CPP_RET_OK) {
978 this->set_error(
"set_qos_overrides", static_cast<int32_t>(qrc));
998 bool ok()
const {
return initialized_ && !__atomic_load_n(&has_error_, __ATOMIC_ACQUIRE); }
1005 (void)__atomic_load_n(&has_error_, __ATOMIC_ACQUIRE);
1010 (void)__atomic_load_n(&has_error_, __ATOMIC_ACQUIRE);
1037 Node(
const char* name, const ::rclcpp::NodeOptions& options) :
Node(name, nullptr) {
1038 apply_options_(options);
1044 Node(
const char* name,
const char* ns, const ::rclcpp::NodeOptions& options) :
Node(name, ns) {
1045 apply_options_(options);
1053#ifdef NROS_CPP_HAS_STD_STRING
1055 explicit Node(const ::std::string& name) : Node(name.c_str(), nullptr) {}
1058 Node(const ::std::string& name, const ::rclcpp::NodeOptions& options)
1059 :
Node(name.c_str(), options) {}
1062 Node(const ::std::string& name, const ::std::string& ns,
1063 const ::rclcpp::NodeOptions& options = ::rclcpp::NodeOptions())
1064 : Node(name.c_str(), ns.c_str(), options) {}
1109 return ::rclcpp::node_interfaces::NodeBaseInterface(
this);
1113 return ::rclcpp::node_interfaces::NodeClockInterface(
this);
1117 return ::rclcpp::node_interfaces::NodeGraphInterface(
this);
1121 return ::rclcpp::node_interfaces::NodeLoggingInterface(
this);
1125 return ::rclcpp::node_interfaces::NodeWaitablesInterface(
this);
1128#if defined(NROS_CPP_HAS_SHARED_PTR)
1143 template <typename... Args> static ::std::shared_ptr<Node> make_shared(Args&&... args) {
1144 return ::std::make_shared<Node>(
static_cast<Args&&
>(args)...);
1148 template <
typename... Args> static ::std::unique_ptr<Node> make_unique(Args&&... args) {
1149 return ::std::unique_ptr<Node>(
new Node(
static_cast<Args&&
>(args)...));
1164#ifdef NROS_CPP_HAS_STD_STRING
1172 template <
typename M>
1173 typename ::rclcpp::Publisher<M>::SharedPtr
create_publisher(const ::std::string& topic,
1174 const ::rclcpp::QoS& qos);
1177 template <
typename M>
1178 typename ::rclcpp::Publisher<M>::SharedPtr
create_publisher(const ::std::string& topic,
1183 template <
typename M,
typename Cb>
1184 typename ::rclcpp::Subscription<M>::SharedPtr
1185 create_subscription(const ::std::string& topic, const ::rclcpp::QoS& qos, Cb cb);
1188 template <
typename M,
typename Cb>
1189 typename ::rclcpp::Subscription<M>::SharedPtr create_subscription(const ::std::string& topic,
1190 ::size_t depth, Cb cb);
1193 template <
typename M,
typename Cb>
1194 typename ::rclcpp::Subscription<M>::SharedPtr
1195 create_subscription(const ::std::string& topic, const ::rclcpp::QoS& qos, Cb cb,
1196 const ::rclcpp::SubscriptionOptions& options) {
1197 return this->create_subscription<M>(topic.c_str(), qos, ::rclcpp::tr::forward_rvalue(cb),
1202 template <
typename M,
typename Cb>
1203 typename ::rclcpp::Subscription<M>::SharedPtr
1204 create_subscription(const ::std::string& topic, ::size_t depth, Cb cb,
1205 const ::rclcpp::SubscriptionOptions& options) {
1206 return this->create_subscription<M>(topic.c_str(), depth, ::rclcpp::tr::forward_rvalue(cb),
1220 template <
typename S>
1221 ::rclcpp::Owned<::rclcpp::PollService<S>>
1225 template <
typename S,
typename F,
1226 typename =
typename std::enable_if<std::is_convertible<
1227 F, void (*)(
const typename S::Request&,
typename S::Response&)>::value>::type>
1228 typename ::rclcpp::Service<S>::SharedPtr
1229 create_service(const ::std::string& name, F callback,
1237 template <
typename S,
typename F,
1238 typename =
typename std::enable_if<
1240 !std::is_convertible<F, void (*)(
const typename S::Request&,
1241 typename S::Response&)>::value>::type,
1243 typename ::rclcpp::Service<S>::SharedPtr
1247 template <
typename S,
typename F>
1248 typename ::rclcpp::Service<S>::SharedPtr create_service(const ::std::string& name, F callback,
1249 const ::rclcpp::QoS& qos,
1250 const ::rclcpp::CallbackGroup* group) {
1251 return this->
template create_service<S>(name.c_str(),
1252 ::rclcpp::tr::forward_rvalue(callback), qos, group);
1271 template <
typename S>
1272 ::rclcpp::Owned<::rclcpp::PollClient<S>>
1276 template <
typename S,
typename F,
1277 typename =
typename std::enable_if<
1278 std::is_convertible<F, void (*)(
const typename S::Response&)>::value>::type>
1279 typename ::rclcpp::Client<S>::SharedPtr
1280 create_client(const ::std::string& name, F callback,
1284 template <
typename S,
typename F,
1285 typename =
typename std::enable_if<
1287 !std::is_convertible<F, void (*)(
const typename S::Response&)>::value>::type,
1289 typename ::rclcpp::Client<S>::SharedPtr
1317 template <
typename M>
1318 typename ::rclcpp::Publisher<M>::SharedPtr
1323 template <
typename M>
1324 typename ::rclcpp::Publisher<M>::SharedPtr
create_publisher(
const char* topic, ::size_t depth);
1334 template <
typename M,
typename Cb>
1335 typename ::rclcpp::Subscription<M>::SharedPtr
1339 template <
typename M,
typename Cb>
1341 ::size_t depth, Cb cb);
1349 template <
typename M,
typename Cb>
1350 typename ::rclcpp::Subscription<M>::SharedPtr
1352 const ::rclcpp::SubscriptionOptions& options);
1355 template <
typename M,
typename Cb>
1356 typename ::rclcpp::Subscription<M>::SharedPtr
1358 const ::rclcpp::SubscriptionOptions& options);
1369 ::rclcpp::Owned<::rclcpp::GenericPublisher>
1376 template <
typename Cb>
1379 const ::rclcpp::QoS& qos, Cb callback);
1383 template <
typename A,
typename B,
typename... R>
1389 static_assert(::rclcpp::detail::refuse<A>::value, NROS_RCLCPP_REFUSE_GENERIC_BY_NAME);
1394 template <
typename A,
typename B,
typename Cb,
typename... R>
1396 Cb&& callback,
const R&...) {
1401 static_assert(::rclcpp::detail::refuse<A>::value, NROS_RCLCPP_REFUSE_GENERIC_BY_NAME);
1406 template <
typename S>
1407 ::rclcpp::Owned<::rclcpp::PollService<S>>
1411 template <
typename S,
typename F,
1412 typename = typename ::rclcpp::tr::enable_if<::rclcpp::tr::is_convertible<
1413 F, void (*)(
const typename S::Request&,
typename S::Response&)>::value>::type>
1414 typename ::rclcpp::Service<S>::SharedPtr
1423 template <
typename S,
typename F,
1424 typename = typename ::rclcpp::tr::enable_if<
1426 !::rclcpp::tr::is_convertible<F, void (*)(
const typename S::Request&,
1427 typename S::Response&)>::value>::type,
1429 typename ::rclcpp::Service<S>::SharedPtr
1438 template <
typename S,
typename F>
1439 typename ::rclcpp::Service<S>::SharedPtr
create_service(
const char* name, F callback,
1440 const ::rclcpp::QoS& qos,
1441 const ::rclcpp::CallbackGroup* group);
1445 template <
typename S>
1446 ::rclcpp::Owned<::rclcpp::PollClient<S>>
1450 template <
typename S,
typename F,
1451 typename = typename ::rclcpp::tr::enable_if<::rclcpp::tr::is_convertible<
1452 F, void (*)(
const typename S::Response&)>::value>::type>
1453 typename ::rclcpp::Client<S>::SharedPtr
1459 typename S,
typename F,
1460 typename = typename ::rclcpp::tr::enable_if<
1462 !::rclcpp::tr::is_convertible<F, void (*)(
const typename S::Response&)>::value>::type,
1464 typename ::rclcpp::Client<S>::SharedPtr
1496 template <
typename T> T
declare_parameter(
const char* name, T default_value = T());
1499 template <
typename T>
bool get_parameter(
const char* name, T& out)
const;
1501 template <
typename T> T
get_parameter(
const char* name)
const;
1526 template <
typename T>
1527 T
declare_parameter(
const char* name, T default_value,
const ParameterDescriptor& descriptor);
1532 template <
typename T>
bool get_parameter_or(
const char* name, T& out, T fallback)
const;
1559 ::size_t text_len)
const;
1569 ::size_t max_names, ::size_t& count)
const;
1590 OnSetParametersCallbackToken& out_handle);
1607 ParameterValue
declare_parameter(
const char* name,
const ParameterValue& default_value);
1609 ParameterValue
declare_parameter(
const char* name,
const ParameterValue& default_value,
1610 const ParameterDescriptor& descriptor);
1615 template <
typename D,
typename = decltype(&D::
floating_po
int_range)>
1616 ParameterValue
declare_parameter(
const char* name,
const ParameterValue& default_value,
1617 const D& descriptor);
1619 template <
typename T,
typename D,
typename = decltype(&D::
floating_po
int_range)>
1622 const ParameterValue& default_value) {
1625 ParameterValue declare_parameter(const ::std::string& name,
const ParameterValue& default_value,
1626 const ParameterDescriptor& descriptor) {
1627 return this->declare_parameter(name.c_str(), default_value, descriptor);
1629 template <
typename D,
typename = decltype(&D::
floating_po
int_range)>
1630 ParameterValue declare_parameter(const ::std::string& name,
const ParameterValue& default_value,
1631 const D& descriptor) {
1632 return this->declare_parameter(name.c_str(), default_value, descriptor);
1634 template <
typename T,
typename D,
typename = decltype(&D::
floating_po
int_range)>
1635 T declare_parameter(const ::std::string& name, T default_value,
const D& descriptor) {
1636 return this->declare_parameter(name.c_str(), default_value, descriptor);
1641 Parameter get_parameter(const ::std::string& name)
const;
1643 bool get_parameter(
const char* name, Parameter& out)
const;
1644 bool get_parameter(const ::std::string& name, Parameter& out)
const {
1645 return this->get_parameter(name.c_str(), out);
1648 ::std::vector<Parameter> get_parameters(const ::std::vector<::std::string>& names)
const;
1654 struct SetParametersOutcome {
1656 ::std::string reason;
1660 SetParametersOutcome set_parameter(
const Parameter& parameter);
1662 ::std::vector<SetParametersOutcome> set_parameters(const ::std::vector<Parameter>& parameters);
1672 template <
typename F>
1673 node_interfaces::OnSetParametersCallbackHandle::SharedPtr
1674 add_on_set_parameters_callback(F callback);
1677 remove_on_set_parameters_callback(
const node_interfaces::OnSetParametersCallbackHandle*
handle);
1681 node_interfaces::NodeParametersInterface::SharedPtr get_node_parameters_interface() {
1682 return node_interfaces::NodeParametersInterface(
this);
1686#ifdef NROS_CPP_HAS_STD_STRING
1690 template <typename T> T declare_parameter(const ::std::string& name, T default_value = T()) {
1691 return this->
template declare_parameter<T>(name.c_str(), default_value);
1693 template <
typename T>
bool get_parameter(const ::std::string& name, T& out)
const {
1694 return this->
template get_parameter<T>(name.c_str(), out);
1696 template <
typename T> T get_parameter(const ::std::string& name)
const {
1697 return this->
template get_parameter<T>(name.c_str());
1699 template <
typename T>
Result set_parameter(const ::std::string& name, T value) {
1700 return this->
template set_parameter<T>(name.c_str(), value);
1702 bool has_parameter(const ::std::string& name)
const {
1703 return this->has_parameter(name.c_str());
1705 Result undeclare_parameter(const ::std::string& name) {
1706 return this->undeclare_parameter(name.c_str());
1708 template <
typename T>
1709 T declare_parameter(const ::std::string& name, T default_value,
1710 const ParameterDescriptor& descriptor) {
1711 return this->
template declare_parameter<T>(name.c_str(), default_value, descriptor);
1713 template <
typename T>
1714 bool get_parameter_or(const ::std::string& name, T& out, T fallback)
const {
1715 return this->
template get_parameter_or<T>(name.c_str(), out, fallback);
1717 ParameterType get_parameter_type(const ::std::string& name)
const {
1718 return this->get_parameter_type(name.c_str());
1732 template <
typename T>
1733 Result declare_parameters(const ::std::string& prefix, const ::std::map<::std::string, T>& m) {
1734 for (typename ::std::map<::std::string, T>::const_iterator it = m.begin(); it != m.end();
1736 const ::std::string full = prefix.empty() ? it->first : (prefix +
"." + it->first);
1737 const ::nros_cpp_node_t* h = this->ffi_handle();
1738 Result r = ::rclcpp::detail::node_param_declare(h, full.c_str(), it->second);
1739 if (!r.ok() && r.raw() != RCLC_RET_ALREADY_EXISTS) {
1746 return Result(RCL_RET_OK);
1770 if (!out.executor_handle_) {
1774 nros_cpp_ret_t ret = nros_cpp_node_create(out.executor_handle_, name, ns, &out.handle_);
1777 out.initialized_ =
true;
1784 if (!initialized_)
return "";
1785 return nros_cpp_node_get_name(&handle_);
1790 if (!initialized_)
return "";
1791 return nros_cpp_node_get_namespace(&handle_);
1810 return Result(nros_cpp_node_get_fully_qualified_name(&handle_, buf, buf_len, out_len));
1831 if (!initialized_)
return nullptr;
1832 return nros_cpp_node_get_serialization_format(&handle_);
1848 if (!initialized_)
return nullptr;
1849 return nros_cpp_node_get_rmw_implementation_identifier(&handle_);
1876 if (!initialized_) return ::rclcpp::Logger(
"",
nullptr);
1877 return ::rclcpp::Logger(nros_cpp_node_get_name(&handle_),
1878 nros_cpp_node_get_logger(&handle_));
1902 Time
now()
const {
return clock_.now(); }
1919 const nros_cpp_node_t*
ffi_handle()
const {
return initialized_ ? &handle_ :
nullptr; }
1933 ::nros_cpp_node_set_qos_overrides(&handle_, overrides, len);
1990 return Result(nros_cpp_executor_get_node_names(executor_handle_, visit, ctx));
2002 return Result(nros_cpp_executor_get_topic_names_and_types(executor_handle_, visit, ctx));
2010 return Result(nros_cpp_executor_get_service_names_and_types(executor_handle_, visit, ctx));
2023 return Result(nros_cpp_executor_count_publishers(executor_handle_, topic_name, out_count));
2030 return Result(nros_cpp_executor_count_subscribers(executor_handle_, topic_name, out_count));
2039 return Result(nros_cpp_executor_count_clients(executor_handle_, service_name, out_count));
2046 return Result(nros_cpp_executor_count_services(executor_handle_, service_name, out_count));
2053 nros_cpp_names_and_types_visit_fn visit,
2056 return Result(nros_cpp_executor_get_publisher_names_and_types_by_node(
2057 executor_handle_, node_name, node_namespace, visit, ctx));
2071 const char* node_namespace,
2072 nros_cpp_names_and_types_visit_fn visit,
2075 return Result(nros_cpp_executor_get_subscription_names_and_types_by_node(
2076 executor_handle_, node_name, node_namespace, visit, ctx));
2083 nros_cpp_names_and_types_visit_fn visit,
2086 return Result(nros_cpp_executor_get_service_names_and_types_by_node(
2087 executor_handle_, node_name, node_namespace, visit, ctx));
2094 nros_cpp_names_and_types_visit_fn visit,
2097 return Result(nros_cpp_executor_get_client_names_and_types_by_node(
2098 executor_handle_, node_name, node_namespace, visit, ctx));
2116 nros_cpp_endpoint_info_visit_fn visit,
void* ctx)
const {
2118 return Result(nros_cpp_executor_get_publishers_info_by_topic(executor_handle_, topic_name,
2131 ::rclcpp::TopicEndpointInfoVisitFn visit,
void* ctx)
const {
2133 ::rclcpp::detail::EndpointInfoTrampoline tramp{visit, ctx};
2134 return Result(nros_cpp_executor_get_publishers_info_by_topic(
2135 executor_handle_, topic_name, &::rclcpp::detail::EndpointInfoTrampoline::thunk,
2144 nros_cpp_endpoint_info_visit_fn visit,
void* ctx)
const {
2146 return Result(nros_cpp_executor_get_subscriptions_info_by_topic(executor_handle_,
2147 topic_name, visit, ctx));
2154 ::rclcpp::TopicEndpointInfoVisitFn visit,
2157 ::rclcpp::detail::EndpointInfoTrampoline tramp{visit, ctx};
2158 return Result(nros_cpp_executor_get_subscriptions_info_by_topic(
2159 executor_handle_, topic_name, &::rclcpp::detail::EndpointInfoTrampoline::thunk,
2169 template <
typename M>
2185 template <
typename M>
2187 const ::rclcpp::QoS& qos, const ::rclcpp::PublisherOptions& options);
2200 template <
typename M>
2219 template <
typename M>
2221 const ::rclcpp::QoS& qos,
2222 const ::rclcpp::SubscriptionOptions& options);
2267 typename M,
typename F,
2268 typename =
typename std::enable_if<std::is_convertible<F, void (*)(
const M&)>::value>::type>
2270 const ::rclcpp::QoS& qos, F callback,
2271 const ::rclcpp::SubscriptionOptions& options = {});
2284 template <
typename M,
typename F,
2285 typename =
typename std::enable_if<
2286 std::is_convertible<F, void (*)(
const M&,
const uint8_t*, size_t)>::value>::type>
2288 const ::rclcpp::QoS& qos, F callback,
2289 const ::rclcpp::SubscriptionOptions& options = {});
2291#if defined(NROS_SAFETY_E2E)
2310 template <
typename M,
typename F,
2311 typename =
typename std::enable_if<std::is_convertible<
2312 F, void (*)(
const M&, const ::nros_cpp_integrity_status_t&)>::value>::type>
2314 const ::rclcpp::QoS& qos, F callback,
2315 const ::rclcpp::SubscriptionOptions& options = {});
2332 template <
typename S>
2349 template <
typename S,
typename F,
2350 typename =
typename std::enable_if<std::is_convertible<
2351 F, void (*)(
const typename S::Request&,
typename S::Response&)>::value>::type>
2354 const ::rclcpp::ServiceOptions& options = {});
2371 template <
typename S>
2386 template <
typename S,
typename F,
2387 typename =
typename std::enable_if<
2388 std::is_convertible<F, void (*)(
const typename S::Response&)>::value>::type>
2391 const ::rclcpp::ClientOptions& options = {});
2403 template <
typename A>
2406 const ::rclcpp::ActionServerOptions& options = {});
2414 template <
typename A>
2421 template <
typename A>
2423 const char* action_name);
2426 template <
typename A>
2428 const char* action_name);
2435 template <
typename M>
2464 nros_cpp_timer_callback_t callback,
void* context =
nullptr) {
2466 size_t handle_id = 0;
2468 executor_handle_,
static_cast<uint8_t
>(clock.get_clock_type()), period_ms, callback,
2469 context, &handle_id);
2471 out.executor_ = executor_handle_;
2472 out.handle_id_ = handle_id;
2473 out.initialized_ =
true;
2496 template <
typename Cb>
2498 const ::rclcpp::CallbackGroup* group =
nullptr,
2499 bool autostart =
true);
2501#ifdef NROS_CPP_HAS_STD_CHRONO
2505 template <typename Rep, typename Period, typename Cb>
2507 const ::rclcpp::CallbackGroup* group =
nullptr,
2508 bool autostart =
true);
2523 void* context =
nullptr) {
2525 size_t handle_id = 0;
2527 nros_cpp_timer_create(executor_handle_, period_ms, callback, context, &handle_id);
2529 out.executor_ = executor_handle_;
2530 out.handle_id_ = handle_id;
2531 out.initialized_ =
true;
2574 template <
class C,
void (C::*Method)()>
2577 out, period_ms, [](
void* ctx) { (
static_cast<C*
>(ctx)->*Method)(); }, self);
2588 template <
class C,
void (C::*Method)()>
2591 out, clock, period_ms, [](
void* ctx) { (
static_cast<C*
>(ctx)->*Method)(); }, self);
2597 template <
class C,
void (C::*Method)()>
2599 uint64_t period_ms, C* self) {
2601 group, out, period_ms, [](
void* ctx) { (
static_cast<C*
>(ctx)->*Method)(); }, self);
2614 void* context =
nullptr) {
2616 size_t handle_id = 0;
2617 nros_cpp_ret_t ret = nros_cpp_timer_create_oneshot(executor_handle_, delay_ms, callback,
2618 context, &handle_id);
2620 out.executor_ = executor_handle_;
2621 out.handle_id_ = handle_id;
2622 out.initialized_ =
true;
2645 if (!::rclcpp::detail::admit_callback_group(name)) {
2646 const ::rclcpp::detail::DeclaredCallbackGroups* g =
2647 ::rclcpp::detail::declared_callback_groups_scope();
2648 const char* list = (g !=
nullptr) ? g->list :
nullptr;
2650 while (name[len] !=
'\0')
2654 this->
set_error(
"create_callback_group: the group is not in this registration's "
2656 ::rclcpp::detail::DECLARED_CALLBACK_GROUP_MISMATCH);
2658 return ::rclcpp::CallbackGroup{name};
2668 ::rclcpp::CallbackGroup::SharedPtr
2670 bool automatically_add_to_executor_with_node =
true) {
2671 (void)automatically_add_to_executor_with_node;
2672 return ::rclcpp::CallbackGroup::SharedPtr(type);
2688 uint64_t period_ms, nros_cpp_timer_callback_t callback,
2689 void* context =
nullptr) {
2691 size_t handle_id = 0;
2693 executor_handle_, &handle_, period_ms, callback, context, group.get_name(), &handle_id);
2695 out.executor_ = executor_handle_;
2696 out.handle_id_ = handle_id;
2697 out.initialized_ =
true;
2722 typename M,
typename F,
2723 typename =
typename std::enable_if<std::is_convertible<F, void (*)(
const M&)>::value>::type>
2726 const ::rclcpp::QoS& qos, F callback,
2727 const ::rclcpp::SubscriptionOptions& options = {});
2739 template <
typename M>
2758 void* context =
nullptr) {
2760 size_t handle_id = 0;
2761 nros_cpp_ret_t ret = nros_cpp_guard_condition_create(executor_handle_, callback, context,
2762 out.storage_, &handle_id);
2764 out.initialized_ =
true;
2765 out.executor_ = executor_handle_;
2766 out.handle_id_ = handle_id;
2807 template <
typename M>
2832 template <
typename M,
class C,
void (C::*Method)(const M& msg)>
2838 template <
typename M,
class C,
void (C::*Method)(const M& msg)>
2859 const int declared = ::rclcpp::declared_depth(type_name, topic);
2862 if (declared == ::rclcpp::DECLARED_DEPTH_UNDECLARED) {
2865 if (declared == qos.depth()) {
2873 "create_subscription_in: ::rclcpp::QoS depth disagrees with the depth declared for "
2874 "this topic in the contract sidecar. Depth multiplies the arena, so the "
2875 "declaration and the code must state one number, not two.",
2895 const int rel = ::rclcpp::declared_reliability(type_name, topic);
2896 if (rel != ::rclcpp::DECLARED_POLICY_UNDECLARED &&
2897 rel !=
static_cast<int>(qos.reliability())) {
2899 this->
get_name(), topic,
"reliability",
2902 static_cast<int>(qos.reliability())));
2903 this->
set_error(
"create_subscription_in: ::rclcpp::QoS reliability disagrees with the "
2904 "reliability declared for this topic in the contract sidecar.",
2908 const int dur = ::rclcpp::declared_durability(type_name, topic);
2909 if (dur != ::rclcpp::DECLARED_POLICY_UNDECLARED &&
2910 dur !=
static_cast<int>(qos.durability())) {
2912 this->
get_name(), topic,
"durability",
2915 this->
set_error(
"create_subscription_in: ::rclcpp::QoS durability disagrees with the "
2916 "durability declared for this topic in the contract sidecar.",
2944 if (name ==
nullptr || nn ==
nullptr) {
2947 const ::rclcpp::declared_params::Node* declaring =
2948 ::rclcpp::declared_param_node((ns !=
nullptr) ? ns :
"", nn);
2949 if (declaring ==
nullptr || ::rclcpp::declared_param_exempt(name)) {
2952 const int declared = ::rclcpp::declared_param_type(declaring, name);
2953 if (declared == passed_type) {
2957 declared, passed_type);
2958 this->
set_error(
"declare_parameter: the code does not declare this parameter the way "
2959 "its contract does (see the line above for the node, the parameter and "
2960 "the contract). The parameter store is sized from the contract's "
2961 "`params:`, so the two must state one name and one type.",
2977 if (!__atomic_load_n(&has_error_, __ATOMIC_RELAXED)) {
2982 __atomic_store_n(&has_error_,
true, __ATOMIC_RELEASE);
2996 nros_cpp_node_destroy(&handle_);
2997 initialized_ =
false;
3003 : handle_(other.handle_), initialized_(other.initialized_),
3004 executor_handle_(other.executor_handle_), clock_(other.clock_), options_(other.options_),
3008 has_error_(other.has_error_), error_what_(other.error_what_),
3009 error_code_(other.error_code_) {
3010 other.initialized_ =
false;
3011 other.executor_handle_ =
nullptr;
3015 if (
this != &other) {
3017 nros_cpp_node_destroy(&handle_);
3019 handle_ = other.handle_;
3020 initialized_ = other.initialized_;
3021 executor_handle_ = other.executor_handle_;
3022 clock_ = other.clock_;
3023 options_ = other.options_;
3024 has_error_ = other.has_error_;
3025 error_what_ = other.error_what_;
3026 error_code_ = other.error_code_;
3027 other.initialized_ =
false;
3028 other.executor_handle_ =
nullptr;
3035 Node& operator=(
const Node&) =
delete;
3047 template <
typename S>
3049 bool (*trampoline)(
const uint8_t*,
size_t, uint8_t*,
size_t,
size_t*,
3051 void* context, const ::rclcpp::QoS& qos,
3052 const ::rclcpp::ServiceOptions& options,
const void* capture =
nullptr,
3053 size_t capture_len = 0,
void (*capture_drop)(
void*) =
nullptr);
3059 template <
typename S>
3061 bool (*trampoline)(
const uint8_t*,
size_t, ::rmw_request_id_t*,
3062 uint8_t*,
size_t,
size_t*,
void*),
3063 void* context, const ::rclcpp::QoS& qos,
3064 const ::rclcpp::ServiceOptions& options,
const void* capture =
nullptr,
3065 size_t capture_len = 0,
void (*capture_drop)(
void*) =
nullptr);
3069 template <
typename S>
3078 template <
typename S,
typename F>
3080 const ::rclcpp::QoS& qos,
3081 ::rclcpp::tr::integral_constant<int, 0>);
3082 template <
typename S,
typename F>
3084 const ::rclcpp::QoS& qos,
3085 ::rclcpp::tr::integral_constant<int, 1>);
3092 void apply_options_(const ::rclcpp::NodeOptions& options) {
3097 if (!options.start_parameter_event_publisher() && initialized_) {
3098 (void)nros_cpp_node_disable_parameter_events(&handle_);
3100 Clock chosen(options.clock_type());
3101 if (!chosen.is_valid()) {
3102 this->set_error(
"NodeOptions::clock_type (not a clock)",
3109 nros_cpp_node_t handle_;
3111 void* executor_handle_;
3119 ::rclcpp::NodeOptions options_;
3141 bool has_error_ =
false;
3142 const char* error_what_ =
nullptr;
3143 int32_t error_code_ = 0;
3155 friend class ::rclcpp::Executor;
3156 friend class ::rclcpp::NodeBuilder;
3159 const char* session_name);
3165 const char* session_name,
const char* node_namespace);
3167 const char* session_name);
3187 template <
int = 0>
struct GlobalStorageHolder {
3188 alignas(8)
static uint8_t storage[NROS_CPP_EXECUTOR_STORAGE_SIZE];
3190 static uint8_t* global_storage() {
return GlobalStorageHolder<>::storage; }
3211 static bool global_initialized() {
3212 return nros_cpp_context_is_live(GlobalStorageHolder<>::storage);
3220alignas(8) uint8_t Node::GlobalStorageHolder<N>::storage[NROS_CPP_EXECUTOR_STORAGE_SIZE] = {};
3254#ifndef NROS_COMPONENT_MAX_TIMERS
3255#define NROS_COMPONENT_MAX_TIMERS 8
3264#if NROS_COMPONENT_MAX_TIMERS < 1
3266#error "NROS_COMPONENT_MAX_TIMERS must be >= 1: it sizes a C array"
3288template <::
size_t MaxTimers = NROS_COMPONENT_MAX_TIMERS>
3290 static_assert(MaxTimers >= 1,
3291 "NodeWithTimers<0> has no pool -- derive ::rclcpp::Node directly, or use "
3292 "the out-ref create_wall_timer(Timer&, ...) family");
3304 Timer* slot = this->next_timer_slot(
"create_wall_timer_in");
3305 if (slot ==
nullptr)
return;
3307 static_cast<C*
>(
this));
3317 void* context =
nullptr) {
3318 Timer* slot = this->next_timer_slot(
"create_wall_timer_in");
3319 if (slot ==
nullptr)
return;
3330 template <
class C,
void (C::*Method)()>
3332 Timer* slot = this->next_timer_slot(
"create_timer_in_group");
3333 if (slot ==
nullptr)
return;
3335 static_cast<C*
>(
this));
3345 nros_cpp_timer_callback_t callback,
void* context =
nullptr) {
3346 Timer* slot = this->next_timer_slot(
"create_timer_in_group");
3347 if (slot ==
nullptr)
return;
3365 Timer* next_timer_slot(
const char* what) {
3366 if (timer_count_ >= MaxTimers) {
3367 this->set_error(what, -1);
3370 return &timers_[timer_count_];
3373 Timer timers_[MaxTimers];
3374 ::size_t timer_count_ = 0;
3387 return init_in(locator, domain_id,
"node");
3390inline Result init_in(
const char* locator, uint8_t domain_id,
const char* session_name) {
3395 return init_in(locator, domain_id, session_name,
nullptr);
3398inline Result init_in(
const char* locator, uint8_t domain_id,
const char* session_name,
3399 const char* node_namespace) {
3403 if (session_name ==
nullptr) {
3406#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0)
3427#ifdef NROS_ENTRY_LOCATOR
3428 if (locator ==
nullptr) {
3429 locator = NROS_ENTRY_LOCATOR;
3437 if (locator !=
nullptr && locator[0] ==
'\0') {
3444#if defined(NROS_ENTRY_DOMAIN_ID_C_ABI)
3445 if (domain_id == 0) {
3446 domain_id =
static_cast<uint8_t
>(NROS_ENTRY_DOMAIN_ID_C_ABI);
3448#elif defined(NROS_ENTRY_DOMAIN_ID)
3449 if (domain_id == 0) {
3450 domain_id =
static_cast<uint8_t
>(NROS_ENTRY_DOMAIN_ID);
3480#ifdef NROS_ENTRY_RMW
3481 const char* rmw = NROS_ENTRY_RMW;
3483 const char* rmw =
nullptr;
3492 if (node_namespace !=
nullptr && node_namespace[0] ==
'\0') {
3493 node_namespace =
nullptr;
3501 nros_cpp_executor_storage_check(::rclcpp::Node::global_storage(),
3502 sizeof(::rclcpp::Node::GlobalStorageHolder<>::storage));
3507 nros_cpp_ret_t ret = nros_cpp_init_rmw(rmw, locator, domain_id, session_name, node_namespace,
3508 ::rclcpp::Node::global_storage());
3515 const char* session_name) {
3518 if (session_name ==
nullptr) {
3521#ifdef NROS_ENTRY_LOCATOR
3522 if (locator ==
nullptr) {
3523 locator = NROS_ENTRY_LOCATOR;
3526#ifdef NROS_ENTRY_DOMAIN_ID
3527 if (domain_id == 0) {
3528 domain_id =
static_cast<uint8_t
>(NROS_ENTRY_DOMAIN_ID);
3540 nros_cpp_executor_storage_check(::rclcpp::Node::global_storage(),
3541 sizeof(::rclcpp::Node::GlobalStorageHolder<>::storage));
3546 nros_cpp_ret_t ret = nros_cpp_init_rmw(rmw, locator, domain_id, session_name,
nullptr,
3547 ::rclcpp::Node::global_storage());
3554 if (!::rclcpp::Node::global_initialized()) {
3559 return Result(nros_cpp_fini(::rclcpp::Node::global_storage()));
3563 if (!::rclcpp::Node::global_initialized())
return nullptr;
3564 return ::rclcpp::Node::global_storage();
3575 bool scoped =
false;
3576 for (
int i = 0; argv !=
nullptr && i < argc && !scoped; ++i) {
3577 const char* a = argv[i];
3578 const char* want =
"--ros-args";
3579 while (a !=
nullptr && *a !=
'\0' && *a == *want) {
3583 scoped = a !=
nullptr && *a ==
'\0' && *want ==
'\0';
3587 if (!scoped && !nros_cpp_baked_ros_args_present()) {
3590 char why[256] = {0};
3591 const int32_t rc = nros_cpp_install_argv_remaps(executor, argc, argv, why,
sizeof(why));
3598 RCLC_LOG_ERROR(::rclcpp::detail::log_handle(
nullptr),
"rclcpp::init: refused: %.120s",
3599 why[0] !=
'\0' ? why :
"invalid executor handle or argv");
3600 NROS_RCLCPP_SAY_REFUSED(NROS_RCLCPP_REFUSE_INIT_ARGV);
3618 if (installed != 0) {
3620 return Result(installed);
3631inline Result init_in(
int argc,
char const*
const* argv,
const char* session_name) {
3632 const char* name = (session_name !=
nullptr) ? session_name :
"nros_cpp";
3642 return ::rclcpp::Node::global_initialized() && !::nros_cpp_termination_requested();
3654 if (!::rclcpp::Node::global_initialized()) {
3657 out.executor_handle_ = ::rclcpp::Node::global_storage();
3658 return ::rclcpp::Node::create(out, name, ns);
3674 const char* ns =
nullptr) {
3675 if (executor_handle ==
nullptr) {
3678 out.executor_handle_ = executor_handle;
3679 return ::rclcpp::Node::create(out, name, ns);
3696 out.executor_handle_ = storage_;
3697 return ::rclcpp::Node::create(out, name, ns);
3720 : executor_handle_(executor_handle), name_(name),
3721 options_(nros_cpp_node_get_default_options()) {}
3728 copy_bounded(name, options_.rmw_name, &options_.rmw_name_len, NROS_CPP_RMW_NAME_LEN);
3735 copy_bounded(loc, options_.locator, &options_.locator_len, NROS_CPP_LOCATOR_LEN);
3742 options_.domain_id_override = id;
3752 copy_bounded(ns, options_.namespace_, &options_.namespace_len, NROS_CPP_NAMESPACE_LEN);
3759 options_.sched_context_id = sc_id;
3766 out.executor_handle_ = executor_handle_;
3768 nros_cpp_node_create_ex(executor_handle_, name_, &options_, &out.handle_);
3770 out.initialized_ =
true;
3776 static void copy_bounded(
const char* src, uint8_t* dst,
size_t* dst_len,
size_t cap) {
3778 if (src !=
nullptr) {
3779 while (src[n] !=
'\0' && n < cap) {
3780 dst[n] =
static_cast<uint8_t
>(src[n]);
3785 for (
size_t i = n; i < cap; ++i) {
3791 void* executor_handle_;
3793 nros_cpp_node_options_t options_;
3807 const DeclaredCallbackGroups& groups) {
3808 const char* missing =
nullptr;
3810 if (first_uncreated_callback_group(groups, &missing, &len)) {
3812 node.
set_error(
"a CALLBACK_GROUPS group was never created",
3813 DECLARED_CALLBACK_GROUP_MISMATCH);
Definition rclcpp.hpp:214
Result create_node(::rclcpp::Node &out, const char *name, const char *ns=nullptr)
Definition node.hpp:3694
NodeBuilder node_builder(const char *name)
Definition node.hpp:3796
NodeBuilder & locator(const char *loc)
Definition node.hpp:3734
NodeBuilder & sched(uint8_t sc_id)
Definition node.hpp:3758
Result build(::rclcpp::Node &out) const
Materialize the Node.
Definition node.hpp:3764
NodeBuilder(void *executor_handle, const char *name)
Definition node.hpp:3719
NodeBuilder & rmw(const char *name)
Definition node.hpp:3727
NodeBuilder & domain_id(uint32_t id)
Definition node.hpp:3741
NodeBuilder & namespace_(const char *ns)
Definition node.hpp:3751
::rclcpp::TimerHandle create_wall_timer(::rclcpp::Duration period, Cb cb, const ::rclcpp::CallbackGroup *group=nullptr, bool autostart=true)
void create_timer_in_group(const CallbackGroup &group, uint64_t period_ms)
Definition node.hpp:3331
void create_timer_in_group(const CallbackGroup &group, uint64_t period_ms, nros_cpp_timer_callback_t callback, void *context=nullptr)
The plain C callback + ctx form, in a group, parked in the pool.
Definition node.hpp:3344
void create_wall_timer_in(uint64_t period_ms)
Definition node.hpp:3303
void create_wall_timer_in(uint64_t period_ms, nros_cpp_timer_callback_t callback, void *context=nullptr)
The plain C callback + ctx escape hatch, parked in the pool.
Definition node.hpp:3316
Node & operator=(Node &&other)
Definition node.hpp:3014
bool check_declared_depth(const char *type_name, const char *topic, const ::rclcpp::QoS &qos)
Definition node.hpp:2858
Result create_subscription(::rclcpp::PollSubscription< M > &out, const char *topic, const ::rclcpp::QoS &qos, const ::rclcpp::SubscriptionOptions &options)
Result create_client(::rclcpp::PollClient< S > &out, const char *service_name, const ::rclcpp::QoS &qos=::rclcpp::QoS::services())
void create_subscription_in(const char *topic, const ::rclcpp::QoS &qos=::rclcpp::QoS::default_profile())
Result create_timer(Timer &out, const Clock &clock, uint64_t period_ms, C *self)
Definition node.hpp:2589
Result create_subscription_in_group(const ::rclcpp::CallbackGroup &group, ::rclcpp::Subscription< M > &out, const char *topic, const ::rclcpp::QoS &qos, F callback, const ::rclcpp::SubscriptionOptions &options={})
const nros_cpp_node_t * ffi_handle() const
Definition node.hpp:1919
Result count_subscribers(const char *topic_name, size_t *out_count) const
Definition node.hpp:2028
SharedPtr shared_from_this()
Definition node.hpp:1100
Result create_timer(Timer &out, const Clock &clock, uint64_t period_ms, nros_cpp_timer_callback_t callback, void *context=nullptr)
Definition node.hpp:2463
Time now() const
Definition node.hpp:1902
Result create_subscription(::rclcpp::PollSubscription< M > &out, const char *topic, const ::rclcpp::QoS &qos=::rclcpp::QoS::default_profile())
Result create_service(::rclcpp::Service< S > &out, const char *service_name, F callback, const ::rclcpp::QoS &qos=::rclcpp::QoS::services(), const ::rclcpp::ServiceOptions &options={})
const char * error_what() const
Definition node.hpp:1002
Result get_parameter_types(const char *const *names, ::size_t count, ParameterType *out) const
Definition rclcpp.hpp:2051
Result create_publisher(::rclcpp::Publisher< M > &out, const char *topic, const ::rclcpp::QoS &qos=::rclcpp::QoS::default_profile())
typename::rclcpp::Service< S >::SharedPtr create_service(const char *, F, const ::rclcpp::QoS &=::rclcpp::QoS::services())
Result create_polling_action_client(::rclcpp::PollingActionClient< A > &out, const char *action_name)
Create an L1 polling-mode action client.
typename::rclcpp::Subscription< M >::SharedPtr create_subscription(const char *topic, ::size_t depth, Cb cb)
create_subscription<M>(topic, depth, callback).
::rclcpp::Handle< const Node > ConstWeakPtr
Const spelling of WeakPtr.
Definition node.hpp:1087
Result add_on_set_parameters_callback(OnSetParametersCallbackType callback, void *context, OnSetParametersCallbackToken &out_handle)
Definition rclcpp.hpp:2110
::rclcpp::Handle< const Node > ConstSharedPtr
rclcpp::Node::ConstSharedPtr.
Definition node.hpp:1082
Result create_timer_in_group(const ::rclcpp::CallbackGroup &group, Timer &out, uint64_t period_ms, C *self)
Definition node.hpp:2598
Node(const char *name, const char *ns, const ::rclcpp::NodeOptions &options)
Definition node.hpp:1044
Result create_client(::rclcpp::Client< S > &out, const char *service_name, F callback, const ::rclcpp::QoS &qos=::rclcpp::QoS::services(), const ::rclcpp::ClientOptions &options={})
::rclcpp::Logger get_logger() const
Definition node.hpp:1875
Result create_service(::rclcpp::PollService< S > &out, const char *service_name, const ::rclcpp::QoS &qos=::rclcpp::QoS::services())
typename::rclcpp::Subscription< M >::SharedPtr create_subscription(const char *topic, const ::rclcpp::QoS &qos, Cb cb, const ::rclcpp::SubscriptionOptions &options)
typename::rclcpp::Subscription< M >::SharedPtr create_subscription(const char *topic, ::size_t depth, Cb cb, const ::rclcpp::SubscriptionOptions &options)
create_subscription<M>(topic, depth, callback, options).
::rclcpp::Handle< Node > WeakPtr
Definition node.hpp:1085
Result create_subscription(::rclcpp::Subscription< M > &out, const char *topic, const ::rclcpp::QoS &qos, F callback, const ::rclcpp::SubscriptionOptions &options={})
::rclcpp::Owned<::rclcpp::PollService< S > > create_service(const char *name, const ::rclcpp::QoS &qos=::rclcpp::QoS::services())
Result create_subscription_with_info(::rclcpp::Subscription< M > &out, const char *topic, const ::rclcpp::QoS &qos, F callback, const ::rclcpp::SubscriptionOptions &options={})
bool get_parameter(const char *name, T &out) const
Definition rclcpp.hpp:1970
typename::rclcpp::Subscription< M >::SharedPtr create_subscription(const char *topic, const ::rclcpp::QoS &qos, Cb cb)
void create_generic_publisher(const A &topic, const B &type, const ::rclcpp::QoS &qos, const R &...)
Definition node.hpp:1384
Result count_clients(const char *service_name, size_t *out_count) const
Definition node.hpp:2037
Result create_wall_timer(Timer &out, uint64_t period_ms, C *self)
Definition node.hpp:2575
Result get_node_names(nros_cpp_node_visit_fn visit, void *ctx) const
Definition node.hpp:1988
Result init(const char *name, const char *ns=nullptr)
Definition node.hpp:913
::rclcpp::node_interfaces::NodeWaitablesInterface::SharedPtr get_node_waitables_interface()
See get_node_base_interface.
Definition node.hpp:1124
typename::rclcpp::Publisher< M >::SharedPtr create_publisher(const char *topic, const ::rclcpp::QoS &qos=::rclcpp::QoS::default_profile())
create_publisher<M>(topic, qos) — available on every target.
::rclcpp::TimerHandle create_wall_timer(::rclcpp::Duration period, Cb cb, const ::rclcpp::CallbackGroup *group=nullptr, bool autostart=true)
bool check_declared_param(const char *name, int passed_type)
Definition node.hpp:2941
Result describe_parameter(const char *name, ParameterDescriptor &out, char *text, ::size_t text_len) const
Definition rclcpp.hpp:2062
T declare_parameter(const char *name, T default_value=T())
rclcpp::Node::declare_parameter<T>(name, default).
Definition rclcpp.hpp:1941
Result remove_on_set_parameters_callback(OnSetParametersCallbackToken handle)
rclcpp::Node::remove_on_set_parameters_callback(handle).
Definition rclcpp.hpp:2117
const char * serialization_format() const
Definition node.hpp:1830
~Node()
Definition node.hpp:2994
static Result create(Node &out, const char *name, const char *ns=nullptr)
Definition node.hpp:1769
bool get_parameter_or(const char *name, T &out, T fallback) const
Definition rclcpp.hpp:2031
typename::rclcpp::Service< S >::SharedPtr create_service(const char *name, F callback, const ::rclcpp::QoS &qos, const ::rclcpp::CallbackGroup *group)
ParameterType get_parameter_type(const char *name) const
Definition rclcpp.hpp:2043
bool ok() const
Definition node.hpp:998
bool has_parameter(const char *name) const
rclcpp::Node::has_parameter(name).
Definition rclcpp.hpp:2002
::rclcpp::CallbackGroup::SharedPtr create_callback_group(::rclcpp::CallbackGroupType type, bool automatically_add_to_executor_with_node=true)
Definition node.hpp:2669
Result count_services(const char *service_name, size_t *out_count) const
Definition node.hpp:2044
void * executor_handle() const
Definition node.hpp:1943
Result list_parameters(const char *prefix, char *out_names, ::size_t name_stride, ::size_t max_names, ::size_t &count) const
Definition rclcpp.hpp:2100
::rclcpp::Publisher< M > create_publisher_in(const char *topic, const ::rclcpp::QoS &qos=::rclcpp::QoS::default_profile())
Definition node.hpp:2809
Result get_publishers_info_by_topic(const char *topic_name, ::rclcpp::TopicEndpointInfoVisitFn visit, void *ctx) const
Definition node.hpp:2130
::rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr get_node_logging_interface()
See get_node_base_interface.
Definition node.hpp:1120
::rclcpp::Handle< Node > SharedPtr
Definition node.hpp:1080
typename::rclcpp::Service< S >::SharedPtr create_service(const char *name, F callback, const ::rclcpp::QoS &qos=::rclcpp::QoS::services())
Callback-style service server (void(const S::Request&, S::Response&)).
Node(Node &&other)
Definition node.hpp:3002
Node(const char *name, const ::rclcpp::NodeOptions &options)
Definition node.hpp:1037
const char * rmw_implementation_identifier() const
Definition node.hpp:1847
Result create_guard_condition(::rclcpp::GuardCondition &out, nros_cpp_guard_callback_t callback, void *context=nullptr)
Definition node.hpp:2757
const char * get_namespace() const
Get the node namespace.
Definition node.hpp:1789
bool initialized() const
Definition node.hpp:1156
void set_error(const char *what, int32_t code)
Definition node.hpp:2973
Node & nros_node()
Definition node.hpp:1160
Result get_client_names_and_types_by_node(const char *node_name, const char *node_namespace, nros_cpp_names_and_types_visit_fn visit, void *ctx) const
Definition node.hpp:2093
Result count_publishers(const char *topic_name, size_t *out_count) const
Definition node.hpp:2021
Result start_parameter_services()
Definition node.hpp:1951
int32_t error_code() const
The raw error code of the first latched failure, or 0.
Definition node.hpp:1009
const char * get_name() const
Get the node name.
Definition node.hpp:1783
bool is_valid() const
Check if the node is initialized and valid.
Definition node.hpp:1905
::rclcpp::node_interfaces::NodeGraphInterface::SharedPtr get_node_graph_interface()
See get_node_base_interface.
Definition node.hpp:1116
Result create_wall_timer(Timer &out, uint64_t period_ms, nros_cpp_timer_callback_t callback, void *context=nullptr)
Definition node.hpp:2522
Result create_timer_in_group(const ::rclcpp::CallbackGroup &group, Timer &out, uint64_t period_ms, nros_cpp_timer_callback_t callback, void *context=nullptr)
Definition node.hpp:2687
::rclcpp::CallbackGroup create_callback_group(const char *name)
Definition node.hpp:2644
Node(::rclcpp::NodeHandle handle, const char *name, const char *ns=nullptr)
Definition node.hpp:958
Node(const char *name, const char *ns=nullptr)
Definition node.hpp:895
Result set_parameters_atomically(const ParameterWrite *writes, ::size_t count)
Definition rclcpp.hpp:2106
::rclcpp::Owned<::rclcpp::PollClient< S > > create_client(const char *name, const ::rclcpp::QoS &qos=::rclcpp::QoS::services())
::rclcpp::SubscriptionHandle<::rclcpp::GenericSubscription > create_generic_subscription(const char *topic, const char *type, const char *type_hash, const ::rclcpp::QoS &qos, Cb callback)
typename::rclcpp::Publisher< M >::SharedPtr create_publisher(const char *topic, ::size_t depth)
create_publisher<M>(topic, depth) — the integer-depth spelling.
Result get_subscription_names_and_types_by_node(const char *node_name, const char *node_namespace, nros_cpp_names_and_types_visit_fn visit, void *ctx) const
Definition node.hpp:2070
bool check_declared_qos(const char *type_name, const char *topic, const ::rclcpp::QoS &qos)
Definition node.hpp:2891
Result create_timer_oneshot(Timer &out, uint64_t delay_ms, nros_cpp_timer_callback_t callback, void *context=nullptr)
Definition node.hpp:2613
Result get_service_names_and_types(nros_cpp_names_and_types_visit_fn visit, void *ctx) const
Definition node.hpp:2008
Result get_topic_names_and_types(nros_cpp_names_and_types_visit_fn visit, void *ctx) const
Definition node.hpp:2000
Result set_parameter(const char *name, T value)
Definition rclcpp.hpp:1994
const Clock * get_clock() const
Const overload of get_clock().
Definition node.hpp:1893
Result get_fully_qualified_name(char *buf, size_t buf_len, size_t *out_len=nullptr) const
Definition node.hpp:1808
Result get_subscriptions_info_by_topic(const char *topic_name, ::rclcpp::TopicEndpointInfoVisitFn visit, void *ctx) const
Definition node.hpp:2153
typename::rclcpp::Client< S >::SharedPtr create_client(const char *, F, const ::rclcpp::QoS &=::rclcpp::QoS::services())
REFUSED — upstream's shared_ptr handler shape.
Result create_polling_action_server(::rclcpp::PollingActionServer< A > &out, const char *action_name)
Clock * get_clock()
Definition node.hpp:1891
void create_generic_subscription(const A &topic, const B &type, const ::rclcpp::QoS &qos, Cb &&callback, const R &...)
Definition node.hpp:1395
const Node & nros_node() const
Const overload of [nros_node].
Definition node.hpp:1162
Result get_publisher_names_and_types_by_node(const char *node_name, const char *node_namespace, nros_cpp_names_and_types_visit_fn visit, void *ctx) const
Definition node.hpp:2052
Result get_publishers_info_by_topic(const char *topic_name, nros_cpp_endpoint_info_visit_fn visit, void *ctx) const
Definition node.hpp:2115
void create_subscription_in_group(const ::rclcpp::CallbackGroup &group, const char *topic, const ::rclcpp::QoS &qos=::rclcpp::QoS::default_profile())
::rclcpp::node_interfaces::NodeBaseInterface::SharedPtr get_node_base_interface()
Definition node.hpp:1108
Node()
Definition node.hpp:878
Result create_publisher_in_group(const ::rclcpp::CallbackGroup &, ::rclcpp::Publisher< M > &out, const char *topic, const ::rclcpp::QoS &qos=::rclcpp::QoS::default_profile())
Definition node.hpp:2740
Result undeclare_parameter(const char *name)
Definition rclcpp.hpp:2039
const ::rclcpp::NodeOptions & get_node_options() const
Definition node.hpp:1051
::rclcpp::node_interfaces::NodeClockInterface::SharedPtr get_node_clock_interface()
See get_node_base_interface.
Definition node.hpp:1112
Result create_publisher(::rclcpp::Publisher< M > &out, const char *topic, const ::rclcpp::QoS &qos, const ::rclcpp::PublisherOptions &options)
Result create_polling_subscription(::rclcpp::PollingSubscription< M > &out, const char *topic, const ::rclcpp::QoS &qos=::rclcpp::QoS::default_profile())
ConstSharedPtr shared_from_this() const
Const overload of [shared_from_this].
Definition node.hpp:1102
void set_qos_overrides(const nros_cpp_qos_override_t *overrides, size_t len)
Definition node.hpp:1931
Result init_on(void *executor_handle, const char *name, const char *ns=nullptr)
Definition node.hpp:924
Result get_subscriptions_info_by_topic(const char *topic_name, nros_cpp_endpoint_info_visit_fn visit, void *ctx) const
Definition node.hpp:2143
::rclcpp::Owned<::rclcpp::GenericPublisher > create_generic_publisher(const char *topic, const char *type, const char *type_hash, const ::rclcpp::QoS &qos=::rclcpp::QoS::default_profile())
Definition rclcpp.hpp:1403
Result get_service_names_and_types_by_node(const char *node_name, const char *node_namespace, nros_cpp_names_and_types_visit_fn visit, void *ctx) const
Definition node.hpp:2082
typename::rclcpp::Client< S >::SharedPtr create_client(const char *name, F callback, const ::rclcpp::QoS &qos=::rclcpp::QoS::services())
Callback-style service client (void(const S::Response&)).
Definition publisher.hpp:179
static constexpr QoS services()
Services profile: RELIABLE + VOLATILE + KEEP_LAST(10).
Definition qos.hpp:805
static constexpr QoS default_profile()
Default profile: RELIABLE + VOLATILE + KEEP_LAST(10).
Definition qos.hpp:799
int32_t raw() const
Get the raw integer code (for FFI interop).
Definition result.hpp:236
bool ok() const
Returns true if the operation succeeded.
Definition result.hpp:227
static constexpr ResultOf success()
Named constructors.
Definition result.hpp:239
Definition result.hpp:332
static ResultOf ok(T value)
Definition result.hpp:334
static ResultOf error(ErrorCode code)
Definition result.hpp:340
Definition service.hpp:146
Definition subscription.hpp:197
static const bool value
Definition qos.hpp:889
One slice's handle; Tag only keeps the five spellings distinct types.
Definition node.hpp:247
Node * node() const
Definition node.hpp:254
Context get_context() const
Definition rclcpp.hpp:337
const NodeInterfaceHandle * operator->() const
Definition node.hpp:258
NodeInterfaceHandle()
Definition node.hpp:251
NodeInterfaceHandle SharedPtr
Upstream's Node*InterfaceSharedPtr — the handle itself (no allocator).
Definition node.hpp:250
NodeInterfaceHandle(Node *node)
Definition node.hpp:252
Definition client.hpp:256
Definition server.hpp:350
rclcpp::Executor — drives transport I/O and dispatches callbacks.
int nros_cpp_ret_t
Definition future.hpp:25
rclcpp::GuardCondition — cross-thread wake source.
Definition rclcpp.hpp:437
void report_declared_depth_mismatch(const char *node_name, const char *topic, int declared, int passed)
Definition node.hpp:516
const char * declared_reliability_spelling(int ordinal)
The contract spelling of a reliability ordinal, for the report above.
Definition node.hpp:611
constexpr const char * PARAM_VALUE_TYPE_MISMATCH_WHAT
The set_error text for a declaration whose value in effect has another type.
Definition node.hpp:683
void report_declared_policy_mismatch(const char *node_name, const char *topic, const char *policy, const char *declared, const char *passed)
Definition node.hpp:587
void report_component_failure(const char *node_name, const char *what, int32_t code)
Definition node.hpp:487
constexpr const char * PARAM_STORE_FULL_WHAT
Definition node.hpp:674
void refuse_param_declare(Node &node, int32_t code)
Definition rclcpp.hpp:1886
constexpr int32_t PARAM_VALUE_TYPE_MISMATCH
Definition node.hpp:669
constexpr int32_t DECLARED_PARAM_MISMATCH
Definition node.hpp:628
int32_t apply_ros_args(void *executor, int argc, char const *const *argv)
Definition node.hpp:3572
Result init_honouring_ros_args(int argc, char const *const *argv, const char *name)
Definition node.hpp:3608
const char * declared_durability_spelling(int ordinal)
The contract spelling of a durability ordinal, for the report above.
Definition node.hpp:619
constexpr int32_t DECLARED_DEPTH_MISMATCH
Definition node.hpp:511
void finish_declared_callback_groups(::rclcpp::Node &node, const DeclaredCallbackGroups &groups)
Definition node.hpp:3806
void report_callback_group_mismatch(const char *node_name, const char *how, const char *name, int len, const char *list)
Definition node.hpp:545
constexpr const char * PARAM_DECLARE_REFUSED_WHAT
The set_error text for any other refusal of a declaration.
Definition node.hpp:679
void report_declared_param_mismatch(const char *fqn, const char *param, const char *contract, int declared, int passed)
Definition node.hpp:634
constexpr int32_t DECLARED_QOS_MISMATCH
Definition node.hpp:582
Definition rclcpp.hpp:336
NodeInterfaceHandle< 3 > NodeLoggingInterface
Definition node.hpp:271
NodeInterfaceHandle< 0 > NodeBaseInterface
Definition node.hpp:268
NodeInterfaceHandle< 1 > NodeClockInterface
Definition node.hpp:269
NodeInterfaceHandle< 2 > NodeGraphInterface
Definition node.hpp:270
NodeInterfaceHandle< 4 > NodeWaitablesInterface
Definition node.hpp:272
Client & operator=(Client &&other)
Definition client.hpp:1000
constexpr uint8_t kDomainIdExplicitZero
Definition node.hpp:473
Result shutdown_in()
Definition node.hpp:3553
Result create_node(::rclcpp::Node &out, const char *name, const char *ns)
Definition node.hpp:3653
@ Reliable
Definition qos.hpp:149
@ BestEffort
Definition qos.hpp:150
Result init_in(const char *locator=nullptr, uint8_t domain_id=0)
Definition node.hpp:3379
Result spin_once(int32_t timeout_ms=10)
Definition rclcpp.hpp:97
void init()
rclcpp::init() — the zero-argument form. ADOPT.
Definition rclcpp.hpp:561
bool ok()
Definition node.hpp:3641
Result spin_in()
Definition rclcpp.hpp:350
Result create_node_on(::rclcpp::Node &out, void *executor_handle, const char *name, const char *ns)
Definition node.hpp:3673
ResultOf<::rclcpp::Node > make_node(const char *name, const char *ns=nullptr)
Definition node.hpp:3685
ResultOf< Publisher< M > > create_publisher(::rclcpp::Node &node, const char *topic, const QoS &qos=QoS::default_profile())
Definition publisher.hpp:705
void * global_handle()
Definition node.hpp:3562
@ InvalidArgument
Null pointer, empty topic name, or out-of-range value.
Definition result.hpp:122
@ AlreadyExists
Already exists (duplicate declare/register).
Definition result.hpp:126
@ NotInitialized
Definition result.hpp:131
Result init_with_rmw(const char *rmw, const char *locator=nullptr, uint8_t domain_id=0, const char *session_name="node")
Definition node.hpp:3514
@ Volatile
Definition qos.hpp:164
@ TransientLocal
Definition qos.hpp:165
ResultOf< void > Result
Definition result.hpp:247
rclcpp::QoS — full DDS-shaped QoS settings.
**auto handle
Definition client.hpp:127
::rclcpp::Owned< Client > SharedPtr
Definition client.hpp:496
rclcpp::Result, rclcpp::ErrorCode, and the RCLCPP_TRY macro.
constexpr const char * resolve_namespace(const char *fallback) const
The launch namespace if one was declared, else fallback.
Definition node.hpp:455
constexpr bool valid() const
Definition node.hpp:447
constexpr NodeHandle()
Definition node.hpp:429
const char * launch_name
Definition node.hpp:412
void * executor
Definition node.hpp:408
constexpr NodeHandle(void *exec)
Definition node.hpp:432
const char * launch_namespace
Launch-declared namespace, same contract.
Definition node.hpp:414
const nros_cpp_qos_override_t * qos_overrides
Definition node.hpp:425
constexpr const char * resolve_name(const char *fallback) const
Definition node.hpp:451
constexpr NodeHandle(void *exec, const char *name, const char *ns, const nros_cpp_qos_override_t *overrides, size_t override_count)
Definition node.hpp:443
constexpr NodeHandle(void *exec, const char *name, const char *ns)
Definition node.hpp:437
size_t qos_override_count
Entries in qos_overrides; 0 = none.
Definition node.hpp:427
rclcpp::Timer — periodic callback driven by the executor.