diff --git a/documentation/example.rst b/documentation/example.rst index c1f5ab2..0278397 100644 --- a/documentation/example.rst +++ b/documentation/example.rst @@ -1,11 +1,21 @@ Examples ======== +Example are built, but not installed. +They can be found under example/O.\* + +Latest versions https://github.com/mdavidsaver/pvxs/blob/master/example/ + Mailbox Server -------------- -Latest version https://github.com/mdavidsaver/pvxs/blob/master/example/mailbox.cpp - .. literalinclude:: ../example/mailbox.cpp :language: c++ :name: mailbox.cpp + +Client Demo +----------- + +.. literalinclude:: ../example/client.cpp + :language: c++ + :name: client.cpp diff --git a/example/Makefile b/example/Makefile index 5e9ded6..7f9bbf0 100644 --- a/example/Makefile +++ b/example/Makefile @@ -16,6 +16,9 @@ spam_SRCS += spam.cpp TESTPROD += ticker ticker_SRCS += ticker.cpp +TESTPROD += client +client_SRCS += client.cpp + PROD_SYS_LIBS += event_core PROD_SYS_LIBS_DEFAULT += event_pthreads diff --git a/example/client.cpp b/example/client.cpp new file mode 100644 index 0000000..03af92b --- /dev/null +++ b/example/client.cpp @@ -0,0 +1,113 @@ +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvxs is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. + */ +/** Meant to be run against the mailbox example. + * eg. in one terminal run: + * + * ./mailbox some:pv:name + * + * And in another terminal run: + * + * ./client some:pv:name + */ + +#include + +#include +#include + +using namespace pvxs; + +int main(int argc, char* argv[]) +{ + if(argc<2) { + std::cerr<<"Usage: "<\n"; + return 1; + } + + // Read $PVXS_LOG from process environment and update + // logging configuration. eg. + // export PVXS_LOG=*=DEBUG + // makes a lot of noise. + logger_config_env(); + + // Create a client context + client::Context ctxt(client::Config::from_env() + .build()); + + // Fetch current value + int32_t current; + { + std::cout<<"Getting current value of '"<wait(5.0); + + std::cout<<"Result is:\n"<(); + } else { + // an example. won't happen with mailbox server + std::cerr<<"Server type doesn't have .value field!\n"; + return 1; + } + } + + { + // attempt to change. + // uses simple builder form to assign .value + + ctxt.put(argv[1]) + .fetchPresent(false) // not needed + .set("value", current+1) + .exec() + ->wait(5.0); + + std::cout<<"First increment successful"< Value { + // allocate an empty container + auto toput(current.cloneEmpty()); + + // fill in .value. + // Assignment implicitly marks .value as changed + toput["value"] = current["value"].as() + 1; + + // return the container to be sent + return toput; + }) + .exec(); + + op->wait(5.0); + + std::cout<<"Second increment successful"<wait(5.0); + + std::cout<<"Result is:\n"<