ROS 2 rclcpp + rcl - lyrical  lyrical
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/parameter.hpp"
27 #include "rclcpp/publisher_options.hpp"
28 #include "rclcpp/qos.hpp"
29 #include "rclcpp/visibility_control.hpp"
30 
31 namespace rclcpp
32 {
33 
36 {
37 public:
39 
66  RCLCPP_PUBLIC
68 
70  RCLCPP_PUBLIC
71  virtual
72  ~NodeOptions() = default;
73 
75  RCLCPP_PUBLIC
76  NodeOptions(const NodeOptions & other);
77 
79  RCLCPP_PUBLIC
80  NodeOptions &
81  operator=(const NodeOptions & other);
82 
84 
92  RCLCPP_PUBLIC
93  const rcl_node_options_t *
94  get_rcl_node_options() const;
95 
97  RCLCPP_PUBLIC
98  rclcpp::Context::SharedPtr
99  context() const;
100 
102  RCLCPP_PUBLIC
103  NodeOptions &
104  context(const rclcpp::Context::SharedPtr & context);
105 
107  RCLCPP_PUBLIC
108  const std::vector<std::string> &
109  arguments() const;
110 
112 
118  RCLCPP_PUBLIC
119  NodeOptions &
120  arguments(const std::vector<std::string> & arguments);
121 
123  RCLCPP_PUBLIC
124  std::vector<rclcpp::Parameter> &
126 
127  RCLCPP_PUBLIC
128  const std::vector<rclcpp::Parameter> &
129  parameter_overrides() const;
130 
132 
137  RCLCPP_PUBLIC
138  NodeOptions &
139  parameter_overrides(const std::vector<rclcpp::Parameter> & parameter_overrides);
140 
142  template<typename ParameterT>
143  NodeOptions &
144  append_parameter_override(const std::string & name, const ParameterT & value)
145  {
146  this->parameter_overrides().emplace_back(name, rclcpp::ParameterValue(value));
147  return *this;
148  }
149 
151  NodeOptions &
153  {
154  this->parameter_overrides().push_back(param);
155  return *this;
156  }
157 
159  RCLCPP_PUBLIC
160  bool
161  use_global_arguments() const;
162 
164 
171  RCLCPP_PUBLIC
172  NodeOptions &
174 
176  RCLCPP_PUBLIC
177  bool
178  enable_rosout() const;
179 
181 
187  RCLCPP_PUBLIC
188  NodeOptions &
190 
192  RCLCPP_PUBLIC
193  bool
194  use_intra_process_comms() const;
195 
197 
206  RCLCPP_PUBLIC
207  NodeOptions &
209 
211  RCLCPP_PUBLIC
212  bool
213  enable_topic_statistics() const;
214 
216 
223  RCLCPP_PUBLIC
224  NodeOptions &
226 
228  RCLCPP_PUBLIC
229  bool
230  start_parameter_services() const;
231 
233 
242  RCLCPP_PUBLIC
243  NodeOptions &
245 
247  RCLCPP_PUBLIC
248  bool
249  enable_logger_service() const;
250 
252 
260  RCLCPP_PUBLIC
261  NodeOptions &
262  enable_logger_service(bool enable_log_service);
263 
265  RCLCPP_PUBLIC
267  log_level() const;
268 
270 
276  RCLCPP_PUBLIC
277  NodeOptions &
279 
281  RCLCPP_PUBLIC
282  bool
284 
286 
292  RCLCPP_PUBLIC
293  NodeOptions &
295 
297  RCLCPP_PUBLIC
298  const rcl_clock_type_t &
299  clock_type() const;
300 
302 
305  RCLCPP_PUBLIC
306  NodeOptions &
308 
310  RCLCPP_PUBLIC
311  const rclcpp::QoS &
312  clock_qos() const;
313 
315 
318  RCLCPP_PUBLIC
319  NodeOptions &
321 
322 
324  RCLCPP_PUBLIC
325  bool
326  use_clock_thread() const;
327 
329 
332  RCLCPP_PUBLIC
333  NodeOptions &
335 
337  RCLCPP_PUBLIC
338  const rclcpp::QoS &
339  parameter_event_qos() const;
340 
342 
345  RCLCPP_PUBLIC
346  NodeOptions &
348 
350  RCLCPP_PUBLIC
351  const rclcpp::QoS &
352  rosout_qos() const;
353 
355 
358  RCLCPP_PUBLIC
359  NodeOptions &
361 
363  RCLCPP_PUBLIC
366 
368 
375  RCLCPP_PUBLIC
376  NodeOptions &
379 
381  RCLCPP_PUBLIC
382  bool
384 
386 
395  RCLCPP_PUBLIC
396  NodeOptions &
398 
400  RCLCPP_PUBLIC
401  bool
403 
405 
418  RCLCPP_PUBLIC
419  NodeOptions &
422 
424  RCLCPP_PUBLIC
425  const rcl_allocator_t &
426  allocator() const;
427 
429 
432  RCLCPP_PUBLIC
433  NodeOptions &
435 
436 private:
437  // This is mutable to allow for a const accessor which lazily creates the node options instance.
439  mutable std::unique_ptr<rcl_node_options_t, void (*)(rcl_node_options_t *)> node_options_;
440 
441  // IMPORTANT: if any of these default values are changed, please update the
442  // documentation in this class.
443 
444  rclcpp::Context::SharedPtr context_ {
445  rclcpp::contexts::get_global_default_context()};
446 
447  std::vector<std::string> arguments_ {};
448 
449  std::vector<rclcpp::Parameter> parameter_overrides_ {};
450 
451  bool use_global_arguments_ {true};
452 
453  bool enable_rosout_ {true};
454 
455  bool use_intra_process_comms_ {false};
456 
457  bool enable_topic_statistics_ {false};
458 
459  bool start_parameter_services_ {true};
460 
461  bool start_parameter_event_publisher_ {true};
462 
463  rcl_clock_type_t clock_type_ {RCL_ROS_TIME};
464 
465  rclcpp::QoS clock_qos_ = rclcpp::ClockQoS();
466 
467  bool use_clock_thread_ {true};
468 
469  bool enable_logger_service_ {false};
470 
472 
473  rclcpp::QoS parameter_event_qos_ = rclcpp::ParameterEventsQoS(
474  rclcpp::QoSInitialization::from_rmw(rmw_qos_profile_parameter_events)
475  );
476 
477  rclcpp::QoS rosout_qos_ = rclcpp::RosoutQoS();
478 
479  rclcpp::PublisherOptionsBase parameter_event_publisher_options_ = rclcpp::PublisherOptionsBase();
480 
481  bool allow_undeclared_parameters_ {false};
482 
483  bool automatically_declare_parameters_from_overrides_ {false};
484 
486 };
487 
488 } // namespace rclcpp
489 
490 #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:98
@ 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:116
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:69
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