rework ChannelProviderRegistry

Replace interface+impls with a single concrete container
which wraps a map.

This breaks code which was sub-classing.
However, no external code can be found which does this.

A build() method is used instead of simple ctor so
that the ctor is private, which will cause theoretical
external sub-class code to fail to compile.

Code using getChannelProviderRegistry()
and existing methods will behave as before.

Add ChannelProviderRegistry::getFactory() for pass through
to ChannelProviderFactory (Registery is just a proxy()...)

Remove existing get/create virtual method in favor of getFactory.
Update both existing implementations.

Add SimpleChannelProviderFactory to cut down on boilerplace
for the common case.

Add method to clear mapping and release any saved sharedInstance.
This commit is contained in:
Michael Davidsaver
2017-04-15 11:46:41 -04:00
committed by mdavidsaver
parent 4a9d79f019
commit 9253c31c0b
3 changed files with 165 additions and 86 deletions

View File

@@ -17,6 +17,7 @@ public:
return "local";
};
TestChannelProvider(const std::tr1::shared_ptr<Configuration>&) {}
ChannelFind::shared_pointer channelFind(std::string const & /*channelName*/,
ChannelFindRequester::shared_pointer const & channelFindRequester)
@@ -57,41 +58,12 @@ public:
}
};
class TestChannelProviderRegistry : public ChannelProviderRegistry {
public:
virtual ~TestChannelProviderRegistry() {};
ChannelProvider::shared_pointer getProvider(std::string const & providerName)
{
if (providerName == "local")
{
return ChannelProvider::shared_pointer(new TestChannelProvider());
}
else
return ChannelProvider::shared_pointer();
}
ChannelProvider::shared_pointer createProvider(std::string const & providerName)
{
return getProvider(providerName);
}
std::auto_ptr<stringVector_t> getProviderNames()
{
std::auto_ptr<stringVector_t> pn(new stringVector_t());
pn->push_back("local");
return pn;
}
};
void testServerContext()
{
ServerContextImpl::shared_pointer ctx = ServerContextImpl::create();
ChannelProviderRegistry::shared_pointer ca(new TestChannelProviderRegistry());
ChannelProviderRegistry::shared_pointer ca(ChannelProviderRegistry::build());
ca->add<TestChannelProvider>("local");
ctx->initialize(ca);
ctx->printInfo();