This is Unofficial EPICS BASE Doxygen Site
clientInfo.cpp
Go to the documentation of this file.
1 /*
2  * Copyright information and license terms for this software can be
3  * found in the file LICENSE that is included with the distribution
4  */
5 
6 #include <epicsMutex.h>
7 #include <epicsGuard.h>
8 #include <epicsEvent.h>
9 #include <epicsThread.h>
10 
11 #include <pv/current_function.h>
12 #include <pv/pvData.h>
13 #include <pv/bitSet.h>
14 #include <pv/reftrack.h>
15 
16 #define epicsExportSharedSymbols
17 #include "pv/logger.h"
18 #include "clientpvt.h"
19 #include "pv/pvAccess.h"
20 
21 namespace {
24 
25 struct Infoer : public pvac::detail::CallbackStorage,
27  public pvac::Operation::Impl,
29 {
31  const pva::Channel::shared_pointer channel;
32 
33  static size_t num_instances;
34 
35  explicit Infoer(pvac::ClientChannel::InfoCallback *cb, const pva::Channel::shared_pointer& channel)
36  :cb(cb), channel(channel)
37  {REFTRACE_INCREMENT(num_instances);}
38  virtual ~Infoer() {
39  CallbackGuard G(*this);
40  cb = 0;
41  G.wait(); // paranoia
42  REFTRACE_DECREMENT(num_instances);
43  }
44 
45 
46  virtual std::string getRequesterName() OVERRIDE FINAL
47  {
48  Guard G(mutex);
49  return channel->getChannelName();
50  }
51 
52  virtual void getDone(
53  const pvd::Status& status,
54  pvd::FieldConstPtr const & field) OVERRIDE FINAL
55  {
56  CallbackGuard G(*this);
58  cb = 0;
59  if(C) {
60  pvac::InfoEvent evt;
62  evt.message = status.getMessage();
63  evt.type = field;
64  CallbackUse U(G);
65  C->infoDone(evt);
66  }
67  pvac::InfoEvent evt;
68  }
69 
70  virtual std::string name() const OVERRIDE FINAL { return channel->getChannelName(); }
71 
72  virtual void cancel() OVERRIDE FINAL {
73  CallbackGuard G(*this);
74  // we can't actually cancel a getField
76  cb = 0;
77  if(C) {
78  pvac::InfoEvent evt;
80  CallbackUse U(G);
81  C->infoDone(evt);
82  }
83  G.wait();
84  }
85 
86  virtual void show(std::ostream& strm) const OVERRIDE FINAL {
87  strm << "Operation(Info"
88  "\"" << name() <<"\""
89  ")";
90  }
91 };
92 
93 size_t Infoer::num_instances;
94 
95 } // namespace
96 
97 namespace pvac {
98 
99 Operation ClientChannel::info(InfoCallback *cb, const std::string& subfld)
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 }
114 
115 namespace detail {
116 
118 {
119  epics::registerRefCounter("pvac::Infoer", &Infoer::num_instances);
120 }
121 
122 }
123 
124 } // namespace pvac
pvd::Status status
void registerRefTrackInfo()
Definition: clientInfo.cpp:117
virtual std::string name() const =0
#define OVERRIDE
Definition: pvAccess.h:55
virtual void getDone(const epics::pvData::Status &status, epics::pvData::FieldConstPtr const &field)=0
const std::string & getMessage() const
Definition: status.h:80
epics::pvData::FieldConstPtr type
Type description resulting from getField operation. NULL unless event==Success.
Definition: client.h:111
Handle for in-progress get/put/rpc operation.
Definition: client.h:50
std::string message
Check when event==Fail.
Definition: client.h:95
virtual void show(std::ostream &) const =0
epicsMutex mutex
Definition: pvAccess.cpp:71
APIs for the epicsMutex mutual exclusion semaphore.
virtual void cancel()=0
enum pvac::PutEvent::event_t event
bool isSuccess() const
Definition: status.h:103
std::tr1::shared_ptr< const Field > FieldConstPtr
Definition: pvIntrospect.h:137
void registerRefCounter(const char *name, const size_t *counter)
Definition: reftrack.cpp:59
request cancelled before completion
Definition: client.h:92
APIs for the epicsEvent binary semaphore.
request ends in failure. Check message
Definition: client.h:91
virtual void infoDone(const InfoEvent &evt)=0
getField operation is complete
C++ and C descriptions for a thread.
It worked!
Definition: client.h:93
#define FINAL
Definition: pvAccess.h:48
See Client API API.
Definition: client.cpp:30