update pvlist to use RPCClient

This commit is contained in:
Michael Davidsaver
2017-06-28 20:36:31 +02:00
parent 858235fd0a
commit a6efd7ce6a
3 changed files with 65 additions and 95 deletions

View File

@ -3,6 +3,7 @@
#include <iostream>
#include <map>
#include <iterator>
#include <vector>
#include <string>
#include <istream>
@ -39,6 +40,8 @@ using namespace std;
using namespace epics::pvData;
using namespace epics::pvAccess;
namespace {
/// Byte to hexchar mapping.
static const char lookup[] = {
'0', '1', '2', '3', '4', '5', '6', '7',
@ -461,6 +464,7 @@ void usage (void)
, DEFAULT_TIMEOUT);
}
}//namespace
/*+**************************************************************************
*
@ -656,32 +660,53 @@ int main (int argc, char *argv[])
}
}
// TODO for now we call eget utility
// TODO timeOut
string cmd = "eget -";
if (debug)
cmd += 'd';
if (quiet)
cmd += 'q';
if (printInfo)
cmd += 'N';
cmd += "s pva://" + serverAddress + "/server?op=";
if (printInfo)
cmd += "info";
else
cmd += "channels";
StructureConstPtr argstype(getFieldCreate()->createFieldBuilder()
->setId("epics:nt/NTURI:1.0")
->add("scheme", pvString)
->add("path", pvString)
->addNestedStructure("query")
->add("op", pvString)
->endNested()
->createStructure());
FILE* egetpipe = popen (cmd.c_str(), "w");
if (!egetpipe)
{
char errStr[64];
epicsSocketConvertErrnoToString(errStr, sizeof(errStr));
fprintf(stderr, "Failed to exec 'eget': %s\n", errStr);
allOK = false;
PVStructure::shared_pointer args(getPVDataCreate()->createPVStructure(argstype));
args->getSubFieldT<PVString>("scheme")->put("pva");
args->getSubFieldT<PVString>("path")->put("server");
args->getSubFieldT<PVString>("query.op")->put(printInfo ? "info" : "channels");
if(debug) {
std::cerr<<"Query to "<<serverAddress<<"\n"<<args<<"\n";
}
pclose(egetpipe);
PVStructure::shared_pointer ret;
try {
RPCClient rpc("server",
createRequest("field()"),
ChannelProvider::shared_pointer(),
serverAddress);
if(debug)
std::cerr<<"Execute\n";
ret = rpc.request(args, timeOut, true);
} catch(std::exception& e) {
std::cerr<<"Error: "<<e.what()<<"\n";
return 1;
}
if(!printInfo) {
PVStringArray::shared_pointer pvs(ret->getSubField<PVStringArray>("value"));
PVStringArray::const_svector val(pvs->view());
std::copy(val.begin(),
val.end(),
std::ostream_iterator<std::string>(std::cout, "\n"));
return allOK ? 0 : 1;
}
std::cout<<ret<<"\n";
}
}