39 [[deprecated(
"Use InterfaceDescription for initializing the Interface")]]
42 const std::string & prefix_name,
const std::string & interface_name,
43 double * value_ptr =
nullptr)
44 : prefix_name_(prefix_name),
45 interface_name_(interface_name),
46 handle_name_(prefix_name_ +
"/" + interface_name_),
52 : prefix_name_(interface_description.get_prefix_name()),
53 interface_name_(interface_description.get_interface_name()),
54 handle_name_(interface_description.get_name())
58 value_ = std::numeric_limits<double>::quiet_NaN();
59 value_ptr_ = std::get_if<double>(&value_);
62 [[deprecated(
"Use InterfaceDescription for initializing the Interface")]]
64 explicit Handle(
const std::string & interface_name)
65 : interface_name_(interface_name), handle_name_(
"/" + interface_name_), value_ptr_(
nullptr)
69 [[deprecated(
"Use InterfaceDescription for initializing the Interface")]]
71 explicit Handle(
const char * interface_name)
72 : interface_name_(interface_name), handle_name_(
"/" + interface_name_), value_ptr_(
nullptr)
98 inline operator bool()
const {
return value_ptr_ !=
nullptr; }
100 const std::string & get_name()
const {
return handle_name_; }
102 const std::string & get_interface_name()
const {
return interface_name_; }
105 "Replaced by get_name method, which is semantically more correct")]]
const std::string &
106 get_full_name()
const
111 const std::string & get_prefix_name()
const {
return prefix_name_; }
113 [[deprecated(
"Use bool get_value(double & value) instead to retrieve the value.")]]
114 double get_value()
const
116 std::shared_lock<std::shared_mutex> lock(handle_mutex_, std::try_to_lock);
117 if (!lock.owns_lock())
119 return std::numeric_limits<double>::quiet_NaN();
123 THROW_ON_NULLPTR(value_ptr_);
128 [[nodiscard]]
bool get_value(
double & value)
const
130 std::shared_lock<std::shared_mutex> lock(handle_mutex_, std::try_to_lock);
131 if (!lock.owns_lock())
137 THROW_ON_NULLPTR(value_ptr_);
143 [[nodiscard]]
bool set_value(
double value)
145 std::unique_lock<std::shared_mutex> lock(handle_mutex_, std::try_to_lock);
146 if (!lock.owns_lock())
152 THROW_ON_NULLPTR(this->value_ptr_);
153 *this->value_ptr_ = value;
159 void copy(
const Handle & other)
noexcept
161 std::unique_lock<std::shared_mutex> lock(other.handle_mutex_);
162 std::unique_lock<std::shared_mutex> lock_this(handle_mutex_);
163 prefix_name_ = other.prefix_name_;
164 interface_name_ = other.interface_name_;
165 handle_name_ = other.handle_name_;
166 value_ = other.value_;
167 if (std::holds_alternative<std::monostate>(value_))
169 value_ptr_ = other.value_ptr_;
173 value_ptr_ = std::get_if<double>(&value_);
177 void swap(Handle & first, Handle & second)
noexcept
179 std::unique_lock<std::shared_mutex> lock(first.handle_mutex_);
180 std::unique_lock<std::shared_mutex> lock_this(second.handle_mutex_);
181 std::swap(first.prefix_name_, second.prefix_name_);
182 std::swap(first.interface_name_, second.interface_name_);
183 std::swap(first.handle_name_, second.handle_name_);
184 std::swap(first.value_, second.value_);
185 std::swap(first.value_ptr_, second.value_ptr_);
189 std::string prefix_name_;
190 std::string interface_name_;
191 std::string handle_name_;
192 HANDLE_DATATYPE value_ = std::monostate{};
197 mutable std::shared_mutex handle_mutex_;