#include #include #include #include #if !defined(_WIN32) #include #define USE_SIGNAL #endif #include //! [Headers] #include #include #include #include //! [Headers] namespace pvd = epics::pvData; namespace pva = epics::pvAccess; namespace { epicsEvent done; #ifdef USE_SIGNAL void alldone(int num) { (void)num; done.signal(); } #endif struct ChanReq : public pva::ChannelRequester { virtual ~ChanReq() {} virtual std::string getRequesterName() { return "ChanReq"; } virtual void channelCreated(const epics::pvData::Status& status, pva::Channel::shared_pointer const & channel) { // called once, recursively during ChannelProvider::createChannel() if(!status.isSuccess()) { std::cout<<"Oops Connect: "<getChannelName()<<"\n"; } } virtual void channelStateChange(pva::Channel::shared_pointer const & channel, pva::Channel::ConnectionState connectionState) { // Called for each connect/disconnect event, and on shutdown (destroy) switch(connectionState) { case pva::Channel::NEVER_CONNECTED: case pva::Channel::CONNECTED: case pva::Channel::DISCONNECTED: case pva::Channel::DESTROYED: std::cout<<"CHANNEL "<getChannelName()<<" "<getChannel()->getChannelName()<<"\n"; // can now execute the get operation channelGet->get(); } else { std::cout<<"Oops GetConnect: "<getChannel()->getChannelName()<<" "<getSubField("value")); if(!valfld) valfld = pvStructure; std::cout<getChannel()->getChannelName()<<" : "<<*valfld<<"\n"; } else { std::cout<<"Oops Get: "< pvs_t; pvs_t pvs; for(int i=1; i(argv[++i]); } else { std::cerr << "--timeout requires value\n"; return 1; } } else { std::cerr<<"Unknown argument: "<createProvider(providerName, conf)); if(!provider) throw std::logic_error("pva provider not registered"); // need to store references to keep get (and channel) from being closed typedef std::set gets_t; gets_t gets; // as we have no channel or operation specific data, // use the same requesters for all PVs pva::ChannelRequester::shared_pointer chanreq(new ChanReq); pva::ChannelGetRequester::shared_pointer getreq(new GetReq); for(pvs_t::const_iterator it=pvs.begin(); it!=pvs.end(); ++it) { const std::string& pv = *it; pva::Channel::shared_pointer chan(provider->createChannel(pv, chanreq)); // if !chan then channelCreated() called with error status if(!chan) continue; // no need to wait for connection pva::ChannelGet::shared_pointer op(chan->createChannelGet(getreq, pvReq)); // if !op then channelGetConnect() called with error status if(!op) continue; gets.insert(op); // drop our explicit Channel reference, ChannelGet holds an additional reference } if(waitTime<0.0) done.wait(); else done.wait(waitTime); } catch(std::exception& e){ std::cerr<<"Error: "<