From a0cc581d3f15ae63a07eb3a8080fa9aa2368705c Mon Sep 17 00:00:00 2001 From: mrkraimer Date: Thu, 19 May 2016 12:01:21 -0400 Subject: [PATCH] still working on RAII --- src/pv/pvaClient.h | 13 +++++-------- src/pvaClient.cpp | 19 ++++++++++--------- src/pvaClientChannel.cpp | 21 +++------------------ src/pvaClientGet.cpp | 18 +++++++++++++----- 4 files changed, 31 insertions(+), 40 deletions(-) diff --git a/src/pv/pvaClient.h b/src/pv/pvaClient.h index 1ff9806..ffa3229 100644 --- a/src/pv/pvaClient.h +++ b/src/pv/pvaClient.h @@ -236,10 +236,6 @@ class epicsShareClass PvaClientChannel : public: POINTER_DEFINITIONS(PvaClientChannel); ~PvaClientChannel(); - /** Destroy the connection to the server. - * - */ - void destroy(); /** ChannelRequester method * @param status The status * @param channel The channel @@ -459,6 +455,10 @@ public: { return shared_from_this(); } + /** Deprecated method + * \deprecated This method will go away in future versions. + */ + void destroy() EPICS_DEPRECATED {} private: static PvaClientChannelPtr create( @@ -1035,10 +1035,7 @@ public: /** Deprecated method * \deprecated This method will go away in future versions. */ - void destroy() EPICS_DEPRECATED - { -channelGet->destroy(); - } + void destroy() EPICS_DEPRECATED {} private: PvaClientGet( PvaClientPtr const &pvaClient, diff --git a/src/pvaClient.cpp b/src/pvaClient.cpp index 8cc1a75..e52747c 100644 --- a/src/pvaClient.cpp +++ b/src/pvaClient.cpp @@ -38,13 +38,6 @@ public: PvaClientChannelCache(){} ~PvaClientChannelCache(){ if(PvaClient::getDebug()) cout << "PvaClientChannelCache::~PvaClientChannelCache\n"; - map::iterator iter; - for(iter = pvaClientChannelMap.begin(); iter != pvaClientChannelMap.end(); ++iter) - { - PvaClientChannelPtr pvaChannel = iter->second; - pvaChannel->destroy(); - } -// pvaClientChannelMap.clear(); } PvaClientChannelPtr getChannel( string const & channelName, @@ -153,8 +146,16 @@ PvaClient::~PvaClient() { } if(PvaClient::debug) showCache(); pvaClientChannelCache.reset(); - if(pvaStarted) ClientFactory::stop(); - if(caStarted) CAClientFactory::stop(); + if(pvaStarted){ + if(PvaClient::debug) cout<< "calling ClientFactory::stop()\n"; + ClientFactory::stop(); + if(PvaClient::debug) cout<< "after calling ClientFactory::stop()\n"; + } + if(caStarted) { + if(PvaClient::debug) cout<< "calling CAClientFactory::stop()\n"; + CAClientFactory::stop(); + if(PvaClient::debug) cout<< "after calling CAClientFactory::stop()\n"; + } } string PvaClient:: getRequesterName() diff --git a/src/pvaClientChannel.cpp b/src/pvaClientChannel.cpp index d4730d3..1d3351a 100644 --- a/src/pvaClientChannel.cpp +++ b/src/pvaClientChannel.cpp @@ -149,25 +149,12 @@ PvaClientChannel::~PvaClientChannel() << " this " << this << " channel " << channel << endl; } - destroy(); -} - -void PvaClientChannel::destroy() -{ - { + { Lock xx(mutex); if(isDestroyed) return; isDestroyed = true; } - if(PvaClient::getDebug()) { - cout << "PvaClientChannel::destroy() " - << " channelName " << channelName - << " this " << this << " channel " << channel - << endl; - } if(PvaClient::getDebug()) showCache(); - if(channel) channel->destroy(); - if(channel) channel.reset(); pvaClientGetCache.reset(); pvaClientPutCache.reset(); } @@ -233,8 +220,7 @@ void PvaClientChannel::channelStateChange( string PvaClientChannel::getRequesterName() { PvaClientPtr yyy = pvaClient.lock(); - if(!yyy) throw std::runtime_error( - "PvaClientChannel::getRequesterName() PvaClient isDestroyed"); + if(!yyy) return string("PvaClientChannel::getRequesterName() PvaClient isDestroyed"); return yyy->getRequesterName(); } @@ -243,8 +229,7 @@ void PvaClientChannel::message( MessageType messageType) { PvaClientPtr yyy = pvaClient.lock(); - if(!yyy) throw std::runtime_error( - "PvaClientChannel::message() pvaClient isDestroyed"); + if(!yyy) return; yyy->message(channelName + " " + message, messageType); } diff --git a/src/pvaClientGet.cpp b/src/pvaClientGet.cpp index 500b46f..4e1242c 100644 --- a/src/pvaClientGet.cpp +++ b/src/pvaClientGet.cpp @@ -68,7 +68,6 @@ PvaClientGet::~PvaClientGet() if(isDestroyed) return; isDestroyed = true; } -// if(channelGet) channelGet->destroy(); } void PvaClientGet::checkGetState() @@ -81,14 +80,13 @@ void PvaClientGet::checkGetState() // from ChannelGetRequester string PvaClientGet::getRequesterName() { - PvaClientPtr yyy = pvaClient.lock(); - if(!yyy) return string(); - return yyy->getRequesterName(); + PvaClientPtr yyy = pvaClient.lock(); + if(!yyy) return string("PvaClientGet::getRequesterName() PvaClient isDestroyed"); + return yyy->getRequesterName(); } void PvaClientGet::message(string const & message,MessageType messageType) { - if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed"); PvaClientPtr yyy = pvaClient.lock(); if(!yyy) return; yyy->message(message, messageType); @@ -99,6 +97,11 @@ void PvaClientGet::channelGetConnect( ChannelGet::shared_pointer const & channelGet, StructureConstPtr const & structure) { + if(PvaClient::getDebug()) { + cout << "PvaClientGet::channelGetConnect" + << " status.isOK " << (status.isOK() ? "true" : "false") + << endl; + } if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed"); { Lock xx(mutex); @@ -121,6 +124,11 @@ void PvaClientGet::getDone( PVStructurePtr const & pvStructure, BitSetPtr const & bitSet) { + if(PvaClient::getDebug()) { + cout << "PvaClientGet::getDone" + << " status.isOK " << (status.isOK() ? "true" : "false") + << endl; + } if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed"); { Lock xx(mutex);