entry removed and using parsing for rr

This commit is contained in:
maliakal_d 2021-09-15 12:11:53 +02:00
parent 7a9e6a13ec
commit 74fde0a77c
4 changed files with 29 additions and 20 deletions

View File

@ -67,7 +67,7 @@ int main(int argc, char *argv[]) {
sls::Detector det(parser.multi_id());
sls::CmdProxy proxy(&det);
proxy.Call(parser.command(), parser.arguments(), parser.detector_id(),
action);
action, std::cout, parser.receiver_id());
} catch (const sls::RuntimeError &e) {
exit(EXIT_FAILURE);
}

View File

@ -29,10 +29,11 @@ std::ostream &operator<<(std::ostream &os,
void CmdProxy::Call(const std::string &command,
const std::vector<std::string> &arguments, int detector_id,
int action, std::ostream &os) {
int action, std::ostream &os, int receiver_id) {
cmd = command;
args = arguments;
det_id = detector_id;
rx_id = receiver_id;
std::string temp;
while (temp != cmd) {
@ -1381,16 +1382,13 @@ IpAddr CmdProxy::getIpFromAuto() {
UdpDestination CmdProxy::getUdpEntry() {
UdpDestination udpDestination{};
bool hasEntry = false;
udpDestination.entry = rx_id;
for (auto it : args) {
size_t pos = it.find('=');
std::string key = it.substr(0, pos);
std::string value = it.substr(pos + 1);
if (key == "entry") {
udpDestination.entry = StringTo<int>(value);
hasEntry = true;
} else if (key == "ip") {
if (key == "ip") {
if (value == "auto") {
auto val = getIpFromAuto();
LOG(logINFO) << "Setting udp_dstip of detector " << det_id
@ -1418,9 +1416,6 @@ UdpDestination CmdProxy::getUdpEntry() {
udpDestination.port2 = StringTo<uint32_t>(value);
}
}
if (!hasEntry) {
throw sls::RuntimeError("Found no entry argument.");
}
return udpDestination;
}
@ -1437,16 +1432,29 @@ std::string CmdProxy::UDPDestinationList(int action) {
"set to ip of rx_hostname."
<< '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
if (!args.empty()) {
WrongNumberOfParameters(0);
}
auto t = det->getDestinationUDPList(StringTo<int>(args[0]),
std::vector<int>{det_id});
if (det_id == -1) {
throw sls::RuntimeError("udp_dstlist must be at module level.");
}
if (rx_id < 0 || rx_id >= MAX_UDP_DESTINATION) {
throw sls::RuntimeError(
"Invalid receiver index to get round robin entry.");
}
auto t = det->getDestinationUDPList(rx_id, std::vector<int>{det_id});
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.empty()) {
WrongNumberOfParameters(1);
}
if (det_id == -1) {
throw sls::RuntimeError("udp_dstlist must be at module level.");
}
if (rx_id < 0 || rx_id >= MAX_UDP_DESTINATION) {
throw sls::RuntimeError(
"Invalid receiver index to set round robin entry.");
}
auto t = getUdpEntry();
det->setDestinationUDPList(t, det_id);
os << ToString(args) << std::endl;

View File

@ -529,7 +529,8 @@ class CmdProxy {
void Call(const std::string &command,
const std::vector<std::string> &arguments, int detector_id = -1,
int action = -1, std::ostream &os = std::cout);
int action = -1, std::ostream &os = std::cout,
int receiver_id = -1);
bool ReplaceIfDepreciated(std::string &command);
size_t GetFunctionMapSize() const noexcept { return functions.size(); };
@ -541,6 +542,7 @@ class CmdProxy {
std::string cmd;
std::vector<std::string> args;
int det_id{-1};
int rx_id{-1};
template <typename V> std::string OutStringHex(const V &value) {
if (value.equal())

View File

@ -2215,13 +2215,12 @@ TEST_CASE("udp_dstlist", "[.cmd]") {
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU || det_type == defs::EIGER) {
REQUIRE_NOTHROW(proxy.Call("udp_dstlist", {"0"}, -1, GET));
REQUIRE_NOTHROW(proxy.Call("udp_dstlist", {}, 0, GET, std::cout, 0));
REQUIRE_THROWS(proxy.Call(
"udp_dstlist",
{"entry=0", "ip=0.0.0.0", "mac=00:00:00:00:00:00", "port=1233"}, -1,
PUT));
"udp_dstlist", {"ip=0.0.0.0", "mac=00:00:00:00:00:00", "port=1233"},
-1, PUT, std::cout, 0));
} else {
REQUIRE_THROWS(proxy.Call("udp_dstlist", {"0"}, -1, GET));
REQUIRE_THROWS(proxy.Call("udp_dstlist", {}, -1, GET, std::cout, 0));
}
}