18 #define epicsExportSharedSymbols 33 :
std::runtime_error(
"Timeout")
42 typedef std::vector<ClientChannel::ConnectCallback*>
listeners_t;
49 Impl() :listeners_inprogress(
false) {REFTRACE_INCREMENT(num_instances);}
50 virtual ~Impl() {REFTRACE_DECREMENT(num_instances);}
58 while(listeners_inprogress) {
60 listeners_done.wait();
75 listeners_inprogress =
true;
81 evt.
peerName = channel->getRemoteAddress();
82 for(listeners_t::const_iterator it=notify.begin(), end=notify.end(); it!=end; ++it)
85 (*it)->connectEvent(evt);
86 }
catch(std::exception& e){
90 for(listeners_t::iterator it2=listeners.begin(), end2=listeners.end(); it2!=end2; ++it2) {
101 listeners_inprogress =
false;
103 listeners_done.signal();
107 listeners_inprogress =
false;
109 listeners_done.signal();
133 return impl ?
impl->name() :
"<NULL>";
142 const std::string&
name,
150 impl->channel = provider->createChannel(name,
impl->internal_shared_from_this(),
151 opt.priority, opt.address);
153 throw std::runtime_error(
"ChannelProvider failed to create Channel");
160 return impl ?
impl->channel->getChannelName() : std::string();
165 if(!
impl)
throw std::logic_error(
"Dead Channel");
170 for(Impl::listeners_t::const_iterator it=
impl->listeners.begin(), end=
impl->listeners.end(); it!=end; ++it)
174 impl->listeners.push_back(cb);
180 removeConnectListener(cb);
187 if(!
impl)
throw std::logic_error(
"Dead Channel");
191 while(
impl->listeners_inprogress) {
193 impl->listeners_done.wait();
196 for(Impl::listeners_t::iterator it=
impl->listeners.begin(), end=
impl->listeners.end(); it!=end; ++it)
199 impl->listeners.erase(it);
209 strm<<
typeid(*
impl->channel.get()).
name()<<
" : ";
210 impl->channel->printInfo(strm);
212 strm<<
"NULL Channel";
217 void register_reftrack()
219 static volatile int done;
231 std::tr1::shared_ptr<epics::pvAccess::Channel>
232 ClientChannel::getChannel()
233 {
return impl->channel; }
238 Impl() {register_reftrack(); REFTRACE_INCREMENT(num_instances);}
239 ~Impl() {REFTRACE_DECREMENT(num_instances);}
244 typedef std::map<std::pair<std::string, ClientChannel::Options>, std::tr1::weak_ptr<ClientChannel::Impl> >
channels_t;
251 const std::tr1::shared_ptr<epics::pvAccess::Configuration>& conf)
255 pva::ChannelProviderRegistry::shared_pointer reg;
257 if(strncmp(
"server:", providerName.c_str(), 7)==0) {
258 name = providerName.substr(7);
260 }
else if(strncmp(
"client:", providerName.c_str(), 7)==0) {
261 name = providerName.substr(7);
267 impl->provider = reg->createProvider(name,
279 impl->provider = provider;
290 if(!impl)
throw std::logic_error(
"Dead Provider");
291 return impl->provider->getProviderName();
298 if(!impl)
throw std::logic_error(
"Dead Provider");
299 Guard G(impl->mutex);
300 Impl::channels_t::key_type K(name, conf);
301 Impl::channels_t::iterator it(impl->channels.find(K));
302 if(it!=impl->channels.end()) {
304 std::tr1::shared_ptr<ClientChannel::Impl> chan(it->second.lock());
308 impl->channels.erase(it);
312 impl->channels[K] = ret.impl;
319 if(!impl)
throw std::logic_error(
"Dead Provider");
320 Guard G(impl->mutex);
322 Impl::channels_t::iterator it(impl->channels.find(std::make_pair(name, conf)));
323 bool found = it!=impl->channels.end();
325 impl->channels.erase(it);
331 if(!impl)
throw std::logic_error(
"Dead Provider");
332 Guard G(impl->mutex);
333 impl->channels.clear();
341 strm <<
"Operation()";
349 strm <<
"ClientChannel(" 350 <<
typeid(*op.impl->channel.get()).
name()<<
", " 351 "\"" << op.impl->channel->getChannelName() <<
"\", " 352 "\"" << op.impl->channel->getProvider()->getProviderName() <<
"\", " 353 "connected="<<(op.impl->channel->isConnected()?
"true":
"false")
356 strm <<
"ClientChannel()";
364 strm <<
"ClientProvider(" 365 <<
typeid(*op.impl->provider.get()).
name()<<
", " 366 "\""<<op.impl->provider->getProviderName()<<
"\")";
368 strm <<
"ClientProvider()";
ClientProvider()
Construct a null provider. All methods throw. May later be assigned from a valid ClientProvider.
static ChannelProviderRegistry::shared_pointer servers()
#define THROW_EXCEPTION2(TYPE, MSG)
friend epicsShareFunc::std::ostream & operator<<(::std::ostream &strm, const ClientProvider &op)
void registerRefTrackInfo()
void show(std::ostream &strm) const
pva::Channel::shared_pointer channel
std::string name() const
Channel name.
static size_t num_instances
std::string name() const
Channel name or an empty string.
std::tr1::shared_ptr< Impl > impl
Handle for in-progress get/put/rpc operation.
void registerRefTrackMonitor()
void registerRefTrackPut()
epicsGuard< epicsMutex > Guard
bool operator<(const Options &) const
virtual std::string getRequesterName() OVERRIDE FINAL
bool connected
Is this a connection, or disconnection, event.
#define LOG(level, format,...)
void registerRefTrackGet()
epicsEvent listeners_done
virtual void connectEvent(const ConnectEvent &evt)=0
APIs for the epicsMutex mutual exclusion semaphore.
Connection state change CB.
static ChannelProviderRegistry::shared_pointer clients()
information on connect/disconnect
ClientChannel()
Construct a null channel. All methods throw. May later be assigned from a valid ClientChannel.
pva::ChannelProvider::shared_pointer provider
void registerRefCounter(const char *name, const size_t *counter)
APIs for the epicsEvent binary semaphore.
virtual void channelStateChange(pva::Channel::shared_pointer const &channel, pva::Channel::ConnectionState connectionState) OVERRIDE FINAL
ClientChannel connect(const std::string &name, const ClientChannel::Options &conf=ClientChannel::Options())
void disconnect()
Clear channel cache.
epicsGuardRelease< epicsMutex > UnGuard
std::vector< ClientChannel::ConnectCallback * > listeners_t
ChannelPut::shared_pointer op
void registerRefTrackRPC()
C++ and C descriptions for a thread.
bool listeners_inprogress
void removeConnectListener(ConnectCallback *)
Remove from list of listeners.
std::map< std::pair< std::string, ClientChannel::Options >, std::tr1::weak_ptr< ClientChannel::Impl > > channels_t
void addConnectListener(ConnectCallback *)
static size_t num_instances
virtual void channelCreated(const pvd::Status &status, pva::Channel::shared_pointer const &channel) OVERRIDE FINAL
Channel creation options.