diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2023-06-27 16:13:58 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2023-06-27 16:13:58 +0200 |
commit | 1d46beadab0396ff75bd1fbad32fb7924ed11aa7 (patch) | |
tree | ca35b6348b7ed7a3170dd7d2c1635b201102e4a5 /lib | |
parent | 71740c7ea14706986507159f8a0e101940f99d4d (diff) | |
download | dabmod-1d46beadab0396ff75bd1fbad32fb7924ed11aa7.tar.gz dabmod-1d46beadab0396ff75bd1fbad32fb7924ed11aa7.tar.bz2 dabmod-1d46beadab0396ff75bd1fbad32fb7924ed11aa7.zip |
RC: handle nonexistent module in showjson
Diffstat (limited to 'lib')
-rw-r--r-- | lib/RemoteControl.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/lib/RemoteControl.cpp b/lib/RemoteControl.cpp index 16359ad..dcae682 100644 --- a/lib/RemoteControl.cpp +++ b/lib/RemoteControl.cpp @@ -590,7 +590,7 @@ void RemoteControllerZmq::process() } } else if (msg.size() == 2 && command == "show") { - std::string module((char*) msg[1].data(), msg[1].size()); + const std::string module((char*) msg[1].data(), msg[1].size()); try { list< vector<string> > r = rcs.get_param_list_values(module); size_t r_size = r.size(); @@ -608,17 +608,22 @@ void RemoteControllerZmq::process() } } else if (msg.size() == 2 && command == "showjson") { - std::string module((char*) msg[1].data(), msg[1].size()); - std::string json = rcs.get_params_json(module); + const std::string module((char*) msg[1].data(), msg[1].size()); + try { + std::string json = rcs.get_params_json(module); - zmq::message_t zmsg(json.size()); - memcpy(zmsg.data(), json.data(), json.size()); + zmq::message_t zmsg(json.size()); + memcpy(zmsg.data(), json.data(), json.size()); - repSocket.send(zmsg, zmq::send_flags::none); + repSocket.send(zmsg, zmq::send_flags::none); + } + catch (const ParameterError &err) { + send_fail_reply(repSocket, err.what()); + } } else if (msg.size() == 3 && command == "get") { - std::string module((char*) msg[1].data(), msg[1].size()); - std::string parameter((char*) msg[2].data(), msg[2].size()); + const std::string module((char*) msg[1].data(), msg[1].size()); + const std::string parameter((char*) msg[2].data(), msg[2].size()); try { std::string value = rcs.get_param(module, parameter); @@ -631,9 +636,9 @@ void RemoteControllerZmq::process() } } else if (msg.size() == 4 && command == "set") { - std::string module((char*) msg[1].data(), msg[1].size()); - std::string parameter((char*) msg[2].data(), msg[2].size()); - std::string value((char*) msg[3].data(), msg[3].size()); + const std::string module((char*) msg[1].data(), msg[1].size()); + const std::string parameter((char*) msg[2].data(), msg[2].size()); + const std::string value((char*) msg[3].data(), msg[3].size()); try { rcs.set_param(module, parameter, value); |