ROS 2 rclcpp + rcl - rolling  rolling-e7363f10
ROS 2 C++ Client Library with ROS Client Library
node.cpp
1 // Copyright 2015 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <algorithm>
16 #include <array>
17 #include <limits>
18 #include <map>
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #include "rcl/arguments.h"
24 
25 #include "rclcpp/create_generic_client.hpp"
26 #include "rclcpp/detail/qos_parameters.hpp"
27 #include "rclcpp/exceptions.hpp"
28 #include "rclcpp/graph_listener.hpp"
29 #include "rclcpp/node.hpp"
30 #include "rclcpp/node_interfaces/node_base.hpp"
31 #include "rclcpp/node_interfaces/node_clock.hpp"
32 #include "rclcpp/node_interfaces/node_graph.hpp"
33 #include "rclcpp/node_interfaces/node_logging.hpp"
34 #include "rclcpp/node_interfaces/node_parameters.hpp"
35 #include "rclcpp/node_interfaces/node_services.hpp"
36 #include "rclcpp/node_interfaces/node_time_source.hpp"
37 #include "rclcpp/node_interfaces/node_timers.hpp"
38 #include "rclcpp/node_interfaces/node_topics.hpp"
39 #include "rclcpp/node_interfaces/node_type_descriptions.hpp"
40 #include "rclcpp/node_interfaces/node_waitables.hpp"
41 #include "rclcpp/qos_overriding_options.hpp"
42 
43 #include "rmw/validate_namespace.h"
44 
45 #include "./detail/resolve_parameter_overrides.hpp"
46 
47 using rclcpp::Node;
49 using rclcpp::exceptions::throw_from_rcl_error;
50 
51 namespace
52 {
53 
54 RCLCPP_LOCAL
55 std::string
56 extend_sub_namespace(const std::string & existing_sub_namespace, const std::string & extension)
57 {
58  // Assumption is that the existing_sub_namespace does not need checking
59  // because it would be checked already when it was set with this function.
60 
61  if (extension.empty()) {
63  "sub_namespace",
64  extension.c_str(),
65  "sub-nodes should not extend nodes by an empty sub-namespace",
66  0);
67  } else if (extension.front() == '/') {
68  // check if the new sub-namespace extension is absolute
70  "sub_namespace",
71  extension.c_str(),
72  "a sub-namespace should not have a leading /",
73  0);
74  }
75 
76  std::string new_sub_namespace;
77  if (existing_sub_namespace.empty()) {
78  new_sub_namespace = extension;
79  } else {
80  new_sub_namespace = existing_sub_namespace + "/" + extension;
81  }
82 
83  // remove any trailing `/` so that new extensions do not result in `//`
84  if (new_sub_namespace.back() == '/') {
85  new_sub_namespace = new_sub_namespace.substr(0, new_sub_namespace.size() - 1);
86  }
87 
88  return new_sub_namespace;
89 }
90 
91 RCLCPP_LOCAL
92 std::string
93 create_effective_namespace(const std::string & node_namespace, const std::string & sub_namespace)
94 {
95  // Assumption is that both the node_namespace and sub_namespace are conforming
96  // and do not need trimming of `/` and other things, as they were validated
97  // in other functions already.
98 
99  // A node may not have a sub_namespace if it is no sub_node. In this case,
100  // just return the original namespace
101  if (sub_namespace.empty()) {
102  return node_namespace;
103  } else if (node_namespace.back() == '/') {
104  // this is the special case where node_namespace is just `/`
105  return node_namespace + sub_namespace;
106  } else {
107  return node_namespace + "/" + sub_namespace;
108  }
109 }
110 
111 } // namespace
112 
114 
123 {
124 public:
125  NodeImpl() = default;
126  ~NodeImpl() = default;
127 };
128 
129 Node::Node(
130  const std::string & node_name,
131  const NodeOptions & options)
132 : Node(node_name, "", options)
133 {
134 }
135 
136 static
138 get_parameter_events_qos(
140  const rclcpp::NodeOptions & options)
141 {
142  auto final_qos = options.parameter_event_qos();
143  const rcl_arguments_t * global_args = nullptr;
144  auto * rcl_options = options.get_rcl_node_options();
145  if (rcl_options->use_global_arguments) {
146  auto context_ptr = node_base.get_context()->get_rcl_context();
147  global_args = &(context_ptr->global_arguments);
148  }
149 
150  auto parameter_overrides = rclcpp::detail::resolve_parameter_overrides(
151  node_base.get_fully_qualified_name(),
152  options.parameter_overrides(),
153  &rcl_options->arguments,
154  global_args);
155 
156  auto final_topic_name = node_base.resolve_topic_or_service_name("/parameter_events", false);
157  auto prefix = "qos_overrides." + final_topic_name + ".";
158  std::array<rclcpp::QosPolicyKind, 4> policies = {
159  rclcpp::QosPolicyKind::Depth,
160  rclcpp::QosPolicyKind::Durability,
161  rclcpp::QosPolicyKind::History,
162  rclcpp::QosPolicyKind::Reliability,
163  };
164  for (const auto & policy : policies) {
165  auto param_name = prefix + rclcpp::qos_policy_kind_to_cstr(policy);
166  auto it = parameter_overrides.find(param_name);
167  auto value = it != parameter_overrides.end() ?
168  it->second :
169  rclcpp::detail::get_default_qos_param_value(policy, options.parameter_event_qos());
170  rclcpp::detail::apply_qos_override(policy, value, final_qos);
171  }
172  return final_qos;
173 }
174 
176  const std::string & node_name,
177  const std::string & namespace_,
178  const NodeOptions & options)
179 : node_base_(new rclcpp::node_interfaces::NodeBase(
180  node_name,
181  namespace_,
182  options.context(),
183  *(options.get_rcl_node_options()),
184  options.use_intra_process_comms())),
185  node_graph_(new rclcpp::node_interfaces::NodeGraph(node_base_.get())),
186  node_logging_(new rclcpp::node_interfaces::NodeLogging(node_base_)),
187  node_timers_(new rclcpp::node_interfaces::NodeTimers(node_base_.get())),
188  node_topics_(new rclcpp::node_interfaces::NodeTopics(node_base_.get(), node_timers_.get())),
189  node_services_(new rclcpp::node_interfaces::NodeServices(node_base_.get())),
190  node_clock_(new rclcpp::node_interfaces::NodeClock(
191  node_base_,
192  node_topics_,
193  node_graph_,
194  node_services_,
195  node_logging_,
196  options.clock_type()
197  )),
198  node_parameters_(new rclcpp::node_interfaces::NodeParameters(
199  node_base_,
200  node_logging_,
201  node_topics_,
202  node_services_,
203  node_clock_,
204  options.parameter_overrides(),
205  options.start_parameter_services(),
206  options.start_parameter_event_publisher(),
207  // This is needed in order to apply parameter overrides to the qos profile provided in
208  // options.
209  get_parameter_events_qos(*node_base_, options),
210  options.parameter_event_publisher_options(),
211  options.allow_undeclared_parameters(),
212  options.automatically_declare_parameters_from_overrides()
213  )),
214  node_time_source_(new rclcpp::node_interfaces::NodeTimeSource(
215  node_base_,
216  node_topics_,
217  node_graph_,
218  node_services_,
219  node_logging_,
220  node_clock_,
221  node_parameters_,
222  options.clock_qos(),
223  options.use_clock_thread()
224  )),
225  node_type_descriptions_(new rclcpp::node_interfaces::NodeTypeDescriptions(
226  node_base_,
227  node_logging_,
228  node_parameters_,
229  node_services_
230  )),
231  node_waitables_(new rclcpp::node_interfaces::NodeWaitables(node_base_.get())),
232  node_options_(options),
233  sub_namespace_(""),
234  effective_namespace_(create_effective_namespace(this->get_namespace(), sub_namespace_))
235 {
236  // we have got what we wanted directly from the overrides,
237  // but declare the parameters anyway so they are visible.
238  rclcpp::detail::declare_qos_parameters(
240  {
241  QosPolicyKind::Depth,
242  QosPolicyKind::Durability,
243  QosPolicyKind::History,
244  QosPolicyKind::Reliability,
245  },
246  node_parameters_,
247  node_topics_->resolve_topic_name("/parameter_events"),
248  options.parameter_event_qos(),
250 
251  if (options.log_level() != rclcpp::Logger::Level::Unset) {
252  node_logging_->get_logger().set_level(options.log_level());
253  }
254  if (options.enable_logger_service()) {
255  node_logging_->create_logger_services(node_services_);
256  }
257 }
258 
260  const Node & other,
261  const std::string & sub_namespace)
262 : node_base_(other.node_base_),
263  node_graph_(other.node_graph_),
264  node_logging_(other.node_logging_),
265  node_timers_(other.node_timers_),
266  node_topics_(other.node_topics_),
267  node_services_(other.node_services_),
268  node_clock_(other.node_clock_),
269  node_parameters_(other.node_parameters_),
270  node_time_source_(other.node_time_source_),
271  node_waitables_(other.node_waitables_),
272  node_options_(other.node_options_),
273  sub_namespace_(extend_sub_namespace(other.get_sub_namespace(), sub_namespace)),
274  effective_namespace_(create_effective_namespace(other.get_namespace(), sub_namespace_)),
275  hidden_impl_(other.hidden_impl_)
276 {
277  // Validate new effective namespace.
278  int validation_result;
279  size_t invalid_index;
280  rmw_ret_t rmw_ret =
281  rmw_validate_namespace(effective_namespace_.c_str(), &validation_result, &invalid_index);
282 
283  if (rmw_ret != RMW_RET_OK) {
284  if (rmw_ret == RMW_RET_INVALID_ARGUMENT) {
285  throw_from_rcl_error(RCL_RET_INVALID_ARGUMENT, "failed to validate subnode namespace");
286  }
287  throw_from_rcl_error(RCL_RET_ERROR, "failed to validate subnode namespace");
288  }
289 
290  if (validation_result != RMW_NAMESPACE_VALID) {
292  effective_namespace_.c_str(),
293  rmw_namespace_validation_result_string(validation_result),
294  invalid_index);
295  }
296 }
297 
298 Node::~Node()
299 {
300  // release sub-interfaces in an order that allows them to consult with node_base during tear-down
301  node_waitables_.reset();
302  node_time_source_.reset();
303  node_parameters_.reset();
304  node_clock_.reset();
305  node_services_.reset();
306  node_topics_.reset();
307  node_timers_.reset();
308  node_logging_.reset();
309  node_graph_.reset();
310 }
311 
312 const char *
314 {
315  return node_base_->get_name();
316 }
317 
318 const char *
320 {
321  return node_base_->get_namespace();
322 }
323 
324 const char *
326 {
327  return node_base_->get_fully_qualified_name();
328 }
329 
332 {
333  return node_logging_->get_logger();
334 }
335 
336 rclcpp::CallbackGroup::SharedPtr
338  rclcpp::CallbackGroupType group_type,
339  bool automatically_add_to_executor_with_node)
340 {
341  return node_base_->create_callback_group(group_type, automatically_add_to_executor_with_node);
342 }
343 
346  const std::string & name,
347  const rclcpp::ParameterValue & default_value,
348  const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor,
349  bool ignore_override)
350 {
351  return this->node_parameters_->declare_parameter(
352  name,
353  default_value,
354  parameter_descriptor,
355  ignore_override);
356 }
357 
360  const std::string & name,
361  rclcpp::ParameterType type,
362  const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor,
363  bool ignore_override)
364 {
365  return this->node_parameters_->declare_parameter(
366  name,
367  type,
368  parameter_descriptor,
369  ignore_override);
370 }
371 
372 void
373 Node::undeclare_parameter(const std::string & name)
374 {
375  this->node_parameters_->undeclare_parameter(name);
376 }
377 
378 bool
379 Node::has_parameter(const std::string & name) const
380 {
381  return this->node_parameters_->has_parameter(name);
382 }
383 
384 rcl_interfaces::msg::SetParametersResult
386 {
387  return node_parameters_->set_parameters_atomically({parameter});
388 }
389 
390 std::vector<rcl_interfaces::msg::SetParametersResult>
391 Node::set_parameters(const std::vector<rclcpp::Parameter> & parameters)
392 {
393  return node_parameters_->set_parameters(parameters);
394 }
395 
396 rcl_interfaces::msg::SetParametersResult
397 Node::set_parameters_atomically(const std::vector<rclcpp::Parameter> & parameters)
398 {
399  return node_parameters_->set_parameters_atomically(parameters);
400 }
401 
403 Node::get_parameter(const std::string & name) const
404 {
405  return node_parameters_->get_parameter(name);
406 }
407 
408 bool
409 Node::get_parameter(const std::string & name, rclcpp::Parameter & parameter) const
410 {
411  return node_parameters_->get_parameter(name, parameter);
412 }
413 
414 std::vector<rclcpp::Parameter>
416  const std::vector<std::string> & names) const
417 {
418  return node_parameters_->get_parameters(names);
419 }
420 
421 rcl_interfaces::msg::ParameterDescriptor
422 Node::describe_parameter(const std::string & name) const
423 {
424  auto result = node_parameters_->describe_parameters({name});
425  if (0 == result.size()) {
427  }
428  if (result.size() > 1) {
429  throw std::runtime_error("number of described parameters unexpectedly more than one");
430  }
431  return result.front();
432 }
433 
434 std::vector<rcl_interfaces::msg::ParameterDescriptor>
435 Node::describe_parameters(const std::vector<std::string> & names) const
436 {
437  return node_parameters_->describe_parameters(names);
438 }
439 
440 std::vector<uint8_t>
441 Node::get_parameter_types(const std::vector<std::string> & names) const
442 {
443  return node_parameters_->get_parameter_types(names);
444 }
445 
446 rcl_interfaces::msg::ListParametersResult
447 Node::list_parameters(const std::vector<std::string> & prefixes, uint64_t depth) const
448 {
449  return node_parameters_->list_parameters(prefixes, depth);
450 }
451 
452 rclcpp::Node::PreSetParametersCallbackHandle::SharedPtr
453 Node::add_pre_set_parameters_callback(PreSetParametersCallbackType callback)
454 {
455  return node_parameters_->add_pre_set_parameters_callback(callback);
456 }
457 
458 rclcpp::Node::OnSetParametersCallbackHandle::SharedPtr
459 Node::add_on_set_parameters_callback(OnSetParametersCallbackType callback)
460 {
461  return node_parameters_->add_on_set_parameters_callback(callback);
462 }
463 
464 rclcpp::Node::PostSetParametersCallbackHandle::SharedPtr
465 Node::add_post_set_parameters_callback(PostSetParametersCallbackType callback)
466 {
467  return node_parameters_->add_post_set_parameters_callback(callback);
468 }
469 
470 void
472 {
473  node_parameters_->remove_pre_set_parameters_callback(handler);
474 }
475 
476 void
478 {
479  node_parameters_->remove_on_set_parameters_callback(handler);
480 }
481 
482 void
484 {
485  node_parameters_->remove_post_set_parameters_callback(handler);
486 }
487 
488 std::vector<std::string>
490 {
491  return node_graph_->get_node_names();
492 }
493 
494 std::map<std::string, std::vector<std::string>>
496 {
497  return node_graph_->get_topic_names_and_types();
498 }
499 
500 std::map<std::string, std::vector<std::string>>
502 {
503  return node_graph_->get_service_names_and_types();
504 }
505 
506 std::map<std::string, std::vector<std::string>>
508  const std::string & node_name,
509  const std::string & namespace_) const
510 {
511  return node_graph_->get_service_names_and_types_by_node(
512  node_name, namespace_);
513 }
514 
515 size_t
516 Node::count_publishers(const std::string & topic_name) const
517 {
518  return node_graph_->count_publishers(topic_name);
519 }
520 
521 size_t
522 Node::count_subscribers(const std::string & topic_name) const
523 {
524  return node_graph_->count_subscribers(topic_name);
525 }
526 
527 size_t
528 Node::count_clients(const std::string & service_name) const
529 {
530  return node_graph_->count_clients(service_name);
531 }
532 
533 size_t
534 Node::count_services(const std::string & service_name) const
535 {
536  return node_graph_->count_services(service_name);
537 }
538 
539 std::vector<rclcpp::TopicEndpointInfo>
540 Node::get_publishers_info_by_topic(const std::string & topic_name, bool no_mangle) const
541 {
542  return node_graph_->get_publishers_info_by_topic(topic_name, no_mangle);
543 }
544 
545 std::vector<rclcpp::TopicEndpointInfo>
546 Node::get_subscriptions_info_by_topic(const std::string & topic_name, bool no_mangle) const
547 {
548  return node_graph_->get_subscriptions_info_by_topic(topic_name, no_mangle);
549 }
550 
551 std::vector<rclcpp::ServiceEndpointInfo>
552 Node::get_clients_info_by_service(const std::string & service_name, bool no_mangle) const
553 {
554  return node_graph_->get_clients_info_by_service(service_name, no_mangle);
555 }
556 
557 std::vector<rclcpp::ServiceEndpointInfo>
558 Node::get_servers_info_by_service(const std::string & service_name, bool no_mangle) const
559 {
560  return node_graph_->get_servers_info_by_service(service_name, no_mangle);
561 }
562 
563 void
565  const node_interfaces::NodeBaseInterface::CallbackGroupFunction & func)
566 {
567  node_base_->for_each_callback_group(func);
568 }
569 
570 rclcpp::Event::SharedPtr
572 {
573  return node_graph_->get_graph_event();
574 }
575 
576 void
578  const rclcpp::Event::SharedPtr & event,
579  std::chrono::nanoseconds timeout)
580 {
581  node_graph_->wait_for_graph_change(event, timeout);
582 }
583 
584 rclcpp::Clock::SharedPtr
586 {
587  return node_clock_->get_clock();
588 }
589 
590 rclcpp::Clock::ConstSharedPtr
592 {
593  return node_clock_->get_clock();
594 }
595 
597 Node::now() const
598 {
599  return node_clock_->get_clock()->now();
600 }
601 
602 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr
604 {
605  return node_base_;
606 }
607 
608 rclcpp::node_interfaces::NodeClockInterface::SharedPtr
610 {
611  return node_clock_;
612 }
613 
614 rclcpp::node_interfaces::NodeGraphInterface::SharedPtr
616 {
617  return node_graph_;
618 }
619 
620 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr
622 {
623  return node_logging_;
624 }
625 
626 rclcpp::node_interfaces::NodeTimeSourceInterface::SharedPtr
628 {
629  return node_time_source_;
630 }
631 
632 rclcpp::node_interfaces::NodeTimersInterface::SharedPtr
634 {
635  return node_timers_;
636 }
637 
638 rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr
640 {
641  return node_topics_;
642 }
643 
644 rclcpp::node_interfaces::NodeTypeDescriptionsInterface::SharedPtr
646 {
647  return node_type_descriptions_;
648 }
649 
650 rclcpp::node_interfaces::NodeServicesInterface::SharedPtr
652 {
653  return node_services_;
654 }
655 
656 rclcpp::node_interfaces::NodeParametersInterface::SharedPtr
658 {
659  return node_parameters_;
660 }
661 
662 rclcpp::node_interfaces::NodeWaitablesInterface::SharedPtr
664 {
665  return node_waitables_;
666 }
667 
668 const std::string &
670 {
671  return this->sub_namespace_;
672 }
673 
674 const std::string &
676 {
677  return this->effective_namespace_;
678 }
679 
680 Node::SharedPtr
681 Node::create_sub_node(const std::string & sub_namespace)
682 {
683  // Cannot use make_shared<Node>() here as it requires the constructor to be
684  // public, and this constructor is intentionally protected instead.
685  return std::shared_ptr<Node>(new Node(*this, sub_namespace));
686 }
687 
688 const NodeOptions &
690 {
691  return this->node_options_;
692 }
693 
694 rclcpp::GenericClient::SharedPtr
696  const std::string & service_name,
697  const std::string & service_type,
698  const rclcpp::QoS & qos,
699  const rclcpp::CallbackGroup::SharedPtr & group)
700 {
702  node_base_,
703  node_graph_,
704  node_services_,
705  extend_name_with_sub_namespace(service_name, this->get_sub_namespace()),
706  service_type,
707  qos,
708  group);
709 }
Internal implementation to provide hidden and API/ABI stable changes to the Node.
Definition: node.cpp:123
@ Unset
The unset log level.
Encapsulation of options for node initialization.
RCLCPP_PUBLIC rclcpp::Logger::Level log_level() const
Return the log_level option.
RCLCPP_PUBLIC const rclcpp::QoS & parameter_event_qos() const
Return a reference to the parameter_event_qos QoS.
RCLCPP_PUBLIC bool enable_logger_service() const
Return the enable_logger_service flag.
RCLCPP_PUBLIC std::vector< rclcpp::Parameter > & parameter_overrides()
Return a reference to the list of parameter overrides.
RCLCPP_PUBLIC const rcl_node_options_t * get_rcl_node_options() const
Return the rcl_node_options used by the node.
Node is the single point of entry for creating publishers and subscribers.
Definition: node.hpp:78
RCLCPP_PUBLIC rclcpp::Logger get_logger() const
Get the logger of the node.
Definition: node.cpp:331
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeWaitablesInterface::SharedPtr get_node_waitables_interface()
Return the Node's internal NodeWaitablesInterface implementation.
Definition: node.cpp:663
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr get_node_topics_interface()
Return the Node's internal NodeTopicsInterface implementation.
Definition: node.cpp:639
RCLCPP_PUBLIC std::vector< rclcpp::ServiceEndpointInfo > get_clients_info_by_service(const std::string &service_name, bool no_mangle=false) const
Return the service endpoint information about clients on a given service.
Definition: node.cpp:552
RCLCPP_PUBLIC std::vector< rclcpp::Parameter > get_parameters(const std::vector< std::string > &names) const
Return the parameters by the given parameter names.
Definition: node.cpp:415
RCLCPP_PUBLIC RCUTILS_WARN_UNUSED OnSetParametersCallbackHandle::SharedPtr add_on_set_parameters_callback(OnSetParametersCallbackType callback)
Add a callback to validate parameters before they are set.
Definition: node.cpp:459
RCLCPP_PUBLIC bool has_parameter(const std::string &name) const
Return true if a given parameter is declared.
Definition: node.cpp:379
RCLCPP_PUBLIC rclcpp::Node::SharedPtr create_sub_node(const std::string &sub_namespace)
Create a sub-node, which will extend the namespace of all entities created with it.
Definition: node.cpp:681
RCLCPP_PUBLIC rcl_interfaces::msg::SetParametersResult set_parameter(const rclcpp::Parameter &parameter)
Set a single parameter.
Definition: node.cpp:385
RCLCPP_PUBLIC rclcpp::Clock::SharedPtr get_clock()
Get a clock as a non-const shared pointer which is managed by the node.
Definition: node.cpp:585
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeTimersInterface::SharedPtr get_node_timers_interface()
Return the Node's internal NodeTimersInterface implementation.
Definition: node.cpp:633
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeParametersInterface::SharedPtr get_node_parameters_interface()
Return the Node's internal NodeParametersInterface implementation.
Definition: node.cpp:657
RCLCPP_PUBLIC std::vector< rclcpp::TopicEndpointInfo > get_publishers_info_by_topic(const std::string &topic_name, bool no_mangle=false) const
Return the topic endpoint information about publishers on a given topic.
Definition: node.cpp:540
RCLCPP_PUBLIC const rclcpp::ParameterValue & declare_parameter(const std::string &name, const rclcpp::ParameterValue &default_value, const rcl_interfaces::msg::ParameterDescriptor &parameter_descriptor=rcl_interfaces::msg::ParameterDescriptor(), bool ignore_override=false)
Declare and initialize a parameter, return the effective value.
Definition: node.cpp:345
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr get_node_logging_interface()
Return the Node's internal NodeLoggingInterface implementation.
Definition: node.cpp:621
RCLCPP_PUBLIC const std::string & get_effective_namespace() const
Return the effective namespace that is used when creating entities.
Definition: node.cpp:675
RCLCPP_PUBLIC size_t count_publishers(const std::string &topic_name) const
Return the number of publishers created for a given topic.
Definition: node.cpp:516
RCLCPP_PUBLIC std::map< std::string, std::vector< std::string > > get_service_names_and_types() const
Return a map of existing service names to list of service types.
Definition: node.cpp:501
RCLCPP_PUBLIC size_t count_subscribers(const std::string &topic_name) const
Return the number of subscribers created for a given topic.
Definition: node.cpp:522
RCLCPP_PUBLIC std::vector< rcl_interfaces::msg::ParameterDescriptor > describe_parameters(const std::vector< std::string > &names) const
Return a vector of parameter descriptors, one for each of the given names.
Definition: node.cpp:435
RCLCPP_PUBLIC Time now() const
Returns current time from the node clock.
Definition: node.cpp:597
RCLCPP_PUBLIC rclcpp::Event::SharedPtr get_graph_event()
Return a graph event, which will be set anytime a graph change occurs.
Definition: node.cpp:571
RCLCPP_PUBLIC void for_each_callback_group(const node_interfaces::NodeBaseInterface::CallbackGroupFunction &func)
Iterate over the callback groups in the node, calling the given function on each valid one.
Definition: node.cpp:564
RCLCPP_PUBLIC rcl_interfaces::msg::ParameterDescriptor describe_parameter(const std::string &name) const
Return the parameter descriptor for the given parameter name.
Definition: node.cpp:422
RCLCPP_PUBLIC std::vector< rclcpp::ServiceEndpointInfo > get_servers_info_by_service(const std::string &service_name, bool no_mangle=false) const
Return the service endpoint information about servers on a given service.
Definition: node.cpp:558
RCLCPP_PUBLIC void remove_on_set_parameters_callback(const OnSetParametersCallbackHandle *const handler)
Remove a callback registered with add_on_set_parameters_callback.
Definition: node.cpp:477
RCLCPP_PUBLIC std::map< std::string, std::vector< std::string > > get_topic_names_and_types() const
Return a map of existing topic names to list of topic types.
Definition: node.cpp:495
RCLCPP_PUBLIC rclcpp::Parameter get_parameter(const std::string &name) const
Return the parameter by the given name.
Definition: node.cpp:403
RCLCPP_PUBLIC Node(const std::string &node_name, const NodeOptions &options=NodeOptions())
Create a new node with the specified name.
Definition: node.cpp:129
RCLCPP_PUBLIC size_t count_services(const std::string &service_name) const
Return the number of services created for a given service.
Definition: node.cpp:534
RCLCPP_PUBLIC const rclcpp::NodeOptions & get_node_options() const
Return the NodeOptions used when creating this node.
Definition: node.cpp:689
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeBaseInterface::SharedPtr get_node_base_interface()
Return the Node's internal NodeBaseInterface implementation.
Definition: node.cpp:603
RCLCPP_PUBLIC rcl_interfaces::msg::SetParametersResult set_parameters_atomically(const std::vector< rclcpp::Parameter > &parameters)
Set one or more parameters, all at once.
Definition: node.cpp:397
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeClockInterface::SharedPtr get_node_clock_interface()
Return the Node's internal NodeClockInterface implementation.
Definition: node.cpp:609
RCLCPP_PUBLIC void remove_pre_set_parameters_callback(const PreSetParametersCallbackHandle *const handler)
Remove a callback registered with add_pre_set_parameters_callback.
Definition: node.cpp:471
RCLCPP_PUBLIC const char * get_name() const
Get the name of the node.
Definition: node.cpp:313
RCLCPP_PUBLIC std::vector< rcl_interfaces::msg::SetParametersResult > set_parameters(const std::vector< rclcpp::Parameter > &parameters)
Set one or more parameters, one at a time.
Definition: node.cpp:391
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeTypeDescriptionsInterface::SharedPtr get_node_type_descriptions_interface()
Return the Node's internal NodeTypeDescriptionsInterface implementation.
Definition: node.cpp:645
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeServicesInterface::SharedPtr get_node_services_interface()
Return the Node's internal NodeServicesInterface implementation.
Definition: node.cpp:651
RCLCPP_PUBLIC std::map< std::string, std::vector< std::string > > get_service_names_and_types_by_node(const std::string &node_name, const std::string &namespace_) const
Return a map of existing service names to list of service types for a specific node.
Definition: node.cpp:507
RCLCPP_PUBLIC void undeclare_parameter(const std::string &name)
Undeclare a previously declared parameter.
Definition: node.cpp:373
RCLCPP_PUBLIC std::vector< uint8_t > get_parameter_types(const std::vector< std::string > &names) const
Return a vector of parameter types, one for each of the given names.
Definition: node.cpp:441
RCLCPP_PUBLIC std::vector< rclcpp::TopicEndpointInfo > get_subscriptions_info_by_topic(const std::string &topic_name, bool no_mangle=false) const
Return the topic endpoint information about subscriptions on a given topic.
Definition: node.cpp:546
RCLCPP_PUBLIC rclcpp::CallbackGroup::SharedPtr create_callback_group(rclcpp::CallbackGroupType group_type, bool automatically_add_to_executor_with_node=true)
Create and return a callback group.
Definition: node.cpp:337
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeTimeSourceInterface::SharedPtr get_node_time_source_interface()
Return the Node's internal NodeTimeSourceInterface implementation.
Definition: node.cpp:627
RCLCPP_PUBLIC RCUTILS_WARN_UNUSED PreSetParametersCallbackHandle::SharedPtr add_pre_set_parameters_callback(PreSetParametersCallbackType callback)
Add a callback that gets triggered before parameters are validated.
Definition: node.cpp:453
RCLCPP_PUBLIC rcl_interfaces::msg::ListParametersResult list_parameters(const std::vector< std::string > &prefixes, uint64_t depth) const
Return a list of parameters with any of the given prefixes, up to the given depth.
Definition: node.cpp:447
RCLCPP_PUBLIC size_t count_clients(const std::string &service_name) const
Return the number of clients created for a given service.
Definition: node.cpp:528
RCLCPP_PUBLIC const char * get_fully_qualified_name() const
Get the fully-qualified name of the node.
Definition: node.cpp:325
RCLCPP_PUBLIC const std::string & get_sub_namespace() const
Return the sub-namespace, if this is a sub-node, otherwise an empty string.
Definition: node.cpp:669
RCLCPP_PUBLIC std::vector< std::string > get_node_names() const
Get the fully-qualified names of all available nodes.
Definition: node.cpp:489
RCLCPP_PUBLIC void wait_for_graph_change(const rclcpp::Event::SharedPtr &event, std::chrono::nanoseconds timeout)
Wait for a graph event to occur by waiting on an Event to become set.
Definition: node.cpp:577
RCLCPP_PUBLIC const char * get_namespace() const
Get the namespace of the node.
Definition: node.cpp:319
RCLCPP_PUBLIC RCUTILS_WARN_UNUSED PostSetParametersCallbackHandle::SharedPtr add_post_set_parameters_callback(PostSetParametersCallbackType callback)
Add a callback that gets triggered after parameters are set successfully.
Definition: node.cpp:465
RCLCPP_PUBLIC rclcpp::node_interfaces::NodeGraphInterface::SharedPtr get_node_graph_interface()
Return the Node's internal NodeGraphInterface implementation.
Definition: node.cpp:615
RCLCPP_PUBLIC void remove_post_set_parameters_callback(const PostSetParametersCallbackHandle *const handler)
Remove a callback registered with add_post_set_parameters_callback.
Definition: node.cpp:483
RCLCPP_PUBLIC rclcpp::GenericClient::SharedPtr create_generic_client(const std::string &service_name, const std::string &service_type, const rclcpp::QoS &qos=rclcpp::ServicesQoS(), const rclcpp::CallbackGroup::SharedPtr &group=nullptr)
Create and return a GenericClient.
Definition: node.cpp:695
Store the type and value of a parameter.
Structure to store an arbitrary parameter with templated get/set methods.
Definition: parameter.hpp:53
Encapsulation of Quality of Service settings.
Definition: qos.hpp:114
Options that are passed in subscription/publisher constructor to specify QoSConfigurability.
Thrown when a node namespace is invalid.
Definition: exceptions.hpp:78
Thrown when a any kind of name (node, namespace, topic, etc.) is invalid.
Definition: exceptions.hpp:43
Thrown if parameter is not declared, e.g. either set or get was called without first declaring.
Definition: exceptions.hpp:310
Pure virtual interface class for the NodeBase part of the Node API.
virtual RCLCPP_PUBLIC std::string resolve_topic_or_service_name(const std::string &name, bool is_service, bool only_expand=false) const =0
Expand and remap a given topic or service name.
virtual RCLCPP_PUBLIC const char * get_fully_qualified_name() const =0
Return the fully qualified name of the node.
virtual RCLCPP_PUBLIC rclcpp::Context::SharedPtr get_context()=0
Return the context of the node.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
RCLCPP_PUBLIC rclcpp::GenericClient::SharedPtr create_generic_client(const std::shared_ptr< node_interfaces::NodeBaseInterface > &node_base, const std::shared_ptr< node_interfaces::NodeGraphInterface > &node_graph, const std::shared_ptr< node_interfaces::NodeServicesInterface > &node_services, const std::string &service_name, const std::string &service_type, const rclcpp::QoS &qos=rclcpp::ServicesQoS(), const rclcpp::CallbackGroup::SharedPtr &group=rclcpp::CallbackGroup::SharedPtr())
Create a generic service client with a name of given type.
Hold output of parsing command line arguments.
Definition: arguments.h:36
#define RCL_RET_INVALID_ARGUMENT
Invalid argument return code.
Definition: types.h:36
#define RCL_RET_ERROR
Unspecified error return code.
Definition: types.h:30