add double and string methods to pvaClientChannel

This commit is contained in:
mrkraimer
2019-04-07 14:34:56 -04:00
parent 99a7e3b0b5
commit 522a050945
4 changed files with 132 additions and 6 deletions

View File

@@ -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<const double> 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<const std::string> 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 double> 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 std::string> 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<std::string> 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.

View File

@@ -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<const double> PvaClientChannel::getDoubleArray(string const & request)
{
return get(request)->getData()->getDoubleArray();
}
shared_vector<const std::string> 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 double> const & value,
string const & request)
{
PvaClientPutPtr clientPut = put(request);
PvaClientPutDataPtr putData = clientPut->getData();
size_t n = value.size();
shared_vector<double> valueArray(n);
for(size_t i=0; i<n; ++i) valueArray[i] = value[i];
putData->putDoubleArray(freeze(valueArray)); clientPut->put();
}
void PvaClientChannel::putStringArray(
shared_vector<const string> const & value,
string const & request)
{
PvaClientPutPtr clientPut = put(request);
PvaClientPutDataPtr putData = clientPut->getData();
size_t n = value.size();
shared_vector<string> valueArray(n);
for(size_t i=0; i<n; ++i) valueArray[i] = value[i];
putData->putStringArray(freeze(valueArray)); clientPut->put();
}
PvaClientPutGetPtr PvaClientChannel::createPutGet(string const & request)
{
PVStructurePtr pvRequest = createRequest->createRequest(request);

View File

@@ -282,7 +282,7 @@ shared_vector<const double> 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<const string> 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();
}

View File

@@ -186,7 +186,7 @@ void PvaClientPutData::putDoubleArray(shared_vector<const double> 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 std::string> 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<std::string> 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);
}