From 8f4fafd6680daf231e37efc570020029a0a0f436 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 10 Jul 2017 13:40:36 +0200 Subject: [PATCH] pvaTestClient: put example --- documentation/examples.h | 11 ++ documentation/mainpage.h | 1 + examples/Makefile | 1 + examples/putme.cpp | 223 +++++++++++++++++++++++++++++++ src/testing/pvaTestClientGet.cpp | 3 +- 5 files changed, 238 insertions(+), 1 deletion(-) create mode 100644 examples/putme.cpp diff --git a/documentation/examples.h b/documentation/examples.h index 57f47c2..a097b0d 100644 --- a/documentation/examples.h +++ b/documentation/examples.h @@ -10,6 +10,17 @@ and again each time a channel becomes Connected. */ /** +@page examples_putme Client Put Example + +This example demonstrates a client which issues a Put operation on startup, +waits for acknowledgement that the put has been handled, +then exits. + +@include putme.cpp + +*/ +/** + @page examples_monitorme Client Monitor Example This example demonstrates a client which sets up a persistent Monitor operation. diff --git a/documentation/mainpage.h b/documentation/mainpage.h index 66b15bc..03a8736 100644 --- a/documentation/mainpage.h +++ b/documentation/mainpage.h @@ -29,6 +29,7 @@ See the @ref providers page. @section main_examples Examples - @ref examples_getme +- @ref examples_putme - @ref examples_monitorme */ diff --git a/examples/Makefile b/examples/Makefile index ad93941..79c2c6e 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -5,6 +5,7 @@ include $(TOP)/configure/CONFIG PROD_LIBS += pvAccess pvData ca Com TESTPROD_HOST += getme +TESTPROD_HOST += putme TESTPROD_HOST += monitorme TESTPROD_HOST += spamme diff --git a/examples/putme.cpp b/examples/putme.cpp new file mode 100644 index 0000000..5ec23ee --- /dev/null +++ b/examples/putme.cpp @@ -0,0 +1,223 @@ +/** + * 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 +#include +//! [Headers] + +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 TestClientChannel::PutCallback +{ + POINTER_DEFINITIONS(PutTracker); + + TestOperation op; + const std::string value; + + PutTracker(TestClientChannel& 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 pvd::PVStructure::const_shared_pointer putBuild(const epics::pvData::StructureConstPtr &build) + { + pvd::PVStructurePtr root(pvd::getPVDataCreate()->createPVStructure(build)); + + pvd::PVScalarPtr valfld(root->getSubFieldT("value")); + + valfld->putFrom(value); + + 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