ROS 2 rclcpp + rcl - rolling  rolling-e7363f10
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 
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  start_parameter_services() const;
214 
216 
225  RCLCPP_PUBLIC
226  NodeOptions &
228 
230  RCLCPP_PUBLIC
231  bool
232  enable_logger_service() const;
233 
235 
243  RCLCPP_PUBLIC
244  NodeOptions &
245  enable_logger_service(bool enable_log_service);
246 
248  RCLCPP_PUBLIC
250  log_level() const;
251 
253 
259  RCLCPP_PUBLIC
260  NodeOptions &
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 start_parameter_services_ {true};
441 
442  bool start_parameter_event_publisher_ {true};
443 
444  rcl_clock_type_t clock_type_ {RCL_ROS_TIME};
445 
446  rclcpp::QoS clock_qos_ = rclcpp::ClockQoS();
447 
448  bool use_clock_thread_ {true};
449 
450  bool enable_logger_service_ {false};
451 
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
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.
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:41
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:69