std::ostream& PVStructure::dumpValue(std::ostream& o) const { o << format::indent() << getStructure()->getID() << ' ' << getFieldName(); String extendsName = getExtendsStructureName(); if(extendsName.length()>0) { o << " extends " << extendsName; } o << std::endl; { format::indent_scope s(o); PVFieldPtrArray const & fieldsData = getPVFields(); if (fieldsData.size() != 0) { size_t length = getStructure()->getNumberFields(); for(size_t i=0; i<length; i++) { PVFieldPtr fieldField = fieldsData[i]; Type type = fieldField->getField()->getType(); if (type == scalar || type == scalarArray) o << format::indent() << fieldField->getField()->getID() << ' ' << fieldField->getFieldName() << ' ' << *(fieldField.get()) << std::endl; else o << *(fieldField.get()); } } } return o; }
PVScalarArrayPtr PVStructure::getScalarArrayField( String const &fieldName,ScalarType elementType) { PVFieldPtr pvField = findSubField(fieldName,this); if(pvField.get()==NULL) { String message("fieldName "); message += fieldName + " does not exist"; this->message(message, errorMessage); return nullPVScalarArray; } FieldConstPtr field = pvField->getField(); Type type = field->getType(); if(type!=scalarArray) { String message("fieldName "); message += fieldName + " does not have type array "; this->message(message, errorMessage); return nullPVScalarArray; } ScalarArrayConstPtr pscalarArray = static_pointer_cast<const ScalarArray>(pvField->getField()); if(pscalarArray->getElementType()!=elementType) { String message("fieldName "); message += fieldName + " is array but does not have elementType "; ScalarTypeFunc::toString(&message,elementType); this->message(message, errorMessage); return nullPVScalarArray; } return std::tr1::static_pointer_cast<PVScalarArray>(pvField); }
bool NTMultiChannel::isCompatible(PVStructurePtr const &pvStructure) { if(!pvStructure) return false; PVUnionArrayPtr pvValue = pvStructure->getSubField<PVUnionArray>("value"); if(!pvValue) return false; PVFieldPtr pvField = pvStructure->getSubField("descriptor"); if(pvField && !pvStructure->getSubField<PVString>("descriptor")) return false; pvField = pvStructure->getSubField("alarm"); if(pvField && !ntField->isAlarm(pvField->getField())) return false; pvField = pvStructure->getSubField("timeStamp"); if(pvField && !ntField->isTimeStamp(pvField->getField())) return false; pvField = pvStructure->getSubField("severity"); if(pvField && !pvStructure->getSubField<PVIntArray>("severity")) return false; pvField = pvStructure->getSubField("status"); if(pvField && !pvStructure->getSubField<PVIntArray>("status")) return false; pvField = pvStructure->getSubField("message"); if(pvField && !pvStructure->getSubField<PVStringArray>("message")) return false; pvField = pvStructure->getSubField("secondsPastEpoch"); if(pvField && !pvStructure->getSubField<PVLongArray>("secondsPastEpoch")) return false; pvField = pvStructure->getSubField("nanoseconds"); if(pvField && !pvStructure->getSubField<PVIntArray>("nanoseconds")) return false; pvField = pvStructure->getSubField("userTag"); if(pvField && !pvStructure->getSubField<PVIntArray>("userTag")) return false; return true; }
bool NTTable::isCompatible(PVStructurePtr const & pvStructure) { if(!pvStructure) return false; PVFieldPtr pvField = pvStructure->getSubField("alarm"); if(pvField && !ntField->isAlarm(pvField->getField())) return false; pvField = pvStructure->getSubField("timeStamp"); if(pvField && !ntField->isTimeStamp(pvField->getField())) return false; PVStringArrayPtr pvLabel = pvStructure->getSubField<PVStringArray>("labels"); if(!pvLabel) return false; return true; }
void PVRecordStructure::init() { PVRecordField::init(); const PVFieldPtrArray & pvFields = pvStructure.lock()->getPVFields(); size_t numFields = pvFields.size(); pvRecordFields->reserve( numFields); PVRecordStructurePtr self = static_pointer_cast<PVRecordStructure>(shared_from_this()); PVRecordPtr pvRecord = getPVRecord(); for(size_t i=0; i<numFields; i++) { PVFieldPtr pvField = pvFields[i]; if(pvField->getField()->getType()==structure) { PVStructurePtr xxx = static_pointer_cast<PVStructure>(pvField); PVRecordStructurePtr pvRecordStructure( new PVRecordStructure(xxx,self,pvRecord)); pvRecordFields->push_back(pvRecordStructure); pvRecordStructure->init(); } else { PVRecordFieldPtr pvRecordField( new PVRecordField(pvField,self,pvRecord)); pvRecordFields->push_back(pvRecordField); pvRecordField->init(); } } }
string PvaClientData::getString() { if(PvaClient::getDebug()) cout << "PvaClientData::getString\n"; PVScalarPtr pvScalar; PVStructurePtr pvStructure = getPVStructure(); PVFieldPtr pvValue = pvStructure->getSubField("value"); if(pvValue) { Type type = pvValue->getField()->getType(); if(type==scalar) pvScalar = static_pointer_cast<PVScalar>(pvValue); } if(!pvScalar) { while(true) { const PVFieldPtrArray fieldPtrArray(pvStructure->getPVFields()); if(fieldPtrArray.size()!=1) { throw std::logic_error( "PvaClientData::getString() pvRequest for multiple fields"); } PVFieldPtr pvField(fieldPtrArray[0]); Type type = pvField->getField()->getType(); if(type==scalar) { pvScalar = static_pointer_cast<PVScalar>(pvField); break; } if(pvField->getField()->getType()!=epics::pvData::structure) break; pvStructure = static_pointer_cast<PVStructure>(pvField); } } if(!pvScalar) { throw std::logic_error( "PvaClientData::getString() did not find a scalar field"); } return convert->toString(pvScalar); }
static PVFieldPtr findSubField( String const & fieldName, PVStructure const *pvStructure) { if( fieldName.length()<1) return PVFieldPtr(); String::size_type index = fieldName.find('.'); String name = fieldName; String restOfName = String(); if(index>0) { name = fieldName.substr(0, index); if(fieldName.length()>index) { restOfName = fieldName.substr(index+1); } } PVFieldPtrArray pvFields = pvStructure->getPVFields(); PVFieldPtr pvField; size_t numFields = pvStructure->getStructure()->getNumberFields(); for(size_t i=0; i<numFields; i++) { pvField = pvFields[i]; size_t result = pvField->getFieldName().compare(name); if(result==0) { if(restOfName.length()==0) return pvFields[i]; if(pvField->getField()->getType()!=structure) return PVFieldPtr(); PVStructurePtr pvStructure = std::tr1::static_pointer_cast<PVStructure>(pvField); return findSubField(restOfName,pvStructure.get()); } } return PVFieldPtr(); }
static PyObject * _getColumn(PyObject *willbenull, PyObject *args) { PyObject *pcapsule = 0; const char *name = 0; if(!PyArg_ParseTuple(args,"Os:nttablePy", &pcapsule, &name)) { PyErr_SetString(PyExc_SyntaxError, "Bad argument. Expected (pvt,index)"); return NULL; } void *pvoid = PyCapsule_GetPointer(pcapsule,"nttablePvt"); if(pvoid==0) { PyErr_SetString(PyExc_SyntaxError, "first arg must be return from _init"); return NULL; } NTTablePvt *pvt = static_cast<NTTablePvt *>(pvoid); PVFieldPtr pvField = pvt->nttable->getColumn(name); Type type = pvField->getField()->getType(); if(type!=scalarArray) { PyErr_SetString(PyExc_SyntaxError, "logic error. Why is a column not a scalarArray?"); return NULL; } PVScalarArrayPtr pvScalarArray = static_pointer_cast<PVScalarArray>(pvField); return getScalarArrayValue(pvScalarArray); }
bool NTScalar::isCompatible(PVStructurePtr const & pvStructure) { if(!pvStructure) return false; PVScalarPtr pvValue = pvStructure->getSubField<PVScalar>("value"); if(!pvValue) return false; PVFieldPtr pvField = pvStructure->getSubField("descriptor"); if(pvField && !pvStructure->getSubField<PVString>("descriptor")) return false; pvField = pvStructure->getSubField("alarm"); if(pvField && !ntField->isAlarm(pvField->getField())) return false; pvField = pvStructure->getSubField("timeStamp"); if(pvField && !ntField->isTimeStamp(pvField->getField())) return false; pvField = pvStructure->getSubField("display"); if(pvField && !ntField->isDisplay(pvField->getField())) return false; pvField = pvStructure->getSubField("control"); if(pvField && !ntField->isControl(pvField->getField())) return false; return true; }
PVRecordField::PVRecordField( PVFieldPtr const & pvField, PVRecordStructurePtr const &parent, PVRecordPtr const & pvRecord) : pvField(pvField), isStructure(pvField->getField()->getType()==structure ? true : false), parent(parent), pvRecord(pvRecord) { }
PVStringPtr PVStructure::getStringField(String const &fieldName) { PVFieldPtr pvField = findSubField(fieldName,this); if(pvField.get()==NULL) { String message("fieldName "); message += fieldName + " does not exist"; this->message(message, errorMessage); return nullPVString; } if(pvField->getField()->getType()==scalar) { ScalarConstPtr pscalar = static_pointer_cast<const Scalar>( pvField->getField()); if(pscalar->getScalarType()==pvString) { return std::tr1::static_pointer_cast<PVString>(pvField); } } String message("fieldName "); message += fieldName + " does not have type string "; this->message(message, errorMessage); return nullPVString; }
PVFieldPtr PVDataCreate::createPVField(PVFieldPtr const & fieldToClone) { switch(fieldToClone->getField()->getType()) { case scalar: { PVScalarPtr pvScalar = static_pointer_cast<PVScalar>(fieldToClone); return createPVScalar(pvScalar); } case scalarArray: { PVScalarArrayPtr pvScalarArray = static_pointer_cast<PVScalarArray>(fieldToClone); return createPVScalarArray(pvScalarArray); } case structure: { PVStructurePtr pvStructure = static_pointer_cast<PVStructure>(fieldToClone); StringArray const & fieldNames = pvStructure->getStructure()->getFieldNames(); PVFieldPtrArray const & pvFieldPtrArray = pvStructure->getPVFields(); return createPVStructure(fieldNames,pvFieldPtrArray); } case structureArray: { PVStructureArrayPtr from = static_pointer_cast<PVStructureArray>(fieldToClone); StructureArrayConstPtr structureArray = from->getStructureArray(); PVStructureArrayPtr to = createPVStructureArray( structureArray); to->copyUnchecked(*from); return to; } case union_: { PVUnionPtr pvUnion = static_pointer_cast<PVUnion>(fieldToClone); return createPVUnion(pvUnion); } case unionArray: { PVUnionArrayPtr from = static_pointer_cast<PVUnionArray>(fieldToClone); UnionArrayConstPtr unionArray = from->getUnionArray(); PVUnionArrayPtr to = createPVUnionArray(unionArray); to->copyUnchecked(*from); return to; } } throw std::logic_error("PVDataCreate::createPVField should never get here"); }
bool PVEnumerated::attach(PVFieldPtr const & pvField) { if(pvField->getField()->getType()!=structure) return false; PVStructurePtr pvStructure = static_pointer_cast<PVStructure>(pvField); pvIndex = pvStructure->getSubField<PVInt>("index"); if(pvIndex.get()==NULL) return false; PVStringArrayPtr pvStringArray = pvStructure->getSubField<PVStringArray>("choices"); if(pvStringArray.get()==NULL) { pvIndex.reset(); return false; } pvChoices = pvStringArray; return true; }
PVStructurePtr PVStructure::getStructureField(String const &fieldName) { PVFieldPtr pvField = findSubField(fieldName,this); if(pvField.get()==NULL) { String message("fieldName "); message += fieldName + " does not exist"; this->message(message, errorMessage); return nullPVStructure; } if(pvField->getField()->getType()==structure) { return std::tr1::static_pointer_cast<PVStructure>(pvField); } String message("fieldName "); message += fieldName + " does not have type structure "; this->message(message, errorMessage); return nullPVStructure; }
void PVStructure::appendPVField( String const &fieldName, PVFieldPtr const & pvField) { size_t origLength = pvFields.size(); size_t newLength = origLength+1; PVFieldPtrArray * xxx = const_cast<PVFieldPtrArray *>(&pvFields); xxx->push_back(pvField); FieldConstPtr field = getFieldCreate()->appendField( structurePtr,fieldName,pvField->getField()); replaceField(field); structurePtr = static_pointer_cast<const Structure>(field); StringArray fieldNames = structurePtr->getFieldNames(); for(size_t i=0; i<newLength; i++) { pvFields[i]->setParentAndName(this,fieldNames[i]); } fixParentStructure(); }
PVFieldPtr PVStructure::getSubField(size_t fieldOffset) const { if(fieldOffset<=getFieldOffset()) { return nullPVField; } if(fieldOffset>getNextFieldOffset()) return nullPVField; size_t numFields = pvFields.size(); for(size_t i=0; i<numFields; i++) { PVFieldPtr pvField = pvFields[i]; if(pvField->getFieldOffset()==fieldOffset) return pvFields[i]; if(pvField->getNextFieldOffset()<=fieldOffset) continue; if(pvField->getField()->getType()==structure) { PVStructure *pvStructure = static_cast<PVStructure *>(pvField.get()); return pvStructure->getSubField(fieldOffset); } } throw std::logic_error("PVStructure.getSubField: Logic error"); }
bool PVAlarm::attach(PVFieldPtr const & pvField) { if(pvField->getField()->getType()!=structure) return false; PVStructurePtr pvStructure = static_pointer_cast<PVStructure>(pvField); pvSeverity = pvStructure->getIntField("severity"); if(pvSeverity.get()==NULL) return false; pvStatus = pvStructure->getIntField("status"); if(pvStatus.get()==NULL) { pvSeverity.reset(); return false; } pvMessage = pvStructure->getStringField("message"); if(pvMessage.get()==NULL) { pvSeverity.reset(); pvStatus.reset(); return false; } return true; }
void ChannelLocal::getField(GetFieldRequester::shared_pointer const &requester, string const &subField) { if(subField.size()<1) { StructureConstPtr structure = pvRecord->getPVRecordStructure()->getPVStructure()->getStructure(); requester->getDone(Status::Ok,structure); return; } PVFieldPtr pvField = pvRecord->getPVRecordStructure()->getPVStructure()->getSubField(subField); if(pvField) { requester->getDone(Status::Ok,pvField->getField()); return; } Status status(Status::STATUSTYPE_ERROR, "client asked for illegal field"); requester->getDone(status,FieldConstPtr()); }
shared_vector<const double> PvaClientData::getDoubleArray() { if(PvaClient::getDebug()) cout << "PvaClientData::getDoubleArray\n"; PVScalarArrayPtr pvScalarArray; PVStructurePtr pvStructure = getPVStructure(); PVFieldPtr pvValue = pvStructure->getSubField("value"); if(pvValue) { Type type = pvValue->getField()->getType(); if(type==scalarArray) { pvScalarArray = static_pointer_cast<PVScalarArray>(pvValue); } } if(!pvScalarArray) { while(true) { const PVFieldPtrArray fieldPtrArray(pvStructure->getPVFields()); if(fieldPtrArray.size()!=1) { throw std::logic_error( "PvaClientData::getDoubleArray() pvRequest for multiple fields"); } PVFieldPtr pvField(fieldPtrArray[0]); Type type = pvField->getField()->getType(); if(type==scalarArray) { pvScalarArray = static_pointer_cast<PVScalarArray>(pvField); break; } if(pvField->getField()->getType()!=epics::pvData::structure) break; pvStructure = static_pointer_cast<PVStructure>(pvField); } } if(!pvScalarArray) { throw std::logic_error( "PvaClientData::getDoubleArray() did not find a scalarArray field"); } ScalarType scalarType = pvScalarArray->getScalarArray()->getElementType(); if(!ScalarTypeFunc::isNumeric(scalarType)) { throw std::logic_error( "PvaClientData::getDoubleArray() did not find a numeric scalarArray field"); } shared_vector<const double> retValue; pvScalarArray->getAs<const double>(retValue); return retValue; }
size_t Convert::fromString(PVStructurePtr const &pvStructure, StringArray const & from, size_t fromStartIndex) { size_t processed = 0; PVFieldPtrArray const & fieldsData = pvStructure->getPVFields(); if (fieldsData.size() != 0) { size_t length = pvStructure->getStructure()->getNumberFields(); for(size_t i=0; i<length; i++) { PVFieldPtr fieldField = fieldsData[i]; Type type = fieldField->getField()->getType(); if(type==structure) { PVStructurePtr pv = static_pointer_cast<PVStructure>(fieldField); size_t count = fromString(pv, from, fromStartIndex); processed += count; fromStartIndex += count; } else if(type==scalarArray) { PVScalarArrayPtr pv = static_pointer_cast<PVScalarArray>(fieldField); size_t count = fromString(pv, from[fromStartIndex]); processed += count; fromStartIndex += count; } else if(type==scalar) { PVScalarPtr pv = static_pointer_cast<PVScalar>(fieldField); fromString(pv, from[fromStartIndex++]); processed++; } else { // union, structureArray, unionArray not supported std::ostringstream oss; oss << "Convert::fromString unsupported fieldType " << type; throw std::logic_error(oss.str()); } } } return processed; }
bool PVTimeStamp::attach(PVFieldPtr const & pvField) { if(pvField->getField()->getType()!=structure) return false; PVStructurePtr xxx = static_pointer_cast<PVStructure>(pvField); PVStructure* pvStructure = xxx.get(); while(true) { PVLongPtr pvLong = pvStructure->getLongField("secondsPastEpoch"); if(pvLong.get()!=NULL) { pvSecs = pvLong; pvNano = pvStructure->getIntField("nanoseconds"); pvUserTag = pvStructure->getIntField("userTag"); } if(pvSecs.get()!=NULL && pvNano.get()!=NULL && pvUserTag.get()!=NULL) return true; detach(); // look up the tree for a timeSyamp pvStructure = pvStructure->getParent(); if(pvStructure==NULL) break; } return false; }
bool PVDisplay::attach(PVFieldPtr const & pvField) { if(pvField->getField()->getType()!=structure) { pvField->message(noDisplayFound,errorMessage); return false; } PVStructurePtr pvStructure = static_pointer_cast<PVStructure>(pvField); pvDescription = pvStructure->getStringField("description"); if(pvDescription.get()==NULL) { pvField->message(noDisplayFound,errorMessage); return false; } pvFormat = pvStructure->getStringField("format"); if(pvFormat.get()==NULL) { pvField->message(noDisplayFound,errorMessage); detach(); return false; } pvUnits = pvStructure->getStringField("units"); if(pvUnits.get()==NULL) { pvField->message(noDisplayFound,errorMessage); detach(); return false; } pvLow = pvStructure->getDoubleField(String("limitLow")); if(pvLow.get()==NULL) { pvField->message(noDisplayFound,errorMessage); detach(); return false; } pvHigh = pvStructure->getDoubleField(String("limitHigh")); if(pvHigh.get()==NULL) { pvField->message(noDisplayFound,errorMessage); detach(); return false; } return true; }
ChannelArrayLocalPtr ChannelArrayLocal::create( ChannelLocalPtr const &channelLocal, ChannelArrayRequester::shared_pointer const & channelArrayRequester, PVStructurePtr const & pvRequest, PVRecordPtr const &pvRecord) { PVFieldPtrArray const & pvFields = pvRequest->getPVFields(); if(pvFields.size()!=1) { Status status( Status::STATUSTYPE_ERROR,"invalid pvRequest"); ChannelArrayLocalPtr channelArray; ArrayConstPtr array; channelArrayRequester->channelArrayConnect(status,channelArray,array); return channelArray; } PVFieldPtr pvField = pvFields[0]; string fieldName(""); while(true) { string name = pvField->getFieldName(); if(fieldName.size()>0) fieldName += '.'; fieldName += name; PVStructurePtr pvs = static_pointer_cast<PVStructure>(pvField); PVFieldPtrArray const & pvfs = pvs->getPVFields(); if(pvfs.size()!=1) break; pvField = pvfs[0]; } size_t indfield = fieldName.find_first_of("field."); if(indfield==0) { fieldName = fieldName.substr(6); } pvField = pvRecord->getPVRecordStructure()->getPVStructure()->getSubField(fieldName); if(!pvField) { Status status( Status::STATUSTYPE_ERROR,fieldName +" not found"); ChannelArrayLocalPtr channelArray; ArrayConstPtr array; channelArrayRequester->channelArrayConnect( status,channelArray,array); return channelArray; } if(pvField->getField()->getType()!=scalarArray && pvField->getField()->getType()!=structureArray && pvField->getField()->getType()!=unionArray) { Status status( Status::STATUSTYPE_ERROR,fieldName +" not array"); ChannelArrayLocalPtr channelArray; ArrayConstPtr array; channelArrayRequester->channelArrayConnect( status,channelArray,array); return channelArray; } PVArrayPtr pvArray = static_pointer_cast<PVArray>(pvField); PVArrayPtr pvCopy; if(pvField->getField()->getType()==scalarArray) { PVScalarArrayPtr xxx = static_pointer_cast<PVScalarArray>(pvField); pvCopy = getPVDataCreate()->createPVScalarArray( xxx->getScalarArray()->getElementType()); } else if(pvField->getField()->getType()==structureArray) { PVStructureArrayPtr xxx = static_pointer_cast<PVStructureArray>(pvField); pvCopy = getPVDataCreate()->createPVStructureArray( xxx->getStructureArray()->getStructure()); } else { PVUnionArrayPtr xxx = static_pointer_cast<PVUnionArray>(pvField); pvCopy = getPVDataCreate()->createPVUnionArray( xxx->getUnionArray()->getUnion()); } ChannelArrayLocalPtr array(new ChannelArrayLocal( channelLocal, channelArrayRequester, pvArray, pvCopy, pvRecord)); if(pvRecord->getTraceLevel()>0) { cout << "ChannelArrayLocal::create"; cout << " recordName " << pvRecord->getRecordName() << endl; } channelArrayRequester->channelArrayConnect( Status::Ok, array, pvCopy->getArray()); return array; }