pvaTestClient: put bitset

This commit is contained in:
Michael Davidsaver
2017-07-10 14:39:23 +02:00
parent be5047ce04
commit 9a77eb328f
3 changed files with 32 additions and 10 deletions

View File

@ -66,19 +66,33 @@ struct PutTracker : public TestClientChannel::PutCallback
op.cancel();
}
virtual pvd::PVStructure::const_shared_pointer putBuild(const epics::pvData::StructureConstPtr &build)
virtual void putBuild(const epics::pvData::StructureConstPtr &build, TestClientChannel::PutCallback::Args& args) OVERRIDE FINAL
{
// At this point we have the user provided value string 'value'
// and the server provided structure (with types).
// note: an exception thrown here will result in putDone() w/ Fail
// allocate a new structure instance.
// we are one-shot so don't bother to re-use
pvd::PVStructurePtr root(pvd::getPVDataCreate()->createPVStructure(build));
// we only know about writes to scalar 'value' field
pvd::PVScalarPtr valfld(root->getSubFieldT<pvd::PVScalar>("value"));
// attempt convert string to actual field type
valfld->putFrom(value);
std::cout<<"Put value "<<valfld<<"\n";
return root;
args.root = root; // non-const -> const
// mark only 'value' field to be sent.
// other fields w/ default values won't be sent.
args.tosend.set(valfld->getFieldOffset());
std::cout<<"Put value "<<valfld<<" sending="<<args.tosend<<"\n";
}
virtual void putDone(const TestPutEvent &evt)
virtual void putDone(const TestPutEvent &evt) OVERRIDE FINAL
{
switch(evt.event) {
case TestPutEvent::Fail:

View File

@ -142,8 +142,13 @@ public:
//! callbacks for put()
struct epicsShareClass PutCallback {
virtual ~PutCallback() {}
struct Args {
Args(epics::pvData::BitSet& tosend) :tosend(tosend) {}
epics::pvData::PVStructure::const_shared_pointer root;
epics::pvData::BitSet& tosend;
};
//! Called to build the value to be sent once the type info is known
virtual epics::pvData::PVStructure::const_shared_pointer putBuild(const epics::pvData::StructureConstPtr& build) =0;
virtual void putBuild(const epics::pvData::StructureConstPtr& build, Args& args) =0;
virtual void putDone(const TestPutEvent& evt)=0;
};

View File

@ -97,10 +97,15 @@ struct GetPutter : public pva::ChannelPutRequester,
} else if(putcb){
TestClientChannel::PutCallback *cb(putcb);
pvd::PVStructure::const_shared_pointer val;
pvd::BitSet::shared_pointer tosend(new pvd::BitSet);
TestClientChannel::PutCallback::Args args(*tosend);
try {
UnGuard U(G);
val = cb->putBuild(structure);
cb->putBuild(structure, args);
if(!args.root)
throw std::logic_error("No put value provided");
else if(args.root->getStructure().get()!=structure.get())
throw std::logic_error("Provided put value with wrong type");
}catch(std::exception& e){
if(putcb) {
event.message = e.what();
@ -111,10 +116,8 @@ struct GetPutter : public pva::ChannelPutRequester,
}
// check putcb again after UnGuard
if(putcb) {
pvd::BitSet::shared_pointer all(new pvd::BitSet);
all->set(0);
channelPut->lastRequest();
channelPut->put(std::tr1::const_pointer_cast<pvd::PVStructure>(val), all);
channelPut->put(std::tr1::const_pointer_cast<pvd::PVStructure>(args.root), tosend);
started = true;
}
}