still working on RAII

This commit is contained in:
mrkraimer
2016-05-19 12:01:21 -04:00
parent adc008dee6
commit a0cc581d3f
4 changed files with 31 additions and 40 deletions

View File

@@ -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,

View File

@@ -38,13 +38,6 @@ public:
PvaClientChannelCache(){}
~PvaClientChannelCache(){
if(PvaClient::getDebug()) cout << "PvaClientChannelCache::~PvaClientChannelCache\n";
map<string,PvaClientChannelPtr>::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()

View File

@@ -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);
}

View File

@@ -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);