예제 #1
0
파일: pvValue.cpp 프로젝트: pheest/pvaSrv
void PvValue::channelGetConnect(
    const Status& status,
    ChannelGet::shared_pointer const & channelGet,
    PVStructure::shared_pointer const & pvStructure,
    BitSet::shared_pointer const & bitSet)
{
    if(!status.isOK()) {
         this->status = status;
    } else {
        this->status = Status::Ok;
        this->channelGet = channelGet;
        pvGetStructure = pvStructure;
        PVFieldPtr pvValue = pvGetStructure->getSubField("value");
        PVFieldPtr pvAlarm = pvGetStructure->getSubField("alarm");
        PVFieldPtr pvTimeStamp = pvGetStructure->getSubField("timeStamp");
        bool allGood = true;
        if(pvValue.get()==NULL) allGood = false;
        if(!allGood) {
            string builder("channel ");
            builder += channelName;
            if(pvValue.get()==NULL) builder += " no value field ";
            if(pvAlarm.get()==NULL) builder += " no alarm field ";
            if(pvTimeStamp.get()==NULL) builder += " no timeStamp field ";
            this->status = Status(Status::STATUSTYPE_ERROR,builder);
            builder.clear();
            pvGetStructure->toString(&builder);
            printf("channel %s pvGetStructure\n%s\n",
                channelName.c_str(),builder.c_str());
        }
    }
    event.signal();
}
예제 #2
0
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;
}
예제 #3
0
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);
}
예제 #4
0
파일: pvValue.cpp 프로젝트: pheest/pvaSrv
Status PvValue::getAlarm(Alarm &alarm)
{
    if(pvGetStructure.get()==NULL) {
        return Status(Status::STATUSTYPE_ERROR, "no alarm field");
    }
    PVAlarm pvAlarm;
    PVFieldPtr pvField = pvGetStructure->getSubField("alarm");
    if(pvField.get()==NULL) {
        return Status(Status::STATUSTYPE_ERROR, "no alarm field");
    }
    if(!pvAlarm.attach(pvField)) {
        return Status(Status::STATUSTYPE_ERROR, "no alarm field");
    }
    pvAlarm.get(alarm);
    return Status::Ok;
}
예제 #5
0
파일: pvValue.cpp 프로젝트: pheest/pvaSrv
Status PvValue::getTimeStamp(TimeStamp &timeStamp)
{
    if(pvGetStructure.get()==NULL) {
        return Status(Status::STATUSTYPE_ERROR, "no timeStamp field");
    }
    PVTimeStamp pvTimeStamp;
    PVFieldPtr pvField = pvGetStructure->getSubField("timeStamp");
    if(pvField.get()==NULL) {
        return Status(Status::STATUSTYPE_ERROR, "no timeStamp field");
    }
    if(!pvTimeStamp.attach(pvField)) {
        return Status(Status::STATUSTYPE_ERROR, "no timeStamp field");
    }
    pvTimeStamp.get(timeStamp);
    return Status::Ok;
}
예제 #6
0
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;
}
예제 #7
0
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");
}
예제 #8
0
bool RecordListRecord::init()
{
    initPVRecord();
    PVStructurePtr pvStructure = getPVStructure();
    database = pvStructure->getStringField("argument.database");
    if(database.get()==NULL) return false;
    regularExpression = pvStructure->getStringField(
        "argument.regularExpression");
    if(regularExpression.get()==NULL) return false;
    status = pvStructure->getStringField("result.status");
    if(status.get()==NULL) return false;
    PVFieldPtr pvField = pvStructure->getSubField("result.names");
    if(pvField.get()==NULL) {
        std::cerr << "no result.names" << std::endl;
        return false;
    }
    name = static_pointer_cast<PVStringArray>(
         pvStructure->getScalarArrayField("result.names",pvString));
    if(name.get()==NULL) return false;
    return true;
}
예제 #9
0
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;
}
예제 #10
0
static void testScalarArrayCommon(string /*fieldName*/,ScalarType stype)
{
    PVStructurePtr pvStructure = standardPVField->scalarArray(
        stype,alarmTimeStamp);
    PVScalarArrayPtr scalarArray = pvStructure->getSubField<PVScalarArray>("value");
    testOk1(scalarArray.get()!=0);
    if(stype==pvBoolean) {
        StringArray values(3);
        values[0] = "true";
        values[1] = "false";
        values[2] = "true";
        convert->fromStringArray(scalarArray, 0,3,values,0);
    } else {
        StringArray values(3);
        values[0] = "0";
        values[1] = "1";
        values[2] = "2";
        convert->fromStringArray(scalarArray, 0,3,values,0);
    }
    PVFieldPtr pvField = pvStructure->getSubField<PVInt>("alarm.status");
    testOk1(pvField.get()!=0);
}
예제 #11
0
void PVStructure::removePVField(String const &fieldName)
{
    PVFieldPtr pvField = getSubField(fieldName);
    if(pvField.get()==NULL) {
        String message("removePVField ");
        message +=  fieldName + " does not exist";
        this->message(message, errorMessage);
        return;
    }
    size_t origLength = pvFields.size();
    size_t newLength = origLength - 1;
    PVFieldPtrArray const & origPVFields = pvFields;
    FieldConstPtrArray origFields = structurePtr->getFields();
    PVFieldPtrArray newPVFields;
    newPVFields.reserve(newLength);
    StringArray newFieldNames;
    newFieldNames.reserve(newLength);
    FieldConstPtrArray fields;
    fields.reserve(newLength);
    for(size_t i=0; i<origLength; i++) {
        if(origPVFields[i]!=pvField) {
            newFieldNames.push_back(origPVFields[i]->getFieldName());
            newPVFields.push_back(origPVFields[i]);
            fields.push_back(origFields[i]);
        }
    }
    PVFieldPtrArray * xxx = const_cast<PVFieldPtrArray *>(&pvFields);
    xxx->swap(newPVFields);
    FieldConstPtr field = getFieldCreate()->createStructure(
        structurePtr->getID(),newFieldNames,fields);
    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]);
    }
}
예제 #12
0
void PrinterBase::impl_print(const PVField& pv)
{
    static const PVField* marker = (const PVField*)&marker;

    /* Depth first recursive iteration.
     * Each PV to be printed is appended to the todo queue.
     * The last child of a structure is followed by a NULL.
     * As the tree is walked structures and structarrays
     * are appended to the inprog queue.
     */
    std::deque<const PVField*> todo, inprog;

    todo.push_back(&pv);

    while(!todo.empty()) {
        const PVField *next = todo.front();
        todo.pop_front();

        if(next==marker) {
            // finished with a structure or structarray,
            // now we fall back to its parent.
            assert(!inprog.empty());
            switch(inprog.back()->getField()->getType()) {
            case structure:
                endStructure(*static_cast<const PVStructure *>(inprog.back()));
                break;

            case structureArray:
                endStructureArray(*static_cast<const PVStructureArray *>(inprog.back()));
                break;

            case union_:
                endUnion(*static_cast<const PVUnion *>(inprog.back()));
                break;

            case unionArray:
                endUnionArray(*static_cast<const PVUnionArray *>(inprog.back()));
                break;

            default:
                assert(false); // oops!
                return;
            }
            inprog.pop_back();

        } else {
            // real field

            if(!next) {
                // NULL entry in a structure array
                encodeNull();
                continue;
            }

            switch(next->getField()->getType()) {
            case scalar:
                encodeScalar(*static_cast<const PVScalar*>(next));
                break;
            case scalarArray:
                encodeArray(*static_cast<const PVScalarArray*>(next));
                break;
            case structure: {
                    const PVStructure &fld = *static_cast<const PVStructure*>(next);
                    const PVFieldPtrArray& vals = fld.getPVFields();

                    inprog.push_back(next);

                    beginStructure(fld);
                    for(size_t i=0, nfld=fld.getStructure()->getNumberFields(); i<nfld; i++)
                        todo.push_back(vals[i].get());

                    todo.push_back(marker);
                    break;
                }
            case structureArray: {
                    const PVStructureArray &fld = *static_cast<const PVStructureArray*>(next);
                    PVStructureArray::const_svector vals(fld.view());

                    inprog.push_back(next);

                    beginStructureArray(fld);
                    for(PVStructureArray::const_svector::const_iterator it=vals.begin();
                        it!=vals.end(); ++it)
                    {
                        todo.push_back(it->get());
                    }

                    todo.push_back(marker);
                    break;
                }
            case union_: {
                    const PVUnion &fld = *static_cast<const PVUnion*>(next);

                    inprog.push_back(next);

                    beginUnion(fld);
                    PVFieldPtr val = fld.get();
                    if (val.get())          // TODO print "(none)" ?
                        todo.push_back(val.get());

                    todo.push_back(marker);
                    break;
                }
            case unionArray: {
                    const PVUnionArray &fld = *static_cast<const PVUnionArray*>(next);
                    PVUnionArray::const_svector vals(fld.view());

                    inprog.push_back(next);

                    beginUnionArray(fld);
                    for(PVUnionArray::const_svector::const_iterator it=vals.begin();
                        it!=vals.end(); ++it)
                    {
                        todo.push_back(it->get());
                    }

                    todo.push_back(marker);
                    break;
                }
            }
        }
    }
}