int main(int argc,char *argv[])
{
    cout << "_____examplePvaClientMonitor starting_______\n";
    try {
        PvaClientPtr pva = PvaClient::get("pva ca");
//PvaClient::setDebug(true);
        exampleMonitor(pva,"PVRdouble","pva");
        PvaClientChannelPtr pvaChannel = pva->createChannel("DBRdouble00","ca");
        pvaChannel->issueConnect();
        Status status = pvaChannel->waitConnect(1.0);
        if(status.isOK()) {
            cout << "exampleMonitor pva\n";
            exampleMonitor(pva,"DBRdouble00","pva");
            cout << "exampleMonitor ca\n";
            exampleMonitor(pva,"DBRdouble00","ca");
        } else {
             cout << "DBRdouble00 not found\n";
        }
        cout << "_____examplePvaClientMonitor done_______\n";
    } catch (std::runtime_error e) {
            cerr << "exception " << e.what() << endl;
            return 1;
    }
    return 0;
}
int main(int argc,char *argv[])
{
    cout << "_____examplePvaClientPut starting_______\n";
    try {
        PvaClientPtr pva = PvaClient::get("pva ca");
        exampleDouble(pva,"PVRdouble","pva");
        exampleDoubleArray(pva,"PVRdoubleArray","pva");
        examplePVFieldPut(pva,"PVRint","pva");
        PvaClientChannelPtr pvaChannel = pva->createChannel("DBRdouble00","ca");
        pvaChannel->issueConnect();
        Status status = pvaChannel->waitConnect(1.0);
        if(status.isOK()) {
            exampleDouble(pva,"DBRdouble00","pva");
            exampleDouble(pva,"DBRdouble00","ca");
            exampleDoubleArray(pva,"DBRdoubleArray","pva");
            exampleDoubleArray(pva,"DBRdoubleArray","ca");
            examplePVFieldPut(pva,"DBRint00","pva");
            examplePVFieldPut(pva,"DBRint00","ca");
        } else {
             cout << "DBRdouble00 not found\n";
        }
        cout << "_____examplePvaClientPut done_______\n";
    } catch (std::runtime_error e) {
        cerr << "exception " << e.what() << endl;
        return 1;
    }
    return 0;
}
int main(int argc,char *argv[])
{
    cout << "_____examplePvaClientNTMulti starting_______\n";
    PvaClientPtr pva = PvaClient::create();
    size_t num = 4;
    shared_vector<string> channelNames(num);
    channelNames[0] = "PVRdouble";
    channelNames[1] = "PVRstring";
    channelNames[2] = "PVRdoubleArray";
    channelNames[3] = "PVRstringArray";
    shared_vector<const string> names(freeze(channelNames));
    example(pva,"pva",names);
    PvaClientChannelPtr pvaChannel = pva->createChannel("DBRdouble00","ca");
    pvaChannel->issueConnect();
    Status status = pvaChannel->waitConnect(1.0);
    if(status.isOK()) {
        channelNames = shared_vector<string>(num);
        channelNames[0] = "DBRdouble01";
        channelNames[1] = "DBRstring01";
        channelNames[2] = "DBRdoubleArray01";
        channelNames[3] = "DBRstringArray01";
        names = freeze(channelNames);
        example(pva,"pva",names);
        example(pva,"ca",names);
    } else {
         cout << "DBRdouble00 not found\n";
    }
    cout << "_____examplePvaClientNTMulti done_______\n";
    return 0;
}
static void exampleDoubleArray(PvaClientPtr const &pva,string const & channelName,string const & providerName)
{
    cout << "__exampleDoubleArray__ channelName " << channelName << " providerName " << providerName << endl;
    PvaClientChannelPtr channel = pva->channel(channelName,providerName,2.0);
    PvaClientPutPtr put = channel->put();
    PvaClientPutDataPtr putData = put->getData();
    PvaClientMonitorPtr monitor = pva->channel(channelName,providerName,2.0)->monitor("value");
    PvaClientMonitorDataPtr monitorData = monitor->getData();
    size_t num = 5;
    shared_vector<double> data(num,0);
    for(size_t i=0; i<num; ++i) data[i] = .1*i;
    putData->putDoubleArray(freeze(data)); put->put();
    cout <<  channel->get("field(value)")->getData()->showChanged(cout) << endl;
    data = shared_vector<double>(num,0);
    for(size_t i=0; i<num; ++i) data[i] = .1*(i + 1);
    putData->putDoubleArray(freeze(data)); put->put();
    cout <<  channel->get("field(value)")->getData()->showChanged(cout) << endl;
    if(!monitor->waitEvent()) {
           cout << "waitEvent returned false. Why???";
    } else while(true) {
         cout << "monitor changed\n" << monitorData->showChanged(cout);
         monitor->releaseEvent();
         if(!monitor->poll()) break;
    }
}
static void exampleProcess(PvaClientPtr const &pva)
{
    cout << "example process\n";
    PvaClientChannelPtr channel = pva->channel("PVRdouble");
    PvaClientProcessPtr process = channel->createProcess();
    process->process();
    cout <<  channel->get("field()")->getData()->showChanged(cout) << endl;
    process->process();
    cout <<  channel->get("field()")->getData()->showChanged(cout) << endl;
}
bool PvaClientMultiChannel::connectionChange()
{
    for(size_t i=0; i<numChannel; ++i) {
         PvaClientChannelPtr pvaClientChannel = pvaClientChannelArray[i];
         Channel::shared_pointer channel = pvaClientChannel->getChannel();
         Channel::ConnectionState stateNow = channel->getConnectionState();
         bool connectedNow = stateNow==Channel::CONNECTED ? true : false;
         if(connectedNow!=isConnected[i]) return true;
    }
    return false;
}
static void examplePVFieldPut(PvaClientPtr const &pva,string const & channelName,string const & providerName)
{
    cout << "__examplePVFieldPut__ channelName " << channelName << " providerName " << providerName << endl;
    PvaClientChannelPtr channel = pva->channel(channelName,providerName,2.0);
    PvaClientPutPtr put = channel->put();
    PvaClientPutDataPtr putData = put->getData();
    PVScalarPtr pvScalar = static_pointer_cast<PVScalar>(putData->getValue());
    convert->fromDouble(pvScalar,1.0); put->put();
    cout <<  channel->get("field(value)")->getData()->showChanged(cout) << endl;
    convert->fromDouble(pvScalar,2.0); put->put();
    cout <<  channel->get("field(value)")->getData()->showChanged(cout) << endl;
}
bool PvaClientMultiChannel::connectionChange()
{
    if(isDestroyed) throw std::runtime_error("pvaClientMultiChannel was destroyed");
    for(size_t i=0; i<numChannel; ++i) {
         PvaClientChannelPtr pvaClientChannel = pvaClientChannelArray[i];
         Channel::shared_pointer channel = pvaClientChannel->getChannel();
         Channel::ConnectionState stateNow = channel->getConnectionState();
         bool connectedNow = stateNow==Channel::CONNECTED ? true : false;
         if(connectedNow!=isConnected[i]) return true;
    }
    return false;
}
PvaClientChannelPtr PvaClient::channel(
        std::string const & channelName,
        std::string const & providerName,
        double timeOut)
{
    PvaClientChannelPtr pvaClientChannel = 
        pvaClientChannelCache->getChannel(channelName,providerName);
    if(pvaClientChannel) return pvaClientChannel;
    pvaClientChannel = createChannel(channelName,providerName);
    pvaClientChannel->connect(timeOut);
    pvaClientChannelCache->addChannel(pvaClientChannel);
    return pvaClientChannel;
}
Example #10
0
void PvaClientChannelCache::showCache()
{
    map<string,PvaClientChannelPtr>::iterator iter;
    for(iter = pvaClientChannelMap.begin(); iter != pvaClientChannelMap.end(); ++iter)
    {
         PvaClientChannelPtr pvaChannel = iter->second;
         Channel::shared_pointer channel = pvaChannel->getChannel();
         string channelName = channel->getChannelName();
         string providerName = channel->getProvider()->getProviderName();
         cout << "channel " << channelName << " provider " << providerName << endl;
         pvaChannel->showCache();
    } 
}
bool ExampleMonitorLinkRecord::init(PvaClientPtr const & pva,string const & channelName,string const & providerName)
{
    initPVRecord();

    PVStructurePtr pvStructure = getPVRecordStructure()->getPVStructure();
    pvValue = pvStructure->getSubField<PVDoubleArray>("value");
    if(!pvValue) {
        return false;
    }
    PvaClientChannelPtr pvaClientChannel = pva->channel(channelName,providerName,0.0);
    monitorRequester = dynamic_pointer_cast<PvaClientMonitorRequester>(getPtrSelf());
    pvaClientMonitor = pvaClientChannel->monitor("value",monitorRequester);
    return true;
}
epics::pvData::shared_vector<epics::pvData::boolean>  PvaClientMultiChannel::getIsConnected()
{
    for(size_t i=0; i<numChannel; ++i) {
         PvaClientChannelPtr pvaClientChannel = pvaClientChannelArray[i];
         if(!pvaClientChannel) {
              isConnected[i] = false;
              continue;
         }
         Channel::shared_pointer channel = pvaClientChannel->getChannel();
         Channel::ConnectionState stateNow = channel->getConnectionState();
         isConnected[i] = (stateNow==Channel::CONNECTED) ? true : false;
    }
    return isConnected;
}
static void exampleProcess(PvaClientPtr const &pva)
{
    cout << "example process\n";
    PvaClientChannelPtr channel = pva->channel("PVRdouble");
    PvaClientProcessPtr process = channel->createProcess();
    try {
        process->process();
        cout <<  channel->get("field()")->getData()->showChanged(cout) << endl;
        process->process();
        cout <<  channel->get("field()")->getData()->showChanged(cout) << endl;
    } catch (std::runtime_error e) {
        cout << "exception " << e.what() << endl;
    }
}
Example #14
0
void PvaClientChannelCache::addChannel(PvaClientChannelPtr const & pvaClientChannel)
{
     Channel::shared_pointer channel = pvaClientChannel->getChannel();
     string name = channel->getChannelName()
         + channel->getProvider()->getProviderName();
     pvaClientChannelMap.insert(std::pair<string,PvaClientChannelPtr>(
         name,pvaClientChannel));
}
static void examplePVFieldPut(PvaClientPtr const &pva)
{
    cout << "example put\n";
    PvaClientChannelPtr channel = pva->channel("exampleDouble");
    PvaClientPutPtr put = channel->put();
    PvaClientPutDataPtr putData = put->getData();
    PVFieldPtr pvField = putData->getValue();
    PVScalarPtr pvScalar = static_pointer_cast<PVScalar>(pvField);
    try {
        convert->fromDouble(pvScalar,1.0); put->put();
        cout <<  channel->get("field()")->getData()->showChanged(cout) << endl;
        convert->fromDouble(pvScalar,2.0); put->put();
        cout <<  channel->get("field()")->getData()->showChanged(cout) << endl;
    } catch (std::runtime_error e) {
        cout << "exception " << e.what() << endl;
    }
}
int main(int argc,char *argv[])
{
    cout << "_____examplePvaClientGet starting_______\n";
    PvaClientPtr pva= PvaClient::create();
    exampleDouble(pva);
    exampleDoubleArray(pva);
    PvaClientChannelPtr pvaChannel = pva->createChannel("DBRdouble00","ca");
    pvaChannel->issueConnect();
    Status status = pvaChannel->waitConnect(1.0);
    if(status.isOK()) {
        exampleCADouble(pva);
        exampleCADoubleArray(pva);
    } else {
         cout << "DBRdouble00 not found\n";
    }
    cout << "_____examplePvaClientGet done_______\n";
    return 0;
}
static void exampleDouble(PvaClientPtr const &pva,string const & channelName,string const & providerName)
{
    cout << "__exampleDouble__ channelName " << channelName << " providerName " << providerName << endl;
    PvaClientChannelPtr channel = pva->channel(channelName,providerName,2.0);
    PvaClientPutPtr put = channel->put();
    PvaClientPutDataPtr putData = put->getData();
    PvaClientMonitorPtr monitor = pva->channel(channelName,providerName,2.0)->monitor("value");
    PvaClientMonitorDataPtr monitorData = monitor->getData();
    putData->putDouble(3.0); put->put();
    cout <<  channel->get("field(value)")->getData()->showChanged(cout) << endl;
    putData->putDouble(4.0); put->put();
    cout <<  channel->get("field(value)")->getData()->showChanged(cout) << endl;
    if(!monitor->waitEvent()) {
           cout << "waitEvent returned false. Why???";
    } else while(true) {
         cout << "monitor changed\n" << monitorData->showChanged(cout);
         monitor->releaseEvent();
         if(!monitor->poll()) break;
    }
}
int main(int argc,char *argv[])
{
    PvaClientPtr pva = PvaClient::create();
    try {
        PvaClientChannelPtr channel = pva->channel("helloPutGet");
        PvaClientPutGetPtr putGet = channel->createPutGet();
        putGet->connect();
        PvaClientPutDataPtr putData = putGet->getPutData();
        PVStructurePtr arg = putData->getPVStructure();
        PVStringPtr pvValue = arg->getSubField<PVString>("argument.value");
        pvValue->put("World");
        putGet->putGet();
        PvaClientGetDataPtr getData = putGet->getGetData();
        cout << getData->getPVStructure() << endl;
    } catch (std::runtime_error e) {
        cout << "exception " << e.what() << endl;
        return 1;
    }
    return 0;
}
Example #19
0
void PvaClientChannelCache::addChannel(PvaClientChannelPtr const & pvaClientChannel)
{
     Channel::shared_pointer channel = pvaClientChannel->getChannel();
     string name = channel->getChannelName()
         + channel->getProvider()->getProviderName();
    map<string,PvaClientChannelPtr>::iterator iter = pvaClientChannelMap.find(name);
    if(iter!=pvaClientChannelMap.end()) {
        throw std::runtime_error("pvaClientChannelCache::addChannel channel already cached");
    }
    pvaClientChannelMap.insert(std::pair<string,PvaClientChannelPtr>(
         name,pvaClientChannel));
}
int main(int argc,char *argv[])
{
    cout << "_____examplePvaClientMultiDouble starting_______\n";
    try {
        PvaClientPtr pva = PvaClient::get("pva ca");
//PvaClient::setDebug(true);
        size_t num = 5;
        shared_vector<string> channelNames(num);
        channelNames[0] = "PVRdouble01";
        channelNames[1] = "PVRint";
        channelNames[2] = "PVRdouble03";
        channelNames[3] = "PVRdouble04";
        channelNames[4] = "PVRdouble05";
        shared_vector<const string> names(freeze(channelNames));
        example(pva,"pva",names);
        PvaClientChannelPtr pvaChannel = pva->createChannel("DBRdouble00","pva");
        pvaChannel->issueConnect();
        Status status = pvaChannel->waitConnect(1.0);
        if(status.isOK()) {
            channelNames = shared_vector<string>(num);
            channelNames[0] = "DBRdouble01";
            channelNames[1] = "DBRint01";
            channelNames[2] = "DBRdouble03";
            channelNames[3] = "DBRdouble04";
            channelNames[4] = "DBRdouble05";
            names = freeze(channelNames);
            example(pva,"pva",names);
            example(pva,"ca",names);
        } else {
            cout << "DBRdouble00 not found\n";
        }
        cout << "_____examplePvaClientMultiDouble done_______\n";
     } catch (std::runtime_error e) {
        cout << "exception " << e.what() << endl;
        return 1;
    }
    return 0;
}
static void exampleCADoubleArray(PvaClientPtr const &pva)
{
    cout << "__exampleCADoubleArray__\n";
    shared_vector<const double> value;
    try {
        cout << "short way\n";
        value =  pva->channel("DBRdoubleArray","ca",5.0)->get()->getData()->getDoubleArray();
        cout << "as doubleArray " << value << endl;
    } catch (std::runtime_error e) {
        cout << "exception " << e.what() << endl;
    }
    try {
        cout << "long way\n";
        PvaClientChannelPtr pvaChannel = pva->createChannel("DBRdoubleArray","ca");
        pvaChannel->connect(2.0);
        PvaClientGetPtr pvaGet = pvaChannel->createGet();
        PvaClientGetDataPtr pvaData = pvaGet->getData();
        value = pvaData->getDoubleArray();
        cout << "as doubleArray " << value << endl;
    } catch (std::runtime_error e) {
        cout << "exception " << e.what() << endl;
    }
}
static void examplePut(PvaClientPtr const &pva)
{
    cout << "example put\n";
    PvaClientChannelPtr channel = pva->channel("exampleDouble");
    PvaClientPutPtr put = channel->put();
    PvaClientPutDataPtr putData = put->getData();
    PvaClientMonitorPtr monitor = pva->channel("exampleDouble")->monitor("");
    PvaClientMonitorDataPtr monitorData = monitor->getData();
    try {
        putData->putDouble(3.0); put->put();
        cout <<  channel->get("field()")->getData()->showChanged(cout) << endl;
        putData->putDouble(4.0); put->put();
        cout <<  channel->get("field()")->getData()->showChanged(cout) << endl;
        if(!monitor->waitEvent()) {
               cout << "waitEvent returned false. Why???";
        } else while(true) {
             cout << "monitor changed\n" << monitorData->showChanged(cout);
             monitor->releaseEvent();
             if(!monitor->poll()) break;
        }
    } catch (std::runtime_error e) {
        cout << "exception " << e.what() << endl;
    }
}
static void exampleCADouble(PvaClientPtr const &pva)
{
    cout << "__exampleCADouble__\n";
    double value;
    try {
        cout << "short way\n";
        value =  pva->channel("DBRdouble00","ca",5.0)->get()->getData()->getDouble();
        cout << "as double " << value << endl;
    } catch (std::runtime_error e) {
        cout << "exception " << e.what() << endl;
    }
    cout << "long way\n";
    PvaClientChannelPtr pvaChannel = pva->createChannel("DBRdouble00","ca");
    pvaChannel->issueConnect();
    Status status = pvaChannel->waitConnect(2.0);
    if(!status.isOK()) {cout << " connect failed\n"; return;}
    PvaClientGetPtr pvaGet = pvaChannel->createGet();
    pvaGet->issueConnect();
    status = pvaGet->waitConnect();
    if(!status.isOK()) {cout << " createGet failed\n"; return;}
    PvaClientGetDataPtr pvaData = pvaGet->getData();
    value = pvaData->getDouble();
    cout << "as double " << value << endl;
}
PvaClientProcessPtr PvaClientProcess::create(
        PvaClientPtr const &pvaClient,
        PvaClientChannelPtr const & pvaClientChannel,
        PVStructurePtr const &pvRequest)
{
    if(PvaClient::getDebug()) {
         cout<< "PvaClientProcess::create(pvaClient,channelName,pvRequest)\n"
             << " channelName " <<  pvaClientChannel->getChannel()->getChannelName()
             << " pvRequest " << pvRequest
             << endl;
    }
    PvaClientProcessPtr channelProcess(new PvaClientProcess(pvaClient,pvaClientChannel,pvRequest));
    channelProcess->channelProcessRequester = ChannelProcessRequesterImplPtr(
        new ChannelProcessRequesterImpl(channelProcess,pvaClient));
    return channelProcess;
}
PvaClientProcess::PvaClientProcess(
        PvaClientPtr const &pvaClient,
        PvaClientChannelPtr const & pvaClientChannel,
        PVStructurePtr const &pvRequest)
: pvaClient(pvaClient),
  pvaClientChannel(pvaClientChannel),
  pvRequest(pvRequest),
  connectState(connectIdle),
  processState(processIdle)
{
    if(PvaClient::getDebug()) {
        cout<< "PvaClientProcess::PvaClientProcess()"
            << " channelName " << pvaClientChannel->getChannel()->getChannelName()
            << endl;
    }
}
static void exampleDouble(PvaClientPtr const &pvaClient)
{
    testDiag("== exampleDouble ==");

    PvaClientChannelPtr pvaChannel;
    try {
        pvaChannel = pvaClient->createChannel("PVRdouble");
        pvaChannel->connect(2.0);
        testDiag("channel connected");
    } catch (std::runtime_error e) {
        testAbort("channel connection exception '%s'", e.what());
    }

    PvaClientPutPtr put;
    PvaClientPutDataPtr putData;
    try {
        put = pvaChannel->createPut();
        putData = put->getData();
        testDiag("put connected");
        if (!putData)
            testAbort("NULL data pointer from putGet");
    } catch (std::runtime_error e) {
        testAbort("put connection exception '%s'", e.what());
    }

    PvaClientGetPtr get;
    PvaClientGetDataPtr getData;
    try {
        get = pvaChannel->createGet();
        getData = get->getData();
        testDiag("get connected");
        if (!getData)
            testAbort("NULL data pointer from putGet");
    } catch (std::runtime_error e) {
        testAbort("get connection exception '%s'", e.what());
    }

    PvaClientMonitorRequesterPtr requester(new MyMonitor());
    PvaClientMonitorPtr monitor;
    expected.set(0);        // structure definition
    try {
        monitor = pvaChannel->monitor(requester);
        testDiag("monitor connected");
    } catch (std::runtime_error e) {
        testAbort("monitor connection exception '%s'", e.what());
    }
    epicsThreadSleep(0.1);  // Allow connection monitor event to fire

    expected.clear();       // FIXME: Magic numbers here...
    expected.set(1);        // value
    expected.set(6);        // timestamp

    try {
        for (int i=0; i<5; ++i) {
            testDiag("= put %d =", i);

            double out = i;
            putData->putDouble(out);
            put->put();

            get->get();
            double in = getData->getDouble();
            testOk(in == out, "get value matches put");
        }

        PvaClientProcessPtr process = pvaChannel->createProcess();
        process->connect();

        testDiag("= process =");
        expected.clear(1);  // no value change
        process->process();
    } catch (std::runtime_error e) {
        testAbort("exception '%s'", e.what());
    }
}