...
This commit is contained in:
@@ -2,15 +2,58 @@
|
|||||||
|
|
||||||
#include <adclib/adclib_device1.h>
|
#include <adclib/adclib_device1.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace adc;
|
using namespace adc;
|
||||||
|
|
||||||
|
|
||||||
|
template <typename ID_T, typename VT>
|
||||||
|
void add_attr_mark(ID_T id, VT const& val, std::string_view acc = "RW")
|
||||||
|
{
|
||||||
|
auto tp = snplib::snplib_get_type_name<VT>();
|
||||||
|
|
||||||
|
std::println("add {}-attr with ID='{}' of type '{}'", acc, id, tp);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename DEV_T, typename VT>
|
||||||
|
void set_attr(DEV_T& dev, typename DEV_T::attr_id_t id, VT const& val)
|
||||||
|
{
|
||||||
|
auto tp = snplib::snplib_get_type_name<VT>();
|
||||||
|
|
||||||
|
std::print("set '{}'-attr value to {} of type '{}':\t", id, val, tp);
|
||||||
|
|
||||||
|
auto err = dev[id] = val;
|
||||||
|
if (err) {
|
||||||
|
std::println("ERROR = {}", err.message());
|
||||||
|
} else {
|
||||||
|
std::println("OK");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename DEV_T, typename VT>
|
||||||
|
void get_attr(DEV_T& dev, typename DEV_T::attr_id_t id, adc_result_t<VT>& val)
|
||||||
|
{
|
||||||
|
std::string tp;
|
||||||
|
|
||||||
|
[&tp]<typename T>(T v) { tp = snplib::snplib_get_type_name<T>(); }(val.value());
|
||||||
|
|
||||||
|
std::print("get '{}'-attr value as one of type '{}':\t", id, tp);
|
||||||
|
|
||||||
|
val = dev[id];
|
||||||
|
if (val) {
|
||||||
|
std::println("OK (value = {})", val.value());
|
||||||
|
} else {
|
||||||
|
std::println("ERROR = {}", val.error().message());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::string id1 = "1", id2 = "2", id3 = "str";
|
std::string id1 = "1", id2 = "2", id3 = "str", id4 = "fsp";
|
||||||
|
|
||||||
int i = 10;
|
int i = 10;
|
||||||
double d = 8.1;
|
double d = 8.1;
|
||||||
std::string s{"dwedjkwlk"};
|
std::string s{"dwedjkwlk"};
|
||||||
|
std::filesystem::path pt{"/etc/ewk/dwkej.wed"};
|
||||||
|
|
||||||
AdcGenericDevice<> dev("DEV#1");
|
AdcGenericDevice<> dev("DEV#1");
|
||||||
|
|
||||||
@@ -58,6 +101,15 @@ int main()
|
|||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// std::println("add RW-attr with id='{}' (val={})", id4, pt.native());
|
||||||
|
add_attr_mark(id4, pt);
|
||||||
|
dev.addFSPathAttr(
|
||||||
|
id4, [&pt]() -> adc_result_t<std::filesystem::path> { return pt; },
|
||||||
|
[&pt](std::filesystem::path const& p) -> adc_error_t {
|
||||||
|
pt = p;
|
||||||
|
return {};
|
||||||
|
});
|
||||||
|
|
||||||
std::print("get '{}'-attr value as native int:\t", id1);
|
std::print("get '{}'-attr value as native int:\t", id1);
|
||||||
adc_result_t<int> ri = dev[id1];
|
adc_result_t<int> ri = dev[id1];
|
||||||
if (ri) {
|
if (ri) {
|
||||||
@@ -133,5 +185,27 @@ int main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
s = "/kgtr/grth/hth34.rth";
|
||||||
|
std::vector<char> vch{std::from_range_t{}, s};
|
||||||
|
std::print("set '{}'-attr value to {} as std::vector<char>:\t", id4, vch);
|
||||||
|
err = dev[id4] = vch;
|
||||||
|
if (err) {
|
||||||
|
std::println("cannot set dev[{}] as std::vector<char>: {}", id4, err.message());
|
||||||
|
} else {
|
||||||
|
std::println("OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
set_attr(dev, id4, vch);
|
||||||
|
|
||||||
|
std::print("get '{}'-attr value as string:\t", id4);
|
||||||
|
rs = dev[id4];
|
||||||
|
if (rs) {
|
||||||
|
std::println("dev[{}] = {}", id3, rs.value());
|
||||||
|
} else {
|
||||||
|
std::println("cannot get dev[{}] as string: {}", id4, rs.error().message());
|
||||||
|
}
|
||||||
|
|
||||||
|
get_attr(dev, id4, rs);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -266,8 +266,10 @@ protected:
|
|||||||
return val;
|
return val;
|
||||||
} else if constexpr (std::constructible_from<UT, std::filesystem::path>) {
|
} else if constexpr (std::constructible_from<UT, std::filesystem::path>) {
|
||||||
return UT(val);
|
return UT(val);
|
||||||
} else if constexpr (std::is_pointer_v<std::decay_t<UT>> && std::same_as<std::filesystem::path::value_type*,
|
} else if constexpr (std::is_pointer_v<std::decay_t<UT>> &&
|
||||||
std::decay_t<UT>>) { // char*/wchar_t*
|
(std::same_as<std::filesystem::path::value_type*, UT> ||
|
||||||
|
std::same_as<const std::filesystem::path::value_type*,
|
||||||
|
UT>)) { // char*/wchar_t*
|
||||||
return val.c_str();
|
return val.c_str();
|
||||||
} else if constexpr (snplib::snplib_char_range_c<UT>) {
|
} else if constexpr (snplib::snplib_char_range_c<UT>) {
|
||||||
using iter_t = std::filesystem::path::value_type*;
|
using iter_t = std::filesystem::path::value_type*;
|
||||||
|
|||||||
Reference in New Issue
Block a user