ChannelProviderRegistry update add()/remove()

add() return created SimpleChannelProviderFactory instance.

remove()

missing Lock
and remove by instance as well as by name.
This commit is contained in:
Michael Davidsaver
2017-06-06 08:28:08 +02:00
parent f8c8925b83
commit 860054a7a2
2 changed files with 20 additions and 3 deletions
+6 -3
View File
@@ -1237,16 +1237,19 @@ public:
//! Add a new Provider which will be built using SimpleChannelProviderFactory<Provider>
template<class Provider>
bool add(const std::string& name, bool replace=true)
ChannelProviderFactory::shared_pointer add(const std::string& name, bool replace=true)
{
typedef SimpleChannelProviderFactory<Provider> 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()
{
+14
View File
@@ -69,6 +69,7 @@ std::auto_ptr<ChannelProviderRegistry::stringVector_t> 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;