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);
const std::string name;
:name(name)
,channel(provider.connect(name))
{
}
virtual ~Getter()
{
}
{
switch(event.event) {
break;
break;
pvd::PVField::const_shared_pointer valfld(event.value->getSubField("value"));
if(!valfld)
valfld = event.value;
break;
}
}
{
if(evt.connected) {
} else {
}
}
};
}
int main(int argc, char *argv[]) {
try {
epics::RefMonitor refmon;
double waitTime = -1.0;
std::string providerName("pva");
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());
pva::ca::CAClientFactory::start();
std::cout<<
"Use provider: "<<providerName<<
"\n";
gets_t gets;
for(pvs_t::const_iterator it=pvs.begin(); it!=pvs.end(); ++it) {
const std::string& pv = *it;
Getter::shared_pointer
get(
new Getter(provider, pv));
gets.insert(get);
}
if(waitTime<0.0)
done.wait();
else
done.wait(waitTime);
if(refmon.running()) {
refmon.stop();
gets.clear();
refmon.current();
}
return 1;
}
return 0;
}
constexpr const _Tp && get(const pair< _Tp, _Up > &&__p) noexcept
virtual const char * what() const noexcept
constexpr void push_back(const value_type &__x)
Represents a single channel.
void removeConnectListener(ConnectCallback *)
Remove from list of listeners.
void addConnectListener(ConnectCallback *)
Append to list of listeners.
Operation get(GetCallback *cb, epics::pvData::PVStructure::const_shared_pointer pvRequest=epics::pvData::PVStructure::const_shared_pointer())
Issue request to retrieve current PV value.
const char * name(ScalarType scalarType)
Connection state change CB.
callback for get() and rpc()
information on connect/disconnect
Information on get/rpc completion.
Handle for in-progress get/put/rpc operation.
void cancel()
Immediate cancellation.
@ Fail
request ends in failure. Check message
@ Cancel
request cancelled before completion