replace destroy by RAII; many implementation changes

This commit is contained in:
mrkraimer
2016-05-13 12:50:47 -04:00
parent 9f8073aaa2
commit 3cc13e2c5a
18 changed files with 531 additions and 445 deletions

View File

@@ -37,11 +37,9 @@ class PvaClientChannelCache
public:
PvaClientChannelCache(){}
~PvaClientChannelCache(){
destroy();
if(PvaClient::getDebug()) cout << "PvaClientChannelCache::~PvaClientChannelCache\n";
pvaClientChannelMap.clear();
}
void destroy() {
pvaClientChannelMap.clear();
}
PvaClientChannelPtr getChannel(
string const & channelName,
string const & providerName);
@@ -68,17 +66,12 @@ void PvaClientChannelCache::addChannel(PvaClientChannelPtr const & pvaClientChan
Channel::shared_pointer channel = pvaClientChannel->getChannel();
string name = channel->getChannelName()
+ channel->getProvider()->getProviderName();
pvaClientChannelMap.insert(std::pair<string,PvaClientChannelPtr>(
name,pvaClientChannel));
}
void PvaClientChannelCache::removeChannel(
string const & channelName,
string const & providerName)
{
string name = channelName + providerName;
map<string,PvaClientChannelPtr>::iterator iter = pvaClientChannelMap.find(name);
if(iter!=pvaClientChannelMap.end()) pvaClientChannelMap.erase(iter);
if(iter!=pvaClientChannelMap.end()) {
throw std::runtime_error("pvaClientChannelCache::addChannel channel already cached");
}
pvaClientChannelMap.insert(std::pair<string,PvaClientChannelPtr>(
name,pvaClientChannel));
}
void PvaClientChannelCache::showCache()
@@ -103,6 +96,8 @@ size_t PvaClientChannelCache::cacheSize()
}
bool PvaClient::debug = false;
PvaClientPtr PvaClient::get(std::string const & providerNames)
{
static PvaClientPtr master;
@@ -141,16 +136,16 @@ PvaClient::PvaClient(std::string const & providerNames)
}
PvaClient::~PvaClient() {
destroy();
}
void PvaClient::destroy()
{
if(PvaClient::debug) cout<< "PvaClient::~PvaClient()\n";
{
Lock xx(mutex);
if(isDestroyed) return;
if(isDestroyed) {
cerr<< "Why was PvaClient::~PvaClient() called more then once????\n";
return;
}
isDestroyed = true;
}
if(PvaClient::debug) showCache();
pvaClientChannelCache.reset();
if(pvaStarted) ClientFactory::stop();
if(caStarted) CAClientFactory::stop();