From d8ae646e704e8665224a047b097119986cc5b3d3 Mon Sep 17 00:00:00 2001 From: Matej Sekoranja Date: Mon, 16 Feb 2015 11:21:13 +0100 Subject: [PATCH] unchecked copy --- src/remote/serializationHelper.cpp | 94 ++++++++++++++++++++++++-- src/remote/serializationHelper.h | 10 +++ src/remoteClient/clientContextImpl.cpp | 6 +- 3 files changed, 103 insertions(+), 7 deletions(-) diff --git a/src/remote/serializationHelper.cpp b/src/remote/serializationHelper.cpp index d9d42d3..17c39d2 100644 --- a/src/remote/serializationHelper.cpp +++ b/src/remote/serializationHelper.cpp @@ -4,8 +4,6 @@ * in file LICENSE that is included with this distribution. */ -#include - #define epicsExportSharedSymbols #include #include @@ -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(from); + PVScalar::shared_pointer toS = std::tr1::static_pointer_cast(to); + toS->assign(*fromS.get()); + break; + } + case scalarArray: + { + PVScalarArray::shared_pointer fromS = std::tr1::static_pointer_cast(from); + PVScalarArray::shared_pointer toS = std::tr1::static_pointer_cast(to); + toS->assign(*fromS.get()); + break; + } + case structure: + { + PVStructure::shared_pointer fromS = std::tr1::static_pointer_cast(from); + PVStructure::shared_pointer toS = std::tr1::static_pointer_cast(to); + copyStructureUnchecked(fromS, toS); + break; + } + case structureArray: + { + PVStructureArray::shared_pointer fromS = std::tr1::static_pointer_cast(from); + PVStructureArray::shared_pointer toS = std::tr1::static_pointer_cast(to); + toS->replace(fromS->view()); + break; + } + case union_: + { + PVUnion::shared_pointer fromS = std::tr1::static_pointer_cast(from); + PVUnion::shared_pointer toS = std::tr1::static_pointer_cast(to); + _convert->copyUnion(fromS, toS); + break; + } + case unionArray: + { + PVUnionArray::shared_pointer fromS = std::static_pointer_cast(from); + PVUnionArray::shared_pointer toS = std::static_pointer_cast(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(pvField->getNumberFields()); + + // serialize field or fields + if(inumberFields==1) { + copyUnchecked(pvField, toPVFields[i]); + } else { + PVStructure::shared_pointer fromPVStructure = std::tr1::static_pointer_cast(pvField); + PVStructure::shared_pointer toPVStructure = std::tr1::static_pointer_cast(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(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(pvField); PVStructure::shared_pointer toPVStructure = std::tr1::static_pointer_cast(toPVFields[i]); diff --git a/src/remote/serializationHelper.h b/src/remote/serializationHelper.h index dfba71f..34270a0 100644 --- a/src/remote/serializationHelper.h +++ b/src/remote/serializationHelper.h @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -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, diff --git a/src/remoteClient/clientContextImpl.cpp b/src/remoteClient/clientContextImpl.cpp index be841b4..6f3eefe 100644 --- a/src/remoteClient/clientContextImpl.cpp +++ b/src/remoteClient/clientContextImpl.cpp @@ -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);