From 522a0509458c720d73febf81d8ba32ec6fbdb896 Mon Sep 17 00:00:00 2001 From: mrkraimer Date: Sun, 7 Apr 2019 14:34:56 -0400 Subject: [PATCH] add double and string methods to pvaClientChannel --- src/pv/pvaClient.h | 70 +++++++++++++++++++++++++++++++++++++++- src/pvaClientChannel.cpp | 58 +++++++++++++++++++++++++++++++++ src/pvaClientData.cpp | 4 +-- src/pvaClientPutData.cpp | 6 ++-- 4 files changed, 132 insertions(+), 6 deletions(-) diff --git a/src/pv/pvaClient.h b/src/pv/pvaClient.h index ff439e0..0f8a7f2 100644 --- a/src/pv/pvaClient.h +++ b/src/pv/pvaClient.h @@ -313,11 +313,42 @@ public: PvaClientGetPtr createGet(std::string const & request = "field(value,alarm,timeStamp)"); /** @brief Creates an PvaClientGet. * - * @param pvRequest The syntax of pvRequest is defined by the copy facility of pvData. + * @param pvRequest The syntax of request is defined by the copy facility of pvData. + * @return The interface. * @return The interface. * @throw runtime_error if failure. */ PvaClientGetPtr createGet(epics::pvData::PVStructurePtr const & pvRequest); + /** @brief Get the value as a double. + * + * @param request The syntax of request is defined by the copy facility of pvData. + * @return The value. + * @throw runtime_error if failure. + */ + double getDouble(std::string const & request = "field(value)"); + /** Get the value as a string. + * + * @param request The syntax of request is defined by the copy facility of pvData. + * @return The value. + * @throw runtime_error if failure. + */ + std::string getString(std::string const & request = "field(value)"); + /** @brief Get the value as a double array. + * + * @param request The syntax of request is defined by the copy facility of pvData. + * @return The value. + * @throw runtime_error if failure. + */ + epics::pvData::shared_vector getDoubleArray( + std::string const & request = "field(value)"); + /** @brief Get the value as a string array. + * + * @param request The syntax of request is defined by the copy facility of pvData. + * @return The value. + * @throw runtime_error if failure. + */ + epics::pvData::shared_vector getStringArray( + std::string const & request = "field(value)"); /** @brief create a PvaClientPut. * * Get a cached PvaClientPut or create and connect to a new PvaClientPut. @@ -341,6 +372,43 @@ public: * @return The interface. */ PvaClientPutPtr createPut(epics::pvData::PVStructurePtr const & pvRequest); + /** @brief Put the value as a double. + * + * @param value The new value. + * @param request The syntax of request is defined by the copy facility of pvData. + * @throw runtime_error if failure. + */ + void putDouble(double value,std::string const & request = "field(value)"); + /** @brief Put the value as a string. + * + * @param value The new value. + * @param request The syntax of request is defined by the copy facility of pvData. + * @throw runtime_error if failure. + */ + void putString(std::string const & value,std::string const & request = "field(value)"); + /** @brief Copy the array to the value field. + * + * @param value The new value. + * @param request The syntax of request is defined by the copy facility of pvData. + * @throw runtime_error if failure. + */ + void putDoubleArray( + epics::pvData::shared_vector const & value, + std::string const & request = "field(value)"); + /** @brief Copy array to the value field. + * + * @param value The new value. + * @param request The syntax of request is defined by the copy facility of pvData. + * @throw runtime_error if failure. + */ + void putStringArray( + epics::pvData::shared_vector const & value, + std::string const & request = "field(value)"); + /** @brief Copy array to the value field. + * @param value data source + * @throw runtime_error if failure. + */ + void putStringArray(std::vector const & value,std::string const & request = "field(value)"); /** @brief create a PvaClientPutGet. * * First call createRequest as implemented by pvDataJava and then calls the next method. diff --git a/src/pvaClientChannel.cpp b/src/pvaClientChannel.cpp index e6c9f09..2ee538e 100644 --- a/src/pvaClientChannel.cpp +++ b/src/pvaClientChannel.cpp @@ -380,6 +380,26 @@ PvaClientGetPtr PvaClientChannel::createGet(PVStructurePtr const & pvRequest) return PvaClientGet::create(yyy,shared_from_this(),pvRequest); } +double PvaClientChannel::getDouble(string const & request) +{ + return get(request)->getData()->getDouble(); +} + +string PvaClientChannel::getString(string const & request) +{ + return get(request)->getData()->getString(); +} + +shared_vector PvaClientChannel::getDoubleArray(string const & request) +{ + return get(request)->getData()->getDoubleArray(); +} + +shared_vector PvaClientChannel::getStringArray(string const & request) +{ + return get(request)->getData()->getStringArray(); +} + PvaClientPutPtr PvaClientChannel::put(string const & request) { @@ -415,6 +435,44 @@ PvaClientPutPtr PvaClientChannel::createPut(PVStructurePtr const & pvRequest) return PvaClientPut::create(yyy,shared_from_this(),pvRequest); } +void PvaClientChannel::putDouble(double value,string const & request) +{ + PvaClientPutPtr clientPut = put(request); + PvaClientPutDataPtr putData = clientPut->getData(); + putData->putDouble(value); clientPut->put(); +} + +void PvaClientChannel::putString(std::string const & value,string const & request) +{ + PvaClientPutPtr clientPut = put(request); + PvaClientPutDataPtr putData = clientPut->getData(); + putData->putString(value); clientPut->put(); +} + +void PvaClientChannel::putDoubleArray( + shared_vector const & value, + string const & request) +{ + PvaClientPutPtr clientPut = put(request); + PvaClientPutDataPtr putData = clientPut->getData(); + size_t n = value.size(); + shared_vector valueArray(n); + for(size_t i=0; iputDoubleArray(freeze(valueArray)); clientPut->put(); +} + +void PvaClientChannel::putStringArray( + shared_vector const & value, + string const & request) +{ + PvaClientPutPtr clientPut = put(request); + PvaClientPutDataPtr putData = clientPut->getData(); + size_t n = value.size(); + shared_vector valueArray(n); + for(size_t i=0; iputStringArray(freeze(valueArray)); clientPut->put(); +} + PvaClientPutGetPtr PvaClientChannel::createPutGet(string const & request) { PVStructurePtr pvRequest = createRequest->createRequest(request); diff --git a/src/pvaClientData.cpp b/src/pvaClientData.cpp index 0f3d50c..7f14e5a 100644 --- a/src/pvaClientData.cpp +++ b/src/pvaClientData.cpp @@ -282,7 +282,7 @@ shared_vector PvaClientData::getDoubleArray() } if(!pvDoubleArray) { throw std::logic_error( - "PvaClientData::getDoubleArray() did not find a scalar field"); + "PvaClientData::getDoubleArray() did not find a scalarArray field"); } return pvDoubleArray->view(); } @@ -324,7 +324,7 @@ shared_vector PvaClientData::getStringArray() } if(!pvStringArray) { throw std::logic_error( - "PvaClientData::getStringArray() did not find a scalar field"); + "PvaClientData::getStringArray() did not find a scalarArray field"); } return pvStringArray->view(); } diff --git a/src/pvaClientPutData.cpp b/src/pvaClientPutData.cpp index 4a71cbb..8698622 100644 --- a/src/pvaClientPutData.cpp +++ b/src/pvaClientPutData.cpp @@ -186,7 +186,7 @@ void PvaClientPutData::putDoubleArray(shared_vector const & value) } if(!pvDoubleArray) { throw std::logic_error( - "PvaClientData::putDoubleArray() did not find a scalar field"); + "PvaClientData::putDoubleArray() did not find a scalarArray field"); } pvDoubleArray->replace(value); } @@ -228,7 +228,7 @@ void PvaClientPutData::putStringArray(shared_vector const & v } if(!pvStringArray) { throw std::logic_error( - "PvaClientData::getStringArray() did not find a scalar field"); + "PvaClientData::getStringArray() did not find a scalarArray field"); } pvStringArray->replace(value); } @@ -262,7 +262,7 @@ void PvaClientPutData::putStringArray(std::vector const & value) } if(!pvScalarArray) { throw std::logic_error( - "PvaClientData::getStringArray() did not find a scalar field"); + "PvaClientData::getStringArray() did not find a scalarArray field"); } convert->fromStringArray(pvScalarArray,0,value.size(),value,0); }