fixup getme example

This commit is contained in:
Michael Davidsaver
2017-07-07 15:28:02 +02:00
parent 9244d78a5b
commit 525b950f62

View File

@ -42,7 +42,13 @@ void alldone(int num)
struct GetReq : public pva::ChannelGetRequester struct GetReq : public pva::ChannelGetRequester
{ {
POINTER_DEFINITIONS(GetReq);
const std::string name; const std::string name;
// we hold strong ref to ChannelGet
// which should only hold weak ref to us
operation_type::shared_pointer op;
GetReq(const std::string& name) :name(name) {} GetReq(const std::string& name) :name(name) {}
virtual ~GetReq() {} virtual ~GetReq() {}
@ -147,25 +153,24 @@ int main(int argc, char *argv[]) {
throw std::logic_error("pva provider not registered"); throw std::logic_error("pva provider not registered");
// need to store references to keep get (and channel) from being closed // need to store references to keep get (and channel) from being closed
typedef std::set<pva::ChannelGet::shared_pointer> gets_t; typedef std::set<GetReq::shared_pointer> gets_t;
gets_t gets; gets_t gets;
for(pvs_t::const_iterator it=pvs.begin(); it!=pvs.end(); ++it) { for(pvs_t::const_iterator it=pvs.begin(); it!=pvs.end(); ++it) {
const std::string& pv = *it; const std::string& pv = *it;
pva::ChannelGetRequester::shared_pointer getreq(new GetReq(pv)); GetReq::shared_pointer getreq(new GetReq(pv));
pva::Channel::shared_pointer chan(provider->createChannel(pv)); pva::Channel::shared_pointer chan(provider->createChannel(pv));
// if !chan then channelCreated() called with error status assert(chan);
if(!chan) continue;
// no need to wait for connection // no need to wait for connection
pva::ChannelGet::shared_pointer op(chan->createChannelGet(getreq, pvReq)); getreq->op = chan->createChannelGet(getreq, pvReq);
// if !op then channelGetConnect() called with error status // if !op then channelGetConnect() called with error status
if(!op) continue; if(!getreq->op) continue;
gets.insert(op); gets.insert(getreq);
// drop our explicit Channel reference, ChannelGet holds an additional reference // drop our explicit Channel reference, ChannelGet holds an additional reference
} }