ROS 2 rclcpp + rcl - humble  humble
ROS 2 C++ Client Library with ROS Client Library
node_parameters_interface.hpp
1 // Copyright 2016 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_INTERFACES__NODE_PARAMETERS_INTERFACE_HPP_
16 #define RCLCPP__NODE_INTERFACES__NODE_PARAMETERS_INTERFACE_HPP_
17 
18 #include <functional>
19 #include <map>
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include "rcl_interfaces/msg/list_parameters_result.hpp"
25 #include "rcl_interfaces/msg/parameter_descriptor.hpp"
26 #include "rcl_interfaces/msg/set_parameters_result.hpp"
27 
28 #include "rclcpp/macros.hpp"
29 #include "rclcpp/node_interfaces/detail/node_interfaces_helpers.hpp"
30 #include "rclcpp/parameter.hpp"
31 #include "rclcpp/visibility_control.hpp"
32 
33 namespace rclcpp
34 {
35 namespace node_interfaces
36 {
37 
39 {
40  RCLCPP_SMART_PTR_DEFINITIONS(OnSetParametersCallbackHandle)
41 
42  using OnParametersSetCallbackType =
43  std::function<
44  rcl_interfaces::msg::SetParametersResult(
45  const std::vector<rclcpp::Parameter> &)>;
46 
47  OnParametersSetCallbackType callback;
48 };
49 
52 {
53 public:
54  RCLCPP_SMART_PTR_ALIASES_ONLY(NodeParametersInterface)
55 
56  RCLCPP_PUBLIC
57  virtual
58  ~NodeParametersInterface() = default;
59 
61 
64  RCLCPP_PUBLIC
65  virtual
68  const std::string & name,
69  const rclcpp::ParameterValue & default_value,
70  const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor =
71  rcl_interfaces::msg::ParameterDescriptor(),
72  bool ignore_override = false) = 0;
73 
75 
78  RCLCPP_PUBLIC
79  virtual
82  const std::string & name,
83  rclcpp::ParameterType type,
84  const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor =
85  rcl_interfaces::msg::ParameterDescriptor(),
86  bool ignore_override = false) = 0;
87 
89 
92  RCLCPP_PUBLIC
93  virtual
94  void
95  undeclare_parameter(const std::string & name) = 0;
96 
98 
101  RCLCPP_PUBLIC
102  virtual
103  bool
104  has_parameter(const std::string & name) const = 0;
105 
107 
110  RCLCPP_PUBLIC
111  virtual
112  std::vector<rcl_interfaces::msg::SetParametersResult>
113  set_parameters(const std::vector<rclcpp::Parameter> & parameters) = 0;
114 
116 
119  RCLCPP_PUBLIC
120  virtual
121  rcl_interfaces::msg::SetParametersResult
123  const std::vector<rclcpp::Parameter> & parameters) = 0;
124 
126  /*
127  * \param[in] names a list of parameter names to check.
128  * \return the list of parameters that were found.
129  * Any parameter not found is omitted from the returned list.
130  */
131  RCLCPP_PUBLIC
132  virtual
133  std::vector<rclcpp::Parameter>
134  get_parameters(const std::vector<std::string> & names) const = 0;
135 
137  /*
138  * \param[in] name the name of the parameter to look for.
139  * \return the parameter if it exists on the node.
140  * \throws std::out_of_range if the parameter does not exist on the node.
141  */
142  RCLCPP_PUBLIC
143  virtual
145  get_parameter(const std::string & name) const = 0;
146 
148  /*
149  * \param[in] name the name of the parameter to look for.
150  * \param[out] parameter the description if parameter exists on the node.
151  * \return true if the parameter exists on the node, or
152  * \return false if the parameter does not exist.
153  */
154  RCLCPP_PUBLIC
155  virtual
156  bool
158  const std::string & name,
159  rclcpp::Parameter & parameter) const = 0;
160 
162  /*
163  * \param[in] prefix the name of the prefix to look for.
164  * \param[out] parameters a map of parameters that matched the prefix.
165  * \return true if any parameters with the prefix exists on the node, or
166  * \return false otherwise.
167  */
168  RCLCPP_PUBLIC
169  virtual
170  bool
172  const std::string & prefix,
173  std::map<std::string, rclcpp::Parameter> & parameters) const = 0;
174 
175  RCLCPP_PUBLIC
176  virtual
177  std::vector<rcl_interfaces::msg::ParameterDescriptor>
178  describe_parameters(const std::vector<std::string> & names) const = 0;
179 
180  RCLCPP_PUBLIC
181  virtual
182  std::vector<uint8_t>
183  get_parameter_types(const std::vector<std::string> & names) const = 0;
184 
185  RCLCPP_PUBLIC
186  virtual
187  rcl_interfaces::msg::ListParametersResult
188  list_parameters(const std::vector<std::string> & prefixes, uint64_t depth) const = 0;
189 
190  using OnParametersSetCallbackType = OnSetParametersCallbackHandle::OnParametersSetCallbackType;
191 
193 
196  RCLCPP_PUBLIC
197  virtual
198  OnSetParametersCallbackHandle::SharedPtr
199  add_on_set_parameters_callback(OnParametersSetCallbackType callback) = 0;
200 
202 
205  RCLCPP_PUBLIC
206  virtual
207  void
209 
211  RCLCPP_PUBLIC
212  virtual
213  const std::map<std::string, rclcpp::ParameterValue> &
215 };
216 
217 } // namespace node_interfaces
218 } // namespace rclcpp
219 
220 RCLCPP_NODE_INTERFACE_HELPERS_SUPPORT(rclcpp::node_interfaces::NodeParametersInterface, parameters)
221 
222 #endif // RCLCPP__NODE_INTERFACES__NODE_PARAMETERS_INTERFACE_HPP_
Store the type and value of a parameter.
Structure to store an arbitrary parameter with templated get/set methods.
Definition: parameter.hpp:53
Pure virtual interface class for the NodeParameters part of the Node API.
virtual RCLCPP_PUBLIC const rclcpp::ParameterValue & declare_parameter(const std::string &name, rclcpp::ParameterType type, const rcl_interfaces::msg::ParameterDescriptor &parameter_descriptor=rcl_interfaces::msg::ParameterDescriptor(), bool ignore_override=false)=0
Declare a parameter.
virtual RCLCPP_PUBLIC OnSetParametersCallbackHandle::SharedPtr add_on_set_parameters_callback(OnParametersSetCallbackType callback)=0
Add a callback for when parameters are being set.
virtual RCLCPP_PUBLIC void remove_on_set_parameters_callback(const OnSetParametersCallbackHandle *const handler)=0
Remove a callback registered with add_on_set_parameters_callback.
virtual RCLCPP_PUBLIC void undeclare_parameter(const std::string &name)=0
Undeclare a parameter.
virtual RCLCPP_PUBLIC const rclcpp::ParameterValue & declare_parameter(const std::string &name, const rclcpp::ParameterValue &default_value, const rcl_interfaces::msg::ParameterDescriptor &parameter_descriptor=rcl_interfaces::msg::ParameterDescriptor(), bool ignore_override=false)=0
Declare and initialize a parameter.
virtual RCLCPP_PUBLIC std::vector< rclcpp::Parameter > get_parameters(const std::vector< std::string > &names) const =0
Get descriptions of parameters given their names.
virtual RCLCPP_PUBLIC bool get_parameter(const std::string &name, rclcpp::Parameter &parameter) const =0
Get the description of one parameter given a name.
virtual RCLCPP_PUBLIC rclcpp::Parameter get_parameter(const std::string &name) const =0
Get the description of one parameter given a name.
virtual RCLCPP_PUBLIC bool has_parameter(const std::string &name) const =0
Return true if the parameter has been declared, otherwise false.
virtual RCLCPP_PUBLIC rcl_interfaces::msg::SetParametersResult set_parameters_atomically(const std::vector< rclcpp::Parameter > &parameters)=0
Set one or more parameters, all at once.
virtual RCLCPP_PUBLIC bool get_parameters_by_prefix(const std::string &prefix, std::map< std::string, rclcpp::Parameter > &parameters) const =0
Get all parameters that have the specified prefix into the parameters map.
virtual RCLCPP_PUBLIC const std::map< std::string, rclcpp::ParameterValue > & get_parameter_overrides() const =0
Return the initial parameter values used by the NodeParameters to override default values.
virtual RCLCPP_PUBLIC std::vector< rcl_interfaces::msg::SetParametersResult > set_parameters(const std::vector< rclcpp::Parameter > &parameters)=0
Set one or more parameters, one at a time.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.