This example demonstrates a client which issues a Get operation on startup, and again each time a channel becomes Connected.
#if !defined(_WIN32)
#include <signal.h>
#define USE_SIGNAL
#endif
#include <epicsEvent.h>
#include <epicsMutex.h>
#include <epicsGuard.h>
#include <epicsGetopt.h>
#include <pv/configuration.h>
#include <pv/caProvider.h>
#include <pv/reftrack.h>
#include <pva/client.h>
namespace pvd = epics::pvData;
namespace pva = epics::pvAccess;
namespace {
epicsEvent done;
#ifdef USE_SIGNAL
void alldone(int num)
{
(void)num;
done.signal();
}
#endif
{
POINTER_DEFINITIONS(Getter);
:name(name)
,channel(provider.connect(name))
{
channel.addConnectListener(this);
}
virtual ~Getter()
{
channel.removeConnectListener(this);
op.cancel();
}
{
switch(event.event) {
std::cout<<
"Error "<<name<<
" : "<<
event.message<<
"\n";
break;
break;
pvd::PVField::const_shared_pointer valfld(event.value->getSubField("value"));
if(!valfld)
valfld = event.value;
break;
}
}
{
if(evt.connected) {
op = channel.get(this);
} else {
}
}
};
}
int main(int argc, char *argv[]) {
try {
epics::RefMonitor refmon;
double waitTime = -1.0;
pvs_t pvs;
int opt;
while((opt = getopt(argc, argv, "hRp:w:")) != -1) {
switch(opt) {
case 'R':
refmon.start(5.0);
break;
case 'p':
providerName = optarg;
break;
case 'w':
waitTime = pvd::castUnsafe<double, std::string>(optarg);
break;
case 'h':
std::cout<<
"Usage: "<<argv[0]<<
" [-p <provider>] [-w <timeout>] [-R] <pvname> ...\n";
return 0;
default:
std::cerr<<
"Unknown argument: "<<(int)opt<<
"\n";
return -1;
}
}
for(int i=optind; i<argc; i++)
pvs.push_back(argv[i]);
#ifdef USE_SIGNAL
signal(SIGINT, alldone);
signal(SIGTERM, alldone);
signal(SIGQUIT, alldone);
#endif
pvd::PVStructure::shared_pointer pvReq(pvd::createRequest("field()"));
pva::Configuration::shared_pointer conf(pva::ConfigurationBuilder()
.push_env()
.build());
std::cout<<
"Use provider: "<<providerName<<
"\n";
gets_t gets;
for(pvs_t::const_iterator it=pvs.begin(); it!=pvs.end(); ++it) {
Getter::shared_pointer get(new Getter(provider, pv));
}
if(waitTime<0.0)
done.wait();
else
done.wait(waitTime);
if(refmon.running()) {
refmon.stop();
gets.clear();
refmon.current();
}
return 1;
}
return 0;
}