From 4618a9dda26fd77254d7dfccf194b337c591b2c6 Mon Sep 17 00:00:00 2001 From: Matej Sekoranja Date: Fri, 31 May 2013 13:26:24 +0200 Subject: [PATCH] ca: templatization of dbr to pvStructure --- pvAccessApp/ca/caChannel.cpp | 171 ++++++++++++++++++++++++----------- 1 file changed, 117 insertions(+), 54 deletions(-) diff --git a/pvAccessApp/ca/caChannel.cpp b/pvAccessApp/ca/caChannel.cpp index 2c66cae..65408f7 100644 --- a/pvAccessApp/ca/caChannel.cpp +++ b/pvAccessApp/ca/caChannel.cpp @@ -473,18 +473,69 @@ static void ca_get_handler(struct event_handler_args args) typedef void (*copyDBRtoPVStructure)(const void * from, unsigned count, PVStructure::shared_pointer const & tp); -void copy_DBR_DOUBLE(const void * dbr, unsigned count, PVStructure::shared_pointer const & pvStructure) + +// template +template +void copy_DBR(const void * dbr, unsigned count, PVStructure::shared_pointer const & pvStructure) { if (count == 1) { - PVDouble::shared_pointer value = pvStructure->getDoubleField("value"); - value->put(static_cast(dbr)[0]); + std::tr1::shared_ptr value = std::tr1::static_pointer_cast(pvStructure->getSubField("value")); + value->put(static_cast(dbr)[0]); } else { - PVDoubleArray::shared_pointer value = - std::tr1::dynamic_pointer_cast(pvStructure->getScalarArrayField("value", pvDouble)); - value->put(0, count, static_cast(dbr), 0); + std::tr1::shared_ptr value = + std::tr1::static_pointer_cast(pvStructure->getScalarArrayField("value", sT)); + value->put(0, count, static_cast(dbr), 0); + } +} + +// string specialization +template<> +void copy_DBR(const void * dbr, unsigned count, PVStructure::shared_pointer const & pvStructure) +{ + if (count == 1) + { + std::tr1::shared_ptr value = std::tr1::static_pointer_cast(pvStructure->getSubField("value")); + value->put(String(static_cast(dbr))); + } + else + { + std::tr1::shared_ptr value = + std::tr1::static_pointer_cast(pvStructure->getScalarArrayField("value", pvString)); + const dbr_string_t* dbrStrings = static_cast(dbr); + StringArray sA; + sA.reserve(count); + for (unsigned i = 0; i < count; i++) + sA.push_back(dbrStrings[i]); + value->put(0, count, sA, 0); + } +} + +// enum specialization +template<> +void copy_DBR(const void * dbr, unsigned count, PVStructure::shared_pointer const & pvStructure) +{ + // TODO + if (count == 1) + { + std::tr1::shared_ptr value = std::tr1::static_pointer_cast(pvStructure->getSubField("value.index")); + value->put(static_cast(dbr)[0]); + } + else + { + // TODO + /* + std::tr1::shared_ptr value = + std::tr1::static_pointer_cast(pvStructure->getScalarArrayField("value", pvString)); + const dbr_string_t* dbrStrings = static_cast(dbr); + StringArray sA; + sA.reserve(count); + for (unsigned i = 0; i < count; i++) + sA.push_back(dbrStrings[i]); + value->put(0, count, sA, 0); + */ } } @@ -513,9 +564,11 @@ static String dbrStatus2alarmMessage[] = { "WRITE_ACCESS_ALARM" // .. 21 }; -void copy_DBR_STS_DOUBLE(const void * dbr, unsigned count, PVStructure::shared_pointer const & pvStructure) +// template +template +void copy_DBR_STS(const void * dbr, unsigned count, PVStructure::shared_pointer const & pvStructure) { - const dbr_sts_double* data = static_cast(dbr); + const T* data = static_cast(dbr); PVStructure::shared_pointer alarm = pvStructure->getStructureField("alarm"); // TODO any mapping @@ -523,12 +576,14 @@ void copy_DBR_STS_DOUBLE(const void * dbr, unsigned count, PVStructure::shared_p alarm->getIntField("severity")->put(data->severity); alarm->getStringField("message")->put(dbrStatus2alarmMessage[data->status]); - copy_DBR_DOUBLE(&data->value, count, pvStructure); + copy_DBR(&data->value, count, pvStructure); } -void copy_DBR_TIME_DOUBLE(const void * dbr, unsigned count, PVStructure::shared_pointer const & pvStructure) +// template +template +void copy_DBR_TIME(const void * dbr, unsigned count, PVStructure::shared_pointer const & pvStructure) { - const dbr_time_double* data = static_cast(dbr); + const T* data = static_cast(dbr); PVStructure::shared_pointer ts = pvStructure->getStructureField("timeStamp"); epics::pvData::int64 spe = data->stamp.secPastEpoch; @@ -536,12 +591,14 @@ void copy_DBR_TIME_DOUBLE(const void * dbr, unsigned count, PVStructure::shared_ ts->getLongField("secondsPastEpoch")->put(spe); ts->getIntField("nanoSeconds")->put(data->stamp.nsec); - copy_DBR_DOUBLE(&data->value, count, pvStructure); + copy_DBR(&data->value, count, pvStructure); } -void copy_DBR_GR_DOUBLE(const void * dbr, unsigned count, PVStructure::shared_pointer const & pvStructure) +// template +template +void copy_DBR_GR(const void * dbr, unsigned count, PVStructure::shared_pointer const & pvStructure) { - const dbr_gr_double* data = static_cast(dbr); + const T* data = static_cast(dbr); PVStructure::shared_pointer alarm = pvStructure->getStructureField("alarm"); alarm->getIntField("status")->put(0); @@ -552,6 +609,7 @@ void copy_DBR_GR_DOUBLE(const void * dbr, unsigned count, PVStructure::shared_po disp->getStringField("units")->put(String(data->units)); disp->getDoubleField("limitHigh")->put(data->upper_disp_limit); disp->getDoubleField("limitLow")->put(data->lower_disp_limit); + /* TODO if (data->precision) { char fmt[16]; @@ -562,6 +620,7 @@ void copy_DBR_GR_DOUBLE(const void * dbr, unsigned count, PVStructure::shared_po { disp->getStringField("format")->put("%f"); } + */ PVStructure::shared_pointer va = pvStructure->getStructureField("valueAlarm"); va->getDoubleField("highAlarmLimit")->put(data->upper_alarm_limit); @@ -569,12 +628,14 @@ void copy_DBR_GR_DOUBLE(const void * dbr, unsigned count, PVStructure::shared_po va->getDoubleField("lowWarningLimit")->put(data->lower_warning_limit); va->getDoubleField("lowAlarmLimit")->put(data->lower_alarm_limit); - copy_DBR_DOUBLE(&data->value, count, pvStructure); + copy_DBR(&data->value, count, pvStructure); } -void copy_DBR_CTRL_DOUBLE(const void * dbr, unsigned count, PVStructure::shared_pointer const & pvStructure) +// template +template +void copy_DBR_CTRL(const void * dbr, unsigned count, PVStructure::shared_pointer const & pvStructure) { - const dbr_ctrl_double* data = static_cast(dbr); + const T* data = static_cast(dbr); PVStructure::shared_pointer alarm = pvStructure->getStructureField("alarm"); alarm->getIntField("status")->put(0); @@ -585,6 +646,8 @@ void copy_DBR_CTRL_DOUBLE(const void * dbr, unsigned count, PVStructure::shared_ disp->getStringField("units")->put(String(data->units)); disp->getDoubleField("limitHigh")->put(data->upper_disp_limit); disp->getDoubleField("limitLow")->put(data->lower_disp_limit); + // TODO + /* if (data->precision) { char fmt[16]; @@ -595,6 +658,7 @@ void copy_DBR_CTRL_DOUBLE(const void * dbr, unsigned count, PVStructure::shared_ { disp->getStringField("format")->put("%f"); } + */ PVStructure::shared_pointer va = pvStructure->getStructureField("valueAlarm"); va->getDoubleField("highAlarmLimit")->put(data->upper_alarm_limit); @@ -606,50 +670,49 @@ void copy_DBR_CTRL_DOUBLE(const void * dbr, unsigned count, PVStructure::shared_ ctrl->getDoubleField("limitHigh")->put(data->upper_ctrl_limit); ctrl->getDoubleField("limitLow")->put(data->lower_ctrl_limit); - copy_DBR_DOUBLE(&data->value, count, pvStructure); + copy_DBR(&data->value, count, pvStructure); } - static copyDBRtoPVStructure copyFuncTable[] = { - 0, // DBR_STRING - 0, // DBR_INT, DBR_SHORT - 0, // DBR_FLOAT - 0, // DBR_ENUM - 0, // DBR_CHAR - 0, // DBR_LONG - copy_DBR_DOUBLE, // DBR_DOUBLE + copy_DBR, // DBR_STRING + copy_DBR, // DBR_INT, DBR_SHORT + copy_DBR, // DBR_FLOAT + copy_DBR, // DBR_ENUM + copy_DBR, // DBR_CHAR + copy_DBR, // DBR_LONG + copy_DBR, // DBR_DOUBLE - 0, // DBR_STS_STRING - 0, // DBR_STS_INT, DBR_STS_SHORT - 0, // DBR_STS_FLOAT - 0, // DBR_STS_ENUM - 0, // DBR_STS_CHAR - 0, // DBR_STS_LONG - copy_DBR_STS_DOUBLE, // DBR_STS_DOUBLE + copy_DBR_STS, // DBR_STS_STRING + copy_DBR_STS, // DBR_STS_INT, DBR_STS_SHORT + copy_DBR_STS, // DBR_STS_FLOAT + copy_DBR_STS, // DBR_STS_ENUM + copy_DBR_STS, // DBR_STS_CHAR + copy_DBR_STS, // DBR_STS_LONG + copy_DBR_STS, // DBR_STS_DOUBLE - 0, // DBR_TIME_STRING - 0, // DBR_TIME_INT, DBR_TIME_SHORT - 0, // DBR_TIME_FLOAT - 0, // DBR_TIME_ENUM - 0, // DBR_TIME_CHAR - 0, // DBR_TIME_LONG - copy_DBR_TIME_DOUBLE, // DBR_TIME_DOUBLE + copy_DBR_TIME, // DBR_TIME_STRING + copy_DBR_TIME, // DBR_TIME_INT, DBR_TIME_SHORT + copy_DBR_TIME, // DBR_TIME_FLOAT + copy_DBR_TIME, // DBR_TIME_ENUM + copy_DBR_TIME, // DBR_TIME_CHAR + copy_DBR_TIME, // DBR_TIME_LONG + copy_DBR_TIME, // DBR_TIME_DOUBLE - 0, // DBR_GR_STRING - 0, // DBR_GR_INT, DBR_GR_SHORT - 0, // DBR_GR_FLOAT - 0, // DBR_GR_ENUM - 0, // DBR_GR_CHAR - 0, // DBR_GR_LONG - copy_DBR_GR_DOUBLE, // DBR_GR_DOUBLE + copy_DBR_TIME, // DBR_GR_STRING -> DBR_STS_STRING + copy_DBR_GR, // DBR_GR_INT, DBR_GR_SHORT + copy_DBR_GR, // DBR_GR_FLOAT + 0,// TODO copy_DBR_GR, // DBR_GR_ENUM + copy_DBR_GR, // DBR_GR_CHAR + copy_DBR_GR, // DBR_GR_LONG + copy_DBR_GR, // DBR_GR_DOUBLE - 0, // DBR_CTRL_STRING - 0, // DBR_CTRL_INT, DBR_CTRL_SHORT - 0, // DBR_CTRL_FLOAT - 0, // DBR_CTRL_ENUM - 0, // DBR_CTRL_CHAR - 0, // DBR_CTRL_LONG - copy_DBR_CTRL_DOUBLE // DBR_CTRL_DOUBLE + copy_DBR_TIME, // DBR_CTRL_STRING -> DBR_STS_STRING + copy_DBR_CTRL, // DBR_CTRL_INT, DBR_CTRL_SHORT + copy_DBR_CTRL, // DBR_CTRL_FLOAT + 0,// TODO copy_DBR_CTRL, // DBR_CTRL_ENUM + copy_DBR_CTRL, // DBR_CTRL_CHAR + copy_DBR_CTRL, // DBR_CTRL_LONG + copy_DBR_CTRL // DBR_CTRL_DOUBLE }; void CAChannelGet::getDone(struct event_handler_args &args)