From 094336b5e0814da7208e96923527f90fabc34df4 Mon Sep 17 00:00:00 2001 From: mrkraimer Date: Fri, 23 Jun 2017 14:45:44 -0400 Subject: [PATCH] let pvaClientMonitor do what pvaMonitor was doing --- src/Makefile | 1 - src/pv/pvaClient.h | 121 +++--------------- src/pvaClientChannel.cpp | 2 +- src/pvaClientMonitor.cpp | 267 +++++++++++++++++++++++---------------- src/pvaMonitor.cpp | 145 --------------------- 5 files changed, 171 insertions(+), 365 deletions(-) delete mode 100644 src/pvaMonitor.cpp diff --git a/src/Makefile b/src/Makefile index daae48f..7e945c7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -20,7 +20,6 @@ LIBSRCS += pvaClientProcess.cpp LIBSRCS += pvaClientGet.cpp LIBSRCS += pvaClientPut.cpp LIBSRCS += pvaClientMonitor.cpp -LIBSRCS += pvaMonitor.cpp LIBSRCS += pvaClientPutGet.cpp LIBSRCS += pvaClientMultiChannel.cpp LIBSRCS += pvaClientMultiGetDouble.cpp diff --git a/src/pv/pvaClient.h b/src/pv/pvaClient.h index a94fd37..08cad2e 100644 --- a/src/pv/pvaClient.h +++ b/src/pv/pvaClient.h @@ -65,8 +65,6 @@ class PvaClientPutGet; typedef std::tr1::shared_ptr PvaClientPutGetPtr; class PvaClientMonitor; typedef std::tr1::shared_ptr PvaClientMonitorPtr; -class PvaMonitor; -typedef std::tr1::shared_ptr PvaMonitorPtr; class PvaClientMonitorRequester; typedef std::tr1::shared_ptr PvaClientMonitorRequesterPtr; typedef std::tr1::weak_ptr PvaClientMonitorRequesterWPtr; @@ -1406,29 +1404,29 @@ typedef std::tr1::shared_ptr MonitorRequesterImplPtr; * */ class epicsShareClass PvaClientMonitor : -// public PvaClientChannelStateChangeRequester, -// public PvaClientMonitorRequester, -// public epics::pvData::Command, + public PvaClientChannelStateChangeRequester, + public PvaClientMonitorRequester, + public epics::pvData::Command, public std::tr1::enable_shared_from_this { public: POINTER_DEFINITIONS(PvaClientMonitor); /** @brief Create a PvaClientMonitor. - * @param &pvaClient Interface to PvaClient - * @param channel Interface to Channel + * @param pvaClient Interface to PvaClient + * @param pvaClientChannel Interface to PvaClientChannel * @param pvRequest The request structure. * @return The interface to the PvaClientMonitor. */ static PvaClientMonitorPtr create( PvaClientPtr const &pvaClient, - epics::pvAccess::Channel::shared_pointer const & channel, + PvaClientChannelPtr const & pvaClientChannel, epics::pvData::PVStructurePtr const &pvRequest ); /** @brief Create a PvaClientMonitor. - * @param &pvaClient Interface to PvaClient. - * @param channelName The channel name. - * @param providerName The provider name. - * @param request The request. For example "value,timeStamp" + * @param pvaClient Interface to PvaClient + * @param channelName channel name + * @param providerName provider name + * @param request The request. * @param stateChangeRequester The state change requester. Can be null. * @param monitorRequester The monitor requester. Can be null; * @return The new instance. @@ -1513,15 +1511,14 @@ private: PvaClientMonitor( PvaClientPtr const &pvaClient, - epics::pvAccess::Channel::shared_pointer const & channel, + PvaClientChannelPtr const & pvaClientChannel, epics::pvData::PVStructurePtr const &pvRequest); - void init(); void checkMonitorState(); enum MonitorConnectState {connectIdle,connectActive,connected}; PvaClient::weak_pointer pvaClient; - epics::pvAccess::Channel::weak_pointer channel; + PvaClientChannelPtr pvaClientChannel; epics::pvData::PVStructurePtr pvRequest; epics::pvData::Mutex mutex; epics::pvData::Event waitForConnect; @@ -1532,112 +1529,24 @@ private: epics::pvData::Status connectStatus; epics::pvData::MonitorPtr monitor; epics::pvData::MonitorElementPtr monitorElement; + PvaClientChannelStateChangeRequesterWPtr pvaClientChannelStateChangeRequester; PvaClientMonitorRequesterWPtr pvaClientMonitorRequester; - MonitorConnectState connectState; bool userPoll; bool userWait; MonitorRequesterImplPtr monitorRequester; - friend class MonitorRequesterImpl; -//public: -// void channelStateChange(PvaClientChannelPtr const & channel, bool isConnected); -// void event(PvaClientMonitorPtr const & monitor); -// void command(); -}; - - -/** - * @brief An easy to use alternative to Monitor. - * - */ -class epicsShareClass PvaMonitor : - public PvaClientChannelStateChangeRequester, - public PvaClientMonitorRequester, - public epics::pvData::Command, - public std::tr1::enable_shared_from_this -{ -public: - POINTER_DEFINITIONS(PvaMonitor); - /** @brief Create a PvaMonitor. - * @param &pvaClient Interface to PvaClient. - * @param channelName The channel name. - * @param providerName The provider name. - * @param request The request. For example "value,timeStamp" - * @param stateChangeRequester The state change requester. Can be null. - * @param monitorRequester The monitor requester. Can be null; - * @return The new instance. - */ - static PvaMonitorPtr create( - PvaClientPtr const &pvaClient, - std::string const & channelName, - std::string const & providerName, - std::string const & request, - PvaClientChannelStateChangeRequesterPtr const & stateChangeRequester, - PvaClientMonitorRequesterPtr const & monitorRequester - ); - /** @brief Destructor - */ - ~PvaMonitor(); - - /** - * @brief Get the PvaClientChannel - * - * @return The PvaClientChannel - */ - PvaClientChannelPtr getPvaClientChannel(); - /** - * @brief Get the PvaClientMonitor - * - * @return The PvaClientMonitor - */ - PvaClientMonitorPtr getPvaClientMonitor(); - /** - * @brief Start the monitor - * - */ - void start(); - /** - * @brief Start or restart the monitor with a new request. - * - * @param request The new request. - */ - void start(const std::string & request); - /** - * @brief Stop the monitor. - * - * @return The PvaClientMonitor - */ - void stop(); - -private: - static epics::pvData::ExecutorPtr executor; - PvaClient::weak_pointer pvaClient; - std::string channelName; - std::string providerName; - std::string request; - PvaClientChannelPtr pvaClientChannel; - PvaClientMonitorPtr pvaClientMonitor; - PvaClientChannelStateChangeRequesterPtr stateChangeRequester; - PvaClientMonitorRequesterPtr monitorRequester; - - PvaMonitor( - PvaClientPtr const &pvaClient, - std::string const & channelName, - std::string const & providerName, - std::string const & request, - PvaClientChannelStateChangeRequesterPtr const & stateChangeRequester, - PvaClientMonitorRequesterPtr const & monitorRequester - ); void init(); public: void channelStateChange(PvaClientChannelPtr const & channel, bool isConnected); void event(PvaClientMonitorPtr const & monitor); void command(); + friend class MonitorRequesterImpl; }; + /** * @brief Optional client callback. * diff --git a/src/pvaClientChannel.cpp b/src/pvaClientChannel.cpp index 0cc956b..c048a4b 100644 --- a/src/pvaClientChannel.cpp +++ b/src/pvaClientChannel.cpp @@ -537,7 +537,7 @@ PvaClientMonitorPtr PvaClientChannel::createMonitor(PVStructurePtr const & pvR if(connectState!=connected) connect(5.0); PvaClientPtr yyy = pvaClient.lock(); if(!yyy) throw std::runtime_error("PvaClient was destroyed"); - return PvaClientMonitor::create(yyy,channel,pvRequest); + return PvaClientMonitor::create(yyy,shared_from_this(),pvRequest); } PVStructurePtr PvaClientChannel::rpc( diff --git a/src/pvaClientMonitor.cpp b/src/pvaClientMonitor.cpp index e15fbcd..b794e33 100644 --- a/src/pvaClientMonitor.cpp +++ b/src/pvaClientMonitor.cpp @@ -25,6 +25,8 @@ using namespace std; namespace epics { namespace pvaClient { +ExecutorPtr PvaClientMonitor::executor(new Executor("pvaClientMonitor",middlePriority)); + class MonitorRequesterImpl : public MonitorRequester { PvaClientMonitor::weak_pointer pvaClientMonitor; @@ -80,21 +82,67 @@ public: PvaClientMonitorPtr PvaClientMonitor::create( PvaClientPtr const &pvaClient, - Channel::shared_pointer const & channel, + PvaClientChannelPtr const & pvaClientChannel, PVStructurePtr const &pvRequest) { - PvaClientMonitorPtr epv(new PvaClientMonitor(pvaClient,channel,pvRequest)); - epv->monitorRequester = MonitorRequesterImplPtr( - new MonitorRequesterImpl(epv,pvaClient)); - return epv; + if(PvaClient::getDebug()) { + cout<< "PvaClientMonitor::create(pvaClient,pvaClientChannel,pvRequest)\n" + << " channelName " << pvaClientChannel->getChannel()->getChannelName() + << endl; + } + PvaClientMonitorPtr clientMonitor(new PvaClientMonitor(pvaClient,pvaClientChannel,pvRequest)); + clientMonitor->monitorRequester = MonitorRequesterImplPtr( + new MonitorRequesterImpl(clientMonitor,pvaClient)); + return clientMonitor; +} + +PvaClientMonitorPtr PvaClientMonitor::create( + PvaClientPtr const &pvaClient, + std::string const & channelName, + std::string const & providerName, + std::string const & request, + PvaClientChannelStateChangeRequesterPtr const & stateChangeRequester, + PvaClientMonitorRequesterPtr const & monitorRequester) +{ + if(PvaClient::getDebug()) { + cout<< "PvaClientMonitor::create(pvaClient,channelName,providerName,request,stateChangeRequester,monitorRequester)\n" + << " channelName " << channelName + << " providerName " << providerName + << " request " << request + << endl; + } + CreateRequest::shared_pointer createRequest(CreateRequest::create()); + PVStructurePtr pvRequest(createRequest->createRequest(request)); + if(!pvRequest) throw std::runtime_error(createRequest->getMessage()); +cout << "calling pvaClient->createChannel\n"; + PvaClientChannelPtr pvaClientChannel = pvaClient->createChannel(channelName,providerName); +cout << "calling createMonitor\n"; + PvaClientMonitorPtr clientMonitor(new PvaClientMonitor(pvaClient,pvaClientChannel,pvRequest)); +cout << "after calling createMonitor\n"; + clientMonitor->monitorRequester = MonitorRequesterImplPtr( + new MonitorRequesterImpl(clientMonitor,pvaClient)); + if(stateChangeRequester) clientMonitor->pvaClientChannelStateChangeRequester = stateChangeRequester; + if(monitorRequester) clientMonitor->pvaClientMonitorRequester = monitorRequester; +cout << "calling init\n"; + clientMonitor->init(); +cout << "after calling init\n"; + return clientMonitor; +} + +void PvaClientMonitor::init() +{ +cout << "init calling setStateChangeRequester\n"; + pvaClientChannel->setStateChangeRequester(shared_from_this()); +cout << "init calling issueConnect\n"; + pvaClientChannel->issueConnect(); } PvaClientMonitor::PvaClientMonitor( PvaClientPtr const &pvaClient, - Channel::shared_pointer const & channel, + PvaClientChannelPtr const & pvaClientChannel, PVStructurePtr const &pvRequest) : pvaClient(pvaClient), - channel(channel), + pvaClientChannel(pvaClientChannel), pvRequest(pvRequest), isStarted(false), connectState(connectIdle), @@ -102,9 +150,7 @@ PvaClientMonitor::PvaClientMonitor( userWait(false) { if(PvaClient::getDebug()) { - cout<< "PvaClientMonitor::PvaClientMonitor()" - << " channelName " << channel->getChannelName() - << endl; + cout<< "PvaClientMonitor::PvaClientMonitor()" << endl; } } @@ -112,11 +158,8 @@ PvaClientMonitor::~PvaClientMonitor() { if(PvaClient::getDebug()) cout<< "PvaClientMonitor::~PvaClientMonitor\n"; if(PvaClient::getDebug()) { - string channelName("disconnected"); - Channel::shared_pointer chan(channel.lock()); - if(chan) channelName = chan->getChannelName(); cout<< "PvaClientMonitor::~PvaClientMonitor" - << " channelName " << channelName + << " channelName " << pvaClientChannel->getChannel()->getChannelName() << endl; } if(monitor) { @@ -125,14 +168,43 @@ PvaClientMonitor::~PvaClientMonitor() } } +void PvaClientMonitor::channelStateChange(PvaClientChannelPtr const & channel, bool isConnected) +{ + if(PvaClient::getDebug()) { + cout<< "PvaClientMonitor::channelStateChange" + << " channelName " << channel->getChannelName() + << " isConnected " << (isConnected ? "true" : "false") + << endl; + } + if(isConnected&&!monitor) + { + if(PvaClient::getDebug()) cout<< "PvaClientMonitor::channelStateChange calling executor.execute\n"; + executor->execute(shared_from_this()); + PvaClientChannelStateChangeRequesterPtr req(pvaClientChannelStateChangeRequester.lock()); + if(req) { + req->channelStateChange(channel,isConnected); + } + } +} + +void PvaClientMonitor::event(PvaClientMonitorPtr const & monitor) +{ + PvaClientMonitorRequesterPtr req(pvaClientMonitorRequester.lock()); + if(req) req->event(monitor); +} + +void PvaClientMonitor::command() +{ + if(PvaClient::getDebug()) cout<< "PvaClientMonitor::command\n"; + connect(); + if(connectState==connected && !isStarted) start(); +} + void PvaClientMonitor::checkMonitorState() { if(PvaClient::getDebug()) { - string channelName("disconnected"); - Channel::shared_pointer chan(channel.lock()); - if(chan) channelName = chan->getChannelName(); cout << "PvaClientMonitor::checkMonitorState" - << " channelName " << channelName + << " channelName " << pvaClientChannel->getChannel()->getChannelName() << " connectState " << connectState << endl; } @@ -159,13 +231,9 @@ void PvaClientMonitor::monitorConnect( Monitor::shared_pointer const & monitor, StructureConstPtr const & structure) { - Channel::shared_pointer chan(channel.lock()); if(PvaClient::getDebug()) { - string channelName("disconnected"); - Channel::shared_pointer chan(channel.lock()); - if(chan) channelName = chan->getChannelName(); cout << "PvaClientMonitor::monitorConnect" - << " channelName " << channelName + << " channelName " << pvaClientChannel->getChannel()->getChannelName() << " status.isOK " << (status.isOK() ? "true" : "false") << endl; } @@ -174,19 +242,16 @@ void PvaClientMonitor::monitorConnect( this->monitor = monitor; if(isStarted) { if(PvaClient::getDebug()) { - string channelName("disconnected"); - Channel::shared_pointer chan(channel.lock()); - if(chan) channelName = chan->getChannelName(); cout << "PvaClientMonitor::monitorConnect" - << " channelName " << channelName + << " channelName " << pvaClientChannel->getChannel()->getChannelName() << " is already started " << endl; } return; } - if(status.isOK() && chan) { + if(status.isOK()) { pvaClientData = PvaClientMonitorData::create(structure); - pvaClientData->setMessagePrefix(chan->getChannelName()); + pvaClientData->setMessagePrefix(pvaClientChannel->getChannel()->getChannelName()); } if(PvaClient::getDebug()) { cout << "PvaClientMonitor::monitorConnect calling waitForConnect.signal\n"; @@ -198,11 +263,8 @@ void PvaClientMonitor::monitorConnect( void PvaClientMonitor::monitorEvent(MonitorPtr const & monitor) { if(PvaClient::getDebug()) { - string channelName("disconnected"); - Channel::shared_pointer chan(channel.lock()); - if(chan) channelName = chan->getChannelName(); cout << "PvaClientMonitor::monitorEvent" - << " channelName " << channelName + << " channelName " << pvaClientChannel->getChannel()->getChannelName() << endl; } PvaClientMonitorRequesterPtr req = pvaClientMonitorRequester.lock(); @@ -218,10 +280,7 @@ void PvaClientMonitor::unlisten(MonitorPtr const & monitor) req->unlisten(); return; } - string channelName("disconnected"); - Channel::shared_pointer chan(channel.lock()); - if(chan) channelName = chan->getChannelName(); - cerr << channelName + "pvaClientMonitor::unlisten called but no PvaClientMonitorRequester\n"; + cerr << pvaClientChannel->getChannel()->getChannelName() + "pvaClientMonitor::unlisten called but no PvaClientMonitorRequester\n"; } @@ -231,11 +290,8 @@ void PvaClientMonitor::connect() issueConnect(); Status status = waitConnect(); if(status.isOK()) return; - Channel::shared_pointer chan(channel.lock()); - string channelName("disconnected"); - if(chan) channelName = chan->getChannelName(); string message = string("channel ") - + channelName + + pvaClientChannel->getChannel()->getChannelName() + " PvaClientMonitor::connect " + status.getMessage(); throw std::runtime_error(message); @@ -244,36 +300,30 @@ void PvaClientMonitor::connect() void PvaClientMonitor::issueConnect() { if(PvaClient::getDebug()) cout << "PvaClientMonitor::issueConnect\n"; - Channel::shared_pointer chan(channel.lock()); if(connectState!=connectIdle) { - string channelName("disconnected"); - if(chan) channelName = chan->getChannelName(); string message = string("channel ") - + channelName + + pvaClientChannel->getChannel()->getChannelName() + " pvaClientMonitor already connected "; throw std::runtime_error(message); } - if(chan) { - connectState = connectActive; - monitor = chan->createMonitor(monitorRequester,pvRequest); - return; - } - throw std::runtime_error("PvaClientMonitor::issueConnect() but channel disconnected"); + connectState = connectActive; + monitor = pvaClientChannel->getChannel()->createMonitor(monitorRequester,pvRequest); } Status PvaClientMonitor::waitConnect() { - if(PvaClient::getDebug()) cout << "PvaClientMonitor::waitConnect\n"; + if(PvaClient::getDebug()) { + cout << "PvaClientMonitor::waitConnect" + << pvaClientChannel->getChannel()->getChannelName() + << endl; + } if(connectState==connected) { if(!connectStatus.isOK()) connectState = connectIdle; return connectStatus; } if(connectState!=connectActive) { - Channel::shared_pointer chan(channel.lock()); - string channelName("disconnected"); - if(chan) channelName = chan->getChannelName(); string message = string("channel ") - + channelName + + pvaClientChannel->getChannel()->getChannelName() + " PvaClientMonitor::waitConnect illegal connect state "; throw std::runtime_error(message); } @@ -292,11 +342,8 @@ Status PvaClientMonitor::waitConnect() void PvaClientMonitor::setRequester(PvaClientMonitorRequesterPtr const & pvaClientMonitorRequester) { if(PvaClient::getDebug()) { - string channelName("disconnected"); - Channel::shared_pointer chan(channel.lock()); - if(chan) channelName = chan->getChannelName(); cout << "PvaClientMonitor::setRequester" - << " channelName " << channelName + << " channelName " << pvaClientChannel->getChannel()->getChannelName() << endl; } this->pvaClientMonitorRequester = pvaClientMonitorRequester; @@ -305,30 +352,21 @@ void PvaClientMonitor::setRequester(PvaClientMonitorRequesterPtr const & pvaClie void PvaClientMonitor::start() { if(PvaClient::getDebug()) { - string channelName("disconnected"); - Channel::shared_pointer chan(channel.lock()); - if(chan) channelName = chan->getChannelName(); cout << "PvaClientMonitor::start" - << " channelName " << channelName + << " channelName " << pvaClientChannel->getChannel()->getChannelName() << " connectState " << connectState << endl; } if(isStarted) { - string channelName("disconnected"); - Channel::shared_pointer chan(channel.lock()); - if(chan) channelName = chan->getChannelName(); cerr << "PvaClientMonitor::start" - << " channelName " << channelName + << " channelName " << pvaClientChannel->getChannel()->getChannelName() << " why is this called twice " << endl; return; } if(connectState==connectIdle) connect(); if(connectState!=connected) { - Channel::shared_pointer chan(channel.lock()); - string channelName("disconnected"); - if(chan) channelName = chan->getChannelName(); - string message = string("channel ") + channelName + string message = string("channel ") + pvaClientChannel->getChannel()->getChannelName() + " PvaClientMonitor::start illegal state "; throw std::runtime_error(message); } @@ -336,15 +374,47 @@ void PvaClientMonitor::start() monitor->start(); } +void PvaClientMonitor::start(string const & request) +{ + if(PvaClient::getDebug()) { + cout<< "PvaMonitor::start(request)" + << " request " << request + << endl; + } + PvaClientPtr client(pvaClient.lock()); + if(!client) throw std::runtime_error("pvaClient was deleted"); + if(!pvaClientChannel->getChannel()->isConnected()) { + client->message( + "PvaClientMonitor::start(request) but not connected", + MessageType::errorMessage); + return; + } + CreateRequest::shared_pointer createRequest(CreateRequest::create()); + PVStructurePtr pvr(createRequest->createRequest(request)); + if(!pvr) throw std::runtime_error(createRequest->getMessage()); + if(monitor) { + if(isStarted) monitor->stop(); + monitor->destroy(); + } + monitorRequester.reset(); + monitor.reset(); + isStarted = false; + connectState = connectIdle; + userPoll = false; + userWait = false; + monitorRequester = MonitorRequesterImplPtr( + new MonitorRequesterImpl(shared_from_this(),client)); + pvRequest = pvr; + connect(); + start(); +} + void PvaClientMonitor::stop() { if(PvaClient::getDebug()) { - string channelName("disconnected"); - Channel::shared_pointer chan(channel.lock()); - if(chan) channelName = chan->getChannelName(); cout << "PvaClientMonitor::stop" - << " channelName " << channelName + << " channelName " << pvaClientChannel->getChannel()->getChannelName() << endl; } if(!isStarted) return; @@ -355,27 +425,18 @@ void PvaClientMonitor::stop() bool PvaClientMonitor::poll() { if(PvaClient::getDebug()) { - string channelName("disconnected"); - Channel::shared_pointer chan(channel.lock()); - if(chan) channelName = chan->getChannelName(); cout << "PvaClientMonitor::poll" - << " channelName " << channelName + << " channelName " << pvaClientChannel->getChannel()->getChannelName() << endl; } checkMonitorState(); if(!isStarted) { - string channelName("disconnected"); - Channel::shared_pointer chan(channel.lock()); - if(chan) channelName = chan->getChannelName(); - string message = string("channel ") + channelName + string message = string("channel ") + pvaClientChannel->getChannel()->getChannelName() + " PvaClientMonitor::poll illegal state "; throw std::runtime_error(message); } if(userPoll) { - string channelName("disconnected"); - Channel::shared_pointer chan(channel.lock()); - if(chan) channelName = chan->getChannelName(); - string message = string("channel ") + channelName + string message = string("channel ") + pvaClientChannel->getChannel()->getChannelName() + " PvaClientMonitor::poll did not release last"; throw std::runtime_error(message); } @@ -389,18 +450,12 @@ bool PvaClientMonitor::poll() bool PvaClientMonitor::waitEvent(double secondsToWait) { if(PvaClient::getDebug()) { - string channelName("disconnected"); - Channel::shared_pointer chan(channel.lock()); - if(chan) channelName = chan->getChannelName(); cout << "PvaClientMonitor::waitEvent" - << " channelName " << channelName + << " channelName " << pvaClientChannel->getChannel()->getChannelName() << endl; } if(!isStarted) { - Channel::shared_pointer chan(channel.lock()); - string channelName("disconnected"); - if(chan) channelName = chan->getChannelName(); - string message = string("channel ") + channelName + string message = string("channel ") + pvaClientChannel->getChannel()->getChannelName() + " PvaClientMonitor::waitEvent illegal state "; throw std::runtime_error(message); } @@ -418,26 +473,17 @@ bool PvaClientMonitor::waitEvent(double secondsToWait) void PvaClientMonitor::releaseEvent() { if(PvaClient::getDebug()) { - string channelName("disconnected"); - Channel::shared_pointer chan(channel.lock()); - if(chan) channelName = chan->getChannelName(); cout << "PvaClientMonitor::releaseEvent" - << " channelName " << channelName + << " channelName " << pvaClientChannel->getChannel()->getChannelName() << endl; } if(!isStarted) { - Channel::shared_pointer chan(channel.lock()); - string channelName("disconnected"); - if(chan) channelName = chan->getChannelName(); - string message = string("channel ") + channelName + string message = string("channel ") + pvaClientChannel->getChannel()->getChannelName() + " PvaClientMonitor::releaseEvent monitor not started "; throw std::runtime_error(message); } if(!userPoll) { - Channel::shared_pointer chan(channel.lock()); - string channelName("disconnected"); - if(chan) channelName = chan->getChannelName(); - string message = string("channel ") + channelName + string message = string("channel ") + pvaClientChannel->getChannel()->getChannelName() + " PvaClientMonitor::releaseEvent did not call poll"; throw std::runtime_error(message); } @@ -448,11 +494,8 @@ void PvaClientMonitor::releaseEvent() PvaClientMonitorDataPtr PvaClientMonitor::getData() { if(PvaClient::getDebug()) { - string channelName("disconnected"); - Channel::shared_pointer chan(channel.lock()); - if(chan) channelName = chan->getChannelName(); cout << "PvaClientMonitor::getData" - << " channelName " << channelName + << " channelName " << pvaClientChannel->getChannel()->getChannelName() << endl; } checkMonitorState(); diff --git a/src/pvaMonitor.cpp b/src/pvaMonitor.cpp deleted file mode 100644 index 032e0b0..0000000 --- a/src/pvaMonitor.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* pvaClientMonitor.cpp */ -/** - * Copyright - See the COPYRIGHT that is included with this distribution. - * EPICS pvData is distributed subject to a Software License Agreement found - * in file LICENSE that is included with this distribution. - */ -/** - * @author mrk - * @date 2017.06 - */ - - -#define epicsExportSharedSymbols - -#include - -using std::tr1::static_pointer_cast; -using std::tr1::dynamic_pointer_cast; -using namespace epics::pvData; -using namespace epics::pvAccess; -using namespace std; - -namespace epics { namespace pvaClient { - -ExecutorPtr PvaMonitor::executor(new Executor("pvaMonitor",middlePriority)); - - -PvaMonitorPtr PvaMonitor::create( - PvaClientPtr const &pvaClient, - std::string const & channelName, - std::string const & providerName, - std::string const & request, - PvaClientChannelStateChangeRequesterPtr const & stateChangeRequester, - PvaClientMonitorRequesterPtr const & monitorRequester) -{ - PvaMonitorPtr epv(new PvaMonitor(pvaClient,channelName,providerName,request, - stateChangeRequester,monitorRequester)); - epv->init(); - return epv; -} - -PvaMonitor::PvaMonitor( - PvaClientPtr const &pvaClient, - std::string const & channelName, - std::string const & providerName, - std::string const & request, - PvaClientChannelStateChangeRequesterPtr const & stateChangeRequester, - PvaClientMonitorRequesterPtr const & monitorRequester) -: pvaClient(pvaClient), - channelName(channelName), - providerName(providerName), - request(request), - stateChangeRequester(stateChangeRequester), - monitorRequester(monitorRequester) -{ - if(PvaClient::getDebug()) { - cout<< "PvaMonitor::PvaMonitor()" - << " channelName " << channelName - << endl; - } -} - -void PvaMonitor::init() -{ - PvaClientPtr client(pvaClient.lock()); - if(!client) throw std::runtime_error("pvaClient was destroyed"); - pvaClientChannel = client->createChannel(channelName,providerName); - pvaClientChannel->setStateChangeRequester(shared_from_this()); - pvaClientChannel->issueConnect(); -} - -PvaMonitor::~PvaMonitor() -{ - if(PvaClient::getDebug()) cout<< "PvaMonitor::~PvaMonitor\n"; - pvaClientChannel.reset(); - pvaClientMonitor.reset(); -} - -PvaClientChannelPtr PvaMonitor::getPvaClientChannel() -{ - return pvaClientChannel; -} - -PvaClientMonitorPtr PvaMonitor::getPvaClientMonitor() -{ - return pvaClientMonitor; -} - -void PvaMonitor::start() -{ - if(PvaClient::getDebug()) cout<< "PvaMonitor::start()\n"; - if(!pvaClientMonitor) { - PvaClientPtr client(pvaClient.lock()); - client->message("PvaMonitor::start but not connected",MessageType::errorMessage); - return; - } - pvaClientMonitor->start(); -} - -void PvaMonitor::start(const string & request) -{ - if(PvaClient::getDebug()) cout<< "PvaMonitor::start(request)\n"; - if(!pvaClientChannel->getChannel()->isConnected()) { - PvaClientPtr client(pvaClient.lock()); - client->message("PvaMonitor::start(request) but not connected",MessageType::errorMessage); - return; - } - pvaClientMonitor.reset(); - pvaClientMonitor = pvaClientChannel->monitor(request,shared_from_this()); -} - -void PvaMonitor::stop() -{ - if(PvaClient::getDebug()) cout<< "PvaMonitor::stop()\n"; - if(!pvaClientMonitor) { - PvaClientPtr client(pvaClient.lock()); - client->message("PvaMonitor::start but not connected",MessageType::errorMessage); - return; - } - pvaClientMonitor->stop(); -} - -void PvaMonitor::channelStateChange(PvaClientChannelPtr const & channel, bool isConnected) -{ - if(PvaClient::getDebug()) cout<< "PvaMonitor::channelStateChange isConnected " << (isConnected ? "true" : "false") << endl; - if(isConnected&&!pvaClientMonitor) - { - if(PvaClient::getDebug()) cout<< "PvaMonitor::channelStateChange calling executor.execute\n"; - executor->execute(shared_from_this()); - } - if(stateChangeRequester) stateChangeRequester->channelStateChange(channel,isConnected); - } - -void PvaMonitor::event(PvaClientMonitorPtr const & monitor) -{ - if(monitorRequester) monitorRequester->event(monitor); -} - -void PvaMonitor::command() -{ - if(PvaClient::getDebug()) cout<< "PvaMonitor::command\n"; - pvaClientMonitor = pvaClientChannel->monitor(request,shared_from_this()); -} - -}}