This is Unofficial EPICS BASE Doxygen Site
pvac::ClientProvider Class Reference

Central client context. More...

#include "client.h"

Classes

struct  Impl
 

Public Member Functions

 ClientProvider ()
 Construct a null provider. All methods throw. May later be assigned from a valid ClientProvider. More...
 
 ClientProvider (const std::string &providerName, const std::tr1::shared_ptr< epics::pvAccess::Configuration > &conf=std::tr1::shared_ptr< epics::pvAccess::Configuration >())
 
 ClientProvider (const std::tr1::shared_ptr< epics::pvAccess::ChannelProvider > &provider)
 
 ~ClientProvider ()
 
std::string name () const
 
ClientChannel connect (const std::string &name, const ClientChannel::Options &conf=ClientChannel::Options())
 
bool disconnect (const std::string &name, const ClientChannel::Options &conf=ClientChannel::Options())
 Remove from channel cache. More...
 
void disconnect ()
 Clear channel cache. More...
 
bool valid () const
 
 operator bool_type () const
 
void reset ()
 

Friends

void detail::registerRefTrack ()
 
epicsShareFunc::std::ostream & operator<< (::std::ostream &strm, const ClientProvider &op)
 

Detailed Description

Central client context.

Definition at line 517 of file client.h.

Constructor & Destructor Documentation

pvac::ClientProvider::ClientProvider ( )
inline

Construct a null provider. All methods throw. May later be assigned from a valid ClientProvider.

Definition at line 526 of file client.h.

526 {}
pvac::ClientProvider::ClientProvider ( const std::string &  providerName,
const std::tr1::shared_ptr< epics::pvAccess::Configuration > &  conf = std::tr1::shared_ptr<epics::pvAccess::Configuration>() 
)

Use named provider.

Parameters
providerNameChannelProvider name, may be prefixed with "clients:" or "servers:" to query epics::pvAccess::ChannelProviderRegistry::clients() or epics::pvAccess::ChannelProviderRegistry::servers(). No prefix implies "clients:".

Definition at line 250 of file client.cpp.

252  :impl(new Impl)
253 {
254  std::string name;
255  pva::ChannelProviderRegistry::shared_pointer reg;
256 
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);
263  } else {
264  name = providerName;
266  }
267  impl->provider = reg->createProvider(name,
268  conf ? conf : pva::ConfigurationBuilder()
269  .push_env()
270  .build());
271 
272  if(!impl->provider)
273  THROW_EXCEPTION2(std::invalid_argument, providerName);
274 }
static ChannelProviderRegistry::shared_pointer servers()
#define THROW_EXCEPTION2(TYPE, MSG)
std::string name() const
Definition: client.cpp:288
static ChannelProviderRegistry::shared_pointer clients()
pvac::ClientProvider::ClientProvider ( const std::tr1::shared_ptr< epics::pvAccess::ChannelProvider > &  provider)
explicit

Definition at line 276 of file client.cpp.

277  :impl(new Impl)
278 {
279  impl->provider = provider;
280 
281  if(!impl->provider)
282  THROW_EXCEPTION2(std::invalid_argument, "null ChannelProvider");
283 }
#define THROW_EXCEPTION2(TYPE, MSG)
pvac::ClientProvider::~ClientProvider ( )

Definition at line 285 of file client.cpp.

285 {}

Member Function Documentation

ClientChannel pvac::ClientProvider::connect ( const std::string &  name,
const ClientChannel::Options conf = ClientChannel::Options() 
)

Get a new Channel

Does not block. Never returns NULL. Uses internal Channel cache.

Definition at line 295 of file client.cpp.

297 {
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()) {
303  // cache hit
304  std::tr1::shared_ptr<ClientChannel::Impl> chan(it->second.lock());
305  if(chan)
306  return ClientChannel(chan);
307  else
308  impl->channels.erase(it); // remove stale
309  }
310  // cache miss
311  ClientChannel ret(impl->provider, name, conf);
312  impl->channels[K] = ret.impl;
313  return ret;
314 }
std::string name() const
Definition: client.cpp:288
bool pvac::ClientProvider::disconnect ( const std::string &  name,
const ClientChannel::Options conf = ClientChannel::Options() 
)

Remove from channel cache.

Definition at line 316 of file client.cpp.

318 {
319  if(!impl) throw std::logic_error("Dead Provider");
320  Guard G(impl->mutex);
321 
322  Impl::channels_t::iterator it(impl->channels.find(std::make_pair(name, conf)));
323  bool found = it!=impl->channels.end();
324  if(found)
325  impl->channels.erase(it);
326  return found;
327 }
std::string name() const
Definition: client.cpp:288
void pvac::ClientProvider::disconnect ( )

Clear channel cache.

Definition at line 329 of file client.cpp.

330 {
331  if(!impl) throw std::logic_error("Dead Provider");
332  Guard G(impl->mutex);
333  impl->channels.clear();
334 }
std::string pvac::ClientProvider::name ( ) const

Definition at line 288 of file client.cpp.

289 {
290  if(!impl) throw std::logic_error("Dead Provider");
291  return impl->provider->getProviderName();
292 }
pvac::ClientProvider::operator bool_type ( ) const
inline

Definition at line 565 of file client.h.

565 { return valid() ? &ClientProvider::valid : 0; }
bool valid() const
Definition: client.h:557
void pvac::ClientProvider::reset ( )
inline

Definition at line 568 of file client.h.

568 { impl.reset(); }
bool pvac::ClientProvider::valid ( void  ) const
inline

Definition at line 557 of file client.h.

557 { return !!impl; }

Friends And Related Function Documentation

void detail::registerRefTrack ( )
friend
epicsShareFunc ::std::ostream& operator<< ( ::std::ostream &  strm,
const ClientProvider op 
)
friend

Definition at line 361 of file client.cpp.

362 {
363  if(op.impl) {
364  strm << "ClientProvider("
365  << typeid(*op.impl->provider.get()).name()<<", "
366  "\""<<op.impl->provider->getProviderName()<<"\")";
367  } else {
368  strm << "ClientProvider()";
369  }
370  return strm;
371 }
std::string name() const
Definition: client.cpp:288
ChannelPut::shared_pointer op
Definition: pvAccess.cpp:132

The documentation for this class was generated from the following files: