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

#include "client.h"

Classes

struct  ConnectCallback
 Connection state change CB. More...
 
struct  GetCallback
 callback for get() and rpc() More...
 
struct  Impl
 
struct  InfoCallback
 
struct  MonitorCallback
 Monitor event notification. More...
 
struct  Options
 Channel creation options. More...
 
struct  PutCallback
 callbacks for put() More...
 

Public Member Functions

 ClientChannel ()
 Construct a null channel. All methods throw. May later be assigned from a valid ClientChannel. More...
 
 ClientChannel (const std::tr1::shared_ptr< epics::pvAccess::ChannelProvider > &provider, const std::string &name, const Options &opt=Options())
 
 ~ClientChannel ()
 
std::string name () const
 Channel name or an empty string. More...
 
bool valid () const
 
 operator bool_type () const
 
void reset ()
 
Operation get (GetCallback *cb, epics::pvData::PVStructure::const_shared_pointer pvRequest=epics::pvData::PVStructure::const_shared_pointer())
 
epics::pvData::PVStructure::const_shared_pointer get (double timeout=3.0, epics::pvData::PVStructure::const_shared_pointer pvRequest=epics::pvData::PVStructure::const_shared_pointer())
 
Operation rpc (GetCallback *cb, const epics::pvData::PVStructure::const_shared_pointer &arguments, epics::pvData::PVStructure::const_shared_pointer pvRequest=epics::pvData::PVStructure::const_shared_pointer())
 
epics::pvData::PVStructure::const_shared_pointer rpc (double timeout, const epics::pvData::PVStructure::const_shared_pointer &arguments, epics::pvData::PVStructure::const_shared_pointer pvRequest=epics::pvData::PVStructure::const_shared_pointer())
 
Operation put (PutCallback *cb, epics::pvData::PVStructure::const_shared_pointer pvRequest=epics::pvData::PVStructure::const_shared_pointer(), bool getprevious=false)
 
detail::PutBuilder put (const epics::pvData::PVStructure::const_shared_pointer &pvRequest=epics::pvData::PVStructure::const_shared_pointer())
 Synchronious put operation. More...
 
Monitor monitor (MonitorCallback *cb, epics::pvData::PVStructure::const_shared_pointer pvRequest=epics::pvData::PVStructure::const_shared_pointer())
 
MonitorSync monitor (const epics::pvData::PVStructure::const_shared_pointer &pvRequest=epics::pvData::PVStructure::const_shared_pointer(), epicsEvent *event=0)
 
Operation info (InfoCallback *cb, const std::string &subfld=std::string())
 
epics::pvData::FieldConstPtr info (double timeout=3.0, const std::string &subfld=std::string())
 Synchronious getField opreation. More...
 
void addConnectListener (ConnectCallback *)
 
void removeConnectListener (ConnectCallback *)
 Remove from list of listeners. More...
 
void show (std::ostream &strm) const
 

Friends

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

Detailed Description

Represents a single channel

This class has two sets of methods, those which block for completion, and those which use callbacks to signal completion.

Those which block accept a 'timeout' argument (in seconds).

Those which use callbacks accept a 'cb' argument and return an Operation or Monitor handle object.

Definition at line 266 of file client.h.

Constructor & Destructor Documentation

pvac::ClientChannel::ClientChannel ( )
inline

Construct a null channel. All methods throw. May later be assigned from a valid ClientChannel.

Definition at line 290 of file client.h.

290 {}
pvac::ClientChannel::ClientChannel ( const std::tr1::shared_ptr< epics::pvAccess::ChannelProvider > &  provider,
const std::string &  name,
const Options opt = Options() 
)

Construct a ClientChannel using epics::pvAccess::ChannelProvider::createChannel()

Does not block.

Exceptions
std::logic_errorif the provider is NULL or name is an empty string
std::runtime_errorif the ChannelProvider can't provide
pvac::ClientChannel::~ClientChannel ( )

Definition at line 156 of file client.cpp.

156 {}

Member Function Documentation

void pvac::ClientChannel::addConnectListener ( ConnectCallback cb)

Append to list of listeners

Parameters
cbChannel dis/connect notification callback. Must outlive ClientChannel or call to removeConnectListener()

Definition at line 163 of file client.cpp.

164 {
165  if(!impl) throw std::logic_error("Dead Channel");
166  ConnectEvent evt;
167  {
168  Guard G(impl->mutex);
169 
170  for(Impl::listeners_t::const_iterator it=impl->listeners.begin(), end=impl->listeners.end(); it!=end; ++it)
171  {
172  if(cb==*it) return; // no duplicates
173  }
174  impl->listeners.push_back(cb);
175  evt.connected = impl->channel->isConnected();
176  }
177  try{
178  cb->connectEvent(evt);
179  }catch(...){
181  throw;
182  }
183 }
void removeConnectListener(ConnectCallback *)
Remove from list of listeners.
Definition: client.cpp:185
Operation pvac::ClientChannel::get ( ClientChannel::GetCallback cb,
epics::pvData::PVStructure::const_shared_pointer  pvRequest = epics::pvData::PVStructure::const_shared_pointer() 
)

Issue request to retrieve current PV value

Parameters
cbCompletion notification callback. Must outlive Operation (call Operation::cancel() to force release)
pvRequestif NULL defaults to "field()".

Definition at line 151 of file clientGet.cpp.

153 {
154  if(!impl) throw std::logic_error("Dead Channel");
155  if(!pvRequest)
156  pvRequest = pvd::createRequest("field()");
157 
158  std::tr1::shared_ptr<Getter> ret(Getter::build(cb));
159 
160  {
161  Guard G(ret->mutex);
162  ret->op = getChannel()->createChannelGet(ret->internal_shared_from_this(),
164  }
165 
166  return Operation(ret);
167 }
PVStructure::shared_pointer createRequest(std::string const &request)
Data interface for a structure,.
Definition: pvData.h:712
shared_ptr< T > const_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:798
epics::pvData::PVStructure::const_shared_pointer pvac::ClientChannel::get ( double  timeout = 3.0,
epics::pvData::PVStructure::const_shared_pointer  pvRequest = epics::pvData::PVStructure::const_shared_pointer() 
)

Block and retrieve current PV value

Parameters
timeoutin seconds
pvRequestif NULL defaults to "field()".
Exceptions
Timeoutor std::runtime_error
Operation pvac::ClientChannel::info ( InfoCallback cb,
const std::string &  subfld = std::string() 
)

Request PV type info.

Note
This type may not be the same as the types used in the get/put/monitor operations.

Definition at line 99 of file clientInfo.cpp.

100 {
101  if(!impl) throw std::logic_error("Dead Channel");
102 
103  std::tr1::shared_ptr<Infoer> ret(Infoer::build(cb, getChannel()));
104 
105  {
106  Guard G(ret->mutex);
107  getChannel()->getField(ret, subfld);
108  // getField is an oddity as it doesn't have an associated Operation class,
109  // and is thus largely out of our control. (eg. can't cancel)
110  }
111 
112  return Operation(ret);
113 }
epics::pvData::FieldConstPtr pvac::ClientChannel::info ( double  timeout = 3.0,
const std::string &  subfld = std::string() 
)

Synchronious getField opreation.

Definition at line 407 of file clientSync.cpp.

408 {
409  InfoWait waiter;
410  {
411  Operation op(info(&waiter, subfld));
412  waiter.wait(timeout);
413  }
414  switch(waiter.result.event) {
415  case InfoEvent::Success:
416  return waiter.result.type;
417  case InfoEvent::Fail:
418  throw std::runtime_error(waiter.result.message);
419  default:
420  case InfoEvent::Cancel: // cancel implies timeout, which should already be thrown
421  THROW_EXCEPTION2(std::logic_error, "Cancelled!?!?");
422  }
423 }
double timeout
Definition: pvutils.cpp:25
#define THROW_EXCEPTION2(TYPE, MSG)
request cancelled before completion
Definition: client.h:92
request ends in failure. Check message
Definition: client.h:91
Operation info(InfoCallback *cb, const std::string &subfld=std::string())
Definition: clientInfo.cpp:99
ChannelPut::shared_pointer op
Definition: pvAccess.cpp:132
It worked!
Definition: client.h:93
Monitor pvac::ClientChannel::monitor ( MonitorCallback cb,
epics::pvData::PVStructure::const_shared_pointer  pvRequest = epics::pvData::PVStructure::const_shared_pointer() 
)

Begin subscription

Parameters
cbCompletion notification callback. Must outlive Monitor (call Monitor::cancel() to force release)

Definition at line 241 of file clientMonitor.cpp.

243 {
244  if(!impl) throw std::logic_error("Dead Channel");
245  if(!pvRequest)
246  pvRequest = pvd::createRequest("field()");
247 
248  std::tr1::shared_ptr<Monitor::Impl> ret(Monitor::Impl::build(cb));
249  ret->chan = getChannel();
250 
251  {
252  Guard G(ret->mutex);
253  ret->op = ret->chan->createMonitor(ret->internal_shared_from_this(),
255  }
256 
257  return Monitor(ret);
258 }
PVStructure::shared_pointer createRequest(std::string const &request)
static std::tr1::shared_ptr< Monitor::Impl > build()
Definition: clientpvt.h:62
Data interface for a structure,.
Definition: pvData.h:712
shared_ptr< T > const_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:798
MonitorSync pvac::ClientChannel::monitor ( const epics::pvData::PVStructure::const_shared_pointer &  pvRequest = epics::pvData::PVStructure::const_shared_pointer(),
epicsEvent *  event = 0 
)

Begin subscription w/o callbacks

Parameters
eventIf not NULL, then subscription events are signaled to this epicsEvent. Use MonitorSync::test() to see if a subscription has an event waiting. Otherwise an internal epicsEvent is allocated for use with MonitorSync::wait()
Note
For simple usage with a single MonitorSync, pass event=NULL and call MonitorSync::wait(). If more than one MonitorSync is being created, then pass a custom epicsEvent and use MonitorSync::test() to find which subscriptions have events pending.

Definition at line 371 of file clientSync.cpp.

373 {
374  std::tr1::shared_ptr<MonitorSync::SImpl> simpl(new MonitorSync::SImpl(event));
375  Monitor mon(monitor(simpl.get(), pvRequest));
376  return MonitorSync(mon, simpl);
377 }
Monitor monitor(MonitorCallback *cb, epics::pvData::PVStructure::const_shared_pointer pvRequest=epics::pvData::PVStructure::const_shared_pointer())
std::string pvac::ClientChannel::name ( ) const

Channel name or an empty string.

Definition at line 158 of file client.cpp.

159 {
160  return impl ? impl->channel->getChannelName() : std::string();
161 }
pvac::ClientChannel::operator bool_type ( ) const
inline

Definition at line 313 of file client.h.

313 { return valid() ? &ClientChannel::valid : 0; }
bool valid() const
Definition: client.h:305
Operation pvac::ClientChannel::put ( PutCallback cb,
epics::pvData::PVStructure::const_shared_pointer  pvRequest = epics::pvData::PVStructure::const_shared_pointer(),
bool  getprevious = false 
)

Initiate request to change PV

Parameters
cbCompletion notification callback. Must outlive Operation (call Operation::cancel() to force release)
pvRequestif NULL defaults to "field()".
getpreviousIf true, fetch a previous value of the PV and make this available as PutCallback::Args::previous and previousmask. If false, then previous=NULL

Definition at line 211 of file clientPut.cpp.

214 {
215  if(!impl) throw std::logic_error("Dead Channel");
216  if(!pvRequest)
217  pvRequest = pvd::createRequest("field()");
218 
219  std::tr1::shared_ptr<Putter> ret(Putter::build(cb, getprevious));
220 
221  {
222  Guard G(ret->mutex);
223  ret->op = getChannel()->createChannelPut(ret->internal_shared_from_this(),
225  }
226 
227  return Operation(ret);
228 
229 }
PVStructure::shared_pointer createRequest(std::string const &request)
Data interface for a structure,.
Definition: pvData.h:712
shared_ptr< T > const_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:798
void pvac::ClientChannel::removeConnectListener ( ConnectCallback cb)

Remove from list of listeners.

Definition at line 185 of file client.cpp.

186 {
187  if(!impl) throw std::logic_error("Dead Channel");
188  Guard G(impl->mutex);
189 
190  // ensure no in-progress callbacks
191  while(impl->listeners_inprogress) {
192  UnGuard U(G);
193  impl->listeners_done.wait();
194  }
195 
196  for(Impl::listeners_t::iterator it=impl->listeners.begin(), end=impl->listeners.end(); it!=end; ++it)
197  {
198  if(cb==*it) {
199  impl->listeners.erase(it);
200  return;
201  }
202  }
203 }
void pvac::ClientChannel::reset ( )
inline

Definition at line 316 of file client.h.

316 { impl.reset(); }
Operation pvac::ClientChannel::rpc ( GetCallback cb,
const epics::pvData::PVStructure::const_shared_pointer &  arguments,
epics::pvData::PVStructure::const_shared_pointer  pvRequest = epics::pvData::PVStructure::const_shared_pointer() 
)

Start an RPC call

Parameters
cbCompletion notification callback. Must outlive Operation (call Operation::cancel() to force release)
argumentsencoded call arguments
pvRequestif NULL defaults to "field()".

Definition at line 158 of file clientRPC.cpp.

161 {
162  if(!impl) throw std::logic_error("Dead Channel");
163  if(!pvRequest)
164  pvRequest = pvd::createRequest("field()");
165 
166  std::tr1::shared_ptr<RPCer> ret(RPCer::build(cb, arguments));
167 
168  {
169  Guard G(ret->mutex);
170  ret->op = getChannel()->createChannelRPC(ret->internal_shared_from_this(),
172  }
173 
174  return Operation(ret);
175 }
PVStructure::shared_pointer createRequest(std::string const &request)
Data interface for a structure,.
Definition: pvData.h:712
shared_ptr< T > const_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:798
pvd::PVStructure::const_shared_pointer pvac::ClientChannel::rpc ( double  timeout,
const epics::pvData::PVStructure::const_shared_pointer &  arguments,
epics::pvData::PVStructure::const_shared_pointer  pvRequest = epics::pvData::PVStructure::const_shared_pointer() 
)

Block and execute remote call

Parameters
timeoutin seconds
argumentsencoded call arguments
pvRequestif NULL defaults to "field()".

Definition at line 91 of file clientSync.cpp.

94 {
95  GetWait waiter;
96  Operation op(rpc(&waiter, arguments, pvRequest));
97  {
98  Guard G(waiter.mutex);
99  while(!waiter.done) {
100  UnGuard U(G);
101  if(!waiter.event.wait(timeout)) {
102  op.cancel();
103  throw Timeout();
104  }
105  }
106  }
107  if(waiter.result.event==pvac::GetEvent::Success)
108  return waiter.result.value;
109  else
110  throw std::runtime_error(waiter.result.message);
111 }
double timeout
Definition: pvutils.cpp:25
Operation rpc(GetCallback *cb, const epics::pvData::PVStructure::const_shared_pointer &arguments, epics::pvData::PVStructure::const_shared_pointer pvRequest=epics::pvData::PVStructure::const_shared_pointer())
Definition: clientRPC.cpp:158
ChannelPut::shared_pointer op
Definition: pvAccess.cpp:132
It worked!
Definition: client.h:93
void pvac::ClientChannel::show ( std::ostream &  strm) const

Definition at line 206 of file client.cpp.

207 {
208  if(impl) {
209  strm<<typeid(*impl->channel.get()).name()<<" : ";
210  impl->channel->printInfo(strm);
211  } else {
212  strm<<"NULL Channel";
213  }
214 }
std::string name() const
Channel name or an empty string.
Definition: client.cpp:158
bool pvac::ClientChannel::valid ( void  ) const
inline

Definition at line 305 of file client.h.

305 { return !!impl; }

Friends And Related Function Documentation

friend class ClientProvider
friend

Definition at line 275 of file client.h.

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

Definition at line 346 of file client.cpp.

347 {
348  if(op.impl) {
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")
354  <<"\")";
355  } else {
356  strm << "ClientChannel()";
357  }
358  return strm;
359 }
std::string name() const
Channel name or an empty string.
Definition: client.cpp:158
ChannelPut::shared_pointer op
Definition: pvAccess.cpp:132

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