diff --git a/example/rpc_client.cpp b/example/rpc_client.cpp index fba4fde..2d80222 100644 --- a/example/rpc_client.cpp +++ b/example/rpc_client.cpp @@ -36,13 +36,17 @@ int main(int argc, char* argv[]) // Create a client context auto ctxt(client::Context::fromEnv()); - auto reply(ctxt.rpc(argv[1]) - .arg("lhs", argv[2]) - .arg("rhs", argv[3]) - .exec() - ->wait(5.0)); + try { + auto reply(ctxt.rpc(argv[1]) + .arg("lhs", argv[2]) + .arg("rhs", argv[3]) + .exec() + ->wait(5.0)); - std::cout<<"Reply\n"< #include +#include #include #include @@ -48,14 +49,21 @@ int main(int argc, char* argv[]) std::unique_ptr&& op, Value&& top) { - // Callback - - // assume arguments encoded NTURI - auto rhs = top["query.rhs"].as(); - auto lhs = top["query.lhs"].as(); + // Callback on PVXS worker thread auto reply(nt::NTScalar{TypeCode::Float64}.create()); - reply["value"] = lhs + rhs; + + try { + // assume arguments encoded NTURI + auto rhs = top["query.rhs"].as(); + auto lhs = top["query.lhs"].as(); + + reply["value"] = lhs + rhs; + + } catch(std::exception& e){ + reply["alarm.severity"] = INVALID_ALARM; + reply["alarm.message"] = e.what(); + } op->reply(reply); // Scale-able applications may reply outside of this callback,