1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* pvAccessCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
#include <pv/pvData.h>
#include <pv/rpcClient.h>
using namespace epics::pvData;
using namespace epics::pvAccess;
static StructureConstPtr requestStructure =
getFieldCreate()->createFieldBuilder()->
add("a", pvString)->
add("b", pvString)->
createStructure();
#define TIMEOUT 3.0
int main()
{
PVStructure::shared_pointer request = getPVDataCreate()->createPVStructure(requestStructure);
request->getSubField<PVString>("a")->put("3.14");
request->getSubField<PVString>("b")->put("2.71");
std::cout<<"simple sync way, allows multiple RPC calls on the client instance\n";
try
{
RPCClient::shared_pointer client = RPCClient::create("sum");
PVStructure::shared_pointer result = client->request(request, TIMEOUT);
std::cout << *result << std::endl;
} catch (std::exception &e)
{
std::cout << "Error: " << e.what() << std::endl;
return 1;
}
std::cout<<"async way, allows multiple RPC calls on the client instance\n";
try
{
RPCClient::shared_pointer client = RPCClient::create("sum");
client->issueRequest(request);
// go get some coffee
PVStructure::shared_pointer result = client->waitResponse(TIMEOUT);
std::cout << *result << std::endl;
} catch (std::exception &e)
{
std::cout << "Error:" << e.what() << std::endl;
return 1;
}
return 0;
}
|