ROS 2 rclcpp + rcl - humble  humble
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/node_options.h"
23 #include "rclcpp/context.hpp"
24 #include "rclcpp/contexts/default_context.hpp"
25 #include "rclcpp/parameter.hpp"
26 #include "rclcpp/publisher_options.hpp"
27 #include "rclcpp/qos.hpp"
28 #include "rclcpp/visibility_control.hpp"
29 
30 namespace rclcpp
31 {
32 
35 {
36 public:
38 
62  RCLCPP_PUBLIC
64 
66  RCLCPP_PUBLIC
67  virtual
68  ~NodeOptions() = default;
69 
71  RCLCPP_PUBLIC
72  NodeOptions(const NodeOptions & other);
73 
75  RCLCPP_PUBLIC
76  NodeOptions &
77  operator=(const NodeOptions & other);
78 
80 
88  RCLCPP_PUBLIC
89  const rcl_node_options_t *
90  get_rcl_node_options() const;
91 
93  RCLCPP_PUBLIC
94  rclcpp::Context::SharedPtr
95  context() const;
96 
98  RCLCPP_PUBLIC
99  NodeOptions &
100  context(rclcpp::Context::SharedPtr context);
101 
103  RCLCPP_PUBLIC
104  const std::vector<std::string> &
105  arguments() const;
106 
108 
114  RCLCPP_PUBLIC
115  NodeOptions &
116  arguments(const std::vector<std::string> & arguments);
117 
119  RCLCPP_PUBLIC
120  std::vector<rclcpp::Parameter> &
122 
123  RCLCPP_PUBLIC
124  const std::vector<rclcpp::Parameter> &
125  parameter_overrides() const;
126 
128 
133  RCLCPP_PUBLIC
134  NodeOptions &
135  parameter_overrides(const std::vector<rclcpp::Parameter> & parameter_overrides);
136 
138  template<typename ParameterT>
139  NodeOptions &
140  append_parameter_override(const std::string & name, const ParameterT & value)
141  {
142  this->parameter_overrides().emplace_back(name, rclcpp::ParameterValue(value));
143  return *this;
144  }
145 
147  RCLCPP_PUBLIC
148  bool
149  use_global_arguments() const;
150 
152 
159  RCLCPP_PUBLIC
160  NodeOptions &
162 
164  RCLCPP_PUBLIC
165  bool
166  enable_rosout() const;
167 
169 
175  RCLCPP_PUBLIC
176  NodeOptions &
178 
180  RCLCPP_PUBLIC
181  bool
182  use_intra_process_comms() const;
183 
185 
194  RCLCPP_PUBLIC
195  NodeOptions &
197 
199  RCLCPP_PUBLIC
200  bool
201  enable_topic_statistics() const;
202 
204 
211  RCLCPP_PUBLIC
212  NodeOptions &
214 
216  RCLCPP_PUBLIC
217  bool
218  start_parameter_services() const;
219 
221 
230  RCLCPP_PUBLIC
231  NodeOptions &
233 
235  RCLCPP_PUBLIC
236  bool
238 
240 
246  RCLCPP_PUBLIC
247  NodeOptions &
249 
251  RCLCPP_PUBLIC
252  const rclcpp::QoS &
253  clock_qos() const;
254 
256 
259  RCLCPP_PUBLIC
260  NodeOptions &
262 
263 
265  RCLCPP_PUBLIC
266  bool
267  use_clock_thread() const;
268 
270 
273  RCLCPP_PUBLIC
274  NodeOptions &
276 
278  RCLCPP_PUBLIC
279  const rclcpp::QoS &
280  parameter_event_qos() const;
281 
283 
286  RCLCPP_PUBLIC
287  NodeOptions &
289 
291  RCLCPP_PUBLIC
292  const rclcpp::QoS &
293  rosout_qos() const;
294 
296 
299  RCLCPP_PUBLIC
300  NodeOptions &
302 
304  RCLCPP_PUBLIC
307 
309 
316  RCLCPP_PUBLIC
317  NodeOptions &
320 
322  RCLCPP_PUBLIC
323  bool
325 
327 
336  RCLCPP_PUBLIC
337  NodeOptions &
339 
341  RCLCPP_PUBLIC
342  bool
344 
346 
359  RCLCPP_PUBLIC
360  NodeOptions &
363 
365  RCLCPP_PUBLIC
366  const rcl_allocator_t &
367  allocator() const;
368 
370 
373  RCLCPP_PUBLIC
374  NodeOptions &
376 
377 private:
378  // This is mutable to allow for a const accessor which lazily creates the node options instance.
380  mutable std::unique_ptr<rcl_node_options_t, void (*)(rcl_node_options_t *)> node_options_;
381 
382  // IMPORTANT: if any of these default values are changed, please update the
383  // documentation in this class.
384 
385  rclcpp::Context::SharedPtr context_ {
386  rclcpp::contexts::get_global_default_context()};
387 
388  std::vector<std::string> arguments_ {};
389 
390  std::vector<rclcpp::Parameter> parameter_overrides_ {};
391 
392  bool use_global_arguments_ {true};
393 
394  bool enable_rosout_ {true};
395 
396  bool use_intra_process_comms_ {false};
397 
398  bool enable_topic_statistics_ {false};
399 
400  bool start_parameter_services_ {true};
401 
402  bool start_parameter_event_publisher_ {true};
403 
404  rclcpp::QoS clock_qos_ = rclcpp::ClockQoS();
405 
406  bool use_clock_thread_ {true};
407 
408  rclcpp::QoS parameter_event_qos_ = rclcpp::ParameterEventsQoS(
409  rclcpp::QoSInitialization::from_rmw(rmw_qos_profile_parameter_events)
410  );
411 
412  rclcpp::QoS rosout_qos_ = rclcpp::RosoutQoS();
413 
414  rclcpp::PublisherOptionsBase parameter_event_publisher_options_ = rclcpp::PublisherOptionsBase();
415 
416  bool allow_undeclared_parameters_ {false};
417 
418  bool automatically_declare_parameters_from_overrides_ {false};
419 
421 };
422 
423 } // namespace rclcpp
424 
425 #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
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 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 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 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.
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.
Encapsulation of Quality of Service settings.
Definition: qos.hpp:111
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:51