void ChannelArrayLocal::setLength(size_t length) { ChannelArrayRequester::shared_pointer requester = channelArrayRequester.lock(); if(!requester) return; if(isDestroyed) { requester->setLengthDone(channelDestroyedStatus,getPtrSelf()); return; } if(pvRecord->getTraceLevel()>1) { cout << "ChannelArrayLocal::setLength" << endl; } try { { epicsGuard <PVRecord> guard(*pvRecord); if(length>=0) { if(pvArray->getLength()!=length) pvArray->setLength(length); } } requester->setLengthDone(Status::Ok,getPtrSelf()); } catch(std::exception e) { string exceptionMessage = e.what(); Status status = Status(Status::STATUSTYPE_ERROR,exceptionMessage); requester->setLengthDone(status,getPtrSelf()); } }
void ChannelArrayLocal::getArray(size_t offset, size_t count, size_t stride) { ChannelArrayRequester::shared_pointer requester = channelArrayRequester.lock(); if(!requester) return; if(isDestroyed) { requester->getArrayDone(channelDestroyedStatus,getPtrSelf(),pvCopy); return; } if(pvRecord->getTraceLevel()>1) { cout << "ChannelArrayLocal::getArray" << endl; } if(offset<0) { requester->getArrayDone(illegalOffsetStatus,getPtrSelf(),pvCopy); return; } if(stride<0) { requester->getArrayDone(illegalStrideStatus,getPtrSelf(),pvCopy); return; } const char *exceptionMessage = NULL; try { bool ok = false; epicsGuard <PVRecord> guard(*pvRecord); while(true) { size_t length = pvArray->getLength(); if(length<=0) break; if(count<=0) { count = (length -offset + stride -1)/stride; if(count>0) ok = true; break; } size_t maxcount = (length -offset + stride -1)/stride; if(count>maxcount) count = maxcount; ok = true; break; } if(ok) { pvCopy->setLength(count); copy(pvArray,offset,stride,pvCopy,0,1,count); } } catch(std::exception e) { exceptionMessage = e.what(); } Status status = Status::Ok; if(exceptionMessage!=NULL) { status = Status(Status::STATUSTYPE_ERROR,exceptionMessage); } requester->getArrayDone(status,getPtrSelf(),pvCopy); }
void ChannelArrayLocal::getLength() { ChannelArrayRequester::shared_pointer requester = channelArrayRequester.lock(); if(!requester) return; size_t length = 0; const char *exceptionMessage = NULL; try { epicsGuard <PVRecord> guard(*pvRecord); length = pvArray->getLength(); } catch(std::exception e) { exceptionMessage = e.what(); } Status status = Status::Ok; if(exceptionMessage!=NULL) { status = Status(Status::STATUSTYPE_ERROR,exceptionMessage); } requester->getLengthDone(status,getPtrSelf(),length); }
ChannelArray::shared_pointer CAChannel::createChannelArray( ChannelArrayRequester::shared_pointer const & channelArrayRequester, epics::pvData::PVStructure::shared_pointer const & /*pvRequest*/) { Status errorStatus(Status::STATUSTYPE_ERROR, "not supported"); ChannelArray::shared_pointer nullChannelArray; EXCEPTION_GUARD(channelArrayRequester->channelArrayConnect(errorStatus, nullChannelArray, Array::const_shared_pointer())); return nullChannelArray; }
ChannelArray::shared_pointer ChannelBase::createChannelArray( ChannelArrayRequester::shared_pointer const &channelArrayRequester, PVStructure::shared_pointer const &pvRequest) { Status status(Status::STATUSTYPE_ERROR, String("ChannelArray not supported")); channelArrayRequester->channelArrayConnect( status, ChannelArray::shared_pointer(), PVArray::shared_pointer()); return ChannelArray::shared_pointer(); }
ChannelArray::shared_pointer DbPv::createChannelArray( ChannelArrayRequester::shared_pointer const &channelArrayRequester, PVStructure::shared_pointer const &pvRequest) { DbPvArray::shared_pointer dbPvArray( new DbPvArray(getPtrSelf(),channelArrayRequester)); if(!dbPvArray->init(pvRequest)) { Status createFailed(Status::STATUSTYPE_ERROR, "create dbPvArray failed"); ScalarArrayConstPtr xxx; channelArrayRequester->channelArrayConnect( createFailed, dbPvArray, xxx); } return dbPvArray; }
void ChannelArrayLocal::putArray( PVArrayPtr const & pvArray, size_t offset, size_t count, size_t stride) { ChannelArrayRequester::shared_pointer requester = channelArrayRequester.lock(); if(!requester) return; if(isDestroyed) { requester->putArrayDone(channelDestroyedStatus,getPtrSelf()); return; } if(pvRecord->getTraceLevel()>1) { cout << "ChannelArrayLocal::putArray" << endl; } if(offset<0) { requester->putArrayDone(illegalOffsetStatus,getPtrSelf()); return; } if(count<0) { requester->putArrayDone(illegalCountStatus,getPtrSelf()); return; } if(stride<0) { requester->putArrayDone(illegalStrideStatus,getPtrSelf()); return; } size_t newLength = offset + count*stride; if(newLength<pvArray->getLength()) pvArray->setLength(newLength); const char *exceptionMessage = NULL; try { epicsGuard <PVRecord> guard(*pvRecord); copy(pvArray,0,1,this->pvArray,offset,stride,count); } catch(std::exception e) { exceptionMessage = e.what(); } Status status = Status::Ok; if(exceptionMessage!=NULL) { status = Status(Status::STATUSTYPE_ERROR,exceptionMessage); } requester->putArrayDone(status,getPtrSelf()); }
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; }