20 #define epicsExportSharedSymbols 40 ChannelProviderRegistry::shared_pointer ChannelProviderRegistry::build() {
45 ChannelProvider::shared_pointer ChannelProviderRegistry::getProvider(std::string
const & providerName) {
46 ChannelProviderFactory::shared_pointer fact(getFactory(providerName));
48 return fact->sharedInstance();
50 return ChannelProvider::shared_pointer();
53 ChannelProvider::shared_pointer ChannelProviderRegistry::createProvider(std::string
const & providerName,
54 const std::tr1::shared_ptr<Configuration>& conf) {
55 ChannelProviderFactory::shared_pointer fact(getFactory(providerName));
57 return fact->newInstance(conf);
59 return ChannelProvider::shared_pointer();
62 ChannelProviderFactory::shared_pointer ChannelProviderRegistry::getFactory(std::string
const & providerName)
65 providers_t::const_iterator iter = providers.find(providerName);
66 if (iter == providers.end())
67 return ChannelProviderFactory::shared_pointer();
72 void ChannelProviderRegistry::getProviderNames(std::set<std::string>& names)
75 for (providers_t::const_iterator iter = providers.begin();
76 iter != providers.end(); iter++)
77 names.insert(iter->first);
81 bool ChannelProviderRegistry::add(
const ChannelProviderFactory::shared_pointer& fact,
bool replace)
85 std::string name(fact->getFactoryName());
86 if(!replace && providers.find(name)!=providers.end())
88 providers[name] = fact;
96 ChannelProvider::weak_pointer
shared;
97 const ChannelProviderRegistry::factoryfn_t
fn;
99 FunctionFactory(
const std::string& name, ChannelProviderRegistry::factoryfn_t fn)
102 virtual ~FunctionFactory() {}
103 virtual std::string getFactoryName() {
return pname; }
105 virtual ChannelProvider::shared_pointer sharedInstance()
108 ChannelProvider::shared_pointer ret(shared.lock());
110 ret =
fn(std::tr1::shared_ptr<Configuration>());
116 virtual ChannelProvider::shared_pointer newInstance(
const std::tr1::shared_ptr<Configuration>& conf)
124 ChannelProviderFactory::shared_pointer ChannelProviderRegistry::add(
const std::string& name, factoryfn_t
fn,
bool replace)
126 ChannelProviderFactory::shared_pointer F(
new FunctionFactory(name, fn));
127 return add(F, replace) ? F : ChannelProviderFactory::shared_pointer();
136 InstanceChannelProviderFactory(
const std::tr1::shared_ptr<ChannelProvider>& provider)
137 :name(provider->getProviderName())
140 virtual ~InstanceChannelProviderFactory() {}
145 virtual ChannelProvider::shared_pointer sharedInstance()
OVERRIDE FINAL 147 return provider.lock();
149 virtual ChannelProvider::shared_pointer newInstance(
const std::tr1::shared_ptr<Configuration>& conf)
OVERRIDE FINAL 151 return provider.lock();
154 const std::string name;
155 const ChannelProvider::weak_pointer provider;
159 ChannelProviderFactory::shared_pointer ChannelProviderRegistry::addSingleton(
const ChannelProvider::shared_pointer& provider,
162 std::tr1::shared_ptr<InstanceChannelProviderFactory> F(
new InstanceChannelProviderFactory(provider));
163 return add(F, replace) ? F : std::tr1::shared_ptr<InstanceChannelProviderFactory>();
166 ChannelProviderFactory::shared_pointer ChannelProviderRegistry::remove(
const std::string& name)
169 ChannelProviderFactory::shared_pointer fact(getFactory(name));
176 bool ChannelProviderRegistry::remove(
const ChannelProviderFactory::shared_pointer& fact)
180 providers_t::iterator iter(providers.find(fact->getFactoryName()));
181 if(iter!=providers.end() && iter->second==fact) {
182 providers.erase(iter);
188 void ChannelProviderRegistry::clear()
195 struct providerRegGbl_t {
196 ChannelProviderRegistry::shared_pointer
clients,
199 :clients(ChannelProviderRegistry::build())
200 ,servers(ChannelProviderRegistry::build())
213 providerRegGbl =
new providerRegGbl_t;
219 registerRefCounter(
"BlockingTCPTransportCodec", &detail::BlockingTCPTransportCodec::num_instances);
224 registerRefCounter(
"ChannelBaseRequester (ABC)", &ChannelBaseRequester::num_instances);
239 return providerRegGbl->clients;
246 return providerRegGbl->servers;
249 ChannelFind::shared_pointer
250 ChannelProvider::channelList(ChannelListRequester::shared_pointer
const &
requester)
252 ChannelFind::shared_pointer ret;
253 requester->channelListResult(
Status::error(
"not implemented"),
260 Channel::shared_pointer
261 ChannelProvider::createChannel(std::string
const & name,
262 ChannelRequester::shared_pointer
const &
requester,
265 return createChannel(name, requester, priority,
"");
#define assert(exp)
Declare that a condition should be true.
ChannelProviderRegistry::shared_pointer servers
LIBCOM_API void epicsStdCall epicsSignalInstallSigPipeIgnore(void)
static Status error(const std::string &m)
TODO only here because of the Lockable.
A lock for multithreading.
static size_t num_instances
void providerRegInit(void *)
static size_t num_instances
#define EPICS_THREAD_ONCE_INIT
ChannelProvider::shared_pointer createClientProvider(const Configuration::shared_pointer &conf)
LIBCOM_API void epicsStdCall epicsThreadOnce(epicsThreadOnceId *id, EPICSTHREADFUNC, void *arg)
ChannelProviderRegistry::shared_pointer clients
static size_t num_instances
const ChannelProcessRequester::weak_pointer requester
LIBCOM_API void epicsStdCall epicsSignalInstallSigAlarmIgnore(void)
void registerRefCounter(const char *name, const size_t *counter)
void registerRefTrackServer()
const ChannelProviderRegistry::factoryfn_t fn
epics::pvData::Mutex sharedM
ChannelProvider::weak_pointer shared
OS-independent routines for ignoring Posix signals.
C++ and C descriptions for a thread.