pva2pva 1.4.2
Loading...
Searching...
No Matches
pdbgroup.h
1#ifndef PDBGROUP_H
2#define PDBGROUP_H
3
4#include <istream>
5#include <map>
6#include <limits>
7
8#include <dbAccess.h>
9
10#include <dbEvent.h>
11#include <dbLock.h>
12
13#include <pv/pvAccess.h>
14
15#include "helper.h"
16#include "pvahelper.h"
17#include "pvif.h"
18#include "pdb.h"
19
20struct QSRV_API GroupConfig
21{
22 struct QSRV_API Field {
23 std::string type, channel, trigger, id;
24 int putorder;
25
26 Field() :putorder(std::numeric_limits<int>::min()) {}
27
28 void swap(Field& o) {
29 std::swap(type, o.type);
30 std::swap(channel, o.channel);
31 std::swap(trigger, o.trigger);
32 std::swap(putorder, o.putorder);
33 std::swap(id, o.id);
34 }
35 };
36
37 struct QSRV_API Group {
38 typedef std::map<std::string, Field> fields_t;
39 fields_t fields;
40 bool atomic, atomic_set;
41 std::string id;
42
43 Group() :atomic(true), atomic_set(false) {}
44
45 void swap(Group& o) {
46 std::swap(fields, o.fields);
47 std::swap(atomic, o.atomic);
48 std::swap(atomic_set, o.atomic_set);
49 std::swap(id, o.id);
50 }
51 };
52
53 typedef std::map<std::string, Group> groups_t;
54 groups_t groups;
55 std::string warning;
56
57 void swap(GroupConfig& o) {
58 std::swap(groups, o.groups);
59 std::swap(warning, o.warning);
60 }
61
62 static void parse(const char *txt, const char *recname,
63 GroupConfig& result);
64};
65
66struct PDBGroupMonitor;
67
68void pdb_group_event(void *user_arg, struct dbChannel *chan,
69 int eventsRemaining, struct db_field_log *pfl);
70
71struct QSRV_API PDBGroupPV : public PDBPV
72{
73 POINTER_DEFINITIONS(PDBGroupPV);
74 weak_pointer weakself;
75 inline shared_pointer shared_from_this() { return shared_pointer(weakself); }
76
77 // only for use in pdb_single_event()
78 // which is not concurrent for all VALUE/PROPERTY.
79 epics::pvData::BitSet scratch;
80
81 epicsMutex lock;
82
83 bool pgatomic, monatomic;
84
85 // get/put/monitor
86 std::string name;
87
88 struct Info {
89 DBCH chan;
90 // used for DBE_PROPERTY subscription when chan has filters
91 DBCH chan2;
92 std::tr1::shared_ptr<PVIFBuilder> builder;
93 FieldName attachment;
94 typedef std::vector<size_t> triggers_t;
95 triggers_t triggers; // index in PDBGroupPV::members
96 DBManyLock locker; // lock only those channels being triggered
97 p2p::auto_ptr<PVIF> pvif;
98 DBEvent evt_VALUE, evt_PROPERTY;
99 bool had_initial_VALUE, had_initial_PROPERTY, allowProc;
100
101 Info() :had_initial_VALUE(false), had_initial_PROPERTY(false), allowProc(false) {}
102 };
103 typedef epics::pvData::shared_vector<Info> members_t;
104 members_t members;
105
106 DBManyLock locker; // all member channels
107
108 epics::pvData::PVStructurePtr complete; // complete copy from subscription
109
110 typedef std::set<PDBGroupMonitor*> interested_t;
111 bool interested_iterating;
112 interested_t interested, interested_add;
113
114 typedef std::set<BaseMonitor::shared_pointer> interested_remove_t;
115 interested_remove_t interested_remove;
116
117 size_t initial_waits;
118
119 static size_t num_instances;
120
121 PDBGroupPV();
122 virtual ~PDBGroupPV();
123
124 virtual
125 epics::pvAccess::Channel::shared_pointer
126 connect(const std::tr1::shared_ptr<PDBProvider>& prov,
127 const epics::pvAccess::ChannelRequester::shared_pointer& req) OVERRIDE FINAL;
128
129 void addMonitor(PDBGroupMonitor*);
130 void removeMonitor(PDBGroupMonitor*);
131 void finalizeMonitor();
132
133 virtual void show(int lvl) OVERRIDE;
134};
135
136struct QSRV_API PDBGroupChannel : public BaseChannel,
137 public std::tr1::enable_shared_from_this<PDBGroupChannel>
138{
139 POINTER_DEFINITIONS(PDBGroupChannel);
140
141 PDBGroupPV::shared_pointer pv;
142 std::vector<ASCLIENT> aspvt;
143 // storage referenced from aspvt
144 ASCred cred;
145
146 static size_t num_instances;
147
148 PDBGroupChannel(const PDBGroupPV::shared_pointer& pv,
149 const std::tr1::shared_ptr<epics::pvAccess::ChannelProvider>& prov,
150 const epics::pvAccess::ChannelRequester::shared_pointer& req);
151 virtual ~PDBGroupChannel();
152
153 virtual epics::pvAccess::ChannelPut::shared_pointer createChannelPut(
154 epics::pvAccess::ChannelPutRequester::shared_pointer const & requester,
155 epics::pvData::PVStructure::shared_pointer const & pvRequest) OVERRIDE FINAL;
156 virtual epics::pvData::Monitor::shared_pointer createMonitor(
157 epics::pvData::MonitorRequester::shared_pointer const & requester,
158 epics::pvData::PVStructure::shared_pointer const & pvRequest) OVERRIDE FINAL;
159
160 virtual void printInfo(std::ostream& out) OVERRIDE FINAL;
161};
162
163struct PDBGroupPut : public epics::pvAccess::ChannelPut,
164 public std::tr1::enable_shared_from_this<PDBGroupPut>
165{
166 POINTER_DEFINITIONS(PDBGroupPut);
167 typedef epics::pvAccess::ChannelPutRequester requester_t;
168 PDBGroupChannel::shared_pointer channel;
169 requester_type::weak_pointer requester;
170
171 // effectively const after ctor
172 bool atomic, doWait;
173 PVIF::proc_t doProc;
174
175 epics::pvData::BitSetPtr changed;
176 epics::pvData::PVStructurePtr pvf;
177 std::vector<std::tr1::shared_ptr<PVIF> > pvif;
178
179 static size_t num_instances;
180
181 PDBGroupPut(const PDBGroupChannel::shared_pointer &channel,
182 const epics::pvAccess::ChannelPutRequester::shared_pointer &requester,
183 const epics::pvData::PVStructure::shared_pointer& pvReq);
184 virtual ~PDBGroupPut();
185
186 virtual void destroy() OVERRIDE FINAL { pvif.clear(); channel.reset(); requester.reset(); }
187 virtual std::tr1::shared_ptr<epics::pvAccess::Channel> getChannel() OVERRIDE FINAL { return channel; }
188 virtual void cancel() OVERRIDE FINAL {}
189 virtual void lastRequest() OVERRIDE FINAL {}
190 virtual void put(
191 epics::pvData::PVStructure::shared_pointer const & pvPutStructure,
192 epics::pvData::BitSet::shared_pointer const & putBitSet) OVERRIDE FINAL;
193 virtual void get() OVERRIDE FINAL;
194};
195
196struct PDBGroupMonitor : public BaseMonitor
197{
198 POINTER_DEFINITIONS(PDBGroupMonitor);
199
200 PDBGroupPV::shared_pointer pv;
201
202 bool atomic;
203
204 static size_t num_instances;
205
206 PDBGroupMonitor(const PDBGroupPV::shared_pointer& pv,
207 const requester_type::weak_pointer& requester,
208 const epics::pvData::PVStructure::shared_pointer& pvReq);
209 virtual ~PDBGroupMonitor();
210
211 virtual void onStart() OVERRIDE FINAL;
212 virtual void onStop() OVERRIDE FINAL;
213 virtual void requestUpdate() OVERRIDE FINAL;
214
215 virtual void destroy() OVERRIDE FINAL;
216
217};
218
219#endif // PDBGROUP_H
Definition pvif.h:100
Definition pvif.h:81
virtual void requestUpdate() OVERRIDE FINAL
Definition pdbgroup.cpp:470