ROS 2 rclcpp + rcl - rolling  rolling-a919a6e5
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 <string>
21 #include <vector>
22 
23 #include "rcl_interfaces/msg/list_parameters_result.hpp"
24 #include "rcl_interfaces/msg/parameter_descriptor.hpp"
25 #include "rcl_interfaces/msg/set_parameters_result.hpp"
26 
27 #include "rclcpp/macros.hpp"
28 #include "rclcpp/node_interfaces/detail/node_interfaces_helpers.hpp"
29 #include "rclcpp/parameter.hpp"
30 #include "rclcpp/visibility_control.hpp"
31 
32 namespace rclcpp
33 {
34 namespace node_interfaces
35 {
36 
38 {
39  RCLCPP_SMART_PTR_DEFINITIONS(PreSetParametersCallbackHandle)
40 
41  using PreSetParametersCallbackType =
42  std::function<void (std::vector<rclcpp::Parameter> &)>;
43 
44  PreSetParametersCallbackType callback;
45 };
46 
48 {
49  RCLCPP_SMART_PTR_DEFINITIONS(OnSetParametersCallbackHandle)
50 
51  using OnSetParametersCallbackType =
52  std::function<
53  rcl_interfaces::msg::SetParametersResult(
54  const std::vector<rclcpp::Parameter> &)>;
55 
56  OnSetParametersCallbackType callback;
57 };
58 
60 {
61  RCLCPP_SMART_PTR_DEFINITIONS(PostSetParametersCallbackHandle)
62 
63  using PostSetParametersCallbackType =
64  std::function<void (const std::vector<rclcpp::Parameter> &)>;
65 
66  PostSetParametersCallbackType callback;
67 };
68 
71 {
72 public:
73  RCLCPP_SMART_PTR_ALIASES_ONLY(NodeParametersInterface)
74 
75  RCLCPP_PUBLIC
76  virtual
77  ~NodeParametersInterface() = default;
78 
80 
83  RCLCPP_PUBLIC
84  virtual
87  const std::string & name,
88  const rclcpp::ParameterValue & default_value,
89  const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor =
90  rcl_interfaces::msg::ParameterDescriptor(),
91  bool ignore_override = false) = 0;
92 
94 
97  RCLCPP_PUBLIC
98  virtual
101  const std::string & name,
102  rclcpp::ParameterType type,
103  const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor =
104  rcl_interfaces::msg::ParameterDescriptor(),
105  bool ignore_override = false) = 0;
106 
108 
111  RCLCPP_PUBLIC
112  virtual
113  void
114  undeclare_parameter(const std::string & name) = 0;
115 
117 
120  RCLCPP_PUBLIC
121  virtual
122  bool
123  has_parameter(const std::string & name) const = 0;
124 
126 
129  RCLCPP_PUBLIC
130  virtual
131  std::vector<rcl_interfaces::msg::SetParametersResult>
132  set_parameters(const std::vector<rclcpp::Parameter> & parameters) = 0;
133 
135 
138  RCLCPP_PUBLIC
139  virtual
140  rcl_interfaces::msg::SetParametersResult
142  const std::vector<rclcpp::Parameter> & parameters) = 0;
143 
145  /*
146  * \param[in] names a list of parameter names to check.
147  * \return the list of parameters that were found.
148  * Any parameter not found is omitted from the returned list.
149  */
150  RCLCPP_PUBLIC
151  virtual
152  std::vector<rclcpp::Parameter>
153  get_parameters(const std::vector<std::string> & names) const = 0;
154 
156  /*
157  * \param[in] name the name of the parameter to look for.
158  * \return the parameter if it exists on the node.
159  * \throws std::out_of_range if the parameter does not exist on the node.
160  */
161  RCLCPP_PUBLIC
162  virtual
164  get_parameter(const std::string & name) const = 0;
165 
167  /*
168  * \param[in] name the name of the parameter to look for.
169  * \param[out] parameter the description if parameter exists on the node.
170  * \return true if the parameter exists on the node, or
171  * \return false if the parameter does not exist.
172  */
173  RCLCPP_PUBLIC
174  virtual
175  bool
177  const std::string & name,
178  rclcpp::Parameter & parameter) const = 0;
179 
181  /*
182  * \param[in] prefix the name of the prefix to look for.
183  * \param[out] parameters a map of parameters that matched the prefix.
184  * \return true if any parameters with the prefix exists on the node, or
185  * \return false otherwise.
186  */
187  RCLCPP_PUBLIC
188  virtual
189  bool
191  const std::string & prefix,
192  std::map<std::string, rclcpp::Parameter> & parameters) const = 0;
193 
194  RCLCPP_PUBLIC
195  virtual
196  std::vector<rcl_interfaces::msg::ParameterDescriptor>
197  describe_parameters(const std::vector<std::string> & names) const = 0;
198 
199  RCLCPP_PUBLIC
200  virtual
201  std::vector<uint8_t>
202  get_parameter_types(const std::vector<std::string> & names) const = 0;
203 
204  RCLCPP_PUBLIC
205  virtual
206  rcl_interfaces::msg::ListParametersResult
207  list_parameters(const std::vector<std::string> & prefixes, uint64_t depth) const = 0;
208 
209  using OnSetParametersCallbackType = OnSetParametersCallbackHandle::OnSetParametersCallbackType;
210  using PostSetParametersCallbackType =
211  PostSetParametersCallbackHandle::PostSetParametersCallbackType;
212  using PreSetParametersCallbackType = PreSetParametersCallbackHandle::PreSetParametersCallbackType;
213 
215 
218  RCLCPP_PUBLIC
219  virtual
220  PreSetParametersCallbackHandle::SharedPtr
221  add_pre_set_parameters_callback(PreSetParametersCallbackType callback) = 0;
222 
224 
227  RCLCPP_PUBLIC
228  virtual
229  OnSetParametersCallbackHandle::SharedPtr
230  add_on_set_parameters_callback(OnSetParametersCallbackType callback) = 0;
231 
233 
236  RCLCPP_PUBLIC
237  virtual
238  PostSetParametersCallbackHandle::SharedPtr
239  add_post_set_parameters_callback(PostSetParametersCallbackType callback) = 0;
240 
242 
245  RCLCPP_PUBLIC
246  virtual
247  void
249 
251 
254  RCLCPP_PUBLIC
255  virtual
256  void
258 
260 
263  RCLCPP_PUBLIC
264  virtual
265  void
267 
269  RCLCPP_PUBLIC
270  virtual
271  const std::map<std::string, rclcpp::ParameterValue> &
273 
275 
289  RCLCPP_PUBLIC
290  virtual
291  void
293 };
294 
295 } // namespace node_interfaces
296 } // namespace rclcpp
297 
298 RCLCPP_NODE_INTERFACE_HELPERS_SUPPORT(rclcpp::node_interfaces::NodeParametersInterface, parameters)
299 
300 #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(OnSetParametersCallbackType callback)=0
Add a callback to validate parameters before they are set.
virtual RCLCPP_PUBLIC PostSetParametersCallbackHandle::SharedPtr add_post_set_parameters_callback(PostSetParametersCallbackType callback)=0
Add a callback that gets triggered after parameters are set successfully.
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 PreSetParametersCallbackHandle::SharedPtr add_pre_set_parameters_callback(PreSetParametersCallbackType callback)=0
Add a callback that gets triggered before parameters are validated.
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 void remove_pre_set_parameters_callback(const PreSetParametersCallbackHandle *const handler)=0
Remove a callback registered with add_pre_set_parameters_callback.
virtual RCLCPP_PUBLIC void enable_parameter_modification()=0
Enable parameter modification recursively during parameter callbacks.
virtual RCLCPP_PUBLIC void remove_post_set_parameters_callback(const PostSetParametersCallbackHandle *const handler)=0
Remove a callback registered with add_post_set_parameters_callback.
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.