From a7fb12a16fec146f99ba0a32c0099588fefa6a9e Mon Sep 17 00:00:00 2001 From: mrkraimer Date: Fri, 17 Jun 2016 12:31:19 -0400 Subject: [PATCH] pvaClientChannel fix bug if already connected; pvaClientMonitor make reconnection get first event --- src/pv/pvaClient.h | 3 ++- src/pvaClientChannel.cpp | 1 + src/pvaClientMonitor.cpp | 50 ++++++++++++++++++++++++++++++++-------- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/pv/pvaClient.h b/src/pv/pvaClient.h index 302aece..117d83f 100644 --- a/src/pv/pvaClient.h +++ b/src/pv/pvaClient.h @@ -1378,7 +1378,7 @@ private: epics::pvData::PVStructurePtr const &pvRequest); void checkMonitorState(); - enum MonitorConnectState {connectIdle,connectActive,connected,monitorStarted}; + enum MonitorConnectState {connectIdle,connectActive,connected}; PvaClient::weak_pointer pvaClient; epics::pvAccess::Channel::weak_pointer channel; @@ -1389,6 +1389,7 @@ private: PvaClientMonitorDataPtr pvaClientData; bool isDestroyed; + bool isStarted; epics::pvData::Status connectStatus; epics::pvData::MonitorPtr monitor; epics::pvData::MonitorElementPtr monitorElement; diff --git a/src/pvaClientChannel.cpp b/src/pvaClientChannel.cpp index 1333608..90ad206 100644 --- a/src/pvaClientChannel.cpp +++ b/src/pvaClientChannel.cpp @@ -224,6 +224,7 @@ void PvaClientChannel::channelCreated(const Status& status, Channel::shared_poin << endl; } Lock xx(mutex); + if(connectState==connected) return; if(connectState!=connectActive) { string message("PvaClientChannel::channelCreated"); message += " channel " + channelName diff --git a/src/pvaClientMonitor.cpp b/src/pvaClientMonitor.cpp index 6bdd970..6b58d5c 100644 --- a/src/pvaClientMonitor.cpp +++ b/src/pvaClientMonitor.cpp @@ -97,6 +97,7 @@ PvaClientMonitor::PvaClientMonitor( channel(channel), pvRequest(pvRequest), isDestroyed(false), + isStarted(false), connectState(connectIdle), userPoll(false), userWait(false) @@ -125,15 +126,24 @@ PvaClientMonitor::~PvaClientMonitor() << endl; } if(monitor) { - if(connectState==monitorStarted) monitor->stop(); + if(isStarted) monitor->stop(); monitor->destroy(); } } 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 + << " connectState " << connectState + << endl; + } if(connectState==connectIdle) connect(); - if(connectState==connected) start(); + if(connectState==connected && !isStarted) start(); } string PvaClientMonitor::getRequesterName() @@ -168,6 +178,18 @@ void PvaClientMonitor::monitorConnect( connectStatus = status; connectState = connected; 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 + << " is already started " + << endl; + } + return; + } if(status.isOK() && chan) { pvaClientData = PvaClientMonitorData::create(structure); pvaClientData->setMessagePrefix(chan->getChannelName()); @@ -285,9 +307,19 @@ void PvaClientMonitor::start() if(chan) channelName = chan->getChannelName(); cout << "PvaClientMonitor::start" << " channelName " << channelName + << " connectState " << connectState << endl; } - if(connectState==monitorStarted) return; + if(isStarted) { + string channelName("disconnected"); + Channel::shared_pointer chan(channel.lock()); + if(chan) channelName = chan->getChannelName(); + cerr << "PvaClientMonitor::start" + << " channelName " << channelName + << " why is this called twice " + << endl; + return; + } if(connectState==connectIdle) connect(); if(connectState!=connected) { Channel::shared_pointer chan(channel.lock()); @@ -297,7 +329,7 @@ void PvaClientMonitor::start() + " PvaClientMonitor::start illegal state "; throw std::runtime_error(message); } - connectState = monitorStarted; + isStarted = true; monitor->start(); } @@ -312,8 +344,8 @@ void PvaClientMonitor::stop() << " channelName " << channelName << endl; } - if(connectState!=monitorStarted) return; - connectState = connected; + if(!isStarted) return; + isStarted = false; monitor->stop(); } @@ -328,7 +360,7 @@ bool PvaClientMonitor::poll() << endl; } checkMonitorState(); - if(connectState!=monitorStarted) { + if(!isStarted) { string channelName("disconnected"); Channel::shared_pointer chan(channel.lock()); if(chan) channelName = chan->getChannelName(); @@ -361,7 +393,7 @@ bool PvaClientMonitor::waitEvent(double secondsToWait) << " channelName " << channelName << endl; } - if(connectState!=monitorStarted) { + if(!isStarted) { Channel::shared_pointer chan(channel.lock()); string channelName("disconnected"); if(chan) channelName = chan->getChannelName(); @@ -390,7 +422,7 @@ void PvaClientMonitor::releaseEvent() << " channelName " << channelName << endl; } - if(connectState!=monitorStarted) { + if(!isStarted) { Channel::shared_pointer chan(channel.lock()); string channelName("disconnected"); if(chan) channelName = chan->getChannelName();