unchecked copy

This commit is contained in:
Matej Sekoranja
2015-02-16 11:21:13 +01:00
parent a21908de89
commit d8ae646e70
3 changed files with 103 additions and 7 deletions

View File

@@ -4,8 +4,6 @@
* in file LICENSE that is included with this distribution.
*/
#include <pv/convert.h>
#define epicsExportSharedSymbols
#include <pv/serializationHelper.h>
#include <pv/introspectionRegistry.h>
@@ -87,11 +85,99 @@ 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::static_pointer_cast<PVUnionArray>(from);
PVUnionArray::shared_pointer toS = std::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 ?
@@ -103,7 +189,7 @@ void SerializationHelper::partialCopy(PVStructure::shared_pointer const & from,
// entire structure
if(static_cast<int32>(offset)==next) {
getConvert()->copy(from, to);
copyStructureUnchecked(from, to);
return;
}
@@ -126,7 +212,7 @@ void SerializationHelper::partialCopy(PVStructure::shared_pointer const & from,
// serialize field or fields
if(inumberFields==1) {
getConvert()->copy(pvField, toPVFields[i]);
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]);

View File

@@ -15,6 +15,7 @@
#include <pv/serialize.h>
#include <pv/pvData.h>
#include <pv/convert.h>
#include <pv/noDefaultMethods.h>
#include <pv/pvIntrospect.h>
#include <pv/byteBuffer.h>
@@ -34,6 +35,7 @@ namespace epics {
public:
static epics::pvData::PVDataCreatePtr _pvDataCreate;
static epics::pvData::ConvertPtr _convert;
/**
* Deserialize PVRequest.
@@ -99,6 +101,14 @@ 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,

View File

@@ -1799,7 +1799,7 @@ namespace epics {
try {
{
Lock lock(m_structureMutex);
convert->copy(putArray, m_arrayData); // TODO avoid isComptabile checks
SerializationHelper::copyUnchecked(putArray, m_arrayData);
m_offset = offset;
m_count = count;
m_stride = stride;
@@ -2153,7 +2153,7 @@ namespace epics {
{
// take new, put current in use
PVStructurePtr pvStructure = m_monitorElement->pvStructurePtr;
convert->copy(pvStructure, newElement->pvStructurePtr);
copyUnchecked(pvStructure, newElement->pvStructurePtr);
BitSetUtil::compress(m_monitorElement->changedBitSet, pvStructure);
BitSetUtil::compress(m_monitorElement->overrunBitSet, pvStructure);
@@ -2225,7 +2225,7 @@ namespace epics {
m_overrunInProgress = false;
}
convert->copy(pvStructure, newElement->pvStructurePtr);
copyUnchecked(pvStructure, newElement->pvStructurePtr);
m_monitorQueue.setUsed(m_monitorElement);