15 #ifndef HARDWARE_INTERFACE__HANDLE_HPP_
16 #define HARDWARE_INTERFACE__HANDLE_HPP_
21 #include <shared_mutex>
26 #include "hardware_interface/hardware_info.hpp"
27 #include "hardware_interface/macros.hpp"
32 using HANDLE_DATATYPE = std::variant<double>;
38 [[deprecated(
"Use InterfaceDescription for initializing the Interface")]]
41 const std::string & prefix_name,
const std::string & interface_name,
42 double * value_ptr =
nullptr)
43 : prefix_name_(prefix_name),
44 interface_name_(interface_name),
45 handle_name_(prefix_name_ +
"/" + interface_name_),
51 : prefix_name_(interface_description.get_prefix_name()),
52 interface_name_(interface_description.get_interface_name()),
53 handle_name_(interface_description.get_name())
57 value_ = std::numeric_limits<double>::quiet_NaN();
58 value_ptr_ = std::get_if<double>(&value_);
61 [[deprecated(
"Use InterfaceDescription for initializing the Interface")]]
63 explicit Handle(
const std::string & interface_name)
64 : interface_name_(interface_name), handle_name_(
"/" + interface_name_), value_ptr_(
nullptr)
68 [[deprecated(
"Use InterfaceDescription for initializing the Interface")]]
70 explicit Handle(
const char * interface_name)
71 : interface_name_(interface_name), handle_name_(
"/" + interface_name_), value_ptr_(
nullptr)
77 std::unique_lock<std::shared_mutex> lock(other.handle_mutex_);
78 std::unique_lock<std::shared_mutex> lock_this(handle_mutex_);
79 prefix_name_ = other.prefix_name_;
80 interface_name_ = other.interface_name_;
81 handle_name_ = other.handle_name_;
82 value_ = other.value_;
83 value_ptr_ = other.value_ptr_;
88 std::unique_lock<std::shared_mutex> lock(other.handle_mutex_);
89 std::unique_lock<std::shared_mutex> lock_this(handle_mutex_);
90 prefix_name_ = std::move(other.prefix_name_);
91 interface_name_ = std::move(other.interface_name_);
92 handle_name_ = std::move(other.handle_name_);
93 value_ = std::move(other.value_);
94 value_ptr_ = std::move(other.value_ptr_);
101 std::unique_lock<std::shared_mutex> lock(other.handle_mutex_);
102 std::unique_lock<std::shared_mutex> lock_this(handle_mutex_);
103 prefix_name_ = other.prefix_name_;
104 interface_name_ = other.interface_name_;
105 handle_name_ = other.handle_name_;
106 value_ = other.value_;
107 value_ptr_ = other.value_ptr_;
116 std::unique_lock<std::shared_mutex> lock(other.handle_mutex_);
117 std::unique_lock<std::shared_mutex> lock_this(handle_mutex_);
118 prefix_name_ = std::move(other.prefix_name_);
119 interface_name_ = std::move(other.interface_name_);
120 handle_name_ = std::move(other.handle_name_);
121 value_ = std::move(other.value_);
122 value_ptr_ = std::move(other.value_ptr_);
127 virtual ~
Handle() =
default;
130 inline operator bool()
const {
return value_ptr_ !=
nullptr; }
132 const std::string & get_name()
const {
return handle_name_; }
134 const std::string & get_interface_name()
const {
return interface_name_; }
137 "Replaced by get_name method, which is semantically more correct")]]
const std::string &
138 get_full_name()
const
143 const std::string & get_prefix_name()
const {
return prefix_name_; }
145 [[deprecated(
"Use bool get_value(double & value) instead to retrieve the value.")]]
146 double get_value()
const
148 std::shared_lock<std::shared_mutex> lock(handle_mutex_, std::try_to_lock);
149 if (!lock.owns_lock())
151 return std::numeric_limits<double>::quiet_NaN();
155 THROW_ON_NULLPTR(value_ptr_);
160 [[nodiscard]]
bool get_value(
double & value)
const
162 std::shared_lock<std::shared_mutex> lock(handle_mutex_, std::try_to_lock);
163 if (!lock.owns_lock())
169 THROW_ON_NULLPTR(value_ptr_);
175 [[nodiscard]]
bool set_value(
double value)
177 std::unique_lock<std::shared_mutex> lock(handle_mutex_, std::try_to_lock);
178 if (!lock.owns_lock())
184 THROW_ON_NULLPTR(this->value_ptr_);
185 *this->value_ptr_ = value;
191 std::string prefix_name_;
192 std::string interface_name_;
193 std::string handle_name_;
194 HANDLE_DATATYPE value_;
199 mutable std::shared_mutex handle_mutex_;
206 :
Handle(interface_description)
214 using Handle::Handle;
216 using SharedPtr = std::shared_ptr<StateInterface>;
217 using ConstSharedPtr = std::shared_ptr<const StateInterface>;
224 :
Handle(interface_description)
237 using Handle::Handle;
239 using SharedPtr = std::shared_ptr<CommandInterface>;
Definition: handle.hpp:221
CommandInterface(const CommandInterface &other)=delete
CommandInterface copy constructor is actively deleted.
A handle used to get and set a value on a given interface.
Definition: handle.hpp:36
Definition: handle.hpp:203
Definition: actuator.hpp:34
Definition: hardware_info.hpp:138