pvAccessCPP  7.1.7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
sharedstate.h
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 #ifndef PV_SHAREDSTATE_H
6 #define PV_SHAREDSTATE_H
7 
8 #include <string>
9 #include <list>
10 
11 #include <shareLib.h>
12 #include <pv/sharedPtr.h>
13 #include <pv/noDefaultMethods.h>
14 #include <pv/bitSet.h>
15 #include <pv/createRequest.h>
16 
17 #include <pva/server.h>
18 
19 namespace epics{namespace pvData{
20 class Structure;
21 class PVStructure;
22 class BitSet;
23 class Status;
24 }} // epics::pvData
25 namespace epics{namespace pvAccess{
26 class ChannelProvider;
27 class Channel;
28 class ChannelRequester;
29 struct ChannelBaseRequester;
30 class GetFieldRequester;
31 void providerRegInit(void*);
32 }} // epics::pvAccess
33 
34 namespace pvas {
35 
36 namespace detail {
37 struct SharedChannel;
38 struct SharedMonitorFIFO;
39 struct SharedPut;
40 struct SharedRPC;
41 }
42 
43 struct Operation;
44 
76 class epicsShareClass SharedPV
78 {
79  friend struct detail::SharedChannel;
80  friend struct detail::SharedMonitorFIFO;
81  friend struct detail::SharedPut;
82  friend struct detail::SharedRPC;
83 public:
84  POINTER_DEFINITIONS(SharedPV);
85  struct epicsShareClass Config {
87  epics::pvData::PVRequestMapper::mode_t mapperMode;
88  Config();
89  };
90 
95  struct epicsShareClass Handler {
96  POINTER_DEFINITIONS(Handler);
97  virtual ~Handler();
98  virtual void onFirstConnect(const SharedPV::shared_pointer& pv) {}
100  virtual void onLastDisconnect(const SharedPV::shared_pointer& pv) {}
102  virtual void onPut(const SharedPV::shared_pointer& pv, Operation& op);
104  virtual void onRPC(const SharedPV::shared_pointer& pv, Operation& op);
105  };
106 
112  static shared_pointer build(const std::tr1::shared_ptr<Handler>& handler, Config* conf=0);
114  static shared_pointer buildReadOnly(Config* conf=0);
116  static shared_pointer buildMailbox(Config* conf=0);
117 private:
118  explicit SharedPV(const std::tr1::shared_ptr<Handler>& handler, Config* conf);
119 public:
120  virtual ~SharedPV();
121 
123  void setHandler(const std::tr1::shared_ptr<Handler>& handler);
124  Handler::shared_pointer getHandler() const;
125 
127  bool isOpen() const;
128 
130  void open(const epics::pvData::PVStructure& value);
131 
138  void open(const epics::pvData::PVStructure& value, const epics::pvData::BitSet& valid);
139 
141  void open(const epics::pvData::StructureConstPtr& type);
142 
153  inline void close(bool destroy=false) { realClose(destroy, true, 0); }
154 
157  std::tr1::shared_ptr<epics::pvData::PVStructure> build();
158 
165  void post(const epics::pvData::PVStructure& value,
166  const epics::pvData::BitSet& changed);
167 
169  void fetch(epics::pvData::PVStructure& value, epics::pvData::BitSet& valid);
170 
173  virtual std::tr1::shared_ptr<epics::pvAccess::Channel> connect(
174  const std::tr1::shared_ptr<epics::pvAccess::ChannelProvider>& provider,
175  const std::string& channelName,
176  const std::tr1::shared_ptr<epics::pvAccess::ChannelRequester>& requester) OVERRIDE FINAL;
177 
178  virtual void disconnect(bool destroy, const epics::pvAccess::ChannelProvider* provider) OVERRIDE FINAL;
179 
180  void setDebug(int lvl);
181  int isDebug() const;
182 
183 private:
184  void realClose(bool destroy, bool close, const epics::pvAccess::ChannelProvider* provider);
185 
186  friend void epics::pvAccess::providerRegInit(void*);
187  static size_t num_instances;
188 
189  weak_pointer internal_self; // const after build()
190 
191  const Config config;
192 
193  mutable epicsMutex mutex;
194 
195  std::tr1::shared_ptr<SharedPV::Handler> handler;
196 
197  typedef std::list<detail::SharedPut*> puts_t;
198  typedef std::list<detail::SharedRPC*> rpcs_t;
199  typedef std::list<detail::SharedMonitorFIFO*> monitors_t;
201  typedef std::list<detail::SharedChannel*> channels_t;
202 
203  std::tr1::shared_ptr<const epics::pvData::Structure> type;
204 
205  puts_t puts;
206  rpcs_t rpcs;
207  monitors_t monitors;
208  getfields_t getfields;
209  channels_t channels;
210 
211  std::tr1::shared_ptr<epics::pvData::PVStructure> current;
214  epics::pvData::BitSet valid;
215 
216  // whether onFirstConnect() has been, or is being, called.
217  // Set when the first getField, Put, or Monitor (but not RPC) is created.
218  // Cleared when the last Channel is destroyed.
219  bool notifiedConn;
220 
221  int debugLvl;
222 
223  EPICS_NOT_COPYABLE(SharedPV)
224 };
225 
229 struct epicsShareClass Operation {
230  POINTER_DEFINITIONS(Operation);
231  struct Impl;
232 private:
233  std::tr1::shared_ptr<Impl> impl;
234 
235  friend struct detail::SharedPut;
236  friend struct detail::SharedRPC;
237  explicit Operation(const std::tr1::shared_ptr<Impl> impl);
238 public:
239  Operation() {}
240 
242  const epics::pvData::PVStructure& pvRequest() const;
243  const epics::pvData::PVStructure& value() const;
244  const epics::pvData::BitSet& changed() const;
247  std::string channelName() const;
248 
251  const epics::pvAccess::PeerInfo* peer() const;
252 
253  void complete();
254  void complete(const epics::pvData::Status& sts);
257  void complete(const epics::pvData::PVStructure& value,
258  const epics::pvData::BitSet& changed);
259 
261  void info(const std::string&);
263  void warn(const std::string&);
264 
265  int isDebug() const;
266 
267  // escape hatch. never NULL
268  std::tr1::shared_ptr<epics::pvAccess::Channel> getChannel();
269  // escape hatch. may be NULL
270  std::tr1::shared_ptr<epics::pvAccess::ChannelBaseRequester> getRequester();
271 
272  bool valid() const;
273 
274 #if __cplusplus>=201103L
275  explicit operator bool() const { return valid(); }
276 #else
277 private:
278  typedef bool (Operation::*bool_type)() const;
279 public:
280  operator bool_type() const { return valid() ? &Operation::valid : 0; }
281 #endif
282 };
283 
284 } // namespace pvas
285 
287 
288 #endif // PV_SHAREDSTATE_H
Information provded by a client to a server-type ChannelProvider.
Definition: security.h:119
bool dropEmptyUpdates
default true. Drop updates which don&#39;t include an field values.
Definition: sharedstate.h:86
An instance of a Client or Server.
Definition: pvAccess.h:1230
A Shared State Process Variable (PV)
Definition: sharedstate.h:76
Interface for something which can provide Channels. aka A &quot;PV&quot;. Typically a SharedPV.
Definition: server.h:114
Operation()
create empty op for later assignment
Definition: sharedstate.h:239
Callbacks associated with a SharedPV.
Definition: sharedstate.h:95
void close(bool destroy=false)
Force any clients to disconnect, and prevent re-connection.
Definition: sharedstate.h:153
An in-progress network operation (Put or RPC).
Definition: sharedstate.h:229
epics::pvData::PVRequestMapper::mode_t mapperMode
default Mask.
Definition: sharedstate.h:87
virtual void onLastDisconnect(const SharedPV::shared_pointer &pv)
Called when the last client disconnects. May close()
Definition: sharedstate.h:100