ROS 2 rclcpp + rcl - rolling  rolling-20536064
ROS 2 C++ Client Library with ROS Client Library
node_options.hpp
1 // Copyright 2019 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 #ifndef RCLCPP__NODE_OPTIONS_HPP_
16 #define RCLCPP__NODE_OPTIONS_HPP_
17 
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
22 #include "rcl/time.h"
23 #include "rcl/node_options.h"
24 #include "rclcpp/context.hpp"
25 #include "rclcpp/contexts/default_context.hpp"
26 #include "rclcpp/logger.hpp"
27 #include "rclcpp/parameter.hpp"
28 #include "rclcpp/publisher_options.hpp"
29 #include "rclcpp/qos.hpp"
30 #include "rclcpp/visibility_control.hpp"
31 
32 namespace rclcpp
33 {
34 
37 {
38 public:
40 
67  RCLCPP_PUBLIC
69 
71  RCLCPP_PUBLIC
72  virtual
73  ~NodeOptions() = default;
74 
76  RCLCPP_PUBLIC
77  NodeOptions(const NodeOptions & other);
78 
80  RCLCPP_PUBLIC
81  NodeOptions &
82  operator=(const NodeOptions & other);
83 
85 
93  RCLCPP_PUBLIC
94  const rcl_node_options_t *
95  get_rcl_node_options() const;
96 
98  RCLCPP_PUBLIC
99  rclcpp::Context::SharedPtr
100  context() const;
101 
103  RCLCPP_PUBLIC
104  NodeOptions &
105  context(const rclcpp::Context::SharedPtr & context);
106 
108  RCLCPP_PUBLIC
109  const std::vector<std::string> &
110  arguments() const;
111 
113 
119  RCLCPP_PUBLIC
120  NodeOptions &
121  arguments(const std::vector<std::string> & arguments);
122 
124  RCLCPP_PUBLIC
125  std::vector<rclcpp::Parameter> &
127 
128  RCLCPP_PUBLIC
129  const std::vector<rclcpp::Parameter> &
130  parameter_overrides() const;
131 
133 
138  RCLCPP_PUBLIC
139  NodeOptions &
140  parameter_overrides(const std::vector<rclcpp::Parameter> & parameter_overrides);
141 
143  template<typename ParameterT>
144  NodeOptions &
145  append_parameter_override(const std::string & name, const ParameterT & value)
146  {
147  this->parameter_overrides().emplace_back(name, rclcpp::ParameterValue(value));
148  return *this;
149  }
150 
152  NodeOptions &
154  {
155  this->parameter_overrides().push_back(param);
156  return *this;
157  }
158 
160  RCLCPP_PUBLIC
161  bool
162  use_global_arguments() const;
163 
165 
172  RCLCPP_PUBLIC
173  NodeOptions &
175 
177  RCLCPP_PUBLIC
178  bool
179  enable_rosout() const;
180 
182 
188  RCLCPP_PUBLIC
189  NodeOptions &
191 
193  RCLCPP_PUBLIC
194  bool
195  use_intra_process_comms() const;
196 
198 
207  RCLCPP_PUBLIC
208  NodeOptions &
210 
212  RCLCPP_PUBLIC
213  bool
214  enable_topic_statistics() const;
215 
217 
224  RCLCPP_PUBLIC
225  NodeOptions &
227 
229  RCLCPP_PUBLIC
230  bool
231  start_parameter_services() const;
232 
234 
243  RCLCPP_PUBLIC
244  NodeOptions &
246 
248  RCLCPP_PUBLIC
249  bool
250  enable_logger_service() const;
251 
253 
261  RCLCPP_PUBLIC
262  NodeOptions &
263  enable_logger_service(bool enable_log_service);
264 
266  RCLCPP_PUBLIC
268  log_level() const;
269 
271 
277  RCLCPP_PUBLIC
278  NodeOptions &
280 
282  RCLCPP_PUBLIC
283  bool
285 
287 
293  RCLCPP_PUBLIC
294  NodeOptions &
296 
298  RCLCPP_PUBLIC
299  const rcl_clock_type_t &
300  clock_type() const;
301 
303 
306  RCLCPP_PUBLIC
307  NodeOptions &
309 
311  RCLCPP_PUBLIC
312  const rclcpp::QoS &
313  clock_qos() const;
314 
316 
319  RCLCPP_PUBLIC
320  NodeOptions &
322 
323 
325  RCLCPP_PUBLIC
326  bool
327  use_clock_thread() const;
328 
330 
333  RCLCPP_PUBLIC
334  NodeOptions &
336 
338  RCLCPP_PUBLIC
339  const rclcpp::QoS &
340  parameter_event_qos() const;
341 
343 
346  RCLCPP_PUBLIC
347  NodeOptions &
349 
351  RCLCPP_PUBLIC
352  const rclcpp::QoS &
353  rosout_qos() const;
354 
356 
359  RCLCPP_PUBLIC
360  NodeOptions &
362 
364  RCLCPP_PUBLIC
367 
369 
376  RCLCPP_PUBLIC
377  NodeOptions &
380 
382  RCLCPP_PUBLIC
383  bool
385 
387 
396  RCLCPP_PUBLIC
397  NodeOptions &
399 
401  RCLCPP_PUBLIC
402  bool
404 
406 
419  RCLCPP_PUBLIC
420  NodeOptions &
423 
425  RCLCPP_PUBLIC
426  const rcl_allocator_t &
427  allocator() const;
428 
430 
433  RCLCPP_PUBLIC
434  NodeOptions &
436 
437 private:
438  // This is mutable to allow for a const accessor which lazily creates the node options instance.
440  mutable std::unique_ptr<rcl_node_options_t, void (*)(rcl_node_options_t *)> node_options_;
441 
442  // IMPORTANT: if any of these default values are changed, please update the
443  // documentation in this class.
444 
445  rclcpp::Context::SharedPtr context_ {
446  rclcpp::contexts::get_global_default_context()};
447 
448  std::vector<std::string> arguments_ {};
449 
450  std::vector<rclcpp::Parameter> parameter_overrides_ {};
451 
452  bool use_global_arguments_ {true};
453 
454  bool enable_rosout_ {true};
455 
456  bool use_intra_process_comms_ {false};
457 
458  bool enable_topic_statistics_ {false};
459 
460  bool start_parameter_services_ {true};
461 
462  bool start_parameter_event_publisher_ {true};
463 
464  rcl_clock_type_t clock_type_ {RCL_ROS_TIME};
465 
466  rclcpp::QoS clock_qos_ = rclcpp::ClockQoS();
467 
468  bool use_clock_thread_ {true};
469 
470  bool enable_logger_service_ {false};
471 
473 
474  rclcpp::QoS parameter_event_qos_ = rclcpp::ParameterEventsQoS(
475  rclcpp::QoSInitialization::from_rmw(rmw_qos_profile_parameter_events)
476  );
477 
478  rclcpp::QoS rosout_qos_ = rclcpp::RosoutQoS();
479 
480  rclcpp::PublisherOptionsBase parameter_event_publisher_options_ = rclcpp::PublisherOptionsBase();
481 
482  bool allow_undeclared_parameters_ {false};
483 
484  bool automatically_declare_parameters_from_overrides_ {false};
485 
487 };
488 
489 } // namespace rclcpp
490 
491 #endif // RCLCPP__NODE_OPTIONS_HPP_
#define rcl_get_default_allocator
Return a properly initialized rcl_allocator_t with default values.
Definition: allocator.h:37
rcutils_allocator_t rcl_allocator_t
Encapsulation of an allocator.
Definition: allocator.h:31
Level
An enum for the type of logger level.
Definition: logger.hpp:84
@ Unset
The unset log level.
Encapsulation of options for node initialization.
RCLCPP_PUBLIC bool start_parameter_event_publisher() const
Return the start_parameter_event_publisher flag.
RCLCPP_PUBLIC const std::vector< std::string > & arguments() const
Return a reference to the list of arguments for the node.
RCLCPP_PUBLIC bool use_clock_thread() const
Return the use_clock_thread flag.
RCLCPP_PUBLIC rclcpp::Logger::Level log_level() const
Return the log_level option.
RCLCPP_PUBLIC bool use_global_arguments() const
Return the use_global_arguments flag.
RCLCPP_PUBLIC const rclcpp::QoS & parameter_event_qos() const
Return a reference to the parameter_event_qos QoS.
RCLCPP_PUBLIC const rclcpp::QoS & rosout_qos() const
Return a reference to the rosout QoS.
NodeOptions & append_parameter_override(const std::string &name, const ParameterT &value)
Append a single parameter override, parameter idiom style.
RCLCPP_PUBLIC bool enable_rosout() const
Return the enable_rosout flag.
RCLCPP_PUBLIC const rclcpp::PublisherOptionsBase & parameter_event_publisher_options() const
Return a reference to the parameter_event_publisher_options.
RCLCPP_PUBLIC bool allow_undeclared_parameters() const
Return the allow_undeclared_parameters flag.
RCLCPP_PUBLIC bool automatically_declare_parameters_from_overrides() const
Return the automatically_declare_parameters_from_overrides flag.
virtual RCLCPP_PUBLIC ~NodeOptions()=default
Destructor.
RCLCPP_PUBLIC const rclcpp::QoS & clock_qos() const
Return a reference to the clock QoS.
RCLCPP_PUBLIC NodeOptions(rcl_allocator_t allocator=rcl_get_default_allocator())
Create NodeOptions with default values, optionally specifying the allocator to use.
RCLCPP_PUBLIC bool enable_logger_service() const
Return the enable_logger_service flag.
RCLCPP_PUBLIC bool start_parameter_services() const
Return the start_parameter_services flag.
RCLCPP_PUBLIC bool use_intra_process_comms() const
Return the use_intra_process_comms flag.
RCLCPP_PUBLIC const rcl_clock_type_t & clock_type() const
Return a reference to the clock type.
RCLCPP_PUBLIC std::vector< rclcpp::Parameter > & parameter_overrides()
Return a reference to the list of parameter overrides.
RCLCPP_PUBLIC const rcl_allocator_t & allocator() const
Return the rcl_allocator_t to be used.
RCLCPP_PUBLIC rclcpp::Context::SharedPtr context() const
Return the context to be used by the node.
RCLCPP_PUBLIC bool enable_topic_statistics() const
Return the enable_topic_statistics flag.
NodeOptions & append_parameter_override(const rclcpp::Parameter &param)
Append a single parameter override, parameter idiom style.
RCLCPP_PUBLIC const rcl_node_options_t * get_rcl_node_options() const
Return the rcl_node_options used by the node.
RCLCPP_PUBLIC NodeOptions & operator=(const NodeOptions &other)
Assignment operator.
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
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
struct rcl_node_options_s rcl_node_options_t
Structure which encapsulates the options for creating a rcl_node_t.
Structure which encapsulates the options for creating a rcl_node_t.
Definition: node_options.h:35
Non-templated part of PublisherOptionsWithAllocator<Allocator>.
static QoSInitialization from_rmw(const rmw_qos_profile_t &rmw_qos)
Create a QoSInitialization from an existing rmw_qos_profile_t, using its history and depth.
Definition: qos.cpp:70
enum rcl_clock_type_e rcl_clock_type_t
Time source type, used to indicate the source of a time measurement.
@ RCL_ROS_TIME
Use ROS time.
Definition: time.h:66