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 {
epicsEvent done;
#ifdef USE_SIGNAL
void alldone(int num)
{
(void)num;
done.signal();
}
#endif
{
POINTER_DEFINITIONS(Getter);
:name(name)
,channel(provider.connect(name))
{
}
virtual ~Getter()
{
}
{
switch(event.event) {
std::cout<<"Error "<<name<<" : "<<event.message<<"\n";
break;
std::cout<<"Cancel "<<name<<"\n";
break;
pvd::PVField::const_shared_pointer valfld(event.value->getSubField("value"));
if(!valfld)
valfld = event.value;
std::cout<<name<<" : "<<*valfld<<"\n";
break;
}
}
{
if(evt.connected) {
} else {
std::cout<<"Disconnect "<<name<<"\n";
}
}
};
}
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++)
#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();
}
std::cerr<<"Error: "<<e.what()<<"\n";
return 1;
}
return 0;
}