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));
}
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;
}
Beispiel #3
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));
}
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;
}
Beispiel #5
0
void ChannelRequesterImpl::channelCreated(const epics::pvData::Status& status, Channel::shared_pointer const & channel)
{
    qDebug() << "ChannelRequesterImpl channelCreated";
    if (status.isSuccess()) {
        // show warning
        if (!status.isOK()) {
             std::cout << "[" << channel->getChannelName() << "] channel create: " << status.toString()  << std::endl;
        }
    } else {
         std::cout << "[" << channel->getChannelName() << "] failed to create a channel: " << status.toString()  << std::endl;
    }
}
Beispiel #6
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();
    } 
}
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;
}
Beispiel #8
0
void CAChannelProvider::destroy()
{
    Lock lock(channelsMutex);
    {
        while (!channels.empty())
        {
            Channel::shared_pointer channel = channels.rbegin()->second.lock();
            if (channel)
                channel->destroy();
        }
    }

    /* Destroy CA Context */
    ca_context_destroy();
}
 virtual void channelCreated(const epics::pvData::Status& status,
                             Channel::shared_pointer const & channel)
 {
     if (status.isSuccess())
     {
         // show warning
         if (!status.isOK())
         {
             std::cout << "[" << channel->getChannelName() << "] channel create: " << status << std::endl;
         }
     }
     else
     {
         std::cout << "[" << channel->getChannelName() << "] failed to create a channel: " << status << std::endl;
     }
 }
Beispiel #10
0
void ChannelRequesterImpl::channelStateChange(Channel::shared_pointer const & channel, Channel::ConnectionState connectionState)
{
    Q_UNUSED(channel);
    qDebug() << "ChannelRequesterImpl channelStateChange " << m_channelIndex;
    if (connectionState == Channel::CONNECTED) {
         std::cout << channel->getChannelName() << " CONNECTED: " << std::endl;
        m_event.signal();
        m_mutexData->SetMutexKnobDataConnected(m_channelIndex, true);
    } else if (connectionState == Channel::DISCONNECTED) {
         std::cout << channel->getChannelName() << " DISCONNECTED: " <<  std::endl;
        m_event.signal();
        m_mutexData->SetMutexKnobDataConnected(m_channelIndex, false);
    } else {
         std::cout << channel->getChannelName() << " " << Channel::ConnectionStateNames[connectionState] <<  std::endl;
    }
}
 // always called from the same thread
 virtual void channelStateChange(Channel::shared_pointer const & c, Channel::ConnectionState connectionState)
 {
     if (connectionState == Channel::CONNECTED)
     {
         cout << c->getChannelName() << " CONNECTED: " << (count+1) << endl;
         if (static_cast<size_t>(++count) == total)
             g_event.signal();
     }
     else if (connectionState == Channel::DISCONNECTED)
     {
         --count;
         cout << c->getChannelName() << " DISCONNECTED: " << count << endl;
     }
     else
         cout << c->getChannelName() << " " << Channel::ConnectionStateNames[connectionState] << endl;
     
 }
Beispiel #12
0
void MyChannelRequester::channelStateChange(Channel::shared_pointer const & channel, Channel::ConnectionState connectionState)
{
    cout << channel->getChannelName() << " state: "
         << Channel::ConnectionStateNames[connectionState]
         << " (" << connectionState << ")" << endl;
    if (connectionState == Channel::CONNECTED)
        connect_event.signal();
}
 virtual void channelCreated(const epics::pvData::Status& status, Channel::shared_pointer const & channel)
 {
     if (!status.isSuccess())
     {
         std::cout << "channelCreated(" << status << ", "
                   << (channel ? channel->getChannelName() : "(0)") << ")" << std::endl;
     }
 }
Beispiel #14
0
void PvValue::channelCreated(
    const Status& status,
    Channel::shared_pointer const & channel)
{
    if(!status.isOK()) {
        this->status = status;
        requester->message(status.getMessage(),errorMessage);
        isConnected = false;
        event.signal();
    }
    this->channel = channel;
    isConnected = true;
    channelGet = channel->createChannelGet(getPtrSelf(),getRequest);
}
PvaClientRPC::PvaClientRPC(
        PvaClientPtr const &pvaClient,
        Channel::shared_pointer const & channel,
        PVStructurePtr const &pvRequest)
: 
  connectState(connectIdle),
  pvaClient(pvaClient),
  channel(channel),
  pvRequest(pvRequest),
  rpcState(rpcIdle),
  responseTimeout(0.0)
{
    if(PvaClient::getDebug()) {
         cout<< "PvaClientRPC::PvaClientRPC()"
             << " channelName " << channel->getChannelName() 
             << endl;
    }
}
PvaClientMonitor::PvaClientMonitor(
        PvaClientPtr const &pvaClient,
        Channel::shared_pointer const & channel,
        PVStructurePtr const &pvRequest)
: pvaClient(pvaClient),
  channel(channel),
  pvRequest(pvRequest),
  isStarted(false),
  connectState(connectIdle),
  userPoll(false),
  userWait(false)
{
    if(PvaClient::getDebug()) {
         cout<< "PvaClientMonitor::PvaClientMonitor()"
             << " channelName " << channel->getChannelName() 
             << endl;
    }
}
 virtual void channelStateChange(Channel::shared_pointer const & c, Channel::ConnectionState connectionState)
 {
     std::cout << "channelStateChange(" << c->getChannelName() << ", " << Channel::ConnectionStateNames[connectionState] << ")" << std::endl;
 }
void runTest()
{
    reset();

    if (verbose)
        printf("%d channel(s) of double array size of %d element(s) (0==scalar), %d iteration(s) per run, %d run(s) (0==forever)\n", channels, arraySize, iterations, runs);

    /*
    StringArray fieldNames;
    fieldNames.push_back("strategy");
    FieldConstPtrArray fields;
    fields.push_back(getFieldCreate()->createScalar(pvInt));
    PVStructure::shared_pointer configuration =
        getPVDataCreate()->createPVStructure(getFieldCreate()->createStructure(fieldNames, fields));
    configuration->getIntField("strategy")->put(bulkMode ? USER_CONTROLED : DELAYED);
    provider->configure(configuration);
    */

    vector<string> channelNames;
    char buf[64];
    for (int i = 0; i < channels; i++)
    {
        if (arraySize > 0)
            sprintf(buf, "testArray%d_%d", arraySize, i);
        else
            sprintf(buf, "test%d", i);
        channelNames.push_back(buf);
    }

    vector<Channel::shared_pointer> channels;
    for (vector<string>::const_iterator i = channelNames.begin();
         i != channelNames.end();
         i++)
    {
        shared_ptr<ChannelRequesterImpl> channelRequesterImpl(
                        new ChannelRequesterImpl()
                    );
        Channel::shared_pointer channel = provider->createChannel(*i, channelRequesterImpl);
        channels.push_back(channel);
    }
    if (bulkMode) provider->flush();

    bool differentConnectionsWarningIssued = false;
    string theRemoteAddress;
    for (vector<Channel::shared_pointer>::iterator i = channels.begin();
         i != channels.end();
         i++)
    {
        Channel::shared_pointer channel = *i;
        shared_ptr<ChannelRequesterImpl> channelRequesterImpl =
                dynamic_pointer_cast<ChannelRequesterImpl>(channel->getChannelRequester());
        if (channelRequesterImpl->waitUntilConnected(5.0))
        {
            string remoteAddress = channel->getRemoteAddress();
            if (theRemoteAddress.empty())
            {
                theRemoteAddress = remoteAddress;
            }
            else if (theRemoteAddress != remoteAddress)
            {
                if (!differentConnectionsWarningIssued)
                {
                    std::cout << "not all channels are hosted by the same connection: " <<
                                 theRemoteAddress << " != " << remoteAddress << std::endl;
                    differentConnectionsWarningIssued = true;
                    // we assumes same connection (thread-safety)
                    exit(2);
                }
            }

            shared_ptr<ChannelGetRequesterImpl> getRequesterImpl(
                            new ChannelGetRequesterImpl(channel->getChannelName())
                        );
            ChannelGet::shared_pointer channelGet = channel->createChannelGet(getRequesterImpl, pvRequest);
            if (bulkMode) provider->flush();

            bool allOK = getRequesterImpl->waitUntilConnected(timeOut);

            if (!allOK)
            {
                std::cout << "[" << channel->getChannelName() << "] failed to get all the gets" << std::endl;
                exit(1);
            }

            channelGetList.push_back(channelGet);

        }
        else
        {
            std::cout << "[" << channel->getChannelName() << "] connection timeout" << std::endl;
            exit(1);
        }
    }
    if (verbose)
        std::cout << "all connected" << std::endl;

    {
        Lock guard(waitLoopPtrMutex);
        waitLoopEvent.reset(new Event());
    }
    epicsTimeGetCurrent(&startTime);
    get_all();
    
    waitLoopEvent->wait();
}
Beispiel #19
0
void MyChannelRequester::channelCreated(const Status& status, Channel::shared_pointer const & channel)
{
    cout << channel->getChannelName() << " created, " << status << endl;
}
Beispiel #20
0
void CAChannelProvider::unregisterChannel(Channel::shared_pointer const & channel)
{
    Lock lock(channelsMutex);
    channels.erase(channel.get());
}
Beispiel #21
0
void CAChannelProvider::registerChannel(Channel::shared_pointer const & channel)
{
    Lock lock(channelsMutex);
    channels[channel.get()] = Channel::weak_pointer(channel);
}
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);
}
void runTest()
{
    reset();

    if (verbose)
        printf("%d channel(s) of double array size of %d element(s) (0==scalar), %d iteration(s) per run, %d run(s) (0==forever)\n", channels, arraySize, iterations, runs);

    vector<string> channelNames;
    char buf[64];
    for (int i = 0; i < channels; i++)
    {
        if (arraySize > 0)
            sprintf(buf, "testArray%d_%d", arraySize, i);
        else
            sprintf(buf, "test%d", i);
        channelNames.push_back(buf);
    }

    vector<Channel::shared_pointer> channels;
    for (vector<string>::const_iterator i = channelNames.begin();
            i != channelNames.end();
            i++)
    {
        TR1::shared_ptr<ChannelRequesterImpl> channelRequesterImpl(
            new ChannelRequesterImpl()
        );
        Channel::shared_pointer channel = provider->createChannel(*i, channelRequesterImpl);
        channels.push_back(channel);
    }

    bool differentConnectionsWarningIssued = false;
    string theRemoteAddress;
    for (vector<Channel::shared_pointer>::iterator i = channels.begin();
            i != channels.end();
            i++)
    {
        Channel::shared_pointer channel = *i;
        TR1::shared_ptr<ChannelRequesterImpl> channelRequesterImpl =
            TR1::dynamic_pointer_cast<ChannelRequesterImpl>(channel->getChannelRequester());
        if (channelRequesterImpl->waitUntilConnected(5.0))
        {
            string remoteAddress = channel->getRemoteAddress();
            if (theRemoteAddress.empty())
            {
                theRemoteAddress = remoteAddress;
            }
            else if (theRemoteAddress != remoteAddress)
            {
                if (!differentConnectionsWarningIssued)
                {
                    std::cout << "not all channels are hosted by the same connection: " <<
                              theRemoteAddress << " != " << remoteAddress << std::endl;
                    differentConnectionsWarningIssued = true;
                    // we assumes same connection (thread-safety)
                    exit(2);
                }
            }

            TR1::shared_ptr<ChannelMonitorRequesterImpl> getRequesterImpl(
                new ChannelMonitorRequesterImpl(channel->getChannelName())
            );
            Monitor::shared_pointer monitor = channel->createMonitor(getRequesterImpl, pvRequest);

            bool allOK = getRequesterImpl->waitUntilConnected(timeOut);

            if (!allOK)
            {
                std::cout << "[" << channel->getChannelName() << "] failed to get all the monitors" << std::endl;
                exit(1);
            }

            channelMonitorList.push_back(monitor);

        }
        else
        {
            std::cout << "[" << channel->getChannelName() << "] connection timeout" << std::endl;
            exit(1);
        }
    }
    if (verbose)
        std::cout << "all connected" << std::endl;

    {
        Lock guard(waitLoopPtrMutex);
        waitLoopEvent.reset(new Event());
    }
    epicsTimeGetCurrent(&startTime);
    monitor_all();

    waitLoopEvent->wait();
}