using new copy API

This commit is contained in:
Matej Sekoranja
2015-02-18 10:03:18 +01:00
parent 1d58caf40d
commit c8c0498cdf
11 changed files with 17 additions and 183 deletions

View File

@@ -24,7 +24,6 @@
#include <iomanip>
#include <map>
#include <pv/convert.h>
#include <pv/event.h>
#include <epicsExit.h>
@@ -970,7 +969,7 @@ void printValues(shared_vector<const string> const & names, vector<PVStructure::
dynamic_pointer_cast<PVStringArray>(getPVDataCreate()->createPVScalarArray(pvString));
PVStringArray::svector values;
values.push_back(getConvert()->toString(scalar));
values.push_back(scalar->getAs<std::string>());
StringArray->replace(freeze(values));
scalarArrays.push_back(StringArray);

View File

@@ -8,6 +8,7 @@
#include <epicsThread.h>
#include <pv/logger.h>
#include <pv/lock.h>
#include <pv/convert.h>
#include <vector>
#include <string>
@@ -19,7 +20,6 @@
#include <epicsExit.h>
#include "pvutils.cpp"
#include <pv/convert.h>
#include <pv/caProvider.h>

View File

@@ -85,143 +85,6 @@ void SerializationHelper::serializeFull(ByteBuffer* buffer, SerializableControl*
}
}
ConvertPtr SerializationHelper::_convert(getConvert());
void SerializationHelper::copyUnchecked(
epics::pvData::PVField::shared_pointer const & from,
epics::pvData::PVField::shared_pointer const & to)
{
switch(from->getField()->getType())
{
case scalar:
{
PVScalar::shared_pointer fromS = std::tr1::static_pointer_cast<PVScalar>(from);
PVScalar::shared_pointer toS = std::tr1::static_pointer_cast<PVScalar>(to);
toS->assign(*fromS.get());
break;
}
case scalarArray:
{
PVScalarArray::shared_pointer fromS = std::tr1::static_pointer_cast<PVScalarArray>(from);
PVScalarArray::shared_pointer toS = std::tr1::static_pointer_cast<PVScalarArray>(to);
toS->assign(*fromS.get());
break;
}
case structure:
{
PVStructure::shared_pointer fromS = std::tr1::static_pointer_cast<PVStructure>(from);
PVStructure::shared_pointer toS = std::tr1::static_pointer_cast<PVStructure>(to);
copyStructureUnchecked(fromS, toS);
break;
}
case structureArray:
{
PVStructureArray::shared_pointer fromS = std::tr1::static_pointer_cast<PVStructureArray>(from);
PVStructureArray::shared_pointer toS = std::tr1::static_pointer_cast<PVStructureArray>(to);
toS->replace(fromS->view());
break;
}
case union_:
{
PVUnion::shared_pointer fromS = std::tr1::static_pointer_cast<PVUnion>(from);
PVUnion::shared_pointer toS = std::tr1::static_pointer_cast<PVUnion>(to);
_convert->copyUnion(fromS, toS);
break;
}
case unionArray:
{
PVUnionArray::shared_pointer fromS = std::tr1::static_pointer_cast<PVUnionArray>(from);
PVUnionArray::shared_pointer toS = std::tr1::static_pointer_cast<PVUnionArray>(to);
toS->replace(fromS->view());
break;
}
default:
{
throw std::logic_error("SerializationHelper::copyUnchecked unknown type");
}
}
}
void SerializationHelper::copyStructureUnchecked(
PVStructure::shared_pointer const & from,
PVStructure::shared_pointer const & to)
{
if (from.get() == to.get())
return;
PVFieldPtrArray const & fromPVFields = from->getPVFields();
PVFieldPtrArray const & toPVFields = to->getPVFields();
size_t fieldsSize = fromPVFields.size();
for(size_t i = 0; i<fieldsSize; i++) {
PVFieldPtr pvField = fromPVFields[i];
int32 inumberFields = static_cast<int32>(pvField->getNumberFields());
// serialize field or fields
if(inumberFields==1) {
copyUnchecked(pvField, toPVFields[i]);
} else {
PVStructure::shared_pointer fromPVStructure = std::tr1::static_pointer_cast<PVStructure>(pvField);
PVStructure::shared_pointer toPVStructure = std::tr1::static_pointer_cast<PVStructure>(toPVFields[i]);
copyStructureUnchecked(fromPVStructure, toPVStructure);
}
}
}
void SerializationHelper::partialCopy(PVStructure::shared_pointer const & from,
PVStructure::shared_pointer const & to,
BitSet::shared_pointer const & maskBitSet,
bool inverse) {
if (from.get() == to.get())
return;
size_t numberFields = from->getNumberFields();
size_t offset = from->getFieldOffset();
int32 next = inverse ?
maskBitSet->nextClearBit(static_cast<uint32>(offset)) :
maskBitSet->nextSetBit(static_cast<uint32>(offset));
// no more changes or no changes in this structure
if(next<0||next>=static_cast<int32>(offset+numberFields)) return;
// entire structure
if(static_cast<int32>(offset)==next) {
copyStructureUnchecked(from, to);
return;
}
PVFieldPtrArray const & fromPVFields = from->getPVFields();
PVFieldPtrArray const & toPVFields = to->getPVFields();
size_t fieldsSize = fromPVFields.size();
for(size_t i = 0; i<fieldsSize; i++) {
PVFieldPtr pvField = fromPVFields[i];
offset = pvField->getFieldOffset();
int32 inumberFields = static_cast<int32>(pvField->getNumberFields());
next = inverse ?
maskBitSet->nextClearBit(static_cast<uint32>(offset)) :
maskBitSet->nextSetBit(static_cast<uint32>(offset));
// no more changes
if(next<0) return;
// no change in this pvField
if(next>=static_cast<int32>(offset+inumberFields)) continue;
// serialize field or fields
if(inumberFields==1) {
copyUnchecked(pvField, toPVFields[i]);
} else {
PVStructure::shared_pointer fromPVStructure = std::tr1::static_pointer_cast<PVStructure>(pvField);
PVStructure::shared_pointer toPVStructure = std::tr1::static_pointer_cast<PVStructure>(toPVFields[i]);
partialCopy(fromPVStructure, toPVStructure, maskBitSet, inverse);
}
}
}
}}

View File

@@ -15,7 +15,6 @@
#include <pv/serialize.h>
#include <pv/pvData.h>
#include <pv/convert.h>
#include <pv/noDefaultMethods.h>
#include <pv/pvIntrospect.h>
#include <pv/byteBuffer.h>
@@ -35,7 +34,6 @@ namespace epics {
public:
static epics::pvData::PVDataCreatePtr _pvDataCreate;
static epics::pvData::ConvertPtr _convert;
/**
* Deserialize PVRequest.
@@ -101,21 +99,6 @@ namespace epics {
*/
static void serializeFull(epics::pvData::ByteBuffer* buffer, epics::pvData::SerializableControl* control, epics::pvData::PVField::shared_pointer const & pvField);
static void copyUnchecked(
epics::pvData::PVField::shared_pointer const & from,
epics::pvData::PVField::shared_pointer const & to);
static void copyStructureUnchecked(
epics::pvData::PVStructure::shared_pointer const & from,
epics::pvData::PVStructure::shared_pointer const & to);
// TODO move somewhere else, to pvData?
static void partialCopy(
epics::pvData::PVStructure::shared_pointer const & from,
epics::pvData::PVStructure::shared_pointer const & to,
epics::pvData::BitSet::shared_pointer const & maskBitSet,
bool inverse = false);
};
}

View File

@@ -14,7 +14,6 @@
#include <pv/timer.h>
#include <pv/bitSetUtil.h>
#include <pv/serializationHelper.h>
#include <pv/convert.h>
#include <pv/queue.h>
#include <pv/standardPVField.h>
@@ -53,7 +52,6 @@ namespace epics {
Status ChannelImpl::channelDisconnected(
Status::STATUSTYPE_WARNING, "channel disconnected");
string emptyString;
ConvertPtr convert = getConvert();
// TODO consider std::unordered_map
//typedef std::tr1::unordered_map<pvAccessID, ResponseRequest::weak_pointer> IOIDResponseRequestMap;
@@ -984,7 +982,7 @@ namespace epics {
try {
lock();
*m_bitSet = *pvPutBitSet;
SerializationHelper::partialCopy(pvPutStructure, m_structure, m_bitSet);
m_structure->copyUnchecked(*pvPutStructure, *m_bitSet);
unlock();
m_channel->checkAndGetTransport()->enqueueSendRequest(shared_from_this());
} catch (std::runtime_error &rte) {
@@ -1250,7 +1248,7 @@ namespace epics {
try {
lock();
*m_putDataBitSet = *bitSet;
SerializationHelper::partialCopy(pvPutStructure, m_putData, m_putDataBitSet);
m_putData->copyUnchecked(*pvPutStructure, *m_putDataBitSet);
unlock();
m_channel->checkAndGetTransport()->enqueueSendRequest(shared_from_this());
} catch (std::runtime_error &rte) {
@@ -1799,7 +1797,7 @@ namespace epics {
try {
{
Lock lock(m_structureMutex);
SerializationHelper::copyUnchecked(putArray, m_arrayData);
m_arrayData->copyUnchecked(*putArray);
m_offset = offset;
m_count = count;
m_stride = stride;
@@ -2291,7 +2289,7 @@ namespace epics {
// deserialize changedBitSet and data, and overrun bit set
changedBitSet->deserialize(payloadBuffer, transport.get());
if (m_up2datePVStructure && m_up2datePVStructure.get() != pvStructure.get())
SerializationHelper::partialCopy(m_up2datePVStructure, pvStructure, changedBitSet, true);
pvStructure->copyUnchecked(*m_up2datePVStructure, *changedBitSet, true);
pvStructure->deserialize(payloadBuffer, transport.get(), changedBitSet.get());
overrunBitSet->deserialize(payloadBuffer, transport.get());

View File

@@ -8,7 +8,6 @@
#include <string>
#include <pv/pvData.h>
#include <pv/convert.h>
#include <pv/event.h>
#define epicsExportSharedSymbols

View File

@@ -21,7 +21,6 @@
#include <pv/remote.h>
#include <pv/hexDump.h>
#include <pv/serializationHelper.h>
#include <pv/convert.h>
#include <pv/byteBuffer.h>
@@ -1116,7 +1115,7 @@ void ServerChannelGetRequesterImpl::getDone(const Status& status, ChannelGet::sh
if (_status.isSuccess())
{
*_bitSet = *bitSet;
SerializationHelper::partialCopy(pvStructure, _pvStructure, _bitSet);
_pvStructure->copyUnchecked(*pvStructure, *_bitSet);
}
}
@@ -1398,7 +1397,7 @@ void ServerChannelPutRequesterImpl::getDone(const Status& status, ChannelPut::sh
if (_status.isSuccess())
{
*_bitSet = *bitSet;
SerializationHelper::partialCopy(pvStructure, _pvStructure, _bitSet);
_pvStructure->copyUnchecked(*pvStructure, *_bitSet);
}
}
TransportSender::shared_pointer thisSender = shared_from_this();
@@ -1686,7 +1685,7 @@ void ServerChannelPutGetRequesterImpl::getGetDone(const Status& status, ChannelP
if (_status.isSuccess())
{
*_pvGetBitSet = *bitSet;
SerializationHelper::partialCopy(pvStructure, _pvGetStructure, _pvGetBitSet);
_pvGetStructure->copyUnchecked(*pvStructure, *_pvGetBitSet);
}
}
TransportSender::shared_pointer thisSender = shared_from_this();
@@ -1702,7 +1701,7 @@ void ServerChannelPutGetRequesterImpl::getPutDone(const Status& status, ChannelP
if (_status.isSuccess())
{
*_pvPutBitSet = *bitSet;
SerializationHelper::partialCopy(pvStructure, _pvPutStructure, _pvPutBitSet);
_pvPutStructure->copyUnchecked(*pvStructure, *_pvPutBitSet);
}
}
TransportSender::shared_pointer thisSender = shared_from_this();
@@ -1718,7 +1717,7 @@ void ServerChannelPutGetRequesterImpl::putGetDone(const Status& status, ChannelP
if (_status.isSuccess())
{
*_pvGetBitSet = *bitSet;
SerializationHelper::partialCopy(pvStructure, _pvGetStructure, _pvGetBitSet);
_pvGetStructure->copyUnchecked(*pvStructure, *_pvGetBitSet);
}
}
TransportSender::shared_pointer thisSender = shared_from_this();
@@ -2304,8 +2303,7 @@ void ServerChannelArrayRequesterImpl::getArrayDone(const Status& status, Channel
_status = status;
if (_status.isSuccess())
{
// TODO cache convert
getConvert()->copy(pvArray, _pvArray);
_pvArray->copyUnchecked(*pvArray);
}
}
TransportSender::shared_pointer thisSender = shared_from_this();

View File

@@ -5,7 +5,6 @@
*/
#include <pv/introspectionRegistry.h>
#include <pv/convert.h>
#include <pv/serializationHelper.h>
using namespace epics::pvData;

View File

@@ -10,7 +10,6 @@
#include <pv/logger.h>
#include <pv/pvAccess.h>
#include <pv/convert.h>
#include <pv/serverContext.h>
#include <pv/clientFactory.h>
#include <pv/clientContextImpl.h>
@@ -1757,8 +1756,7 @@ std::ostringstream oss;
oss << *monitorReq->getPVStructure();
testDiag("%s:\n%s", CURRENT_FUNCTION, oss.str().c_str());
ConvertPtr convert = getConvert();
convert->copy(valueField, previousValue);
previousValue->copyUnchecked(*valueField);
testOk(valueField->equals(*previousValue.get()) == true , "%s: value field equals to a previous value",
CURRENT_FUNCTION);
@@ -1801,7 +1799,7 @@ testDiag("%s:\n%s", CURRENT_FUNCTION, oss.str().c_str());
testOk(valueField->equals(*previousValue.get()) == false , "%s: value field not equals to a previous value",
CURRENT_FUNCTION);
convert->copy(valueField, previousValue);
previousValue->copyUnchecked(*valueField);
}

View File

@@ -15,7 +15,6 @@
#include <epicsExit.h>
#include <pv/standardPVField.h>
#include <pv/pvTimeStamp.h>
#include <pv/convert.h>
#include <stdlib.h>
#include <time.h>
@@ -24,7 +23,6 @@
#include <cmath>
#include <pv/logger.h>
#include <pv/convert.h>
// TODO temp
#include "testADCSim.cpp"
@@ -1003,7 +1001,7 @@ public:
if (putBitSet->cardinality())
{
lock();
getConvert()->copy(pvPutStructure, m_pvStructure);
m_pvStructure->copyUnchecked(*pvPutStructure);
unlock();
}
@@ -1125,7 +1123,7 @@ public:
if (putBitSet->cardinality())
{
lock();
getConvert()->copy(pvPutStructure, m_putStructure);
m_putStructure->copyUnchecked(*pvPutStructure);
unlock();
}
@@ -1947,7 +1945,7 @@ public:
{
{
lock();
getConvert()->copyStructure(m_pvStructure, m_ccopy);
m_ccopy->copyUnchecked(*m_pvStructure);
unlock();
}
}

View File

@@ -14,7 +14,6 @@
#include <sstream>
#include <vector>
#include <pv/CDRMonitor.h>
#include <pv/convert.h>
using std::tr1::static_pointer_cast;
using namespace epics::pvData;