PVStructurePtr MasarService::request( PVStructurePtr const & pvArgument) throw (epics::pvAccess::RPCRequestException) { try{ assert(dslRdb.get() != NULL); string functionName(pvArgument->getSubFieldT<PVString>("function")->get()); if(functionName.empty()) { throw epics::pvAccess::RPCRequestException( Status::STATUSTYPE_ERROR,"pvArgument has an unsupported function"); } if(!NTNameValue::is_a(pvArgument->getStructure())) { // support non NTNameValue Pair for some general purpose client, for example command line tools const StringArray& fieldNames = pvArgument->getStructure()->getFieldNames(); size_t fieldcounts = fieldNames.size(); shared_vector<string> names (fieldcounts-1); shared_vector<string> values (fieldcounts-1); size_t counts = 0; for (size_t i = 0; i < fieldcounts; i ++) { if(fieldNames[i].compare("function")!=0) { names[counts] = fieldNames[i]; values[counts] = pvArgument->getSubFieldT<PVString>(fieldNames[i])->get(); counts += 1; } } PVStructurePtr result = dslRdb->request(functionName, freeze(names), freeze(values)); return result; } else{ const shared_vector<const string> name = pvArgument->getSubFieldT<PVStringArray>("name")->view(); const shared_vector<const string> value = pvArgument->getSubFieldT<PVStringArray>("value")->view(); PVStructurePtr result = dslRdb->request(functionName, name, value); return result; } }catch(epics::pvAccess::RPCRequestException&){ throw; }catch(std::exception& e){ // since request(RPCRequestException) in our base class has a throw() specifier, // if anything else is thrown we abort() :P // so must translate all exceptions to RPCRequestException. throw epics::pvAccess::RPCRequestException(Status::STATUSTYPE_ERROR, std::string("request failed ") + e.what()); } }
size_t fromString(PVStructurePtr const & pvStructure, StringArray const & from, size_t fromStartIndex = 0) { // handle enum in a special way if (pvStructure->getStructure()->getID() == "enum_t") { int32 index = -1; PVInt::shared_pointer pvIndex = pvStructure->getSubField<PVInt>("index"); if (!pvIndex) throw std::runtime_error("enum_t structure does not have 'int index' field"); PVStringArray::shared_pointer pvChoices = pvStructure->getSubField<PVStringArray>("choices"); if (!pvChoices) throw std::runtime_error("enum_t structure does not have 'string choices[]' field"); PVStringArray::const_svector choices(pvChoices->view()); if (enumMode == AutoEnum || enumMode == StringEnum) { shared_vector<string>::const_iterator it = std::find(choices.begin(), choices.end(), from[fromStartIndex]); if (it != choices.end()) index = static_cast<int32>(it - choices.begin()); else if (enumMode == StringEnum) throw runtime_error("enum string value '" + from[fromStartIndex] + "' invalid"); } if ((enumMode == AutoEnum && index == -1) || enumMode == NumberEnum) { istringstream iss(from[fromStartIndex]); iss >> index; // not fail and entire value is parsed (e.g. to detect 1.2 parsing to 1) if (iss.fail() || !iss.eof()) throw runtime_error("enum value '" + from[fromStartIndex] + "' invalid"); if (index < 0 || index >= static_cast<int32>(choices.size())) throw runtime_error("index '" + from[fromStartIndex] + "' out of bounds"); }
void testPVNTField() { testDiag("testPVNTField"); StringArray choices; choices.resize(3); choices[0] = "one"; choices[1] = "two"; choices[2] = "three"; PVStructurePtr pvStructure = PVStructurePtr( pvntField->createEnumerated(choices)); cout << *pvStructure << endl; testOk1(ntField->isEnumerated(pvStructure->getStructure())); pvStructure = PVStructurePtr(pvntField->createTimeStamp()); cout << *pvStructure << endl; testOk1(ntField->isTimeStamp(pvStructure->getStructure())); pvStructure = PVStructurePtr(pvntField->createAlarm()); cout << *pvStructure << endl; testOk1(ntField->isAlarm(pvStructure->getStructure())); pvStructure = PVStructurePtr(pvntField->createDisplay()); cout << *pvStructure << endl; testOk1(ntField->isDisplay(pvStructure->getStructure())); pvStructure = PVStructurePtr(pvDataCreate->createPVStructure(standardField->doubleAlarm())); cout << *pvStructure << endl; testOk1(ntField->isAlarmLimit(pvStructure->getStructure())); PVStructureArrayPtr pvStructureArray = PVStructureArrayPtr( pvntField->createEnumeratedArray()); cout << *pvStructure << endl; cout << *pvStructureArray->getStructureArray()->getStructure(); pvStructureArray = PVStructureArrayPtr( pvntField->createTimeStampArray()); cout << *pvStructure << endl; cout << *pvStructureArray->getStructureArray()->getStructure(); pvStructureArray = PVStructureArrayPtr( pvntField->createAlarmArray()); cout << *pvStructure << endl; cout << *pvStructureArray->getStructureArray()->getStructure(); }
void testDeserializeStructureAndCreatePVStructure() { buffer->clear(); registry->reset(); StructureConstPtr structureIn = getStructure("structure1"); serialize(structureIn,registry); buffer->flip(); PVStructurePtr pvStructureOut = registry->deserializeStructureAndCreatePVStructure(buffer,control); StructureConstPtr structureOut = pvStructureOut->getStructure(); assert(structureIn->getFieldName() == structureOut->getFieldName()); assert(structureIn->getType() == structureOut->getType()); delete pvStructureOut; }
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"); }
PVStructurePtr PVDataCreate::createPVStructure(PVStructurePtr const & structToClone) { FieldConstPtrArray field; if(!structToClone) { // is this correct?! FieldConstPtrArray fields(0); StringArray fieldNames(0); StructureConstPtr structure = fieldCreate->createStructure(fieldNames,fields); return PVStructurePtr(new PVStructure(structure)); } StructureConstPtr structure = structToClone->getStructure(); PVStructurePtr pvStructure(new PVStructure(structure)); pvStructure->copyUnchecked(*structToClone); return pvStructure; }
static void testRequest() { StringArray nullNames; FieldConstPtrArray nullFields; StringArray optionNames(1); FieldConstPtrArray optionFields(1); optionNames[0] = "process"; optionFields[0] = fieldCreate->createScalar(pvString); StringArray recordNames(1); FieldConstPtrArray recordFields(1); recordNames[0] = "_options"; recordFields[0] = fieldCreate->createStructure(optionNames,optionFields); StringArray fieldNames(2); FieldConstPtrArray fieldFields(2); fieldNames[0] = "alarm"; fieldFields[0] = fieldCreate->createStructure(nullNames,nullFields); fieldNames[1] = "timeStamp"; fieldFields[1] = fieldCreate->createStructure(nullNames,nullFields); StringArray topNames(2); FieldConstPtrArray topFields(2); topNames[0] = "record"; topFields[0] = fieldCreate->createStructure(recordNames,recordFields); topNames[1] = "field"; topFields[1] = fieldCreate->createStructure(fieldNames,fieldFields); StructureConstPtr topStructure = fieldCreate->createStructure( topNames,topFields); cout << *topStructure << endl; PVStructurePtr pvTop = pvDataCreate->createPVStructure(topStructure); cout << *pvTop << endl; cout << *pvTop->getStructure() << endl; PVStructurePtr xxx = pvTop->getSubField<PVStructure>("record"); cout << *xxx << endl; xxx = pvTop->getSubField<PVStructure>("field"); cout << *xxx << endl; PVStringPtr pvString = pvTop->getSubField<PVString>("record._options.process"); pvString->put("true"); cout << *pvTop << endl; string subName("record._options.process"); PVFieldPtr pvField = pvTop->getSubField<PVString>(subName); string fieldName = pvField->getFieldName(); string fullName = pvField->getFullName(); cout << "fieldName " << fieldName << " fullName " << fullName << endl; testOk1(fieldName.compare("process")==0); testOk1(fullName.compare(subName)==0); }
ChannelGetLocalPtr ChannelGetLocal::create( ChannelLocalPtr const &channelLocal, ChannelGetRequester::shared_pointer const & channelGetRequester, PVStructurePtr const & pvRequest, PVRecordPtr const &pvRecord) { PVCopyPtr pvCopy = PVCopy::create( pvRecord->getPVRecordStructure()->getPVStructure(), pvRequest, ""); if(!pvCopy) { Status status( Status::STATUSTYPE_ERROR, "invalid pvRequest"); ChannelGet::shared_pointer channelGet; channelGetRequester->channelGetConnect( status, channelGet, nullStructure); ChannelGetLocalPtr localGet; return localGet; } PVStructurePtr pvStructure = pvCopy->createPVStructure(); BitSetPtr bitSet(new BitSet(pvStructure->getNumberFields())); ChannelGetLocalPtr get(new ChannelGetLocal( getProcess(pvRequest,false), channelLocal, channelGetRequester, pvCopy, pvStructure, bitSet, pvRecord)); if(pvRecord->getTraceLevel()>0) { cout << "ChannelGetLocal::create"; cout << " recordName " << pvRecord->getRecordName() << endl; } channelGetRequester->channelGetConnect( Status::Ok,get,pvStructure->getStructure()); return get; }
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; }
static void test() { NTMultiChannelBuilderPtr builder = NTMultiChannel::createBuilder(); testOk(builder.get() != 0, "Got builder"); NTMultiChannelPtr multiChannel = builder-> addDescriptor()-> addAlarm()-> addTimeStamp()-> addSeverity() -> add("extra1",fieldCreate->createScalar(pvString)) -> add("extra2",fieldCreate->createScalarArray(pvString)) -> create(); testOk1(multiChannel.get() != 0); PVStructurePtr pvStructure = multiChannel->getPVStructure(); testOk1(pvStructure.get()!=NULL); testOk1(NTMultiChannel::is_a(pvStructure->getStructure())); size_t nchan = 3; shared_vector<string> names(nchan); names[0] = "channel 0"; names[1] = "channel 1"; names[2] = "channel 2"; shared_vector<const string> channelNames(freeze(names)); PVStringArrayPtr pvChannelName = multiChannel->getChannelName(); pvChannelName->replace(channelNames); if(debug) {cout << *pvStructure << endl;} UnionConstPtr unionPtr = fieldCreate->createFieldBuilder()-> add("doubleValue", pvDouble)-> add("intValue", pvInt)-> createUnion(); multiChannel = builder-> value(unionPtr) -> addDescriptor()-> addAlarm()-> addTimeStamp()-> addSeverity() -> addIsConnected() -> create(); testOk1(multiChannel.get() != 0); pvStructure = multiChannel->getPVStructure(); if(debug) {cout << *pvStructure << endl;} pvChannelName = multiChannel->getChannelName(); pvChannelName->replace(channelNames); PVUnionArrayPtr pvValue = multiChannel->getValue(); shared_vector<PVUnionPtr> unions(nchan); unions[0] = pvDataCreate->createPVUnion(unionPtr); unions[1] = pvDataCreate->createPVUnion(unionPtr); unions[2] = pvDataCreate->createPVUnion(unionPtr); unions[0]->select("doubleValue"); unions[1]->select("intValue"); unions[2]->select("intValue"); PVDoublePtr pvDouble = unions[0]->get<PVDouble>(); pvDouble->put(1.235); PVIntPtr pvInt = unions[1]->get<PVInt>(); pvInt->put(5); pvInt = unions[2]->get<PVInt>(); pvInt->put(7); pvValue->replace(freeze(unions)); shared_vector<int32> severities(nchan); severities[0] = 0; severities[1] = 1; severities[2] = 2; PVIntArrayPtr pvSeverity = multiChannel->getSeverity(); pvSeverity->replace(freeze(severities)); if(debug) {cout << *pvStructure << endl;} PVBooleanArrayPtr pvIsConnected = multiChannel->getIsConnected(); shared_vector<const epics::pvData::boolean> isConnected = pvIsConnected->view(); multiChannel = builder-> value(unionPtr) -> addDescriptor()-> addAlarm()-> addTimeStamp()-> addSeverity() -> addStatus() -> addMessage() -> addSecondsPastEpoch() -> addNanoseconds() -> addUserTag() -> addIsConnected() -> create(); testOk1(multiChannel.get() != 0); pvStructure = multiChannel->getPVStructure(); if(debug) {cout << *pvStructure << endl;} testOk1(NTMultiChannel::isCompatible(pvStructure)==true); PVStructurePtr pvTimeStamp = multiChannel->getTimeStamp(); testOk1(pvTimeStamp.get() !=0); PVStructurePtr pvAlarm = multiChannel->getAlarm(); testOk1(pvAlarm.get() !=0); pvValue = multiChannel->getValue(); testOk1(pvValue.get() !=0); pvChannelName = multiChannel->getChannelName(); testOk1(pvChannelName.get() !=0); pvIsConnected = multiChannel->getIsConnected(); testOk1(pvIsConnected.get() !=0); pvSeverity = multiChannel->getSeverity(); testOk1(pvSeverity.get() !=0); PVIntArrayPtr pvStatus = multiChannel->getStatus(); testOk1(pvStatus.get() !=0); PVStringArrayPtr pvMessage = multiChannel->getMessage(); testOk1(pvMessage.get() !=0); PVLongArrayPtr pvSecondsPastEpoch = multiChannel->getSecondsPastEpoch(); testOk1(pvSecondsPastEpoch.get() !=0); PVIntArrayPtr pvNanoseconds = multiChannel->getNanoseconds(); testOk1(pvNanoseconds.get() !=0); PVIntArrayPtr pvUserTag = multiChannel->getUserTag(); testOk1(pvUserTag.get() !=0); PVStringPtr pvDescriptor = multiChannel->getDescriptor(); testOk1(pvDescriptor.get() !=0); }
bool NTMatrix::isCompatible(PVStructurePtr const & pvStructure) { if(!pvStructure) return false; return isCompatible(pvStructure->getStructure()); }
static void test() { NTScalarMultiChannelBuilderPtr builder = NTScalarMultiChannel::createBuilder(); testOk(builder.get() != 0, "Got builder"); NTScalarMultiChannelPtr multiChannel = builder-> addDescriptor()-> addAlarm()-> addTimeStamp()-> addSeverity() -> add("extra1",fieldCreate->createScalar(pvString)) -> add("extra2",fieldCreate->createScalarArray(pvString)) -> create(); testOk1(multiChannel.get() != 0); PVStructurePtr pvStructure = multiChannel->getPVStructure(); testOk1(pvStructure.get()!=NULL); testOk1(NTScalarMultiChannel::is_a(pvStructure->getStructure())); size_t nchan = 3; shared_vector<string> names(nchan); names[0] = "channel 0"; names[1] = "channel 1"; names[2] = "channel 2"; shared_vector<const string> channelNames(freeze(names)); PVStringArrayPtr pvChannelName = multiChannel->getChannelName(); pvChannelName->replace(channelNames); if(debug) {cout << *pvStructure << endl;} multiChannel = builder-> value(pvDouble) -> addDescriptor()-> addAlarm()-> addTimeStamp()-> addSeverity() -> addIsConnected() -> create(); testOk1(multiChannel.get() != 0); pvStructure = multiChannel->getPVStructure(); if(debug) {cout << *pvStructure << endl;} pvChannelName = multiChannel->getChannelName(); pvChannelName->replace(channelNames); PVDoubleArrayPtr pvValue = multiChannel->getValue<PVDoubleArray>(); PVDoubleArray::svector doubles(nchan); doubles.resize(nchan); doubles[0] = 3.14159; doubles[1] = 2.71828; doubles[2] = 137.036; pvValue->replace(freeze(doubles)); shared_vector<int32> severities(nchan); severities[0] = 0; severities[1] = 1; severities[2] = 2; PVIntArrayPtr pvSeverity = multiChannel->getSeverity(); pvSeverity->replace(freeze(severities)); if(debug) {cout << *pvStructure << endl;} PVBooleanArrayPtr pvIsConnected = multiChannel->getIsConnected(); shared_vector<const epics::pvData::boolean> isConnected = pvIsConnected->view(); multiChannel = builder-> value(pvDouble) -> addDescriptor()-> addAlarm()-> addTimeStamp()-> addSeverity() -> addStatus() -> addMessage() -> addSecondsPastEpoch() -> addNanoseconds() -> addUserTag() -> addIsConnected() -> create(); testOk1(multiChannel.get() != 0); pvStructure = multiChannel->getPVStructure(); if(debug) {cout << *pvStructure << endl;} testOk1(NTScalarMultiChannel::isCompatible(pvStructure)==true); PVStructurePtr pvTimeStamp = multiChannel->getTimeStamp(); testOk1(pvTimeStamp.get() !=0); PVStructurePtr pvAlarm = multiChannel->getAlarm(); testOk1(pvAlarm.get() !=0); pvValue = multiChannel->getValue<PVDoubleArray>(); testOk1(pvValue.get() !=0); pvChannelName = multiChannel->getChannelName(); testOk1(pvChannelName.get() !=0); pvIsConnected = multiChannel->getIsConnected(); testOk1(pvIsConnected.get() !=0); pvSeverity = multiChannel->getSeverity(); testOk1(pvSeverity.get() !=0); PVIntArrayPtr pvStatus = multiChannel->getStatus(); testOk1(pvStatus.get() !=0); PVStringArrayPtr pvMessage = multiChannel->getMessage(); testOk1(pvMessage.get() !=0); PVLongArrayPtr pvSecondsPastEpoch = multiChannel->getSecondsPastEpoch(); testOk1(pvSecondsPastEpoch.get() !=0); PVIntArrayPtr pvNanoseconds = multiChannel->getNanoseconds(); testOk1(pvNanoseconds.get() !=0); PVIntArrayPtr pvUserTag = multiChannel->getUserTag(); testOk1(pvUserTag.get() !=0); PVStringPtr pvDescriptor = multiChannel->getDescriptor(); testOk1(pvDescriptor.get() !=0); }
bool NTHistogram::isCompatible(PVStructurePtr const & pvStructure) { if(!pvStructure.get()) return false; return isCompatible(pvStructure->getStructure()); }
bool NTAttribute::is_a(PVStructurePtr const & pvStructure) { return is_a(pvStructure->getStructure()); }
bool NTScalar::is_a(PVStructurePtr const & pvStructure) { return is_a(pvStructure->getStructure()); }