pvAccessCPP 7.1.8
Loading...
Searching...
No Matches
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
19namespace epics{namespace pvData{
20class Structure;
21class PVStructure;
22class BitSet;
23class Status;
24}} // epics::pvData
25namespace epics{namespace pvAccess{
26class ChannelProvider;
27class Channel;
28class ChannelRequester;
29struct ChannelBaseRequester;
30class GetFieldRequester;
31void providerRegInit(void*);
32}} // epics::pvAccess
33
34namespace pvas {
35
36namespace detail {
37struct SharedChannel;
38struct SharedMonitorFIFO;
39struct SharedPut;
40struct SharedRPC;
41}
42
43struct Operation;
44
76class epicsShareClass SharedPV
78{
79 friend struct detail::SharedChannel;
80 friend struct detail::SharedMonitorFIFO;
81 friend struct detail::SharedPut;
82 friend struct detail::SharedRPC;
83public:
84 POINTER_DEFINITIONS(SharedPV);
85 struct epicsShareClass Config {
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);
117private:
118 explicit SharedPV(const std::tr1::shared_ptr<Handler>& handler, Config* conf);
119public:
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
131
138 void open(const epics::pvData::PVStructure& value, const epics::pvData::BitSet& valid);
139
142
153 inline void close(bool destroy=false) { realClose(destroy, true, 0); }
154
157 std::tr1::shared_ptr<epics::pvData::PVStructure> build();
158
166 const epics::pvData::BitSet& changed);
167
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
183private:
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
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;
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
229struct epicsShareClass Operation {
230 POINTER_DEFINITIONS(Operation);
231 struct Impl;
232private:
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);
238public:
240
247 std::string channelName() const;
248
252
253 void complete();
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
277private:
278 typedef bool (Operation::*bool_type)() const;
279public:
280 operator bool_type() const { return valid() ? &Operation::valid : 0; }
281#endif
282};
283
284} // namespace pvas
285
287
288#endif // PV_SHAREDSTATE_H
An instance of a Client or Server.
Definition pvAccess.h:1231
A Shared State Process Variable (PV)
Definition sharedstate.h:78
void warn(const std::string &)
Send warning message to client. Does not complete().
void close(bool destroy=false)
Force any clients to disconnect, and prevent re-connection.
static shared_pointer buildMailbox(Config *conf=0)
A SharedPV which accepts all Put operations, and fails all RPC operations. In closed state.
void open(const epics::pvData::PVStructure &value, const epics::pvData::BitSet &valid)
Begin allowing clients to connect.
void setHandler(const std::tr1::shared_ptr< Handler > &handler)
Replace Handler given with ctor.
void fetch(epics::pvData::PVStructure &value, epics::pvData::BitSet &valid)
Update arguments with current value, which is the initial value from open() with accumulated post() c...
bool isOpen() const
test open-ness. cf. open() and close()
virtual void disconnect(bool destroy, const epics::pvAccess::ChannelProvider *provider)
Disconnect all Channels created through the given ChannelProvider.
std::tr1::shared_ptr< epics::pvData::PVStructure > build()
Create a new container which may be used to prepare to call post().
void post(const epics::pvData::PVStructure &value, const epics::pvData::BitSet &changed)
Update the cached PVStructure in this SharedPV.
void info(const std::string &)
Send info message to client. Does not complete().
bool dropEmptyUpdates
default true. Drop updates which don't include an field values.
Definition sharedstate.h:86
const epics::pvData::PVStructure & pvRequest() const
pvRequest blob, may be used to modify handling.
static shared_pointer build(const std::tr1::shared_ptr< Handler > &handler, Config *conf=0)
Allocate a new PV in the closed state.
virtual void onRPC(const SharedPV::shared_pointer &pv, Operation &op)
Client requests RPC.
void complete(const epics::pvData::Status &sts)
Complete with success or error w/o data.
void open(const epics::pvData::PVStructure &value)
Shorthand for.
const epics::pvData::BitSet & changed() const
Applies to value(). Which fields of input data are actual valid. Others should not be used.
void complete(const epics::pvData::PVStructure &value, const epics::pvData::BitSet &changed)
Sucessful completion with data (RPC only)
std::string channelName() const
The name of the channel through which this request was made (eg. for logging purposes).
Operation()
create empty op for later assignment
void open(const epics::pvData::StructureConstPtr &type)
Shorthand for.
virtual std::tr1::shared_ptr< epics::pvAccess::Channel > connect(const std::tr1::shared_ptr< epics::pvAccess::ChannelProvider > &provider, const std::string &channelName, const std::tr1::shared_ptr< epics::pvAccess::ChannelRequester > &requester)
may call Handler::onFirstConnect()
virtual void onPut(const SharedPV::shared_pointer &pv, Operation &op)
Client requests Put.
epics::pvData::PVRequestMapper::mode_t mapperMode
default Mask.
Definition sharedstate.h:87
const epics::pvData::PVStructure & value() const
Input data.
void complete()
shorthand for successful completion w/o data (Put or RPC with void return)
const epics::pvAccess::PeerInfo * peer() const
Information about peer transport and authentication.
static shared_pointer buildReadOnly(Config *conf=0)
A SharedPV which fails all Put and RPC operations. In closed state.
virtual void onLastDisconnect(const SharedPV::shared_pointer &pv)
Called when the last client disconnects. May close()
std::tr1::shared_ptr< const Structure > StructureConstPtr
Copyright - See the COPYRIGHT that is included with this distribution.
See Server API API.
Definition server.h:24
Information provded by a client to a server-type ChannelProvider.
Definition security.h:119
An in-progress network operation (Put or RPC).
Callbacks associated with a SharedPV.
Definition sharedstate.h:95
Interface for something which can provide Channels. aka A "PV". Typically a SharedPV.
Definition server.h:114