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 <map>
19 #include <memory>
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/parameter.hpp"
29 #include "rclcpp/visibility_control.hpp"
30 
31 namespace rclcpp
32 {
33 namespace node_interfaces
34 {
35 
37 {
38  RCLCPP_SMART_PTR_DEFINITIONS(OnSetParametersCallbackHandle)
39 
40  using OnParametersSetCallbackType =
41  std::function<
42  rcl_interfaces::msg::SetParametersResult(
43  const std::vector<rclcpp::Parameter> &)>;
44 
45  OnParametersSetCallbackType callback;
46 };
47 
50 {
51 public:
52  RCLCPP_SMART_PTR_ALIASES_ONLY(NodeParametersInterface)
53 
54  RCLCPP_PUBLIC
55  virtual
56  ~NodeParametersInterface() = default;
57 
59 
62  RCLCPP_PUBLIC
63  virtual
66  const std::string & name,
67  const rclcpp::ParameterValue & default_value,
68  const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor =
69  rcl_interfaces::msg::ParameterDescriptor(),
70  bool ignore_override = false) = 0;
71 
73 
76  RCLCPP_PUBLIC
77  virtual
80  const std::string & name,
81  rclcpp::ParameterType type,
82  const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor =
83  rcl_interfaces::msg::ParameterDescriptor(),
84  bool ignore_override = false) = 0;
85 
87 
90  RCLCPP_PUBLIC
91  virtual
92  void
93  undeclare_parameter(const std::string & name) = 0;
94 
96 
99  RCLCPP_PUBLIC
100  virtual
101  bool
102  has_parameter(const std::string & name) const = 0;
103 
105 
108  RCLCPP_PUBLIC
109  virtual
110  std::vector<rcl_interfaces::msg::SetParametersResult>
111  set_parameters(const std::vector<rclcpp::Parameter> & parameters) = 0;
112 
114 
117  RCLCPP_PUBLIC
118  virtual
119  rcl_interfaces::msg::SetParametersResult
121  const std::vector<rclcpp::Parameter> & parameters) = 0;
122 
124  /*
125  * \param[in] names a list of parameter names to check.
126  * \return the list of parameters that were found.
127  * Any parameter not found is omitted from the returned list.
128  */
129  RCLCPP_PUBLIC
130  virtual
131  std::vector<rclcpp::Parameter>
132  get_parameters(const std::vector<std::string> & names) const = 0;
133 
135  /*
136  * \param[in] name the name of the parameter to look for.
137  * \return the parameter if it exists on the node.
138  * \throws std::out_of_range if the parameter does not exist on the node.
139  */
140  RCLCPP_PUBLIC
141  virtual
143  get_parameter(const std::string & name) const = 0;
144 
146  /*
147  * \param[in] name the name of the parameter to look for.
148  * \param[out] parameter the description if parameter exists on the node.
149  * \return true if the parameter exists on the node, or
150  * \return false if the parameter does not exist.
151  */
152  RCLCPP_PUBLIC
153  virtual
154  bool
156  const std::string & name,
157  rclcpp::Parameter & parameter) const = 0;
158 
160  /*
161  * \param[in] prefix the name of the prefix to look for.
162  * \param[out] parameters a map of parameters that matched the prefix.
163  * \return true if any parameters with the prefix exists on the node, or
164  * \return false otherwise.
165  */
166  RCLCPP_PUBLIC
167  virtual
168  bool
170  const std::string & prefix,
171  std::map<std::string, rclcpp::Parameter> & parameters) const = 0;
172 
173  RCLCPP_PUBLIC
174  virtual
175  std::vector<rcl_interfaces::msg::ParameterDescriptor>
176  describe_parameters(const std::vector<std::string> & names) const = 0;
177 
178  RCLCPP_PUBLIC
179  virtual
180  std::vector<uint8_t>
181  get_parameter_types(const std::vector<std::string> & names) const = 0;
182 
183  RCLCPP_PUBLIC
184  virtual
185  rcl_interfaces::msg::ListParametersResult
186  list_parameters(const std::vector<std::string> & prefixes, uint64_t depth) const = 0;
187 
188  using OnParametersSetCallbackType = OnSetParametersCallbackHandle::OnParametersSetCallbackType;
189 
191 
194  RCLCPP_PUBLIC
195  virtual
196  OnSetParametersCallbackHandle::SharedPtr
197  add_on_set_parameters_callback(OnParametersSetCallbackType callback) = 0;
198 
200 
203  RCLCPP_PUBLIC
204  virtual
205  void
207 
209  RCLCPP_PUBLIC
210  virtual
211  const std::map<std::string, rclcpp::ParameterValue> &
213 };
214 
215 } // namespace node_interfaces
216 } // namespace rclcpp
217 
218 #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.