ROS 2 rclcpp + rcl - rolling  rolling-a919a6e5
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 
65  RCLCPP_PUBLIC
67 
69  RCLCPP_PUBLIC
70  virtual
71  ~NodeOptions() = default;
72 
74  RCLCPP_PUBLIC
75  NodeOptions(const NodeOptions & other);
76 
78  RCLCPP_PUBLIC
79  NodeOptions &
80  operator=(const NodeOptions & other);
81 
83 
91  RCLCPP_PUBLIC
92  const rcl_node_options_t *
93  get_rcl_node_options() const;
94 
96  RCLCPP_PUBLIC
97  rclcpp::Context::SharedPtr
98  context() const;
99 
101  RCLCPP_PUBLIC
102  NodeOptions &
103  context(rclcpp::Context::SharedPtr context);
104 
106  RCLCPP_PUBLIC
107  const std::vector<std::string> &
108  arguments() const;
109 
111 
117  RCLCPP_PUBLIC
118  NodeOptions &
119  arguments(const std::vector<std::string> & arguments);
120 
122  RCLCPP_PUBLIC
123  std::vector<rclcpp::Parameter> &
125 
126  RCLCPP_PUBLIC
127  const std::vector<rclcpp::Parameter> &
128  parameter_overrides() const;
129 
131 
136  RCLCPP_PUBLIC
137  NodeOptions &
138  parameter_overrides(const std::vector<rclcpp::Parameter> & parameter_overrides);
139 
141  template<typename ParameterT>
142  NodeOptions &
143  append_parameter_override(const std::string & name, const ParameterT & value)
144  {
145  this->parameter_overrides().emplace_back(name, rclcpp::ParameterValue(value));
146  return *this;
147  }
148 
150  NodeOptions &
152  {
153  this->parameter_overrides().push_back(param);
154  return *this;
155  }
156 
158  RCLCPP_PUBLIC
159  bool
160  use_global_arguments() const;
161 
163 
170  RCLCPP_PUBLIC
171  NodeOptions &
173 
175  RCLCPP_PUBLIC
176  bool
177  enable_rosout() const;
178 
180 
186  RCLCPP_PUBLIC
187  NodeOptions &
189 
191  RCLCPP_PUBLIC
192  bool
193  use_intra_process_comms() const;
194 
196 
205  RCLCPP_PUBLIC
206  NodeOptions &
208 
210  RCLCPP_PUBLIC
211  bool
212  enable_topic_statistics() const;
213 
215 
222  RCLCPP_PUBLIC
223  NodeOptions &
225 
227  RCLCPP_PUBLIC
228  bool
229  start_parameter_services() const;
230 
232 
241  RCLCPP_PUBLIC
242  NodeOptions &
244 
246  RCLCPP_PUBLIC
247  bool
248  enable_logger_service() const;
249 
251 
259  RCLCPP_PUBLIC
260  NodeOptions &
261  enable_logger_service(bool enable_log_service);
262 
264  RCLCPP_PUBLIC
265  bool
267 
269 
275  RCLCPP_PUBLIC
276  NodeOptions &
278 
280  RCLCPP_PUBLIC
281  const rcl_clock_type_t &
282  clock_type() const;
283 
285 
288  RCLCPP_PUBLIC
289  NodeOptions &
291 
293  RCLCPP_PUBLIC
294  const rclcpp::QoS &
295  clock_qos() const;
296 
298 
301  RCLCPP_PUBLIC
302  NodeOptions &
304 
305 
307  RCLCPP_PUBLIC
308  bool
309  use_clock_thread() const;
310 
312 
315  RCLCPP_PUBLIC
316  NodeOptions &
318 
320  RCLCPP_PUBLIC
321  const rclcpp::QoS &
322  parameter_event_qos() const;
323 
325 
328  RCLCPP_PUBLIC
329  NodeOptions &
331 
333  RCLCPP_PUBLIC
334  const rclcpp::QoS &
335  rosout_qos() const;
336 
338 
341  RCLCPP_PUBLIC
342  NodeOptions &
344 
346  RCLCPP_PUBLIC
349 
351 
358  RCLCPP_PUBLIC
359  NodeOptions &
362 
364  RCLCPP_PUBLIC
365  bool
367 
369 
378  RCLCPP_PUBLIC
379  NodeOptions &
381 
383  RCLCPP_PUBLIC
384  bool
386 
388 
401  RCLCPP_PUBLIC
402  NodeOptions &
405 
407  RCLCPP_PUBLIC
408  const rcl_allocator_t &
409  allocator() const;
410 
412 
415  RCLCPP_PUBLIC
416  NodeOptions &
418 
419 private:
420  // This is mutable to allow for a const accessor which lazily creates the node options instance.
422  mutable std::unique_ptr<rcl_node_options_t, void (*)(rcl_node_options_t *)> node_options_;
423 
424  // IMPORTANT: if any of these default values are changed, please update the
425  // documentation in this class.
426 
427  rclcpp::Context::SharedPtr context_ {
428  rclcpp::contexts::get_global_default_context()};
429 
430  std::vector<std::string> arguments_ {};
431 
432  std::vector<rclcpp::Parameter> parameter_overrides_ {};
433 
434  bool use_global_arguments_ {true};
435 
436  bool enable_rosout_ {true};
437 
438  bool use_intra_process_comms_ {false};
439 
440  bool enable_topic_statistics_ {false};
441 
442  bool start_parameter_services_ {true};
443 
444  bool start_parameter_event_publisher_ {true};
445 
446  rcl_clock_type_t clock_type_ {RCL_ROS_TIME};
447 
448  rclcpp::QoS clock_qos_ = rclcpp::ClockQoS();
449 
450  bool use_clock_thread_ {true};
451 
452  bool enable_logger_service_ {false};
453 
454  rclcpp::QoS parameter_event_qos_ = rclcpp::ParameterEventsQoS(
455  rclcpp::QoSInitialization::from_rmw(rmw_qos_profile_parameter_events)
456  );
457 
458  rclcpp::QoS rosout_qos_ = rclcpp::RosoutQoS();
459 
460  rclcpp::PublisherOptionsBase parameter_event_publisher_options_ = rclcpp::PublisherOptionsBase();
461 
462  bool allow_undeclared_parameters_ {false};
463 
464  bool automatically_declare_parameters_from_overrides_ {false};
465 
467 };
468 
469 } // namespace rclcpp
470 
471 #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 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:63
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