Compare commits

..

No commits in common. "4e133de5b296b5b0d174eaeae295a0703fc7d2b5" and "51c6fb4bbaab58bef64690b5e099aaf2323d35e1" have entirely different histories.

3 changed files with 13 additions and 50 deletions

View File

@ -344,8 +344,7 @@ 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));
} }
@ -357,17 +356,14 @@ 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));
} }
@ -376,8 +372,7 @@ 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));
@ -390,8 +385,7 @@ 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));
} }

View File

@ -304,36 +304,6 @@ 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;

View File

@ -162,14 +162,13 @@ 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()) {
epn.makeAbstract('@'); if (epn.isLocalSeqpacket() || epn.isLocalStream()) {
// if (epn.isLocalSeqpacket() || epn.isLocalStream()) { if (epn.path()[0] == '@') { // replace '@' to '\0' (use of UNIX abstract namespace)
// if (epn.path()[0] == '@') { // replace '@' to '\0' (use of UNIX abstract namespace) auto it = std::ranges::find(ep, '@');
// auto it = std::ranges::find(ep, '@'); *it = '\0';
// *it = '\0'; epn = adc::AdcEndpoint(ep);
// epn = adc::AdcEndpoint(ep); }
// } }
// }
// std::cout << "try to start listenning at '" << ep << "' ..."; // std::cout << "try to start listenning at '" << ep << "' ...";