add pvxcall
This commit is contained in:
+8
-2
@@ -306,9 +306,15 @@ void Connection::handle_GPR(pva_app_msg_t cmd)
|
||||
|
||||
} else if(gpr->state==GPROp::Exec) {
|
||||
to_wire(R, uint8_t(0x00));
|
||||
if(cmd!=CMD_GET)
|
||||
if(cmd==CMD_PUT) {
|
||||
to_wire_valid(R, info->prototype);
|
||||
|
||||
} else if(cmd==CMD_RPC) {
|
||||
to_wire(R, Value::Helper::desc(gpr->rpcarg));
|
||||
if(gpr->rpcarg)
|
||||
to_wire_full(R, gpr->rpcarg);
|
||||
}
|
||||
|
||||
} else if(gpr->state==GPROp::Done) {
|
||||
// we're actually building CMD_DESTROY_REQUEST
|
||||
// nothing more needed
|
||||
@@ -384,7 +390,7 @@ std::shared_ptr<Operation> RPCBuilder::exec()
|
||||
ctx->tcp_loop.call([&ret, this]() {
|
||||
auto chan = Channel::build(ctx, _name);
|
||||
|
||||
auto op = std::make_shared<GPROp>(Operation::Put, chan);
|
||||
auto op = std::make_shared<GPROp>(Operation::RPC, chan);
|
||||
op->done = std::move(_result);
|
||||
op->rpcarg = std::move(_argument);
|
||||
op->pvRequest = _build();
|
||||
|
||||
@@ -22,6 +22,9 @@ pvxget_SRCS += get.cpp
|
||||
PROD += pvxput
|
||||
pvxput_SRCS += put.cpp
|
||||
|
||||
PROD += pvxcall
|
||||
pvxcall_SRCS += call.cpp
|
||||
|
||||
PROD_SYS_LIBS += event_core
|
||||
|
||||
PROD_SYS_LIBS_DEFAULT += event_pthreads
|
||||
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* pvxs is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <atomic>
|
||||
|
||||
#include <epicsStdlib.h>
|
||||
#include <epicsGetopt.h>
|
||||
#include <epicsThread.h>
|
||||
|
||||
#include <pvxs/client.h>
|
||||
#include <pvxs/nt.h>
|
||||
#include <pvxs/log.h>
|
||||
#include "utilpvt.h"
|
||||
|
||||
using namespace pvxs;
|
||||
|
||||
namespace {
|
||||
|
||||
void usage(const char* argv0)
|
||||
{
|
||||
std::cerr<<"Usage: "<<argv0<<" <opts> <pvname> <fld>=<value> ...\n"
|
||||
"\n"
|
||||
" -h Show this message.\n"
|
||||
" -v Make more noise.\n"
|
||||
" -d Shorthand for $PVXS_LOG=\"pvxs.*=DEBUG\". Make a lot of noise.\n"
|
||||
" -w <sec> Operation timeout in seconds. default 5 sec.\n"
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
logger_config_env(); // from $PVXS_LOG
|
||||
double timeout = 5.0;
|
||||
bool verbose = false;
|
||||
|
||||
{
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "hvdw:")) != -1) {
|
||||
switch(opt) {
|
||||
case 'h':
|
||||
usage(argv[0]);
|
||||
return 0;
|
||||
case 'v':
|
||||
verbose = true;
|
||||
break;
|
||||
case 'd':
|
||||
logger_level_set("pvxs.*", Level::Debug);
|
||||
break;
|
||||
case 'w':
|
||||
if(epicsParseDouble(optarg, &timeout, nullptr)) {
|
||||
std::cerr<<"Invalid timeout value: "<<optarg<<"\n";
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
std::cerr<<"\nUnknown argument: "<<char(opt)<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(optind==argc) {
|
||||
usage(argv[0]);
|
||||
std::cerr<<"\nExpected PV name\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string pvname(argv[optind++]);
|
||||
std::list<std::string> keys;
|
||||
std::map<std::string, std::string> values;
|
||||
|
||||
for(auto n : range(optind, argc)) {
|
||||
std::string fv(argv[n]);
|
||||
auto sep = fv.find_first_of('=');
|
||||
|
||||
if(sep==std::string::npos) {
|
||||
std::cerr<<"Error: expected <fld>=<value> not \""<<escape(fv)<<"\"\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto key(fv.substr(0, sep));
|
||||
|
||||
if(values.find(key)!=values.end()) {
|
||||
std::cerr<<"Error: duplicate argument name "<<key<<"\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
values[key] = fv.substr(sep+1);
|
||||
keys.push_back(key);
|
||||
}
|
||||
|
||||
auto uri = nt::NTURI({}).build();
|
||||
|
||||
for(auto& key : keys) {
|
||||
using namespace pvxs::members;
|
||||
|
||||
uri += {Struct("query", {String(key)})};
|
||||
}
|
||||
|
||||
auto arg = uri.create();
|
||||
arg["path"] = pvname;
|
||||
auto query = arg["query"];
|
||||
|
||||
for(auto& pair : values) {
|
||||
query[pair.first] = pair.second;
|
||||
}
|
||||
|
||||
auto ctxt = client::Config::from_env().build();
|
||||
|
||||
if(verbose)
|
||||
std::cout<<"Effective config\n"<<ctxt.config();
|
||||
|
||||
epicsEvent done;
|
||||
int ret=2;
|
||||
|
||||
auto op =ctxt.rpc(pvname, std::move(arg))
|
||||
.result([&ret, &done](client::Result&& result) {
|
||||
try {
|
||||
auto val = result();
|
||||
if(val)
|
||||
std::cout<<val;
|
||||
ret=0;
|
||||
}catch(std::exception& e){
|
||||
std::cerr<<"Error "<<typeid(e).name()<<" : "<<e.what()<<"\n";
|
||||
ret=1;
|
||||
}
|
||||
done.trigger();
|
||||
})
|
||||
.exec();
|
||||
|
||||
// expedite search after starting all requests
|
||||
ctxt.hurryUp();
|
||||
|
||||
SigInt sig([&done]() {
|
||||
done.signal();
|
||||
});
|
||||
|
||||
if(!done.wait(timeout)) {
|
||||
std::cerr<<"Timeout\n";
|
||||
return 1;
|
||||
} else {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user