pva2pva 1.4.2
Loading...
Searching...
No Matches
chancache.h
1#ifndef CHANCACHE_H
2#define CHANCACHE_H
3
4#include <string>
5#include <map>
6#include <set>
7#include <deque>
8
9#include <epicsMutex.h>
10#include <epicsTimer.h>
11
12#include <pv/pvAccess.h>
13
14#include "weakmap.h"
15#include "weakset.h"
16
17struct ChannelCache;
19struct MonitorUser;
20struct GWChannel;
21
22struct MonitorCacheEntry : public epics::pvData::MonitorRequester
23{
24 POINTER_DEFINITIONS(MonitorCacheEntry);
25 static size_t num_instances;
26 weak_pointer weakref;
27
28 ChannelCacheEntry * const chan;
29
30 const size_t bufferSize; // DS requested buffer size
31
32 // to avoid yet another mutex borrow interested.mutex() for our members
33 inline epicsMutex& mutex() const { return interested.mutex(); }
34
35 typedef std::vector<epicsUInt8> pvrequest_t;
36
37 bool havedata; // set when initial update is received
38 bool done; // set when unlisten() is received
39 size_t nwakeups; // # of upstream monitorEvent() calls
40 size_t nevents; // # of upstream events poll()'d
41
42 epics::pvData::StructureConstPtr typedesc;
46 epics::pvData::MonitorElement::shared_pointer lastelem;
47 epics::pvData::MonitorPtr mon;
48 epics::pvData::Status startresult;
49
50 typedef weak_set<MonitorUser> interested_t;
51 interested_t interested;
52
53 MonitorCacheEntry(ChannelCacheEntry *ent, const epics::pvData::PVStructure::shared_pointer& pvr);
54 virtual ~MonitorCacheEntry();
55
56 virtual void monitorConnect(epics::pvData::Status const & status,
57 epics::pvData::MonitorPtr const & monitor,
58 epics::pvData::StructureConstPtr const & structure);
59 virtual void monitorEvent(epics::pvData::MonitorPtr const & monitor);
60 virtual void unlisten(epics::pvData::MonitorPtr const & monitor);
61
62 virtual std::string getRequesterName();
63};
64
65struct MonitorUser : public epics::pvData::Monitor
66{
67 POINTER_DEFINITIONS(MonitorUser);
68 static size_t num_instances;
69 // const after construction
70 weak_pointer weakref;
71
72 const MonitorCacheEntry::shared_pointer entry;
73 const epics::pvData::MonitorRequester::weak_pointer req;
74 const std::tr1::weak_ptr<GWChannel> srvchan;
75
76 inline epicsMutex& mutex() const { return entry->mutex(); }
77
78 // guards queues and member variables
79 bool initial;
80 bool running;
81 bool inoverflow;
82 size_t nwakeups; // # of monitorEvent() calls to req
83 size_t nevents; // total # events queued
84 size_t ndropped; // # of events drop because our queue was full
85
86 std::deque<epics::pvData::MonitorElementPtr> filled, empty;
87 std::set<epics::pvData::MonitorElementPtr> inuse;
88
89 epics::pvData::MonitorElementPtr overflowElement;
90
91 MonitorUser(const MonitorCacheEntry::shared_pointer&,
92 const epics::pvData::MonitorRequester::shared_pointer&,
93 const std::tr1::shared_ptr<GWChannel>&);
94 virtual ~MonitorUser();
95
96 virtual void destroy();
97
98 virtual epics::pvData::Status start();
99 virtual epics::pvData::Status stop();
100 virtual epics::pvData::MonitorElementPtr poll();
101 virtual void release(epics::pvData::MonitorElementPtr const & monitorElement);
102
103 virtual std::string getRequesterName();
104};
105
106struct ChannelCacheEntry
107{
108 POINTER_DEFINITIONS(ChannelCacheEntry);
109 static size_t num_instances;
110
111 const std::string channelName;
112 ChannelCache * const cache;
113
114 // to avoid yet another mutex borrow interested.mutex() for our members
115 inline epicsMutex& mutex() const { return interested.mutex(); }
116
117 // clientChannel
118 epics::pvAccess::Channel::shared_pointer channel;
119 epics::pvAccess::ChannelRequester::shared_pointer requester;
120
121 bool dropPoke;
122
123 typedef weak_set<GWChannel> interested_t;
124 interested_t interested;
125
126 typedef MonitorCacheEntry::pvrequest_t pvrequest_t;
128 mon_entries_t mon_entries;
129
130 ChannelCacheEntry(ChannelCache*, const std::string& n);
131 virtual ~ChannelCacheEntry();
132
133 // this exists as a seperate object to prevent a reference loop
134 // ChannelCacheEntry -> pva::Channel -> CRequester
135 struct CRequester : public epics::pvAccess::ChannelRequester
136 {
137 static size_t num_instances;
138
139 CRequester(const ChannelCacheEntry::shared_pointer& p);
140 virtual ~CRequester();
141 ChannelCacheEntry::weak_pointer chan;
142 // for Requester
143 virtual std::string getRequesterName();
144 // for ChannelRequester
145 virtual void channelCreated(const epics::pvData::Status& status,
146 epics::pvAccess::Channel::shared_pointer const & channel);
147 virtual void channelStateChange(epics::pvAccess::Channel::shared_pointer const & channel,
148 epics::pvAccess::Channel::ConnectionState connectionState);
149 };
150};
151
154struct ChannelCache
155{
156 typedef std::map<std::string, ChannelCacheEntry::shared_pointer > entries_t;
157
158 // cacheLock should not be held while calling *Requester methods
159 epicsMutex cacheLock;
160
161 entries_t entries;
162
163 epics::pvAccess::ChannelProvider::shared_pointer provider; // client Provider
164
165 epicsTimerQueueActive *timerQueue;
166 epicsTimer *cleanTimer;
167 struct cacheClean;
168 cacheClean *cleaner;
169 size_t cleanerRuns;
170 size_t cleanerDust;
171
172 ChannelCache(const epics::pvAccess::ChannelProvider::shared_pointer& prov);
173 ~ChannelCache();
174
175 ChannelCacheEntry::shared_pointer lookup(const std::string& name);
176};
177
178#endif // CHANCACHE_H
a std::set-ish container where entries are removed when ref. counts fall to zero
Definition weakset.h:58
An associative map where a weak_ptr to the value is stored.
Definition weakmap.h:60
Definition chancache.h:107
epics::pvData::MonitorElement::shared_pointer lastelem
Definition chancache.h:46