/** * Copyright - See the COPYRIGHT that is included with this distribution. * pvAccessCPP is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. */ #include #include #include #include #include #if !defined(_WIN32) #include #define USE_SIGNAL #endif #include #include #include #include //! [Headers] #include #include #include //! [Headers] #include namespace pvd = epics::pvData; namespace pva = epics::pvAccess; namespace { typedef epicsGuard Guard; typedef epicsGuardRelease UnGuard; epicsMutex mutex; epicsEvent done; size_t waitingFor; #ifdef USE_SIGNAL void alldone(int num) { (void)num; done.signal(); } #endif struct PutTracker : public pvac::ClientChannel::PutCallback { POINTER_DEFINITIONS(PutTracker); pvac::Operation op; const std::string value; PutTracker(pvac::ClientChannel& channel, const pvd::PVStructure::const_shared_pointer& pvReq, const std::string& value) :op(channel.put(this, pvReq)) // put() starts here ,value(value) {} virtual ~PutTracker() { op.cancel(); } virtual void putBuild(const epics::pvData::StructureConstPtr &build, pvac::ClientChannel::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("value")); // attempt convert string to actual field type valfld->putFrom(value); 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 "<] [-w ] [-r ] pvname=value ...\n"; } std::string strip(const std::string& inp) { size_t f=inp.find_first_not_of(" \t\n\r"), l=inp.find_last_not_of (" \t\n\r"); if(f==inp.npos || f>l) throw std::invalid_argument("Empty string"); return inp.substr(f, l-f+1); } } // namespace int main(int argc, char *argv[]) { try { double waitTime = 5.0; std::string providerName("pva"), request("field()"); int opt; while( (opt=getopt(argc, argv, "hP:w:r:"))!=-1) { switch(opt) { case 'P': providerName = optarg; break; case 'w': waitTime = pvd::castUnsafe(optarg); break; case 'r': request = optarg; break; default: std::cerr<<"Unknown argument "< > args_t; args_t args; for(int i=optind; i