update RPCClient
Addition ctor to use specific Provider (w/ custom config). Start connect immediately. Remove need to issueConnect()/waitConnect().
This commit is contained in:
@@ -24,48 +24,43 @@ int main()
|
||||
request->getSubField<PVString>("a")->put("3.14");
|
||||
request->getSubField<PVString>("b")->put("2.71");
|
||||
|
||||
// simplest way
|
||||
std::cout<<"simplest way\n";
|
||||
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)
|
||||
{
|
||||
std::cout << e.what() << std::endl;
|
||||
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");
|
||||
std::cout << "Error: " << *result << std::endl;
|
||||
} catch (std::exception &e)
|
||||
{
|
||||
std::cout << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user