From 860054a7a2aad94b4b89a70e07415e8b7265a0ba Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Tue, 6 Jun 2017 08:28:08 +0200 Subject: [PATCH] ChannelProviderRegistry update add()/remove() add() return created SimpleChannelProviderFactory instance. remove() missing Lock and remove by instance as well as by name. --- src/client/pv/pvAccess.h | 9 ++++++--- src/factory/ChannelAccessFactory.cpp | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/client/pv/pvAccess.h b/src/client/pv/pvAccess.h index e208845..d43711a 100644 --- a/src/client/pv/pvAccess.h +++ b/src/client/pv/pvAccess.h @@ -1237,16 +1237,19 @@ public: //! Add a new Provider which will be built using SimpleChannelProviderFactory template - bool add(const std::string& name, bool replace=true) + ChannelProviderFactory::shared_pointer add(const std::string& name, bool replace=true) { typedef SimpleChannelProviderFactory Factory; typename Factory::shared_pointer fact(new Factory(name)); - return add(fact, replace); + return add(fact, replace) ? fact : typename Factory::shared_pointer(); } - //! Attempt to remove named factory. Return Factory which was removed, or NULL if not found. + //! Attempt to remove a factory with the given name. Return Factory which was removed, or NULL if not found. ChannelProviderFactory::shared_pointer remove(const std::string& name); + //! Attempt to remove a factory. Return true if Factory was previously registered, and now removed. + bool remove(const ChannelProviderFactory::shared_pointer& factory); + //! Drop all factories void clear() { diff --git a/src/factory/ChannelAccessFactory.cpp b/src/factory/ChannelAccessFactory.cpp index 150b5ea..f510fb8 100644 --- a/src/factory/ChannelAccessFactory.cpp +++ b/src/factory/ChannelAccessFactory.cpp @@ -69,6 +69,7 @@ std::auto_ptr ChannelProviderRegistry:: bool ChannelProviderRegistry::add(const ChannelProviderFactory::shared_pointer& fact, bool replace) { + assert(fact); Lock G(mutex); std::string name(fact->getFactoryName()); if(!replace && providers.find(name)!=providers.end()) @@ -79,6 +80,7 @@ bool ChannelProviderRegistry::add(const ChannelProviderFactory::shared_pointer& ChannelProviderFactory::shared_pointer ChannelProviderRegistry::remove(const std::string& name) { + Lock G(mutex); ChannelProviderFactory::shared_pointer ret; providers_t::iterator iter(providers.find(name)); if(iter!=providers.end()) { @@ -88,6 +90,18 @@ ChannelProviderFactory::shared_pointer ChannelProviderRegistry::remove(const std return ret; } +bool ChannelProviderRegistry::remove(const ChannelProviderFactory::shared_pointer& fact) +{ + assert(fact); + Lock G(mutex); + providers_t::iterator iter(providers.find(fact->getFactoryName())); + if(iter!=providers.end() && iter->second==fact) { + providers.erase(iter); + return true; + } + return false; +} + ChannelProviderRegistry::shared_pointer getChannelProviderRegistry() { static Mutex mutex; static ChannelProviderRegistry::shared_pointer global_reg;