Example #1
0
void PVField::computeOffset(const PVField   *  pvField) {
    const PVStructure * pvTop = pvField->getParent();
    if(pvTop==NULL) {
        if(pvField->getField()->getType()!=structure) {
           PVField *xxx = const_cast<PVField *>(pvField);
           xxx->fieldOffset = 0;
           xxx->nextFieldOffset = 1;
           return;
        }
        pvTop = static_cast<const PVStructure *>(pvField);
    } else {
        while(pvTop->getParent()!=NULL) pvTop = pvTop->getParent();
    }
    size_t offset = 0;
    size_t nextOffset = 1;
    PVFieldPtrArray  pvFields = pvTop->getPVFields();
    for(size_t i=0; i < pvTop->getStructure()->getNumberFields(); i++) {
        offset = nextOffset;
        PVField *pvField = pvFields[i].get();
        FieldConstPtr field = pvField->getField();
        switch(field->getType()) {
        case scalar:
        case scalarArray:
        case structureArray:
        case union_:
        case unionArray: {
            nextOffset++;
            pvField->fieldOffset = offset;
            pvField->nextFieldOffset = nextOffset;
            break;
        }
        case structure: {
            pvField->computeOffset(pvField,offset);
            nextOffset = pvField->getNextFieldOffset();
        }
        }
    }
    PVField *top = (PVField *)pvTop;
    PVField *xxx = const_cast<PVField *>(top);
    xxx->fieldOffset = 0;
    xxx->nextFieldOffset = nextOffset;
}
void Union::dumpFields(std::ostream& o) const
{
    size_t numberFields = fields.size();
    for(size_t i=0; i<numberFields; i++) {
        FieldConstPtr pfield = fields[i];
        o << format::indent() << pfield->getID() << ' ' << fieldNames[i] << std::endl;
        switch(pfield->getType()) {
            case scalar:
            case scalarArray:
                break;
            case structure:
            {
                Field const *xxx = pfield.get();
                Structure const *pstruct = static_cast<Structure const*>(xxx);
                format::indent_scope s(o);
                pstruct->dumpFields(o);
                break;
            }
            case structureArray:
            {
                format::indent_scope s(o);
                o << *pfield;
                break;
            }
            case union_:
            {
                Field const *xxx = pfield.get();
                Union const *punion = static_cast<Union const*>(xxx);
                format::indent_scope s(o);
                punion->dumpFields(o);
                break;
            }
            case unionArray:
            {
                format::indent_scope s(o);
                o << *pfield;
                break;
            }
        }
    }
}
bool NTAttribute::isCompatible(StructureConstPtr const & structure)
{
    if (structure.get() == 0) return false;

    ScalarConstPtr nameField = structure->getField<Scalar>("name");
    if (nameField.get() == 0 || nameField->getScalarType() != pvString)
        return false;

    UnionConstPtr valueField = structure->getField<Union>("value");
    if (valueField.get() == 0 || !valueField->isVariant())
        return false;

    FieldConstPtr field = structure->getField("tags");
    if (field.get())
    {
        ScalarArrayConstPtr tagsField = structure->getField<ScalarArray>("tags");
        if (tagsField.get() == 0 || tagsField->getElementType() != pvString)
            return false;
    }

    field = structure->getField("descriptor");
    if (field.get())
    {
        ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor");
        if (!descriptorField.get() || descriptorField->getScalarType() != pvString)
            return false;
    }

    NTFieldPtr ntField = NTField::get();

    field = structure->getField("alarm");
    if (field.get() && !ntField->isAlarm(field))
        return false;

    field = structure->getField("timeStamp");
    if (field.get() && !ntField->isTimeStamp(field))
        return false;

    return true;
}
bool NTMatrix::isCompatible(StructureConstPtr const & structure)
{
    if (structure.get() == 0) return false;

    ScalarArrayConstPtr valueField = structure->getField<ScalarArray>("value");
    if (valueField.get() == 0 || valueField->getElementType() != pvDouble)
        return false;

    FieldConstPtr field = structure->getField("dim");
    if (field.get())
    {
        ScalarArrayConstPtr dimField = structure->getField<ScalarArray>("dim");
        if (dimField.get() == 0 || dimField->getElementType() != pvInt)
            return false;
    }

    field = structure->getField("descriptor");
    if (field.get())
    {
        ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor");
        if (!descriptorField.get() || descriptorField->getScalarType() != pvString)
            return false;
    }

    NTFieldPtr ntField = NTField::get();

    field = structure->getField("alarm");
    if (field.get() && !ntField->isAlarm(field))
        return false;

    field = structure->getField("timeStamp");
    if (field.get() && !ntField->isTimeStamp(field))
        return false;

    field = structure->getField("display");
    if (field.get() && !ntField->isDisplay(field))
        return false;

    return true;
}
Example #5
0
void testSerializeCommon(FieldConstPtr serverField1, FieldConstPtr clientField2)
{
	//server serializes field 1
	serialize(serverField1,serverRegistry);

	//full should be serialized
	buffer->flip();
	checkTypeCode(IntrospectionRegistry::FULL_WITH_ID_TYPE_CODE);

	//client deserializes 1
	FieldConstPtr clientField1 = deserialize(clientRegistry);
	assert(serverField1->getFieldName() == clientField1->getFieldName());
	assert(serverField1->getType() == clientField1->getType());

	//client serializes the same field
	serialize(serverField1,clientRegistry);

	//only id should be serialized
	buffer->flip();
	checkTypeCode(IntrospectionRegistry::ONLY_ID_TYPE_CODE);

	//server deserializes the same field
	serverField1 = deserialize(serverRegistry);
	assert(serverField1->getFieldName() == clientField1->getFieldName());
	assert(serverField1->getType() == clientField1->getType());

	//client requests new field
	serialize(clientField2,clientRegistry);

	//full should be serialized
	buffer->flip();
	checkTypeCode(IntrospectionRegistry::FULL_WITH_ID_TYPE_CODE);

	//server deserializes new field
	FieldConstPtr serverField2 = deserialize(serverRegistry);
	assert(serverField2->getFieldName() == clientField2->getFieldName());
	assert(serverField2->getType() == clientField2->getType());
}
Example #6
0
bool NTScalar::isCompatible(StructureConstPtr const &structure)
{
    if (structure.get() == 0) return false;

    ScalarConstPtr valueField = structure->getField<Scalar>("value");
    if (valueField.get() == 0)
        return false;

    FieldConstPtr field = structure->getField("descriptor");
    if (field.get())
    {
        ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor");
        if (!descriptorField.get() || descriptorField->getScalarType() != pvString)
            return false;
    }

    NTFieldPtr ntField = NTField::get();

    field = structure->getField("alarm");
    if (field.get() && !ntField->isAlarm(field))
        return false;

    field = structure->getField("timeStamp");
    if (field.get() && !ntField->isTimeStamp(field))
        return false;

    field = structure->getField("display");
    if (field.get() && !ntField->isDisplay(field))
        return false;

    field = structure->getField("control");
    if (field.get() && !ntField->isControl(field))
        return false;

    return true;
}
bool NTNDArray::isCompatible(StructureConstPtr const &structure)
{
    if(!structure.get()) return false;

    UnionConstPtr valueField = structure->getField<Union>("value");
    if(!NTValueType::isCompatible(valueField)) return false;

    StructureConstPtr codecField = structure->getField<Structure>("codec");
    if(!NTCodec::isCompatible(codecField)) return false;

    ScalarConstPtr compressedSizeField = structure->getField<Scalar>("compressedSize");
    if (compressedSizeField.get() == 0)
        return false;

    if (compressedSizeField->getScalarType() != pvLong)
        return false;


    ScalarConstPtr uncompressedSizeField = structure->getField<Scalar>("uncompressedSize");
    if (uncompressedSizeField.get() == 0)
        return false;

    if (uncompressedSizeField->getScalarType() != pvLong)
        return false;

    StructureArrayConstPtr dimensionField = structure->getField<StructureArray>("dimension");
    if (dimensionField.get() == 0)
        return false;
    StructureConstPtr dimElementStruc = dimensionField->getStructure();

    if(!NTDimension::isCompatible(dimElementStruc))
       return false;

    NTFieldPtr ntField = NTField::get();

    StructureConstPtr dataTimeStampField = structure->getField<Structure>(
        "dataTimeStamp");
    if (dataTimeStampField.get() == 0 || !ntField->isTimeStamp(dataTimeStampField))
        return false;


    ScalarConstPtr uniqueIdField = structure->getField<Scalar>("uniqueId");
    if (uniqueIdField.get() == 0)
        return false;

    if (uniqueIdField->getScalarType() != pvInt)
        return false;


    StructureArrayConstPtr attributeField = structure->getField<StructureArray>( "attribute");

    StructureConstPtr attributeElementStruc = attributeField->getStructure();

    if (!NTNDArrayAttribute::isCompatible(attributeElementStruc))
        return false;


    FieldConstPtr field = structure->getField("descriptor");
    if (field.get())
    {
        ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor");
        if (!descriptorField.get() || descriptorField->getScalarType() != pvString)
            return false;
    }

    field = structure->getField("alarm");
    if (field.get() && !ntField->isAlarm(field))
        return false;

    field = structure->getField("timeStamp");
    if (field.get() && !ntField->isTimeStamp(field))
        return false;

    field = structure->getField("display");
    if (field.get() && !ntField->isDisplay(field))
        return false;

    return true;
}
Example #8
0
StructureConstPtr StandardField::createProperties(String id,FieldConstPtr field,String properties)
{
    bool gotAlarm = false;
    bool gotTimeStamp = false;
    bool gotDisplay = false;
    bool gotControl = false;
    bool gotValueAlarm = false;
    int numProp = 0;
    if(properties.find("alarm")!=String::npos) { gotAlarm = true; numProp++; }
    if(properties.find("timeStamp")!=String::npos) { gotTimeStamp = true; numProp++; }
    if(properties.find("display")!=String::npos) { gotDisplay = true; numProp++; }
    if(properties.find("control")!=String::npos) { gotControl = true; numProp++; }
    if(properties.find("valueAlarm")!=String::npos) { gotValueAlarm = true; numProp++; }
    StructureConstPtr valueAlarm;
    Type type= field->getType();
    while(gotValueAlarm) {
        if(type==epics::pvData::scalar || type==epics::pvData::scalarArray) {
           ScalarType scalarType = (type==epics::pvData::scalar) ?
		static_pointer_cast<const Scalar>(field)->getScalarType() :
		static_pointer_cast<const ScalarArray>(field)->getElementType();
           switch(scalarType) {
               case pvBoolean: valueAlarm = booleanAlarmField; break;
               case pvByte: valueAlarm = byteAlarmField; break;
               case pvShort: valueAlarm = shortAlarmField; break;
               case pvInt: valueAlarm = intAlarmField; break;
               case pvLong: valueAlarm = longAlarmField; break;
               case pvUByte: valueAlarm = ubyteAlarmField; break;
               case pvUShort: valueAlarm = ushortAlarmField; break;
               case pvUInt: valueAlarm = uintAlarmField; break;
               case pvULong: valueAlarm = ulongAlarmField; break;
               case pvFloat: valueAlarm = floatAlarmField; break;
               case pvDouble: valueAlarm = doubleAlarmField; break;
               case pvString:
                throw std::logic_error(String("valueAlarm property not supported for pvString"));
           }
           break;
        }
        if(type==structure) {
            StructureConstPtr structurePtr = static_pointer_cast<const Structure>(field);
            StringArray names = structurePtr->getFieldNames();
            if(names.size()==2) {
                FieldConstPtrArray fields = structurePtr->getFields();
                FieldConstPtr first = fields[0];
                FieldConstPtr second = fields[1];
                String nameFirst = names[0];
                String nameSecond = names[1];
                int compareFirst = nameFirst.compare("index");
                int compareSecond = nameSecond.compare("choices");
                if(compareFirst==0 && compareSecond==0) {
                    if(first->getType()==epics::pvData::scalar
                    && second->getType()==epics::pvData::scalarArray) {
                        ScalarConstPtr scalarFirst = static_pointer_cast<const Scalar>(first);
                        ScalarArrayConstPtr scalarArraySecond = 
                            static_pointer_cast<const ScalarArray>(second);
                        if(scalarFirst->getScalarType()==pvInt
                        && scalarArraySecond->getElementType()==pvString) {
                            valueAlarm = enumeratedAlarmField;
                            break;
                        }
                    }
                }
            }
        }
        throw std::logic_error(String("valueAlarm property for illegal type"));
    }
    size_t numFields = numProp+1;
    FieldConstPtrArray fields(numFields);
    StringArray names(numFields);
    int next = 0;
    names[0] = "value";
    fields[next++] = field;
    if(gotAlarm) {
        names[next] = "alarm";
        fields[next++] = alarmField;
    }
    if(gotTimeStamp) {
        names[next] = "timeStamp";
        fields[next++] = timeStampField;
    }
    if(gotDisplay) {
        names[next] = "display";
        fields[next++] = displayField;
    }
    if(gotControl) {
        names[next] = "control";
        fields[next++] = controlField;
    }
    if(gotValueAlarm) {
        names[next] = "valueAlarm";
        fields[next++] = valueAlarm;
    }
    return fieldCreate->createStructure(id,names,fields);
}