int main(int argc,char *argv[])
{
    PVDatabasePtr master = PVDatabase::getMaster();
    PVRecordPtr pvRecord;
    bool result = false;
    string recordName;

    recordName = "exampleServer";
    pvRecord = ExampleServer::create(recordName);
    result = master->addRecord(pvRecord);
    if(!result) cout<< "record " << recordName << " not added" << endl;

    recordName = "traceRecordPGRPC";
    pvRecord = TraceRecord::create(recordName);
    result = master->addRecord(pvRecord);
    if(!result) cout<< "record " << recordName << " not added" << endl;

   
    ContextLocal::shared_pointer contextLocal = ContextLocal::create();
    contextLocal->start();

    PVStringArrayPtr pvNames = master->getRecordNames();
    shared_vector<const string> names = pvNames->view();
    for(size_t i=0; i<names.size(); ++i) cout << names[i] << endl;

    contextLocal->waitForExit();

    return 0;
}
Exemplo n.º 2
0
int main(int argc,char *argv[])
{
    string provider("pva");
    string linkedRecordName("doubleArray");
    bool generateLinkedRecord(true);
    if(argc==2 && string(argv[1])==string("-help")) {
        cout << "provider  linkedRecordName generateLinkedRecord" << endl;
        cout << "default" << endl;
        cout << provider << " " << " " << linkedRecordName << " true" << endl;
        return 0;
    }
    if(argc>1) provider = argv[1];
    if(argc>2) linkedRecordName = argv[2];
    if(argc>3) {
        string val = argv[3];
        if(val=="false") generateLinkedRecord = false;
    }
    try {
        PVDatabasePtr master = PVDatabase::getMaster();
        ChannelProviderLocalPtr channelProvider = getChannelProviderLocal();
        PvaClientPtr pva= PvaClient::get(provider);
        ServerContext::shared_pointer ctx =
        startPVAServer("local",0,true,true);
        
        if(generateLinkedRecord) {
            NTScalarArrayBuilderPtr ntScalarArrayBuilder = NTScalarArray::createBuilder();
            PVStructurePtr pvStructure = ntScalarArrayBuilder->
                value(pvDouble)->
                addAlarm()->
                addTimeStamp()->
                createPVStructure();
            PVRecordPtr pvRecord(PVRecord::create(linkedRecordName,pvStructure));
            master->addRecord(pvRecord);
        }
        ExampleMonitorLinkRecordPtr pvMonitorRecord(
            ExampleMonitorLinkRecord::create(
                 pva, "exampleMonitorLink",provider,linkedRecordName));
        master->addRecord(pvMonitorRecord);
        ExampleGetLinkRecordPtr pvGetRecord(
            ExampleGetLinkRecord::create(
                 pva,"exampleGetLink",provider,linkedRecordName));
        master->addRecord(pvGetRecord);
        ExamplePutLinkRecordPtr pvPutRecord(
            ExamplePutLinkRecord::create(
                 pva,"examplePutLink",provider,linkedRecordName));
        master->addRecord(pvPutRecord);
        cout << "exampleMonitorLink\n";
        string str;
        while(true) {
            cout << "Type exit to stop: \n";
            getline(cin,str);
            if(str.compare("exit")==0) break;
        }
        ctx->destroy();
    } catch (std::runtime_error e) {
        cerr << "exception " << e.what() << endl;
        return 1;
    }
    return 0;
}
Exemplo n.º 3
0
int main(int argc,char *argv[])
{
    string provider("pva");
    if(argc>1) provider = argv[1];
    PVDatabasePtr master = PVDatabase::getMaster();
    NTScalarArrayBuilderPtr ntScalarArrayBuilder = NTScalarArray::createBuilder();
    PVStructurePtr pvStructure = ntScalarArrayBuilder->
        value(pvDouble)->
        addAlarm()->
        addTimeStamp()->
        createPVStructure();
    master->addRecord(PVRecord::create("doubleArray",pvStructure));
    ChannelProviderLocalPtr channelProvider = getChannelProviderLocal();
    if(provider=="pva") ClientFactory::start();
    ServerContext::shared_pointer ctx =
        startPVAServer(PVACCESS_ALL_PROVIDERS,0,true,true);
    ExampleLinkPtr pvRecord(
        ExampleLink::create(
           "exampleLink",provider,"doubleArray")); 
    master->addRecord(pvRecord);
    cout << "exampleLink\n";
    string str;
    while(true) {
        cout << "Type exit to stop: \n";
        getline(cin,str);
        if(str.compare("exit")==0) break;

    }
    ctx->destroy();
    epicsThreadSleep(3.0);
//    channelProvider->destroy();
//    if(provider=="pva") ClientFactory::stop();
//    epicsThreadSleep(3.0);
    return 0;
}
Exemplo n.º 4
0
int main(int argc,char *argv[])
{
    string doubleArrayRecordName("doubleArray");
    if(argc==2 && string(argv[1])==string("-help")) {
        cout << "doubleArrayRecordName" << endl;
        cout << "default" << endl;
        cout << doubleArrayRecordName << endl;
        return 0;
    }
    if(argc>1) doubleArrayRecordName = argv[1];
    try {
        PVDatabasePtr master = PVDatabase::getMaster();
        ChannelProviderLocalPtr channelProvider = getChannelProviderLocal();
        NTScalarArrayBuilderPtr ntScalarArrayBuilder = NTScalarArray::createBuilder();
        PVStructurePtr pvStructure = ntScalarArrayBuilder->
            value(pvDouble)->
            addAlarm()->
            addTimeStamp()->
            createPVStructure();
        master->addRecord(PVRecord::create(doubleArrayRecordName,pvStructure));
        ServerContext::shared_pointer ctx =
            startPVAServer(PVACCESS_ALL_PROVIDERS,0,true,true);
        string str;
        while(true) {
            cout << "Type exit to stop: \n";
            getline(cin,str);
            if(str.compare("exit")==0) break;
        }
        ctx->destroy();
    } catch (std::runtime_error e) {
        cerr << "exception " << e.what() << endl;
        return 1;
    }
    return 0;
}
static void exampleServerCallFunc(const iocshArgBuf *args)
{
    PVDatabasePtr master = PVDatabase::getMaster();
    char *recordName = args[0].sval;
    ExampleServerPtr record = ExampleServer::create(recordName);
    bool result = master->addRecord(record);
    if(!result) cout << "recordname" << " not added" << endl;
    PVRecordPtr pvRecord = TraceRecord::create(
        "laptopTraceRecordPGRPC");
    if(!pvRecord) {
          cout << "TraceRecord::create failed" << endl;
    } else {
        result = master->addRecord(pvRecord);
        if(!result) cout<< "record " << recordName << " not added" << endl;
    }
}
Exemplo n.º 6
0
int main(int argc,char *argv[])
{
    PVDatabasePtr master = PVDatabase::getMaster();
    ChannelProviderLocalPtr channelProvider = getChannelProviderLocal();
    PVRecordPtr pvRecord;
    string recordName;

    recordName = "powerSupply";
    pvRecord = PowerSupplyRecord::create(recordName);
    master->addRecord(pvRecord);

    ServerContext::shared_pointer ctx =
        startPVAServer(PVACCESS_ALL_PROVIDERS,0,true,true);
    
    string str;
    while(true) {
        cout << "Type exit to stop: \n";
        getline(cin,str);
        if(str.compare("exit")==0) break;

    }
    ctx->destroy();
epicsThreadSleep(3.0); // should not be necessary
    return 0;
}
static void createRecords(
    PVDatabasePtr const &master,
    ScalarType scalarType,
    string const &recordNamePrefix,
    string const &properties)
{
    string recordName = recordNamePrefix;
    PVStructurePtr pvStructure = standardPVField->scalar(scalarType,properties);
    PVRecordPtr pvRecord = PVRecord::create(recordName,pvStructure);
    bool result = master->addRecord(pvRecord);
    if(!result) cout<< "record " << recordName << " not added" << endl;
    recordName += "Array";
    pvStructure = standardPVField->scalarArray(scalarType,properties);
    pvRecord = PVRecord::create(recordName,pvStructure);
    result = master->addRecord(pvRecord);
}
Exemplo n.º 8
0
adPvaServer::adPvaServer(
    const string & portName,
    const string & imageName,
    int queueSize,
    int blockingCallbacks,
    const string & NDArrayPort,
    int NDArrayAddr,
    int maxbuffers,
    int maxmemory)
: NDPluginDriver(portName.c_str(), queueSize, blockingCallbacks, 
      NDArrayPort.c_str(), NDArrayAddr, 1, NUM_AD_IMAGE_SERVER_PARAMS,
      maxbuffers, maxmemory,
      0,  // interfaceMask
      0,  // interruptMask,
      ASYN_CANBLOCK,
      1,  // autoconnect
      0,  // priority
      0), // stack-size
  imageName(imageName)
{
    createParam("arrayPVName", asynParamOctet, &arrayPVName);

    setStringParam(NDPluginDriverPluginType, "EPICS V4 AD Image Server");
    setStringParam(arrayPVName, imageName.c_str());

    callParamCallbacks();
 
    PVDatabasePtr master = PVDatabase::getMaster();
    record = NDArrayRecord::create(imageName);
    bool result = master->addRecord(record);
    if(!result) std::cerr << "recordname" << " not added" << std::endl;

    connectToArrayPort();
}
static void createDumbPowerSupplyRecord(
    PVDatabasePtr const &master,
    string const &recordName)
{
     StructureConstPtr top = fieldCreate->createFieldBuilder()->
         add("alarm",standardField->alarm()) ->
            add("timeStamp",standardField->timeStamp()) ->
            addNestedStructure("power") ->
               add("value",pvDouble) ->
               add("alarm",standardField->alarm()) ->
               endNested()->
            addNestedStructure("voltage") ->
               add("value",pvDouble) ->
               add("alarm",standardField->alarm()) ->
               endNested()->
            addNestedStructure("current") ->
               add("value",pvDouble) ->
               add("alarm",standardField->alarm()) ->
               endNested()->
            createStructure();
    PVStructurePtr pvStructure = pvDataCreate->createPVStructure(top);
    PVRecordPtr pvRecord = PVRecord::create(recordName,pvStructure);
    bool result = master->addRecord(pvRecord);
    if(!result) cout<< "record " << recordName << " not added" << endl;
}
Exemplo n.º 10
0
static void exampleRPCCallFunc(const iocshArgBuf *args)
{
    PVDatabasePtr master = PVDatabase::getMaster();
    char *recordName = args[0].sval;
    ExampleRPCPtr record = ExampleRPC::create(recordName);
    bool result = master->addRecord(record);
    if(!result) cout << "recordname" << " not added" << endl;
}
Exemplo n.º 11
0
static void createVariantUnionRecord(
    PVDatabasePtr const &master,
    string const &recordName)
{
    StructureConstPtr top = fieldCreate->createFieldBuilder()->
         add("value",fieldCreate->createVariantUnion())->
         createStructure();
    PVStructurePtr pvStructure = pvDataCreate->createPVStructure(top);
    PVRecordPtr pvRecord = PVRecord::create(recordName,pvStructure);
    bool result = master->addRecord(pvRecord);
    if(!result) cout<< "record " << recordName << " not added" << endl;
}
Exemplo n.º 12
0
static void doubleArrayCallFunc(const iocshArgBuf *args)
{
    string recordName("doubleArray");
    char *sval = args[0].sval;
    if(sval) recordName = string(sval);
    PVDatabasePtr master = PVDatabase::getMaster();
    NTScalarArrayBuilderPtr ntScalarArrayBuilder = NTScalarArray::createBuilder();
    PVStructurePtr pvStructure = ntScalarArrayBuilder->
                                 value(pvDouble)->
                                 addAlarm()->
                                 addTimeStamp()->
                                 createPVStructure();
    bool result = master->addRecord(PVRecord::create(recordName,pvStructure));
    if(!result) cout<< "record " << recordName << " not added" << endl;
}
Exemplo n.º 13
0
static void createRegularUnionArrayRecord(
    PVDatabasePtr const &master,
    string const &recordName)
{
    StructureConstPtr top = fieldCreate->createFieldBuilder()->
         addNestedUnionArray("value")->
             add("string",pvString)->
             addArray("stringArray",pvString)->
             endNested()->
         createStructure();
    PVStructurePtr pvStructure = pvDataCreate->createPVStructure(top);
    PVRecordPtr pvRecord = PVRecord::create(recordName,pvStructure);
    bool result = master->addRecord(pvRecord);
    if(!result) cout<< "record " << recordName << " not added" << endl;
}
int main(int argc,char *argv[])
{
    bool result(false);
    string recordName;
    recordName = "arrayPerformance";
    size_t size = 10000000;
    double delay = .0001;
    string providerName("local");
    size_t nMonitor = 1;
    int queueSize = 2;
    double waitTime = 0.0;
    if(argc==2 && string(argv[1])==string("-help")) {
        cout << "arrayPerformanceMain recordName size";
        cout << " delay providerName nMonitor queueSize waitTime" << endl;
        cout << "default" << endl;
        cout << "arrayPerformance ";
        cout << recordName << " ";
        cout << size << " ";
        cout << delay << " ";
        cout << providerName << " ";
        cout << nMonitor << " ";
        cout << queueSize << " ";
        cout << "0.0" << endl;
        return 0;
    }
    if(argc>1) recordName = argv[1];
    if(argc>2) size = strtoul(argv[2],0,0);
    if(argc>3) delay = atof(argv[3]);
    if(argc>4) providerName = argv[4];
    if(argc>5) nMonitor = strtoul(argv[5],0,0);
    if(argc>6) queueSize = strtol(argv[6],0,0);
    if(argc>7) waitTime = atof(argv[7]);
    cout << "arrayPerformance ";
    cout << recordName << " ";
    cout << size << " ";
    cout << delay << " ";
    cout << providerName << " ";
    cout << nMonitor << " ";
    cout << queueSize << " ";
       cout << waitTime << endl;
    ClientFactory::start();
    PVDatabasePtr master = PVDatabase::getMaster();
    ChannelProviderLocalPtr channelProvider = getChannelProviderLocal();
    PVRecordPtr pvRecord;
    pvRecord = ArrayPerformance::create(recordName,size,delay);
    result = master->addRecord(pvRecord);
    PVRecordPtr arrayPreformance = pvRecord;
    arrayPreformance->setTraceLevel(0);
    pvRecord = TraceRecord::create("traceRecordPGRPC");
    result = master->addRecord(pvRecord);
    if(!result) cout<< "record " << recordName << " not added" << endl;
    pvRecord.reset();
    ServerContext::shared_pointer pvaServer = 
        startPVAServer(PVACCESS_ALL_PROVIDERS,0,true,true);
    std::vector<LongArrayMonitorPtr> longArrayMonitor(nMonitor);
    for(size_t i=0; i<nMonitor; ++i) {
       longArrayMonitor[i]
         = LongArrayMonitor::create(providerName,recordName,queueSize,waitTime);
    }
    epicsThreadSleep(1.0);
    for(size_t i=0; i<nMonitor; ++i) longArrayMonitor[i]->start();
    cout << "arrayPerformance\n";
    string str;
    while(true) {
        cout << "Type exit to stop: \n";
        getline(cin,str);
        if(str.compare("exit")==0) break;

    }
    arrayPreformance.reset();
    for(size_t i=0; i<nMonitor; ++i) longArrayMonitor[i]->stop();
    for(size_t i=0; i<nMonitor; ++i) longArrayMonitor[i]->destroy();
    pvaServer->shutdown();
    epicsThreadSleep(1.0);
    pvaServer->destroy();
    ClientFactory::stop();
    epicsThreadSleep(1.0);
    channelProvider->destroy();
    return 0;
}
Exemplo n.º 15
0
void ExampleDatabase::create()
{
    PVDatabasePtr master = PVDatabase::getMaster();
    PVRecordPtr pvRecord;
    string recordName;
    bool result(false);
    recordName = "traceRecordPGRPC";
    pvRecord = TraceRecord::create(recordName);
    result = master->addRecord(pvRecord);
    if(!result) cout<< "record " << recordName << " not added" << endl;
    string properties;
    properties = "alarm,timeStamp";
    createRecords(master,pvByte,"byte01",properties);
    createRecords(master,pvShort,"short01",properties);
    createRecords(master,pvLong,"long01",properties);
    createRecords(master,pvUByte,"ubyte01",properties);
    createRecords(master,pvUInt,"uint01",properties);
    createRecords(master,pvUShort,"ushort01",properties);
    createRecords(master,pvULong,"ulong01",properties);
    createRecords(master,pvFloat,"float01",properties);

    StringArray choices(2);
    choices[0] = "zero";
    choices[1] = "one";
    master->addRecord(PVRecord::create(
         "exampleEnum",standardPVField->enumerated(choices,properties)));

    createRecords(master,pvBoolean,"exampleBoolean",properties);
    createRecords(master,pvByte,"exampleByte",properties);
    createRecords(master,pvShort,"exampleShort",properties);
    createRecords(master,pvInt,"exampleInt",properties);
    createRecords(master,pvLong,"exampleLong",properties);
    createRecords(master,pvFloat,"exampleFloat",properties);
    createRecords(master,pvDouble,"exampleDouble",properties);
    createRecords(master,pvDouble,"exampleDouble01",properties);
    createRecords(master,pvDouble,"exampleDouble02",properties);
    createRecords(master,pvDouble,"exampleDouble03",properties);
    createRecords(master,pvDouble,"exampleDouble04",properties);
    createRecords(master,pvDouble,"exampleDouble05",properties);
    createRecords(master,pvString,"exampleString",properties);
    createStructureArrayRecord(master,"exampleStructureArray");
    createRegularUnionRecord(master,"exampleRegularUnion");
    createVariantUnionRecord(master,"exampleVariantUnion");
    createRegularUnionArrayRecord(master,"exampleRegularUnionArray");
    createVariantUnionArrayRecord(master,"exampleVariantUnionArray");
    createDumbPowerSupplyRecord(master,"exampleDumbPowerSupply");
    recordName = "examplePowerSupply";
    PVStructurePtr pvStructure = createPowerSupply();
    PowerSupplyPtr psr = PowerSupply::create(recordName,pvStructure);
    if(!psr) {
          cout << "PowerSupply::create failed" << endl;
    } else {
        result = master->addRecord(psr);
        if(!result) cout<< "record " << recordName << " not added" << endl;
    }
    recordName = "exampleHello";
    result = master->addRecord(ExampleHello::create(recordName));
    if(!result) cout<< "record " << recordName << " not added" << endl;
    RPCServer::shared_pointer server(new RPCServer());
    server->registerService("exampleHelloRPC",ExampleHelloRPC::create());
}
Exemplo n.º 16
0
int main(int argc,char *argv[])
{
    double delay = 0.01;
    size_t event_count = 10;
    bool random_count = false;
    bool realistic = false;

    int opt;
    while ((opt = getopt(argc, argv, "d:e:h:mr")) != -1)
    {
        switch (opt)
        {
        case 'd':
            delay = atof(optarg);
            break;
        case 'e':
            event_count = (size_t)atol(optarg);
            break;
        case 'h':
            help(argv[0]);
            return 0;
        case 'm':
        	random_count = true;
            break;
        case 'r':
        	realistic = true;
            break;
        default:
            help(argv[0]);
            return -1;
        }
    }

    cout << "Delay : " << delay << " seconds" << endl;
    cout << "Events: " << event_count << endl;
    cout << "Realistic: " << realistic << endl;

    PVDatabasePtr master = PVDatabase::getMaster();
    ChannelProviderLocalPtr channelProvider = getChannelProviderLocal();


    NeutronPVRecord::shared_pointer neutrons = NeutronPVRecord::create("neutrons");
    if (! master->addRecord(neutrons))
        throw std::runtime_error("Cannot add record " + neutrons->getRecordName());

    shared_ptr<FakeNeutronEventRunnable> runnable(new FakeNeutronEventRunnable(neutrons, delay, event_count, random_count, realistic));
    shared_ptr<epicsThread> thread(new epicsThread(*runnable, "processor", epicsThreadGetStackSize(epicsThreadStackMedium)));
    thread->start();

    PVRecordPtr pvRecord = TraceRecord::create("traceRecordPGRPC");
    if (! master->addRecord(pvRecord))
        throw std::runtime_error("Cannot add record " + pvRecord->getRecordName());
    // Release record, held by database
    pvRecord.reset();

    ServerContext::shared_pointer pvaServer = 
        startPVAServer(PVACCESS_ALL_PROVIDERS,0,true,true);
    cout << "neutronServer running\n";
    string str;
    while(true) {
        cout << "Type exit to stop: \n";
        getline(cin,str);
        if(str.compare("exit")==0) break;

    }
    runnable->shutdown();
    pvaServer->shutdown();
    epicsThreadSleep(1.0);
    pvaServer->destroy();
    channelProvider->destroy();

    return 0;
}