rclcpp  master
C++ ROS Client Library API
node_options.hpp
Go to the documentation of this file.
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"
25 #include "rclcpp/parameter.hpp"
27 #include "rclcpp/qos.hpp"
29 
30 namespace rclcpp
31 {
32 
35 {
36 public:
38 
59 
62  virtual
63  ~NodeOptions() = default;
64 
67  NodeOptions(const NodeOptions & other);
68 
71  NodeOptions &
72  operator=(const NodeOptions & other);
73 
75 
81  const rcl_node_options_t *
82  get_rcl_node_options() const;
83 
86  rclcpp::Context::SharedPtr
87  context() const;
88 
91  NodeOptions &
92  context(rclcpp::Context::SharedPtr context);
93 
97  arguments() const;
98 
100 
107  NodeOptions &
108  arguments(const std::vector<std::string> & arguments);
109 
114 
117  parameter_overrides() const;
118 
120 
126  NodeOptions &
127  parameter_overrides(const std::vector<rclcpp::Parameter> & parameter_overrides);
128 
130  template<typename ParameterT>
131  NodeOptions &
132  append_parameter_override(const std::string & name, const ParameterT & value)
133  {
135  return *this;
136  }
137 
140  bool
141  use_global_arguments() const;
142 
144 
152  NodeOptions &
153  use_global_arguments(bool use_global_arguments);
154 
157  bool
158  use_intra_process_comms() const;
159 
161 
171  NodeOptions &
172  use_intra_process_comms(bool use_intra_process_comms);
173 
176  bool
177  start_parameter_services() const;
178 
180 
190  NodeOptions &
191  start_parameter_services(bool start_parameter_services);
192 
195  bool
197 
199 
206  NodeOptions &
207  start_parameter_event_publisher(bool start_parameter_event_publisher);
208 
211  const rclcpp::QoS &
212  parameter_event_qos() const;
213 
215 
219  NodeOptions &
220  parameter_event_qos(const rclcpp::QoS & parameter_event_qos);
221 
226 
228 
236  NodeOptions &
238  const rclcpp::PublisherOptionsBase & parameter_event_publisher_options);
239 
242  bool
244 
246 
256  NodeOptions &
257  allow_undeclared_parameters(bool allow_undeclared_parameters);
258 
261  bool
263 
265 
276  NodeOptions &
278  bool automatically_declare_parameters_from_overrides);
279 
282  const rcl_allocator_t &
283  allocator() const;
284 
286 
290  NodeOptions &
291  allocator(rcl_allocator_t allocator);
292 
293 protected:
295  size_t
296  get_domain_id_from_env() const;
297 
298 private:
299  // This is mutable to allow for a const accessor which lazily creates the node options instance.
302 
303  // IMPORTANT: if any of these default values are changed, please update the
304  // documentation in this class.
305 
306  rclcpp::Context::SharedPtr context_ {
308 
309  std::vector<std::string> arguments_ {};
310 
311  std::vector<rclcpp::Parameter> parameter_overrides_ {};
312 
313  bool use_global_arguments_ {true};
314 
315  bool use_intra_process_comms_ {false};
316 
317  bool start_parameter_services_ {true};
318 
319  bool start_parameter_event_publisher_ {true};
320 
321  rclcpp::QoS parameter_event_qos_ = rclcpp::ParameterEventsQoS(
322  rclcpp::QoSInitialization::from_rmw(rmw_qos_profile_parameter_events)
323  );
324 
325  rclcpp::PublisherOptionsBase parameter_event_publisher_options_ = rclcpp::PublisherOptionsBase();
326 
327  bool allow_undeclared_parameters_ {false};
328 
329  bool automatically_declare_parameters_from_overrides_ {false};
330 
332 };
333 
334 } // namespace rclcpp
335 
336 #endif // RCLCPP__NODE_OPTIONS_HPP_
NodeOptions & operator=(const NodeOptions &other)
Assignment operator.
DefaultContext::SharedPtr get_global_default_context()
Non-templated part of PublisherOptionsWithAllocator<Allocator>.
Definition: publisher_options.hpp:33
const rclcpp::PublisherOptionsBase & parameter_event_publisher_options() const
Return a reference to the parameter_event_publisher_options.
Encapsulation of Quality of Service settings.
Definition: qos.hpp:55
bool use_global_arguments() const
Return the use_global_arguments flag.
Encapsulation of options for node initialization.
Definition: node_options.hpp:34
virtual ~NodeOptions()=default
Destructor.
This header provides the get_node_topics_interface() template function.
Definition: allocator_common.hpp:24
const std::vector< std::string > & arguments() const
Return a reference to the list of arguments for the node.
Definition: qos.hpp:184
const rcl_node_options_t * get_rcl_node_options() const
Return the rcl_node_options used by the node.
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...
NodeOptions(rcl_allocator_t allocator=rcl_get_default_allocator())
Create NodeOptions with default values, optionally specifying the allocator to use.
bool automatically_declare_parameters_from_overrides() const
Return the automatically_declare_parameters_from_overrides flag.
bool allow_undeclared_parameters() const
Return the allow_undeclared_parameters flag.
const rcl_allocator_t & allocator() const
Return the rcl_allocator_t to be used.
NodeOptions & append_parameter_override(const std::string &name, const ParameterT &value)
Append a single parameter override, parameter idiom style.
Definition: node_options.hpp:132
const rclcpp::QoS & parameter_event_qos() const
Return a reference to the parameter_event_qos QoS.
std::vector< rclcpp::Parameter > & parameter_overrides()
Return a reference to the list of parameter overrides.
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
Store the type and value of a parameter.
Definition: parameter_value.hpp:71
#define rcl_get_default_allocator
bool start_parameter_event_publisher() const
Return the start_parameter_event_publisher flag.
rclcpp::Context::SharedPtr context() const
Return the context to be used by the node.
bool use_intra_process_comms() const
Return the use_intra_process_comms flag.
bool start_parameter_services() const
Return the start_parameter_services flag.
size_t get_domain_id_from_env() const
Retrieve the ROS_DOMAIN_ID environment variable and populate options.
T emplace_back(T... args)