RPC cleanup: RPCService is a sub-set of RPCServiceAsync
This commit is contained in:
@@ -41,12 +41,76 @@ struct SumService : public pva::RPCService
|
||||
}
|
||||
};
|
||||
|
||||
void testSum(const pva::ChannelProvider::shared_pointer& cli_prov)
|
||||
{
|
||||
pva::RPCClient client("sum", pvd::createRequest("field()"), cli_prov);
|
||||
|
||||
pvd::ValueBuilder args("epics:nt/NTURI:1.0");
|
||||
args.add<pvd::pvString>("scheme", "pva")
|
||||
.add<pvd::pvString>("path", "sum");
|
||||
|
||||
pvd::PVStructurePtr reply;
|
||||
|
||||
testDiag("Request");
|
||||
reply = client.request(args.addNested("query")
|
||||
.add<pvd::pvDouble>("lhs", 5.0)
|
||||
.add<pvd::pvDouble>("rhs", 3.0)
|
||||
.endNested()
|
||||
.buildPVStructure());
|
||||
|
||||
pvd::int32 value = reply->getSubFieldT<pvd::PVScalar>("value")->getAs<pvd::int32>();
|
||||
testOk(value==8, "Reply value = %d", (unsigned)value);
|
||||
|
||||
testDiag("Wait for connect (already connected)");
|
||||
testOk1(client.waitConnect());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct FailService : public pva::RPCService
|
||||
{
|
||||
virtual epics::pvData::PVStructure::shared_pointer request(
|
||||
epics::pvData::PVStructure::shared_pointer const & args
|
||||
) OVERRIDE FINAL
|
||||
{
|
||||
testDiag("failing()");
|
||||
throw std::runtime_error("oops");
|
||||
}
|
||||
};
|
||||
|
||||
void testRPCFail(const pva::ChannelProvider::shared_pointer& cli_prov)
|
||||
{
|
||||
|
||||
testDiag("Fail");
|
||||
|
||||
pva::RPCClient client("fail", pvd::createRequest("field()"), cli_prov);
|
||||
|
||||
pvd::ValueBuilder args("epics:nt/NTURI:1.0");
|
||||
args.add<pvd::pvString>("scheme", "pva")
|
||||
.add<pvd::pvString>("path", "fail");
|
||||
|
||||
|
||||
testDiag("Request");
|
||||
try{
|
||||
(void)client.request(args.addNested("query")
|
||||
.add<pvd::pvDouble>("lhs", 5.0)
|
||||
.add<pvd::pvDouble>("rhs", 3.0)
|
||||
.endNested()
|
||||
.buildPVStructure());
|
||||
testFail("Missing expected exception");
|
||||
}catch(pva::RPCRequestException& e){
|
||||
testPass("caught expected rpc exception: %s", e.what());
|
||||
}catch(std::exception& e){
|
||||
testFail("caught un-expected exception: %s", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
MAIN(testRPC)
|
||||
{
|
||||
testPlan(2);
|
||||
testPlan(3);
|
||||
try {
|
||||
pva::Configuration::shared_pointer conf(pva::ConfigurationBuilder()
|
||||
//.push_env()
|
||||
@@ -65,8 +129,14 @@ MAIN(testRPC)
|
||||
serv.getServer()->getServerPort(),
|
||||
serv.getServer()->getBroadcastPort());
|
||||
|
||||
std::tr1::shared_ptr<pva::RPCService> service(new SumService);
|
||||
serv.registerService("sum", service);
|
||||
{
|
||||
std::tr1::shared_ptr<pva::RPCService> service(new SumService);
|
||||
serv.registerService("sum", service);
|
||||
}
|
||||
{
|
||||
std::tr1::shared_ptr<pva::RPCService> service(new FailService);
|
||||
serv.registerService("fail", service);
|
||||
}
|
||||
|
||||
testDiag("Client Setup");
|
||||
pva::ClientFactory::start();
|
||||
@@ -75,26 +145,9 @@ MAIN(testRPC)
|
||||
if(!cli_prov)
|
||||
testAbort("No pva provider");
|
||||
testDiag("Client Ready");
|
||||
pva::RPCClient client("sum", pvd::createRequest("field()"), cli_prov);
|
||||
|
||||
pvd::ValueBuilder args("epics:nt/NTURI:1.0");
|
||||
args.add<pvd::pvString>("scheme", "pva")
|
||||
.add<pvd::pvString>("path", "sum");
|
||||
|
||||
pvd::PVStructurePtr reply;
|
||||
|
||||
testDiag("Request");
|
||||
reply = client.request(args.addNested("query")
|
||||
.add<pvd::pvDouble>("lhs", 5.0)
|
||||
.add<pvd::pvDouble>("rhs", 3.0)
|
||||
.endNested()
|
||||
.buildPVStructure());
|
||||
|
||||
pvd::int32 value = reply->getSubFieldT<pvd::PVScalar>("value")->getAs<pvd::int32>();
|
||||
testOk(value==8, "Reply value = %d", (unsigned)value);
|
||||
|
||||
testDiag("Wait for connect (already connected)");
|
||||
testOk1(client.waitConnect());
|
||||
testSum(cli_prov);
|
||||
testRPCFail(cli_prov);
|
||||
|
||||
}catch(std::exception& e){
|
||||
PRINT_EXCEPTION(e);
|
||||
|
||||
Reference in New Issue
Block a user