ROS 2 rclcpp + rcl - jazzy  jazzy
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  using OnParametersSetCallbackType [[deprecated("use OnSetParametersCallbackType instead")]] =
56  OnSetParametersCallbackType;
57 
58  OnSetParametersCallbackType callback;
59 };
60 
62 {
63  RCLCPP_SMART_PTR_DEFINITIONS(PostSetParametersCallbackHandle)
64 
65  using PostSetParametersCallbackType =
66  std::function<void (const std::vector<rclcpp::Parameter> &)>;
67 
68  PostSetParametersCallbackType callback;
69 };
70 
73 {
74 public:
75  RCLCPP_SMART_PTR_ALIASES_ONLY(NodeParametersInterface)
76 
77  RCLCPP_PUBLIC
78  virtual
79  ~NodeParametersInterface() = default;
80 
82 
85  RCLCPP_PUBLIC
86  virtual
89  const std::string & name,
90  const rclcpp::ParameterValue & default_value,
91  const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor =
92  rcl_interfaces::msg::ParameterDescriptor(),
93  bool ignore_override = false) = 0;
94 
96 
99  RCLCPP_PUBLIC
100  virtual
101  const rclcpp::ParameterValue &
103  const std::string & name,
104  rclcpp::ParameterType type,
105  const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor =
106  rcl_interfaces::msg::ParameterDescriptor(),
107  bool ignore_override = false) = 0;
108 
110 
113  RCLCPP_PUBLIC
114  virtual
115  void
116  undeclare_parameter(const std::string & name) = 0;
117 
119 
122  RCLCPP_PUBLIC
123  virtual
124  bool
125  has_parameter(const std::string & name) const = 0;
126 
128 
131  RCLCPP_PUBLIC
132  virtual
133  std::vector<rcl_interfaces::msg::SetParametersResult>
134  set_parameters(const std::vector<rclcpp::Parameter> & parameters) = 0;
135 
137 
140  RCLCPP_PUBLIC
141  virtual
142  rcl_interfaces::msg::SetParametersResult
144  const std::vector<rclcpp::Parameter> & parameters) = 0;
145 
147  /*
148  * \param[in] names a list of parameter names to check.
149  * \return the list of parameters that were found.
150  * Any parameter not found is omitted from the returned list.
151  */
152  RCLCPP_PUBLIC
153  virtual
154  std::vector<rclcpp::Parameter>
155  get_parameters(const std::vector<std::string> & names) const = 0;
156 
158  /*
159  * \param[in] name the name of the parameter to look for.
160  * \return the parameter if it exists on the node.
161  * \throws std::out_of_range if the parameter does not exist on the node.
162  */
163  RCLCPP_PUBLIC
164  virtual
166  get_parameter(const std::string & name) const = 0;
167 
169  /*
170  * \param[in] name the name of the parameter to look for.
171  * \param[out] parameter the description if parameter exists on the node.
172  * \return true if the parameter exists on the node, or
173  * \return false if the parameter does not exist.
174  */
175  RCLCPP_PUBLIC
176  virtual
177  bool
179  const std::string & name,
180  rclcpp::Parameter & parameter) const = 0;
181 
183  /*
184  * \param[in] prefix the name of the prefix to look for.
185  * \param[out] parameters a map of parameters that matched the prefix.
186  * \return true if any parameters with the prefix exists on the node, or
187  * \return false otherwise.
188  */
189  RCLCPP_PUBLIC
190  virtual
191  bool
193  const std::string & prefix,
194  std::map<std::string, rclcpp::Parameter> & parameters) const = 0;
195 
196  RCLCPP_PUBLIC
197  virtual
198  std::vector<rcl_interfaces::msg::ParameterDescriptor>
199  describe_parameters(const std::vector<std::string> & names) const = 0;
200 
201  RCLCPP_PUBLIC
202  virtual
203  std::vector<uint8_t>
204  get_parameter_types(const std::vector<std::string> & names) const = 0;
205 
206  RCLCPP_PUBLIC
207  virtual
208  rcl_interfaces::msg::ListParametersResult
209  list_parameters(const std::vector<std::string> & prefixes, uint64_t depth) const = 0;
210 
211  using OnSetParametersCallbackType = OnSetParametersCallbackHandle::OnSetParametersCallbackType;
212  using PostSetParametersCallbackType =
213  PostSetParametersCallbackHandle::PostSetParametersCallbackType;
214  using PreSetParametersCallbackType = PreSetParametersCallbackHandle::PreSetParametersCallbackType;
215 
217 
220  RCLCPP_PUBLIC
221  virtual
222  PreSetParametersCallbackHandle::SharedPtr
223  add_pre_set_parameters_callback(PreSetParametersCallbackType callback) = 0;
224 
226 
229  RCLCPP_PUBLIC
230  virtual
231  OnSetParametersCallbackHandle::SharedPtr
232  add_on_set_parameters_callback(OnSetParametersCallbackType callback) = 0;
233 
235 
238  RCLCPP_PUBLIC
239  virtual
240  PostSetParametersCallbackHandle::SharedPtr
241  add_post_set_parameters_callback(PostSetParametersCallbackType callback) = 0;
242 
244 
247  RCLCPP_PUBLIC
248  virtual
249  void
251 
253 
256  RCLCPP_PUBLIC
257  virtual
258  void
260 
262 
265  RCLCPP_PUBLIC
266  virtual
267  void
269 
271  RCLCPP_PUBLIC
272  virtual
273  const std::map<std::string, rclcpp::ParameterValue> &
275 };
276 
277 } // namespace node_interfaces
278 } // namespace rclcpp
279 
280 RCLCPP_NODE_INTERFACE_HELPERS_SUPPORT(rclcpp::node_interfaces::NodeParametersInterface, parameters)
281 
282 #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 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.