RPCClient: reimplemented as in Java, backported 3.0.4

This commit is contained in:
Matej Sekoranja
2014-09-01 11:48:25 +02:00
parent c157a25490
commit c1115437e3
4 changed files with 343 additions and 233 deletions

View File

@@ -23,11 +23,23 @@ int main()
PVStructure::shared_pointer request = getPVDataCreate()->createPVStructure(requestStructure);
request->getSubField<PVString>("a")->put("3.14");
request->getSubField<PVString>("b")->put("2.71");
RPCClient::shared_pointer client = RPCClientFactory::create("sum");
// simplest way
try
{
PVStructure::shared_pointer result = RPCClient::sendRequest("sum", request, TIMEOUT);
std::cout << *result << std::endl;
} catch (RPCRequestException &e)
{
std::cout << e.what() << std::endl;
return 1;
}
// simple sync way, allows multiple RPC calls on the clinet instance
try
{
RPCClient::shared_pointer client = RPCClient::create("sum");
PVStructure::shared_pointer result = client->request(request, TIMEOUT);
std::cout << *result << std::endl;
} catch (RPCRequestException &e)
@@ -36,5 +48,24 @@ int main()
return 1;
}
// async way, allows multiple RPC calls on the clinet instance
try
{
RPCClient::shared_pointer client = RPCClient::create("sum");
client->issueConnect();
if (client->waitConnect(TIMEOUT))
{
client->issueRequest(request);
PVStructure::shared_pointer result = client->waitResponse(TIMEOUT);
std::cout << *result << std::endl;
}
else
throw std::runtime_error("connection timeout");
} catch (std::exception &e)
{
std::cout << e.what() << std::endl;
return 1;
}
return 0;
}
}