8 #include <epicsEvent.h>
9 #include <epicsUnitTest.h>
10 #include <dbUnitTest.h>
12 #include <pv/pvUnitTest.h>
13 #include <pv/pvAccess.h>
15 #include "pvahelper.h"
25 #define DUMBREQUESTER(NAME) \
26 virtual std::string getRequesterName() OVERRIDE { return #NAME; }
29 inline std::string toString(
const T& tbs)
31 std::ostringstream oss;
39 epics::pvData::PVScalar::shared_pointer field;
41 ScalarAccessor(
const epics::pvData::PVStructurePtr& s,
const char *name)
42 :field(s->getSubFieldT<epics::pvData::PVScalar>(name))
44 operator value_type() {
45 return field->getAs<T>();
52 field->putFrom<T>(field->getAs<T>()+v);
64 epics::pvAccess::Channel::shared_pointer chan;
65 epics::pvData::Status status;
66 epics::pvAccess::Channel::ConnectionState laststate;
69 virtual void channelCreated(
const epics::pvData::Status& status, epics::pvAccess::Channel::shared_pointer
const & channel);
70 virtual void channelStateChange(epics::pvAccess::Channel::shared_pointer
const & channel, epics::pvAccess::Channel::ConnectionState connectionState);
72 bool waitForConnect();
81 epics::pvData::Status status;
82 epics::pvData::FieldConstPtr fielddesc;
88 const epics::pvData::Status& status,
89 epics::pvData::FieldConstPtr
const & field)
91 this->status = status;
102 bool connected, done;
103 epics::pvData::Status statusConnect, statusDone;
104 epics::pvAccess::ChannelGet::shared_pointer channelGet;
105 epics::pvData::Structure::const_shared_pointer fielddesc;
106 epics::pvData::PVStructure::shared_pointer value;
107 epics::pvData::BitSet::shared_pointer changed;
112 virtual void channelGetConnect(
113 const epics::pvData::Status& status,
114 epics::pvAccess::ChannelGet::shared_pointer
const & channelGet,
115 epics::pvData::Structure::const_shared_pointer
const & structure);
117 virtual void getDone(
118 const epics::pvData::Status& status,
119 epics::pvAccess::ChannelGet::shared_pointer
const & channelGet,
120 epics::pvData::PVStructure::shared_pointer
const & pvStructure,
121 epics::pvData::BitSet::shared_pointer
const & bitSet);
129 bool connected, doneGet, donePut;
130 epics::pvData::Status statusConnect, statusPut, statusGet;
131 epics::pvAccess::ChannelPut::shared_pointer put;
132 epics::pvData::Structure::const_shared_pointer fielddesc;
133 epics::pvData::PVStructure::shared_pointer value;
134 epics::pvData::BitSet::shared_pointer changed;
139 virtual void channelPutConnect(
140 const epics::pvData::Status& status,
141 epics::pvAccess::ChannelPut::shared_pointer
const & channelPut,
142 epics::pvData::Structure::const_shared_pointer
const & structure);
144 virtual void putDone(
145 const epics::pvData::Status& status,
146 epics::pvAccess::ChannelPut::shared_pointer
const & channelPut);
148 virtual void getDone(
149 const epics::pvData::Status& status,
150 epics::pvAccess::ChannelPut::shared_pointer
const & channelPut,
151 epics::pvData::PVStructure::shared_pointer
const & pvStructure,
152 epics::pvData::BitSet::shared_pointer
const & bitSet);
165 epics::pvData::Status connectStatus;
166 epics::pvData::MonitorPtr mon;
167 epics::pvData::StructureConstPtr dtype;
172 virtual void monitorConnect(epics::pvData::Status
const & status,
173 epics::pvData::MonitorPtr
const & monitor,
174 epics::pvData::StructureConstPtr
const & structure);
175 virtual void monitorEvent(epics::pvData::MonitorPtr
const & monitor);
176 virtual void unlisten(epics::pvData::MonitorPtr
const & monitor);
178 bool waitForConnect();
186 std::tr1::weak_ptr<TestPVChannel> weakself;
188 const std::tr1::shared_ptr<TestPV> pv;
189 ConnectionState state;
195 const std::tr1::shared_ptr<epics::pvAccess::ChannelRequester>& req);
198 virtual std::string getRemoteAddress() {
return "localhost:1234"; }
199 virtual ConnectionState getConnectionState();
201 virtual void getField(epics::pvAccess::GetFieldRequester::shared_pointer
const & requester,std::string
const & subField);
203 virtual epics::pvData::Monitor::shared_pointer createMonitor(
204 epics::pvData::MonitorRequester::shared_pointer
const & monitorRequester,
205 epics::pvData::PVStructure::shared_pointer
const & pvRequest);
211 std::tr1::weak_ptr<TestPVMonitor> weakself;
213 const TestPVChannel::shared_pointer channel;
214 const epics::pvData::MonitorRequester::weak_pointer requester;
222 const epics::pvData::MonitorRequester::shared_pointer& req,
226 virtual void destroy();
228 virtual epics::pvData::Status start();
229 virtual epics::pvData::Status stop();
230 virtual epics::pvData::MonitorElementPtr poll();
231 virtual void release(epics::pvData::MonitorElementPtr
const & monitorElement);
233 std::deque<epics::pvData::MonitorElementPtr> buffer, free;
234 epics::pvData::MonitorElementPtr overflow;
239 POINTER_DEFINITIONS(
TestPV);
240 std::tr1::weak_ptr<TestPV> weakself;
242 const std::string name;
243 std::tr1::weak_ptr<TestProvider>
const provider;
245 epics::pvData::PVDataCreatePtr factory;
247 const epics::pvData::StructureConstPtr dtype;
248 epics::pvData::PVStructurePtr value;
250 TestPV(
const std::string& name,
251 const std::tr1::shared_ptr<TestProvider>& provider,
252 const epics::pvData::StructureConstPtr& dtype);
255 void post(
bool notify =
true);
256 void post(
const epics::pvData::BitSet& changed,
bool notify =
true);
260 mutable epicsMutex lock;
267 struct TestProvider :
public epics::pvAccess::ChannelProvider, std::tr1::enable_shared_from_this<TestProvider>
271 virtual std::string getProviderName() {
return "TestProvider"; }
273 virtual void destroy();
275 virtual epics::pvAccess::ChannelFind::shared_pointer channelFind(std::string
const & channelName,
276 epics::pvAccess::ChannelFindRequester::shared_pointer
const & channelFindRequester);
277 virtual epics::pvAccess::ChannelFind::shared_pointer channelList(epics::pvAccess::ChannelListRequester::shared_pointer
const & channelListRequester);
278 virtual epics::pvAccess::Channel::shared_pointer createChannel(std::string
const & channelName,epics::pvAccess::ChannelRequester::shared_pointer
const & channelRequester,
279 short priority = PRIORITY_DEFAULT);
280 virtual epics::pvAccess::Channel::shared_pointer createChannel(std::string
const & channelName, epics::pvAccess::ChannelRequester::shared_pointer
const & channelRequester,
281 short priority, std::string
const & address);
286 TestPV::shared_pointer addPV(
const std::string& name,
const epics::pvData::StructureConstPtr& tdef);
290 mutable epicsMutex lock;
294 static void testCounts();
322 #endif // UTILITIES_H