Compare commits
2 Commits
51c6fb4bba
...
4e133de5b2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e133de5b2 | ||
|
|
3f34efd244 |
@ -344,7 +344,8 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (found) {
|
if (found) {
|
||||||
msg.ack(msg_t::DEVICE_KEY, attrs);
|
// msg.ack(msg_t::DEVICE_KEY, attrs);
|
||||||
|
msg.ack(constants::ADC_DEVICE_NETPROTO_KEY_DEVICE, attrs);
|
||||||
} else {
|
} else {
|
||||||
msg.err(std::make_error_code(AdcDeviceNetServerSessionError::ERROR_UNKNOWN_DEVICE_ID));
|
msg.err(std::make_error_code(AdcDeviceNetServerSessionError::ERROR_UNKNOWN_DEVICE_ID));
|
||||||
}
|
}
|
||||||
@ -356,14 +357,17 @@ public:
|
|||||||
for (auto& [ptr, dev_wr] : _serverPtr->_devices) {
|
for (auto& [ptr, dev_wr] : _serverPtr->_devices) {
|
||||||
names.emplace_back(dev_wr.ident());
|
names.emplace_back(dev_wr.ident());
|
||||||
}
|
}
|
||||||
msg.ack(msg_t::NAMES_KEY, names);
|
// msg.ack(msg_t::NAMES_KEY, names);
|
||||||
|
msg.ack(constants::ADC_DEVICE_NETPROTO_KEY_NAMES, names);
|
||||||
} else if (msg.isHELLO()) {
|
} else if (msg.isHELLO()) {
|
||||||
msg.ack(msg_t::HELLO_KEY, _serverPtr->_serverIdent);
|
// msg.ack(msg_t::HELLO_KEY, _serverPtr->_serverIdent);
|
||||||
|
msg.ack(constants::ADC_DEVICE_NETPROTO_KEY_HELLO, _serverPtr->_serverIdent);
|
||||||
} else if (msg.isGET()) { // get attribute value
|
} else if (msg.isGET()) { // get attribute value
|
||||||
attrs = msg.template attrs<attr_vec_t>(0, 1);
|
attrs = msg.template attrs<attr_vec_t>(0, 1);
|
||||||
if (attrs.size()) {
|
if (attrs.size()) {
|
||||||
auto val = _bindDevice->getAttr(get_elem(0));
|
auto val = _bindDevice->getAttr(get_elem(0));
|
||||||
msg.ack(msg_t::GET_KEY, get_elem(0), val);
|
// msg.ack(msg_t::GET_KEY, get_elem(0), val);
|
||||||
|
msg.ack(constants::ADC_DEVICE_NETPROTO_KEY_GET, get_elem(0), val);
|
||||||
} else { // no attr name!
|
} else { // no attr name!
|
||||||
msg.err(std::make_error_code(AdcDeviceNetServerSessionError::ERROR_NO_PROTO_ATTRNAME));
|
msg.err(std::make_error_code(AdcDeviceNetServerSessionError::ERROR_NO_PROTO_ATTRNAME));
|
||||||
}
|
}
|
||||||
@ -372,7 +376,8 @@ public:
|
|||||||
if (attrs.size() >= 2) {
|
if (attrs.size() >= 2) {
|
||||||
auto val = msg.template joinAttrs<serialized_t>(1);
|
auto val = msg.template joinAttrs<serialized_t>(1);
|
||||||
_bindDevice->setAttr(get_elem(0), val);
|
_bindDevice->setAttr(get_elem(0), val);
|
||||||
msg.ack(msg_t::SET_KEY, get_elem(0), val);
|
// msg.ack(msg_t::SET_KEY, get_elem(0), val);
|
||||||
|
msg.ack(constants::ADC_DEVICE_NETPROTO_KEY_SET, get_elem(0), val);
|
||||||
} else { // no attr name or its value!
|
} else { // no attr name or its value!
|
||||||
if (attrs.size() == 1) {
|
if (attrs.size() == 1) {
|
||||||
msg.err(std::make_error_code(AdcDeviceNetServerSessionError::ERROR_NO_PROTO_ATTRVALUE));
|
msg.err(std::make_error_code(AdcDeviceNetServerSessionError::ERROR_NO_PROTO_ATTRVALUE));
|
||||||
@ -385,7 +390,8 @@ public:
|
|||||||
if (attrs.size()) {
|
if (attrs.size()) {
|
||||||
auto cmd_name = get_elem(0);
|
auto cmd_name = get_elem(0);
|
||||||
_bindDevice->exec(cmd_name);
|
_bindDevice->exec(cmd_name);
|
||||||
msg.ack(msg_t::CMD_KEY, cmd_name);
|
// msg.ack(msg_t::CMD_KEY, cmd_name);
|
||||||
|
msg.ack(constants::ADC_DEVICE_NETPROTO_KEY_CMD, cmd_name);
|
||||||
} else { // no cmd name!
|
} else { // no cmd name!
|
||||||
msg.err(std::make_error_code(AdcDeviceNetServerSessionError::ERROR_NO_PROTO_CMDNAME));
|
msg.err(std::make_error_code(AdcDeviceNetServerSessionError::ERROR_NO_PROTO_CMDNAME));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -304,6 +304,36 @@ public:
|
|||||||
return proto() == protoMarkWSS;
|
return proto() == protoMarkWSS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add '\0' char (or replace special-meaning char/char-sequence) to construct UNIX abstract namespace
|
||||||
|
// endpoint path
|
||||||
|
template <typename T = std::nullptr_t>
|
||||||
|
AdcEndpoint& makeAbstract(const T& mark = nullptr)
|
||||||
|
requires(traits::adc_input_char_range<T> || std::same_as<std::remove_cv_t<T>, char> ||
|
||||||
|
std::is_null_pointer_v<std::remove_cv_t<T>>)
|
||||||
|
{
|
||||||
|
if (!(isLocalStream() || isLocalSeqpacket())) { // only local proto is valid!
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
if constexpr (std::is_null_pointer_v<T>) { // just insert '\0'
|
||||||
|
auto it = _endpoint.insert(std::string::const_iterator(_path.begin()), '\0');
|
||||||
|
_path = std::string_view(it, _endpoint.end());
|
||||||
|
} else if constexpr (std::same_as<std::remove_cv_t<T>, char>) { // replace a character (mark)
|
||||||
|
auto pos = std::distance(_endpoint.cbegin(), std::string::const_iterator(_path.begin()));
|
||||||
|
if (_endpoint[pos] == mark) {
|
||||||
|
_endpoint[pos] = '\0';
|
||||||
|
}
|
||||||
|
} else { // replace a character range (mark)
|
||||||
|
if (std::ranges::equal(_path | std::views::take(std::ranges::size(mark), mark))) {
|
||||||
|
auto pos = std::distance(_endpoint.cbegin(), std::string::const_iterator(_path.begin()));
|
||||||
|
_endpoint.replace(pos, std::ranges::size(mark), 1, '\0');
|
||||||
|
_path = std::string_view(_endpoint.begin() + pos, _endpoint.end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string _endpoint;
|
std::string _endpoint;
|
||||||
std::string_view _proto, _host, _path, _portView;
|
std::string_view _proto, _host, _path, _portView;
|
||||||
|
|||||||
@ -162,13 +162,14 @@ int main(int argc, char* argv[])
|
|||||||
for (auto& ep : epnt) {
|
for (auto& ep : epnt) {
|
||||||
adc::AdcEndpoint epn(ep);
|
adc::AdcEndpoint epn(ep);
|
||||||
if (epn.isValid()) {
|
if (epn.isValid()) {
|
||||||
if (epn.isLocalSeqpacket() || epn.isLocalStream()) {
|
epn.makeAbstract('@');
|
||||||
if (epn.path()[0] == '@') { // replace '@' to '\0' (use of UNIX abstract namespace)
|
// if (epn.isLocalSeqpacket() || epn.isLocalStream()) {
|
||||||
auto it = std::ranges::find(ep, '@');
|
// if (epn.path()[0] == '@') { // replace '@' to '\0' (use of UNIX abstract namespace)
|
||||||
*it = '\0';
|
// auto it = std::ranges::find(ep, '@');
|
||||||
epn = adc::AdcEndpoint(ep);
|
// *it = '\0';
|
||||||
}
|
// epn = adc::AdcEndpoint(ep);
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// std::cout << "try to start listenning at '" << ep << "' ...";
|
// std::cout << "try to start listenning at '" << ep << "' ...";
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user