Пример #1
0
static PVStructurePtr createPowerSupply()
{
    FieldCreatePtr fieldCreate = getFieldCreate();
    StandardFieldPtr standardField = getStandardField();
    PVDataCreatePtr pvDataCreate = getPVDataCreate();

    size_t nfields = 5;
    StringArray names;
    names.reserve(nfields);
    FieldConstPtrArray powerSupply;
    powerSupply.reserve(nfields);
    names.push_back("alarm");
    powerSupply.push_back(standardField->alarm());
    names.push_back("timeStamp");
    powerSupply.push_back(standardField->timeStamp());
    string properties("alarm,display");
    names.push_back("voltage");
    powerSupply.push_back(standardField->scalar(pvDouble,properties));
    names.push_back("power");
    powerSupply.push_back(standardField->scalar(pvDouble,properties));
    names.push_back("current");
    powerSupply.push_back(standardField->scalar(pvDouble,properties));
    return pvDataCreate->createPVStructure(
            fieldCreate->createStructure(names,powerSupply));
}
Пример #2
0
void PVStructure::appendPVFields(
    StringArray const & fieldNames,
    PVFieldPtrArray const & pvFields)
{
    size_t origLength = this->pvFields.size();
    size_t extra = fieldNames.size();
    if(extra==0) return;
    size_t newLength = origLength + extra;
    PVFieldPtrArray * xxx = const_cast<PVFieldPtrArray *>(&this->pvFields);
    xxx->reserve(newLength);
    for(size_t i=0; i<extra; i++) {
        xxx->push_back(pvFields[i]);
    }
    FieldConstPtrArray fields;
    fields.reserve(extra);
    for(size_t i=0; i<extra; i++) fields.push_back(pvFields[i]->getField());
    FieldConstPtr field = getFieldCreate()->appendFields(
        structurePtr,fieldNames,fields);
    replaceField(field);
    structurePtr = static_pointer_cast<const Structure>(field);
    StringArray names = structurePtr->getFieldNames();
    for(size_t i=0; i<newLength; i++) {
        (*xxx)[i]->setParentAndName(this,names[i]);
    }
    fixParentStructure();
}
Пример #3
0
static StructureConstPtr createResultField()
{
    FieldCreatePtr fieldCreate = getFieldCreate();
    
    StringArray fieldNames;
    fieldNames.push_back("c");
    FieldConstPtrArray fields;
    fields.push_back(fieldCreate->createScalar(pvDouble));
    return fieldCreate->createStructure(fieldNames, fields);
}
Пример #4
0
// returns this service's result structure type definition.
StructureConstPtr makeResponseStructure()
{
    FieldCreatePtr factory = getFieldCreate();

    FieldConstPtrArray fields;
    StringArray names;

    names.push_back("greeting");
    fields.push_back(factory->createScalar(pvString));

    return factory->createStructure(names, fields);
}
static UnionConstPtr deserializeUnionField(const FieldCreate* fieldCreate, ByteBuffer* buffer, DeserializableControl* control)
{
    string id = SerializeHelper::deserializeString(buffer, control);
    const std::size_t size = SerializeHelper::readSize(buffer, control);
    FieldConstPtrArray fields; fields.reserve(size);
    StringArray fieldNames; fieldNames.reserve(size);
    for (std::size_t i = 0; i < size; i++)
    {
        fieldNames.push_back(SerializeHelper::deserializeString(buffer, control));
        fields.push_back(control->cachedDeserialize(buffer));
    }

    if (id.empty())
        return fieldCreate->createUnion(fieldNames, fields);
    else
    	return fieldCreate->createUnion(id, fieldNames, fields);
}
Пример #6
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]);
    }
}
Пример #7
0
void ExampleServiceRPC::request(
    ChannelRPCRequester::shared_pointer const & channelRPCRequester,
    epics::pvData::PVStructure::shared_pointer const & pvArgument)
{
    String buffer;
    PVStringPtr pvfunction = pvArgument->getStringField("function");
    PVStringArrayPtr pvnames = static_pointer_cast<PVStringArray>
        (pvArgument->getScalarArrayField("names",pvString));
    PVStringArrayPtr pvvalues = static_pointer_cast<PVStringArray>
        (pvArgument->getScalarArrayField("values",pvString));
    buffer += "pvArgument ";
    bool is = true;
    if(pvfunction==0) is = false;
    if(pvnames==0) is = false;
    if(pvvalues==0) is = false;
    if(is) {
        buffer += "is a NTNameValue\n";
    } else {
        buffer += "is not a NTNameValue\n ";
    }
    pvArgument->toString(&buffer);
    printf("%s\n",buffer.c_str());
    StandardFieldPtr standardField = getStandardField();
    StandardPVFieldPtr standardPVField = getStandardPVField();
    FieldCreatePtr  fieldCreate = getFieldCreate();
    PVDataCreatePtr  pvDataCreate = getPVDataCreate();
    size_t n = 5;
    FieldConstPtrArray fields;
    StringArray names;
    fields.reserve(n);
    names.reserve(n);
    names.push_back("alarm");
    names.push_back("timeStamp");
    names.push_back("label");
    names.push_back("position");
    names.push_back("alarms");
StructureConstPtr xxx = standardField->alarm();
printf("xxx %p\n",xxx.get());
    fields.push_back(standardField->alarm());
    fields.push_back(standardField->timeStamp());
    fields.push_back(fieldCreate->createScalarArray(pvString));
    fields.push_back(fieldCreate->createScalarArray(pvDouble));
    fields.push_back(fieldCreate->createStructureArray(standardField->alarm()));
    StructureConstPtr structure = fieldCreate->createStructure(names,fields);
printf("structure %p\n",structure.get());
buffer.clear();
structure->toString(&buffer);
printf("structure\n%s\n",buffer.c_str());
    PVStructurePtr pvStructure = pvDataCreate->createPVStructure(structure);
    PVTimeStamp pvTimeStamp;
    TimeStamp timeStamp;
    pvTimeStamp.attach(pvStructure->getStructureField("timeStamp"));
    timeStamp.getCurrent();
    pvTimeStamp.set(timeStamp);
    StringArray label;
    label.reserve(2);
    for(int i=0; i<2; i++) {
        label.push_back(names[i+3]);
    }
    PVStringArrayPtr pvLabel = static_pointer_cast<PVStringArray>
        (pvStructure->getScalarArrayField("label",pvString));
    pvLabel->put(0,2,label,0);
    PVDoubleArrayPtr pvPositions = static_pointer_cast<PVDoubleArray>
        (pvStructure->getScalarArrayField("position",pvDouble));
    double positions[2];
    positions[0] = 1.0;
    positions[1] = 2.0;
    pvPositions->put(0,2,positions,0);
    PVStructureArrayPtr pvAlarms = static_pointer_cast<PVStructureArray>
        (pvStructure->getStructureArrayField("alarms"));
    PVAlarm pvAlarm;
    Alarm alarm;
    PVStructurePtrArray palarms;
    size_t na=2;
    palarms.reserve(na);
    for(size_t i=0; i<na; i++) {
        palarms.push_back(pvDataCreate->createPVStructure(standardField->alarm()));
    }
    for(size_t i=0; i<na; i++) {
        pvAlarm.attach(palarms[i]);
        alarm.setMessage("test");
        alarm.setSeverity(majorAlarm);
        alarm.setStatus(clientStatus);
        pvAlarm.set(alarm);
    }
    pvAlarms->put(0,2,palarms,0);
    String labels[2];
    labels[0] = pvPositions->getFieldName();
    labels[1] = pvAlarms->getFieldName();
    pvLabel->put(0,2,labels,0);
    buffer.erase();
    pvStructure->toString(&buffer);
    printf("%s\n",buffer.c_str());
    channelRPCRequester->requestDone(Status::Ok,pvStructure);
}
int main()
{
    for (int i = 0; i < 10; i++) {
    {
    /*
    ClientContextImpl::shared_pointer context = createClientContextImpl();
    context->printInfo();

    context->initialize();
    context->printInfo();

    epicsThreadSleep ( SLEEP_TIME );
    
    ChannelProvider::shared_pointer provider = context->getProvider();
    */
    
    ClientFactory::start();
    ChannelProvider::shared_pointer provider = getChannelProviderRegistry()->getProvider("pva");

    ChannelFindRequester::shared_pointer findRequester(new ChannelFindRequesterImpl());
    ChannelFind::shared_pointer channelFind = provider->channelFind("testSomething", findRequester);
    epicsThreadSleep ( SLEEP_TIME );
    //channelFind->destroy();

    ChannelRequester::shared_pointer channelRequester(new ChannelRequesterImpl());
    Channel::shared_pointer channel = provider->createChannel("testStructureArrayTest", channelRequester);
    epicsThreadSleep ( SLEEP_TIME );
    channel->printInfo();
        
        {
    GetFieldRequester::shared_pointer getFieldRequesterImpl(new GetFieldRequesterImpl());
    channel->getField(getFieldRequesterImpl, "");
    epicsThreadSleep ( SLEEP_TIME );
        }
        
        {
    ChannelProcessRequester::shared_pointer channelProcessRequester(new ChannelProcessRequesterImpl());
    PVStructure::shared_pointer pvRequest;
    ChannelProcess::shared_pointer channelProcess = channel->createChannelProcess(channelProcessRequester, pvRequest);
    epicsThreadSleep ( SLEEP_TIME );
    channelProcess->process();
    epicsThreadSleep ( SLEEP_TIME );
    channelProcess->destroy();
    epicsThreadSleep ( SLEEP_TIME );
        }
        
        {
    ChannelGetRequester::shared_pointer channelGetRequesterImpl(new ChannelGetRequesterImpl());
    PVStructure::shared_pointer pvRequest = CreateRequest::create()->createRequest("field()");
    ChannelGet::shared_pointer channelGet = channel->createChannelGet(channelGetRequesterImpl, pvRequest);
    epicsThreadSleep ( 3.0 );
    channelGet->get();
    epicsThreadSleep ( 3.0 );
    channelGet->destroy();
        }
    
        {
    ChannelPutRequester::shared_pointer channelPutRequesterImpl(new ChannelPutRequesterImpl());
    PVStructure::shared_pointer pvRequest = CreateRequest::create()->createRequest("field(value,timeStamp)");
    ChannelPut::shared_pointer channelPut = channel->createChannelPut(channelPutRequesterImpl, pvRequest);
    epicsThreadSleep ( SLEEP_TIME );
    channelPut->get();
    epicsThreadSleep ( SLEEP_TIME );
    // TODO !!!
    //channelPut->put();
    //epicsThreadSleep ( SLEEP_TIME );
    channelPut->destroy();
        }

        {
    ChannelPutGetRequester::shared_pointer channelPutGetRequesterImpl(new ChannelPutGetRequesterImpl());
    PVStructure::shared_pointer pvRequest = CreateRequest::create()->createRequest("putField(value,timeStamp)getField(timeStamp)");
    ChannelPutGet::shared_pointer channelPutGet = channel->createChannelPutGet(channelPutGetRequesterImpl, pvRequest);
    epicsThreadSleep ( SLEEP_TIME );
    channelPutGet->getGet();
    epicsThreadSleep ( SLEEP_TIME );
    channelPutGet->getPut();
    epicsThreadSleep ( SLEEP_TIME );
    // TODO !!!
    //channelPutGet->putGet();
    //epicsThreadSleep ( SLEEP_TIME );
    channelPutGet->destroy();
        }

        {
    ChannelRPCRequester::shared_pointer channelRPCRequesterImpl(new ChannelRPCRequesterImpl());
    PVStructure::shared_pointer pvRequest = CreateRequest::create()->createRequest("record[]field(arguments)");
    ChannelRPC::shared_pointer channelRPC = channel->createChannelRPC(channelRPCRequesterImpl, pvRequest);
    epicsThreadSleep ( SLEEP_TIME );
    // for test simply use pvRequest as arguments
    channelRPC->request(pvRequest);
    epicsThreadSleep ( SLEEP_TIME );
    channelRPC->destroy();
        }
         
        {
    ChannelArrayRequester::shared_pointer channelArrayRequesterImpl(new ChannelArrayRequesterImpl());
    StringArray fieldNames; fieldNames.push_back("field");
    FieldConstPtrArray fields; fields.push_back(getFieldCreate()->createScalar(pvString));
    PVStructure::shared_pointer pvRequest(getPVDataCreate()->createPVStructure(getFieldCreate()->createStructure(fieldNames, fields)));

    ChannelArray::shared_pointer channelArray = channel->createChannelArray(channelArrayRequesterImpl, pvRequest);
    epicsThreadSleep ( SLEEP_TIME );
    channelArray->getArray(0,0,1);
    epicsThreadSleep ( SLEEP_TIME );
    // TODO !!!
    //channelArray->putArray(0,0,1);
    //epicsThreadSleep ( SLEEP_TIME );
    channelArray->setLength(3);
    epicsThreadSleep ( SLEEP_TIME );
    channelArray->getLength();
    epicsThreadSleep ( SLEEP_TIME );
    channelArray->destroy();
        }

        {
    MonitorRequester::shared_pointer monitorRequesterImpl(new MonitorRequesterImpl());
    PVStructure::shared_pointer pvRequest = CreateRequest::create()->createRequest("field()");
    Monitor::shared_pointer monitor = channel->createMonitor(monitorRequesterImpl, pvRequest);

    epicsThreadSleep( SLEEP_TIME );

    Status status = monitor->start();
    std::cout << "monitor->start() = " << status << std::endl;

    epicsThreadSleep( 3*SLEEP_TIME );

    status = monitor->stop();
    std::cout << "monitor->stop() = " << status << std::endl;


    monitor->destroy();
        }
    
    epicsThreadSleep ( 3*SLEEP_TIME );
    printf("Destroying channel... \n");
    channel->destroy();
    printf("done.\n");

    epicsThreadSleep ( 3*SLEEP_TIME );
        
    }
    
    ClientFactory::stop();

    /*
    printf("Destroying context... \n");
    context->destroy();
    printf("done.\n");
    */
    
    epicsThreadSleep ( SLEEP_TIME ); }
    //std::cout << "-----------------------------------------------------------------------" << std::endl;
    //epicsExitCallAtExits();
    return(0);
}