From 35b3403de65bf12078dc0c022519d213b7e92b57 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Wed, 1 May 2019 14:11:44 -0700 Subject: [PATCH] remove deprecated pvCopy --- src/copy/Makefile | 2 - src/copy/pv/pvCopy.h | 233 ------------- src/copy/pvCopy.cpp | 652 ------------------------------------ testApp/copy/Makefile | 5 - testApp/copy/testPVCopy.cpp | 299 ----------------- testApp/pvDataAllTests.c | 2 - 6 files changed, 1193 deletions(-) delete mode 100644 src/copy/pv/pvCopy.h delete mode 100644 src/copy/pvCopy.cpp delete mode 100644 testApp/copy/testPVCopy.cpp diff --git a/src/copy/Makefile b/src/copy/Makefile index ced2948..4e605d7 100644 --- a/src/copy/Makefile +++ b/src/copy/Makefile @@ -3,8 +3,6 @@ SRC_DIRS += $(PVDATA_SRC)/copy INC += pv/createRequest.h -INC += pv/pvCopy.h LIBSRCS += createRequest.cpp LIBSRCS += requestmapper.cpp -LIBSRCS += pvCopy.cpp diff --git a/src/copy/pv/pvCopy.h b/src/copy/pv/pvCopy.h deleted file mode 100644 index 607ce25..0000000 --- a/src/copy/pv/pvCopy.h +++ /dev/null @@ -1,233 +0,0 @@ -/* pvCopy.h */ -/* - * Copyright information and license terms for this software can be - * found in the file LICENSE that is included with the distribution - */ -/** - * @author Marty Kraimer - * @date 2013.04 - */ -#ifndef PVCOPY_H -#define PVCOPY_H -#include -#include -#include - -#include -#include - -#include -#include - -namespace epics { namespace pvData{ - -class PVCopyTraverseMasterCallback; -typedef std::tr1::shared_ptr PVCopyTraverseMasterCallbackPtr; - -/** - * @brief Callback for traversing master structure - * - * Must be implemented by code that creates pvCopy. - */ -class epicsShareClass PVCopyTraverseMasterCallback -{ -public: - POINTER_DEFINITIONS(PVCopyTraverseMasterCallback); - virtual ~PVCopyTraverseMasterCallback() {} - /** - * Called once for each field in master. - * @param pvField The field in master. - */ - virtual void nextMasterPVField(epics::pvData::PVFieldPtr const &pvField) = 0; -}; - - -class PVCopy; -typedef std::tr1::shared_ptr PVCopyPtr; - -struct CopyNode; -typedef std::tr1::shared_ptr CopyNodePtr; -struct CopyMasterNode; -typedef std::tr1::shared_ptr CopyMasterNodePtr; -struct CopyStructureNode; -typedef std::tr1::shared_ptr CopyStructureNodePtr; - - -/** - * @brief Support for subset of fields in a pvStructure. - * - * Class that manages one or more PVStructures that holds an arbitrary subset of the fields - * in another PVStructure called master. - */ -class epicsShareClass EPICS_DEPRECATED PVCopy : - public std::tr1::enable_shared_from_this -{ -public: - POINTER_DEFINITIONS(PVCopy); - /** - * Create a new pvCopy - * @param pvMaster The top-level structure for which a copy of - * an arbitrary subset of the fields in master will be created and managed. - * @param pvRequest Selects the set of subfields desired and options for each field. - * @param structureName The name for the top level of any PVStructure created. - */ - static PVCopyPtr create( - PVStructurePtr const &pvMaster, - PVStructurePtr const &pvRequest, - std::string const & structureName); - virtual ~PVCopy(){} - void destroy(); - /** - * Get the top-level structure of master - * @returns The master top-level structure. - * This should not be modified. - */ - PVStructurePtr getPVMaster(); - /** - * Traverse all the fields in master. - * @param callback This is called for each field on master. - */ - void traverseMaster(PVCopyTraverseMasterCallbackPtr const & callback) - { - traverseMaster(headNode,callback); - } - /** - * Get the introspection interface for a PVStructure for e copy. - */ - StructureConstPtr getStructure(); - /** - * Create a copy instance. Monitors keep a queue of monitor elements. - * Since each element needs a PVStructure, multiple top-level structures will be created. - */ - PVStructurePtr createPVStructure(); - /** - * Given a field in pvMaster. return the offset in copy for the same field. - * A value of std::string::npos means that the copy does not have this field. - * @param masterPVField The field in master. - */ - std::size_t getCopyOffset(PVFieldPtr const &masterPVField); - /** - * Given a field in pvMaster. return the offset in copy for the same field. - * A value of std::string::npos means that the copy does not have this field. - * @param masterPVStructure A structure in master that has masterPVField. - * @param masterPVField The field in master. - */ - std::size_t getCopyOffset( - PVStructurePtr const &masterPVStructure, - PVFieldPtr const &masterPVField); - /** - * Given an offset in the copy get the corresponding field in pvMaster. - * @param structureOffset The offset in the copy. - */ - PVFieldPtr getMasterPVField(std::size_t structureOffset); - /** - * Initialize the fields in copyPVStructure by giving each field - * the value from the corresponding field in pvMaster. - * bitSet will be set to show that all fields are changed. - * @param copyPVStructure A copy top-level structure. - * @param bitSet A bitSet for copyPVStructure. - */ - void initCopy( - PVStructurePtr const ©PVStructure, - BitSetPtr const &bitSet); - /** - * Set all fields in copyPVStructure to the value of the corresponding field in pvMaster. - * Each field that is changed has it's corresponding bit set in bitSet. - * @param copyPVStructure A copy top-level structure. - * @param bitSet A bitSet for copyPVStructure. - */ - void updateCopySetBitSet( - PVStructurePtr const ©PVStructure, - BitSetPtr const &bitSet); - /** - * For each set bit in bitSet - * set the field in copyPVStructure to the value of the corresponding field in pvMaster. - * @param copyPVStructure A copy top-level structure. - * @param bitSet A bitSet for copyPVStructure. - */ - void updateCopyFromBitSet( - PVStructurePtr const ©PVStructure, - BitSetPtr const &bitSet); - /** - * For each set bit in bitSet - * set the field in pvMaster to the value of the corresponding field in copyPVStructure - * @param copyPVStructure A copy top-level structure. - * @param bitSet A bitSet for copyPVStructure. - */ - void updateMaster( - PVStructurePtr const ©PVStructure, - BitSetPtr const &bitSet); - /** - * Get the options for the field at the specified offset. - * @param fieldOffset the offset in copy. - * @returns A NULL is returned if no options were specified for the field. - * If options were specified,PVStructurePtr is a structures - * with a set of PVString subfields that specify name,value pairs.s - * name is the subField name and value is the subField value. - */ - PVStructurePtr getOptions(std::size_t fieldOffset); - /** - * For debugging. - */ - std::string dump(); -private: - void dump( - std::string *builder, - CopyNodePtr const &node, - int indentLevel); - PVCopyPtr getPtrSelf() - { - return shared_from_this(); - } - void traverseMaster(CopyNodePtr const &node, PVCopyTraverseMasterCallbackPtr const & callback); - - PVStructurePtr pvMaster; - StructureConstPtr structure; - CopyNodePtr headNode; - PVStructurePtr cacheInitStructure; - PVCopy(PVStructurePtr const &pvMaster); - friend class PVCopyMonitor; - bool init(PVStructurePtr const &pvRequest); - std::string dump( - std::string const &value, - CopyNodePtr const &node, - int indentLevel); - StructureConstPtr createStructure( - PVStructurePtr const &pvMaster, - PVStructurePtr const &pvFromRequest); - CopyNodePtr createStructureNodes( - PVStructurePtr const &pvMasterStructure, - PVStructurePtr const &pvFromRequest, - PVStructurePtr const &pvFromField); - void updateStructureNodeSetBitSet( - PVStructurePtr const &pvCopy, - CopyStructureNodePtr const &structureNode, - BitSetPtr const &bitSet); - void updateSubFieldSetBitSet( - PVFieldPtr const &pvCopy, - PVFieldPtr const &pvMaster, - BitSetPtr const &bitSet); - void updateStructureNodeFromBitSet( - PVStructurePtr const &pvCopy, - CopyStructureNodePtr const &structureNode, - BitSetPtr const &bitSet, - bool toCopy, - bool doAll); - void updateSubFieldFromBitSet( - PVFieldPtr const &pvCopy, - PVFieldPtr const &pvMasterField, - BitSetPtr const &bitSet, - bool toCopy, - bool doAll); - CopyMasterNodePtr getCopyOffset( - CopyStructureNodePtr const &structureNode, - PVFieldPtr const &masterPVField); - CopyMasterNodePtr getMasterNode( - CopyStructureNodePtr const &structureNode, - std::size_t structureOffset); - -}; - -}} - -#endif /* PVCOPY_H */ diff --git a/src/copy/pvCopy.cpp b/src/copy/pvCopy.cpp deleted file mode 100644 index 532286a..0000000 --- a/src/copy/pvCopy.cpp +++ /dev/null @@ -1,652 +0,0 @@ -/* pvCopy.cpp */ -/* - * Copyright information and license terms for this software can be - * found in the file LICENSE that is included with the distribution - */ -/** - * @author Marty Kraimer - * @date 2013.04 - */ -#include -#include -#include -#include - -#include -#include -#undef EPICS_DEPRECATED -#define EPICS_DEPRECATED - -#define epicsExportSharedSymbols - -#include - -#include - -using std::tr1::static_pointer_cast; -using std::tr1::dynamic_pointer_cast; -using std::string; -using std::size_t; -using std::cout; -using std::endl; - -namespace epics { namespace pvData { - -/** - * Convenience method for implementing dump. - * It generates a newline and inserts blanks at the beginning of the newline. - * @param builder The std::string * being constructed. - * @param indentLevel Indent level, Each level is four spaces. - */ -static void newLine(string *buffer, int indentLevel) -{ - *buffer += "\n"; - *buffer += string(indentLevel*4, ' '); -} - -struct CopyNode { - CopyNode() - : isStructure(false), - structureOffset(0), - nfields(0) - {} - bool isStructure; - size_t structureOffset; // In the copy - size_t nfields; - PVStructurePtr options; -}; - -struct CopyMasterNode : public CopyNode{ - PVFieldPtr masterPVField; -}; - -typedef std::vector CopyNodePtrArray; -typedef std::tr1::shared_ptr CopyNodePtrArrayPtr; - -struct CopyStructureNode : public CopyNode { - CopyNodePtrArrayPtr nodes; -}; - -PVCopyPtr PVCopy::create( - PVStructurePtr const &pvMaster, - PVStructurePtr const &pvRequest, - string const & structureName) -{ - PVStructurePtr pvStructure(pvRequest); - if(structureName.size()>0) { - if(pvRequest->getStructure()->getNumberFields()>0) { - pvStructure = pvRequest->getSubField(structureName); - if(!pvStructure) return PVCopyPtr(); - } - } else if(pvStructure->getSubField("field")) { - pvStructure = pvRequest->getSubField("field"); - } - PVCopyPtr pvCopy(new PVCopy(pvMaster)); - bool result = pvCopy->init(pvStructure); - if(!result) pvCopy.reset(); - return pvCopy; -} - -PVCopy::PVCopy( - PVStructurePtr const &pvMaster) -: pvMaster(pvMaster) -{ -} - -void PVCopy::destroy() -{ - headNode.reset(); -} - -PVStructurePtr PVCopy::getPVMaster() -{ - return pvMaster; -} - -void PVCopy::traverseMaster(CopyNodePtr const &innode, PVCopyTraverseMasterCallbackPtr const & callback) -{ - CopyNodePtr node = innode; - if(!node->isStructure) { - CopyMasterNodePtr masterNode = static_pointer_cast(node); - callback->nextMasterPVField(masterNode->masterPVField); - return; - } - CopyStructureNodePtr structNode = static_pointer_cast(node); - CopyNodePtrArrayPtr nodes = structNode->nodes; - for(size_t i=0; i< nodes->size(); i++) { - node = (*nodes)[i]; - traverseMaster(node,callback); - } -} - -StructureConstPtr PVCopy::getStructure() -{ - return structure; -} - -PVStructurePtr PVCopy::createPVStructure() -{ - if(cacheInitStructure) { - PVStructurePtr save = cacheInitStructure; - cacheInitStructure.reset(); - return save; - } - PVStructurePtr pvStructure = - getPVDataCreate()->createPVStructure(structure); - return pvStructure; -} - -PVStructurePtr PVCopy::getOptions(std::size_t fieldOffset) -{ - if(fieldOffset==0) return headNode->options; - CopyNodePtr node = headNode; - while(true) { - if(!node->isStructure) { - if(node->structureOffset==fieldOffset) return node->options; - return PVStructurePtr(); - } - CopyStructureNodePtr structNode = static_pointer_cast(node); - CopyNodePtrArrayPtr nodes = structNode->nodes; - boolean okToContinue = false; - for(size_t i=0; i< nodes->size(); i++) { - node = (*nodes)[i]; - size_t soff = node->structureOffset; - if(fieldOffset>=soff && fieldOffsetnfields) { - if(fieldOffset==soff) return node->options; - if(!node->isStructure) { - return PVStructurePtr(); - } - okToContinue = true; - break; - } - } - if(okToContinue) continue; - throw std::invalid_argument("fieldOffset not valid"); - } -} - -size_t PVCopy::getCopyOffset(PVFieldPtr const &masterPVField) -{ - if(masterPVField->getFieldOffset()==0) return 0; - if(!headNode->isStructure) { - CopyMasterNodePtr masterNode = static_pointer_cast(headNode); - if((masterNode->masterPVField.get())==masterPVField.get()) { - return headNode->structureOffset; - } - PVStructure * parent = masterPVField->getParent(); - size_t offsetParent = parent->getFieldOffset(); - size_t off = masterPVField->getFieldOffset(); - size_t offdiff = off -offsetParent; - if(offdiffnfields) return headNode->structureOffset + offdiff; - return string::npos; - } - CopyStructureNodePtr node = static_pointer_cast(headNode); - CopyMasterNodePtr masterNode = getCopyOffset(node,masterPVField); - if(masterNode) return masterNode->structureOffset; - return string::npos; -} - -size_t PVCopy::getCopyOffset( - PVStructurePtr const &masterPVStructure, - PVFieldPtr const &masterPVField) -{ - CopyMasterNodePtr masterNode; - if(!headNode->isStructure) { - masterNode = static_pointer_cast(headNode); - if(masterNode->masterPVField.get()!=masterPVStructure.get()) return string::npos; - } else { - CopyStructureNodePtr node = static_pointer_cast(headNode); - masterNode = getCopyOffset(node,masterPVField); - } - if(!masterNode) return string::npos; - size_t diff = masterPVField->getFieldOffset() - - masterPVStructure->getFieldOffset(); - return masterNode->structureOffset + diff; -} - -PVFieldPtr PVCopy::getMasterPVField(size_t structureOffset) -{ - CopyMasterNodePtr masterNode; - if(!headNode->isStructure) { - masterNode = static_pointer_cast(headNode); - } else { - CopyStructureNodePtr node = static_pointer_cast(headNode); - masterNode = getMasterNode(node,structureOffset); - } - if(!masterNode) { - throw std::invalid_argument( - "PVCopy::getMasterPVField: setstructureOffset not valid"); - } - size_t diff = structureOffset - masterNode->structureOffset; - PVFieldPtr pvMasterField = masterNode->masterPVField; - if(diff==0) return pvMasterField; - PVStructurePtr pvStructure - = static_pointer_cast(pvMasterField); - return pvStructure->getSubField( - pvMasterField->getFieldOffset() + diff); -} - -void PVCopy::initCopy( - PVStructurePtr const ©PVStructure, - BitSetPtr const &bitSet) -{ - bitSet->clear(); - bitSet->set(0); - updateCopyFromBitSet(copyPVStructure,bitSet); -} - -void PVCopy::updateCopySetBitSet( - PVStructurePtr const ©PVStructure, - BitSetPtr const &bitSet) -{ - if(headNode->isStructure) { - CopyStructureNodePtr node = static_pointer_cast(headNode); - updateStructureNodeSetBitSet(copyPVStructure,node,bitSet); - } else { - CopyMasterNodePtr masterNode = static_pointer_cast(headNode); - PVFieldPtr pvMasterField= masterNode->masterPVField; - PVFieldPtr copyPVField = copyPVStructure; - PVFieldPtr pvField = pvMasterField; - if(pvField->getField()->getType()==epics::pvData::structure) { - updateSubFieldSetBitSet(copyPVField,pvMasterField,bitSet); - return; - } - bool isEqual = (*copyPVField == *pvField); - if(!isEqual) { - copyPVField->copyUnchecked(*pvField); - bitSet->set(copyPVField->getFieldOffset()); - } - } -} - -void PVCopy::updateCopyFromBitSet( - PVStructurePtr const ©PVStructure, - BitSetPtr const &bitSet) -{ - bool doAll = bitSet->get(0); - if(headNode->isStructure) { - CopyStructureNodePtr node = static_pointer_cast(headNode); - updateStructureNodeFromBitSet(copyPVStructure,node,bitSet,true,doAll); - } else { - CopyMasterNodePtr masterNode = static_pointer_cast(headNode); - updateSubFieldFromBitSet(copyPVStructure, masterNode->masterPVField,bitSet, true,doAll); - } -} - -void PVCopy::updateMaster( - PVStructurePtr const ©PVStructure, - BitSetPtr const &bitSet) -{ - bool doAll = bitSet->get(0); - if(headNode->isStructure) { - CopyStructureNodePtr node = - static_pointer_cast(headNode); - updateStructureNodeFromBitSet( - copyPVStructure,node,bitSet,false,doAll); - } else { - CopyMasterNodePtr masterNode = - static_pointer_cast(headNode); - updateSubFieldFromBitSet( copyPVStructure,masterNode->masterPVField,bitSet,false,doAll); - } -} - -string PVCopy::dump() -{ - string builder; - dump(&builder,headNode,0); - return builder; -} - -void PVCopy::dump(string *builder,CopyNodePtr const &node,int indentLevel) -{ - newLine(builder,indentLevel); - std::stringstream ss; - ss << (node->isStructure ? "structureNode" : "masterNode"); - ss << " structureOffset " << node->structureOffset; - ss << " nfields " << node->nfields; - *builder += ss.str(); - PVStructurePtr options = node->options; - if(options) { - newLine(builder,indentLevel +1); - - // TODO !!! ugly - std::ostringstream oss; - oss << *options; - *builder += oss.str(); - - newLine(builder,indentLevel); - } - if(!node->isStructure) { - CopyMasterNodePtr masterNode = static_pointer_cast(node); - string name = masterNode->masterPVField->getFullName(); - *builder += " masterField " + name; - return; - } - CopyStructureNodePtr structureNode = - static_pointer_cast(node); - CopyNodePtrArrayPtr nodes = structureNode->nodes; - for(size_t i=0; isize(); ++i) { - if((*nodes)[i].get()==NULL) { - newLine(builder,indentLevel +1); - ss.str(""); - ss << "node[" << i << "] is null"; - *builder += ss.str(); - continue; - } - dump(builder,(*nodes)[i],indentLevel+1); - } -} - -bool PVCopy::init(epics::pvData::PVStructurePtr const &pvRequest) -{ - PVStructurePtr pvMasterStructure = pvMaster; - size_t len = pvRequest->getPVFields().size(); - bool entireMaster = false; - if(len==string::npos) entireMaster = true; - if(len==0) entireMaster = true; - PVStructurePtr pvOptions; - if(len==1) { - pvOptions = pvRequest->getSubField("_options"); - } - if(entireMaster) { - structure = pvMasterStructure->getStructure(); - CopyMasterNodePtr masterNode(new CopyMasterNode()); - headNode = masterNode; - masterNode->options = pvOptions; - masterNode->isStructure = false; - masterNode->structureOffset = 0; - masterNode->masterPVField = pvMasterStructure; - masterNode->nfields = pvMasterStructure->getNumberFields(); - return true; - } - structure = createStructure(pvMasterStructure,pvRequest); - if(!structure) return false; - cacheInitStructure = createPVStructure(); - headNode = createStructureNodes( - pvMaster, - pvRequest, - cacheInitStructure); - return true; -} - -string PVCopy::dump( - string const &value, - CopyNodePtr const &node, - int indentLevel) -{ - throw std::logic_error(string("Not Implemented")); -} - - -StructureConstPtr PVCopy::createStructure( - PVStructurePtr const &pvMaster, - PVStructurePtr const &pvFromRequest) -{ - if(pvFromRequest->getStructure()->getNumberFields()==0) { - return pvMaster->getStructure(); - } - PVFieldPtrArray const &pvFromRequestFields = pvFromRequest->getPVFields(); - StringArray const &fromRequestFieldNames = pvFromRequest->getStructure()->getFieldNames(); - size_t length = pvFromRequestFields.size(); - if(length==0) return StructureConstPtr(); - FieldConstPtrArray fields; fields.reserve(length); - StringArray fieldNames; fields.reserve(length); - for(size_t i=0; igetSubField(fieldName); - if(!pvMasterField) continue; - FieldConstPtr field = pvMasterField->getField(); - if(field->getType()==epics::pvData::structure) { - PVStructurePtr pvRequestStructure = static_pointer_cast( - pvFromRequestFields[i]); - if(pvRequestStructure->getNumberFields()>0) { - StringArray const &names = pvRequestStructure->getStructure()-> - getFieldNames(); - size_t num = names.size(); - if(num>0 && names[0].compare("_options")==0) --num; - if(num>0) { - if(pvMasterField->getField()->getType()!=epics::pvData::structure) continue; - fieldNames.push_back(fieldName); - fields.push_back(createStructure( - static_pointer_cast(pvMasterField), - pvRequestStructure)); - continue; - } - } - } - fieldNames.push_back(fieldName); - fields.push_back(field); - } - size_t numsubfields = fields.size(); - if(numsubfields==0) return StructureConstPtr(); - return getFieldCreate()->createStructure(fieldNames, fields); -} - -CopyNodePtr PVCopy::createStructureNodes( - PVStructurePtr const &pvMasterStructure, - PVStructurePtr const &pvFromRequest, - PVStructurePtr const &pvFromCopy) -{ - PVFieldPtrArray const & copyPVFields = pvFromCopy->getPVFields(); - PVStructurePtr pvOptions; - PVFieldPtr pvField = pvFromRequest->getSubField("_options"); - if(pvField) pvOptions = static_pointer_cast(pvField); - size_t number = copyPVFields.size(); - CopyNodePtrArrayPtr nodes(new CopyNodePtrArray()); - nodes->reserve(number); - for(size_t i=0; igetFieldName(); - - PVStructurePtr requestPVStructure = pvFromRequest->getSubField(fieldName); - PVStructurePtr pvSubFieldOptions = requestPVStructure->getSubField("_options"); - PVFieldPtr pvMasterField; - PVFieldPtrArray const & pvMasterFields = pvMasterStructure->getPVFields(); - for(size_t j=0; igetFieldName().compare(fieldName)==0) { - pvMasterField = pvMasterFields[j]; - break; - } - } - size_t numberRequest = requestPVStructure->getPVFields().size(); - if(pvSubFieldOptions) numberRequest--; - if(numberRequest>0) { - nodes->push_back(createStructureNodes( - static_pointer_cast(pvMasterField), - requestPVStructure, - static_pointer_cast(copyPVField))); - continue; - } - CopyMasterNodePtr masterNode(new CopyMasterNode()); - masterNode->options = pvSubFieldOptions; - masterNode->isStructure = false; - masterNode->masterPVField = pvMasterField; - masterNode->nfields = copyPVField->getNumberFields(); - masterNode->structureOffset = copyPVField->getFieldOffset(); - nodes->push_back(masterNode); - } - CopyStructureNodePtr structureNode(new CopyStructureNode()); - structureNode->isStructure = true; - structureNode->nodes = nodes; - structureNode->structureOffset = pvFromCopy->getFieldOffset(); - structureNode->nfields = pvFromCopy->getNumberFields(); - structureNode->options = pvOptions; - return structureNode; -} - -void PVCopy::updateStructureNodeSetBitSet( - PVStructurePtr const &pvCopy, - CopyStructureNodePtr const &structureNode, - epics::pvData::BitSetPtr const &bitSet) -{ - for(size_t i=0; inodes->size(); i++) { - CopyNodePtr node = (*structureNode->nodes)[i]; - PVFieldPtr pvField = pvCopy->getSubField(node->structureOffset); - if(node->isStructure) { - PVStructurePtr xxx = static_pointer_cast(pvField); - CopyStructureNodePtr yyy = - static_pointer_cast(node); - updateStructureNodeSetBitSet(xxx,yyy,bitSet); - } else { - CopyMasterNodePtr masterNode = - static_pointer_cast(node); - updateSubFieldSetBitSet(pvField,masterNode->masterPVField,bitSet); - } - } -} - -void PVCopy::updateSubFieldSetBitSet( - PVFieldPtr const &pvCopy, - PVFieldPtr const &pvMaster, - BitSetPtr const &bitSet) -{ - FieldConstPtr field = pvCopy->getField(); - Type type = field->getType(); - if(type!=epics::pvData::structure) { - bool isEqual = (*pvCopy == *pvMaster); - if(isEqual) { - if(type==structureArray) { - // always act as though a change occurred. - // Note that array elements are shared. - bitSet->set(pvCopy->getFieldOffset()); - } - } - if(isEqual) return; - pvCopy->copyUnchecked(*pvMaster); - bitSet->set(pvCopy->getFieldOffset()); - return; - } - PVStructurePtr pvCopyStructure = static_pointer_cast(pvCopy); - PVFieldPtrArray const & pvCopyFields = pvCopyStructure->getPVFields(); - PVStructurePtr pvMasterStructure = - static_pointer_cast(pvMaster); - PVFieldPtrArray const & pvMasterFields = - pvMasterStructure->getPVFields(); - size_t length = pvCopyFields.size(); - for(size_t i=0; istructureOffset; - if(!doAll) { - size_t nextSet = bitSet->nextSetBit(offset); - if(nextSet==string::npos) return; - } - if(offset>=pvCopy->getNextFieldOffset()) return; - if(!doAll) doAll = bitSet->get(offset); - CopyNodePtrArrayPtr nodes = structureNode->nodes; - for(size_t i=0; isize(); i++) { - CopyNodePtr node = (*nodes)[i]; - PVFieldPtr pvField = pvCopy->getSubFieldT(node->structureOffset); - if(node->isStructure) { - PVStructurePtr xxx = static_pointer_cast(pvField); - CopyStructureNodePtr subStructureNode = - static_pointer_cast(node); - updateStructureNodeFromBitSet( - xxx,subStructureNode,bitSet,toCopy,doAll); - } else { - CopyMasterNodePtr masterNode = - static_pointer_cast(node); - updateSubFieldFromBitSet( - pvField,masterNode->masterPVField,bitSet,toCopy,doAll); - } - } -} - -void PVCopy::updateSubFieldFromBitSet( - PVFieldPtr const &pvCopy, - PVFieldPtr const &pvMasterField, - BitSetPtr const &bitSet, - bool toCopy, - bool doAll) -{ - if(!doAll) { - doAll = bitSet->get(pvCopy->getFieldOffset()); - } - if(!doAll) { - size_t offset = pvCopy->getFieldOffset(); - size_t nextSet = bitSet->nextSetBit(offset); - if(nextSet==string::npos) return; - if(nextSet>=pvCopy->getNextFieldOffset()) return; - } - if(pvCopy->getField()->getType()==epics::pvData::structure) { - PVStructurePtr pvCopyStructure = - static_pointer_cast(pvCopy); - PVFieldPtrArray const & pvCopyFields = pvCopyStructure->getPVFields(); - if(pvMasterField->getField()->getType() !=epics::pvData::structure) - { - throw std::logic_error(string("Logic error")); - } - PVStructurePtr pvMasterStructure = - static_pointer_cast(pvMasterField); - PVFieldPtrArray const & pvMasterFields = - pvMasterStructure->getPVFields(); - for(size_t i=0; icopyUnchecked(*pvMasterField); - } else { - pvMasterField->copyUnchecked(*pvCopy); - } - } -} - -CopyMasterNodePtr PVCopy::getCopyOffset( - CopyStructureNodePtr const &structureNode, - PVFieldPtr const &masterPVField) -{ - size_t offset = masterPVField->getFieldOffset(); - CopyNodePtrArrayPtr nodes = structureNode->nodes; - for(size_t i=0; i< nodes->size(); i++) { - CopyNodePtr node = (*nodes)[i]; - if(!node->isStructure) { - CopyMasterNodePtr masterNode = - static_pointer_cast(node); - size_t off = masterNode->masterPVField->getFieldOffset(); - size_t nextOffset = masterNode->masterPVField->getNextFieldOffset(); - if(offset>= off && offset(node); - CopyMasterNodePtr masterNode = - getCopyOffset(subNode,masterPVField); - if(masterNode) return masterNode; - } - } - return CopyMasterNodePtr(); -} - -CopyMasterNodePtr PVCopy::getMasterNode( - CopyStructureNodePtr const &structureNode, - std::size_t structureOffset) -{ - CopyNodePtrArrayPtr nodes = structureNode->nodes; - for(size_t i=0; i< nodes->size(); i++) { - CopyNodePtr node = (*nodes)[i]; - if(structureOffset>=(node->structureOffset + node->nfields)) continue; - if(!node->isStructure) { - CopyMasterNodePtr masterNode = - static_pointer_cast(node); - return masterNode; - } - CopyStructureNodePtr subNode = - static_pointer_cast(node); - return getMasterNode(subNode,structureOffset); - } - return CopyMasterNodePtr(); -} - -}} diff --git a/testApp/copy/Makefile b/testApp/copy/Makefile index bee2227..4e043d5 100644 --- a/testApp/copy/Makefile +++ b/testApp/copy/Makefile @@ -6,8 +6,3 @@ TESTPROD_HOST += testCreateRequest testCreateRequest_SRCS = testCreateRequest.cpp testHarness_SRCS += testCreateRequest.cpp TESTS += testCreateRequest - -TESTPROD_HOST += testPVCopy -testPVCopy_SRCS += testPVCopy.cpp -testHarness_SRCS += testPVCopy.cpp -TESTS += testPVCopy diff --git a/testApp/copy/testPVCopy.cpp b/testApp/copy/testPVCopy.cpp deleted file mode 100644 index e81fc61..0000000 --- a/testApp/copy/testPVCopy.cpp +++ /dev/null @@ -1,299 +0,0 @@ -/*testPVCopyMain.cpp */ -/* - * Copyright information and license terms for this software can be - * found in the file LICENSE that is included with the distribution - */ -/** - * @author mrk - */ - -/* Author: Marty Kraimer */ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#undef EPICS_DEPRECATED -#define EPICS_DEPRECATED - -#include -#include -#include -#include -#include - - -using namespace std; -using std::tr1::static_pointer_cast; -using namespace epics::pvData; - -static void testPVScalar( - string const & valueNameMaster, - string const & valueNameCopy, - PVStructurePtr const & pvMaster, - PVCopyPtr const & pvCopy) -{ - PVStructurePtr pvStructureCopy; - PVScalarPtr pvValueMaster; - PVScalarPtr pvValueCopy; - BitSetPtr bitSet; - ConvertPtr convert = getConvert(); - - pvValueMaster = pvMaster->getSubField(valueNameMaster); - convert->fromDouble(pvValueMaster,.04); - StructureConstPtr structure = pvCopy->getStructure(); - pvStructureCopy = pvCopy->createPVStructure(); - pvValueCopy = pvStructureCopy->getSubField(valueNameCopy); - bitSet = BitSetPtr(new BitSet(pvStructureCopy->getNumberFields())); - pvCopy->initCopy(pvStructureCopy, bitSet); - - convert->fromDouble(pvValueMaster,.06); - testOk1(convert->toDouble(pvValueCopy)==.04); - pvCopy->updateCopySetBitSet(pvStructureCopy,bitSet); - testOk1(convert->toDouble(pvValueCopy)==.06); - testOk1(bitSet->get(pvValueCopy->getFieldOffset())); - - pvCopy->getCopyOffset(pvValueMaster); - - bitSet->clear(); - convert->fromDouble(pvValueMaster,1.0); - - bitSet->set(0); - testOk1(convert->toDouble(pvValueCopy)==0.06); - pvCopy->updateCopyFromBitSet(pvStructureCopy,bitSet); - testOk1(convert->toDouble(pvValueCopy)==1.0); - - convert->fromDouble(pvValueCopy,2.0); - bitSet->set(0); - - testOk1(convert->toDouble(pvValueMaster)==1.0); - pvCopy->updateMaster(pvStructureCopy,bitSet); - testOk1(convert->toDouble(pvValueMaster)==2.0); - -} - -static void testPVScalarArray( - string const & valueNameMaster, - string const & valueNameCopy, - PVStructurePtr const & pvMaster, - PVCopyPtr const & pvCopy) -{ - PVStructurePtr pvStructureCopy; - PVScalarArrayPtr pvValueMaster; - PVScalarArrayPtr pvValueCopy; - BitSetPtr bitSet; - size_t n = 5; - shared_vector values(n); - shared_vector cvalues; - - pvValueMaster = pvMaster->getSubField(valueNameMaster); - for(size_t i=0; i xxx(freeze(values)); - pvValueMaster->putFrom(xxx); - StructureConstPtr structure = pvCopy->getStructure(); - - pvStructureCopy = pvCopy->createPVStructure(); - pvValueCopy = pvStructureCopy->getSubField(valueNameCopy); - bitSet = BitSetPtr(new BitSet(pvStructureCopy->getNumberFields())); - pvCopy->initCopy(pvStructureCopy, bitSet); - - values.resize(n); - for(size_t i=0; i yyy(freeze(values)); - pvValueMaster->putFrom(yyy); - pvValueCopy->getAs(cvalues); - testOk1(cvalues[0]==0.0); - pvCopy->updateCopySetBitSet(pvStructureCopy,bitSet); - pvValueCopy->getAs(cvalues); - testOk1(cvalues[0]==0.06); - - pvCopy->getCopyOffset(pvValueMaster); - - bitSet->clear(); - values.resize(n); - for(size_t i=0; i zzz(freeze(values)); - pvValueMaster->putFrom(zzz); - - bitSet->set(0); - pvValueCopy->getAs(cvalues); - testOk1(cvalues[0]==0.06); - pvCopy->updateCopyFromBitSet(pvStructureCopy,bitSet); - pvValueCopy->getAs(cvalues); - testOk1(cvalues[0]==1.0); - - values.resize(n); - for(size_t i=0; i ttt(freeze(values)); - pvValueMaster->putFrom(ttt); - bitSet->set(0); - - pvValueMaster->getAs(cvalues); - testOk1(cvalues[0]==2.0); - pvCopy->updateMaster(pvStructureCopy,bitSet); - pvValueMaster->getAs(cvalues); - testOk1(cvalues[0]==1.0); -} - -static void scalarTest() -{ - testDiag("scalarTest()"); - PVStructurePtr pvMaster; - string request; - PVStructurePtr pvRequest; - PVFieldPtr pvMasterField; - PVCopyPtr pvCopy; - string valueNameMaster; - string valueNameCopy; - - StandardPVFieldPtr standardPVField = getStandardPVField(); - pvMaster = standardPVField->scalar(pvDouble,"alarm,timeStamp,display"); - - valueNameMaster = request = "value"; - CreateRequest::shared_pointer createRequest = CreateRequest::create(); - pvRequest = createRequest->createRequest(request); - pvCopy = PVCopy::create(pvMaster,pvRequest,""); - valueNameCopy = "value"; - testPVScalar(valueNameMaster,valueNameCopy,pvMaster,pvCopy); - request = ""; - valueNameMaster = "value"; - pvRequest = createRequest->createRequest(request); - - pvCopy = PVCopy::create(pvMaster,pvRequest,""); - valueNameCopy = "value"; - testPVScalar(valueNameMaster,valueNameCopy,pvMaster,pvCopy); - request = "alarm,timeStamp,value"; - valueNameMaster = "value"; - pvRequest = createRequest->createRequest(request); - - pvCopy = PVCopy::create(pvMaster,pvRequest,""); - valueNameCopy = "value"; - testPVScalar(valueNameMaster,valueNameCopy,pvMaster,pvCopy); -} - -static void arrayTest() -{ - testDiag("arrayTest"); - - PVStructurePtr pvMaster; - string request; - PVStructurePtr pvRequest; - PVFieldPtr pvMasterField; - PVCopyPtr pvCopy; - string valueNameMaster; - string valueNameCopy; - - CreateRequest::shared_pointer createRequest = CreateRequest::create(); - StandardPVFieldPtr standardPVField = getStandardPVField(); - pvMaster = standardPVField->scalarArray(pvDouble,"alarm,timeStamp"); - valueNameMaster = request = "value"; - pvRequest = createRequest->createRequest(request); - - pvCopy = PVCopy::create(pvMaster,pvRequest,""); - valueNameCopy = "value"; - testPVScalarArray(valueNameMaster,valueNameCopy,pvMaster,pvCopy); - request = ""; - valueNameMaster = "value"; - pvRequest = createRequest->createRequest(request); - - pvCopy = PVCopy::create(pvMaster,pvRequest,""); - valueNameCopy = "value"; - testPVScalarArray(valueNameMaster,valueNameCopy,pvMaster,pvCopy); - request = "alarm,timeStamp,value"; - valueNameMaster = "value"; - pvRequest = createRequest->createRequest(request); - - pvCopy = PVCopy::create(pvMaster,pvRequest,""); - valueNameCopy = "value"; - testPVScalarArray(valueNameMaster,valueNameCopy,pvMaster,pvCopy); -} - -static PVStructurePtr createPowerSupply() -{ - FieldCreatePtr fieldCreate = getFieldCreate(); - StandardFieldPtr standardField = getStandardField(); - PVDataCreatePtr pvDataCreate = getPVDataCreate(); - - size_t nfields = 5; - StringArray names; - names.reserve(nfields); - FieldConstPtrArray powerSupply; - powerSupply.reserve(nfields); - names.push_back("alarm"); - powerSupply.push_back(standardField->alarm()); - names.push_back("timeStamp"); - powerSupply.push_back(standardField->timeStamp()); - string properties("alarm,display"); - names.push_back("voltage"); - powerSupply.push_back(standardField->scalar(pvDouble,properties)); - names.push_back("power"); - powerSupply.push_back(standardField->scalar(pvDouble,properties)); - names.push_back("current"); - powerSupply.push_back(standardField->scalar(pvDouble,properties)); - return pvDataCreate->createPVStructure( - fieldCreate->createStructure(names,powerSupply)); -} - - - -static void powerSupplyTest() -{ - testDiag("powerSupplyTest"); - - PVStructurePtr pvMaster; - string request; - PVStructurePtr pvRequest; - PVFieldPtr pvMasterField; - PVCopyPtr pvCopy; - string builder; - string valueNameMaster; - string valueNameCopy; - - CreateRequest::shared_pointer createRequest = CreateRequest::create(); - pvMaster = createPowerSupply(); - valueNameMaster = request = "power.value"; - pvRequest = createRequest->createRequest(request); - - pvCopy = PVCopy::create(pvMaster,pvRequest,""); - valueNameCopy = "power.value"; - testPVScalar(valueNameMaster,valueNameCopy,pvMaster,pvCopy); - request = ""; - valueNameMaster = "power.value"; - pvRequest = createRequest->createRequest(request); - - pvCopy = PVCopy::create(pvMaster,pvRequest,""); - valueNameCopy = "power.value"; - testPVScalar(valueNameMaster,valueNameCopy,pvMaster,pvCopy); - request = "alarm,timeStamp,voltage.value,power.value,current.value"; - valueNameMaster = "power.value"; - pvRequest = createRequest->createRequest(request); - - pvCopy = PVCopy::create(pvMaster,pvRequest,""); - valueNameCopy = "power.value"; - testPVScalar(valueNameMaster,valueNameCopy,pvMaster,pvCopy); - request = "alarm,timeStamp,voltage{value,alarm},power{value,alarm,display},current.value"; - valueNameMaster = "power.value"; - pvRequest = createRequest->createRequest(request); - - pvCopy = PVCopy::create(pvMaster,pvRequest,""); - valueNameCopy = "power.value"; - testPVScalar(valueNameMaster,valueNameCopy,pvMaster,pvCopy); -} - -MAIN(testPVCopy) -{ - testPlan(67); - scalarTest(); - arrayTest(); - powerSupplyTest(); - return testDone(); -} - diff --git a/testApp/pvDataAllTests.c b/testApp/pvDataAllTests.c index 0a07c83..ad0f1f1 100644 --- a/testApp/pvDataAllTests.c +++ b/testApp/pvDataAllTests.c @@ -16,7 +16,6 @@ /* copy */ int testCreateRequest(void); -int testPVCopy(void); /* misc */ int testBaseException(void); @@ -81,7 +80,6 @@ void pvDataAllTests(void) /* copy */ runTest(testCreateRequest); - runTest(testPVCopy); /* property */ runTest(testCreateRequest);