pvAccessCPP  7.1.7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
responseHandlers.h
1 
7 #ifndef RESPONSEHANDLERS_H_
8 #define RESPONSEHANDLERS_H_
9 
10 #include <list>
11 
12 #include <pv/timer.h>
13 
14 #include <pv/serverContext.h>
15 #include <pv/remote.h>
16 #include <pv/serverChannelImpl.h>
17 #include <pv/baseChannelRequester.h>
18 #include <pv/securityImpl.h>
19 
20 namespace epics {
21 namespace pvAccess {
22 
25 class AbstractServerResponseHandler : public ResponseHandler {
26 protected:
27  ServerContextImpl::shared_pointer _context;
28 public:
29  AbstractServerResponseHandler(ServerContextImpl::shared_pointer const & context, std::string description) :
30  ResponseHandler(context.get(), description), _context(context) {
31  }
32 
33  virtual ~AbstractServerResponseHandler() {}
34 };
35 
39 class ServerBadResponse : public AbstractServerResponseHandler {
40 public:
41  ServerBadResponse(ServerContextImpl::shared_pointer const & context) :
42  AbstractServerResponseHandler(context, "Bad request") {
43  }
44 
45  virtual ~ServerBadResponse() {
46  }
47 
48  virtual void handleResponse(osiSockAddr* responseFrom,
49  Transport::shared_pointer const & transport, epics::pvData::int8 version, epics::pvData::int8 command,
50  std::size_t payloadSize, epics::pvData::ByteBuffer* payloadBuffer) OVERRIDE FINAL;
51 };
52 
56 class ServerConnectionValidationHandler : public AbstractServerResponseHandler {
57 public:
58  ServerConnectionValidationHandler(ServerContextImpl::shared_pointer const & context) :
59  AbstractServerResponseHandler(context, "Connection validation") {
60  }
62 
63  virtual void handleResponse(osiSockAddr* responseFrom,
64  Transport::shared_pointer const & transport, epics::pvData::int8 version, epics::pvData::int8 command,
65  std::size_t payloadSize, epics::pvData::ByteBuffer* payloadBuffer) OVERRIDE FINAL;
66 };
67 
71 class ServerNoopResponse : public AbstractServerResponseHandler {
72 public:
73  ServerNoopResponse(ServerContextImpl::shared_pointer const & context, std::string description) :
74  AbstractServerResponseHandler(context, description) {
75  }
76  virtual ~ServerNoopResponse() {}
77 };
78 
82 class ServerEchoHandler : public AbstractServerResponseHandler {
83 public:
84  ServerEchoHandler(ServerContextImpl::shared_pointer const & context) :
85  AbstractServerResponseHandler(context, "Echo request") {
86  }
87  virtual ~ServerEchoHandler() {}
88 
89  virtual void handleResponse(osiSockAddr* responseFrom,
90  Transport::shared_pointer const & transport, epics::pvData::int8 version, epics::pvData::int8 command,
91  std::size_t payloadSize, epics::pvData::ByteBuffer* payloadBuffer) OVERRIDE FINAL;
92 };
93 
94 class EchoTransportSender : public TransportSender {
95 public:
96  EchoTransportSender(osiSockAddr* echoFrom, size_t payloadSize, epics::pvData::ByteBuffer& payloadBuffer) {
97  memcpy(&_echoFrom, echoFrom, sizeof(osiSockAddr));
98  toEcho.resize(payloadSize);
99  if (payloadSize) {
100  payloadBuffer.getArray(&toEcho[0], payloadSize);
101  }
102  }
103 
104  virtual ~EchoTransportSender() {}
105 
106  virtual void send(epics::pvData::ByteBuffer* buffer, TransportSendControl* control) OVERRIDE FINAL {
107  control->startMessage(CMD_ECHO, toEcho.size(), toEcho.size());
108  control->setRecipient(_echoFrom);
109  if (toEcho.size() > 0) {
110  buffer->putArray<char>(&toEcho[0], toEcho.size());
111  }
112  }
113 
114 private:
115  osiSockAddr _echoFrom;
116  std::vector<char> toEcho;
117 };
118 
119 /****************************************************************************************/
123 // TODO object pool!!!
124 class ServerSearchHandler : public AbstractServerResponseHandler
125 {
126 public:
127  static const std::string SUPPORTED_PROTOCOL;
128 
129  ServerSearchHandler(ServerContextImpl::shared_pointer const & context);
130  virtual ~ServerSearchHandler() {}
131 
132  virtual void handleResponse(osiSockAddr* responseFrom,
133  Transport::shared_pointer const & transport, epics::pvData::int8 version, epics::pvData::int8 command,
134  std::size_t payloadSize, epics::pvData::ByteBuffer* payloadBuffer) OVERRIDE FINAL;
135 };
136 
137 
138 class ServerChannelFindRequesterImpl:
139  public ChannelFindRequester,
140  public TransportSender,
141  public epics::pvData::TimerCallback,
142  public std::tr1::enable_shared_from_this<ServerChannelFindRequesterImpl>
143 {
144 public:
145  ServerChannelFindRequesterImpl(ServerContextImpl::shared_pointer const & context,
146  const PeerInfo::const_shared_pointer& peer,
147  epics::pvData::int32 expectedResponseCount);
148  virtual ~ServerChannelFindRequesterImpl() {}
149  void clear();
150  ServerChannelFindRequesterImpl* set(std::string _name, epics::pvData::int32 searchSequenceId,
151  epics::pvData::int32 cid, osiSockAddr const & sendTo, bool responseRequired, bool serverSearch);
152  virtual void channelFindResult(const epics::pvData::Status& status, ChannelFind::shared_pointer const & channelFind, bool wasFound) OVERRIDE FINAL;
153 
154  virtual std::tr1::shared_ptr<const PeerInfo> getPeerInfo() OVERRIDE FINAL;
155  virtual void send(epics::pvData::ByteBuffer* buffer, TransportSendControl* control) OVERRIDE FINAL;
156 
157  virtual void callback() OVERRIDE FINAL;
158  virtual void timerStopped() OVERRIDE FINAL;
159 
160 private:
161  ServerGUID _guid;
162  std::string _name;
163  epics::pvData::int32 _searchSequenceId;
164  epics::pvData::int32 _cid;
165  osiSockAddr _sendTo;
166  bool _responseRequired;
167  bool _wasFound;
168  const ServerContextImpl::shared_pointer _context;
169  const PeerInfo::const_shared_pointer _peer;
170  mutable epics::pvData::Mutex _mutex;
171  const epics::pvData::int32 _expectedResponseCount;
172  epics::pvData::int32 _responseCount;
173  bool _serverSearch;
174 };
175 
176 /****************************************************************************************/
180 class ServerCreateChannelHandler : public AbstractServerResponseHandler
181 {
182 public:
183  ServerCreateChannelHandler(ServerContextImpl::shared_pointer const & context)
184  :AbstractServerResponseHandler(context, "Create channel request")
185  {}
186  virtual ~ServerCreateChannelHandler() {}
187 
188  virtual void handleResponse(osiSockAddr* responseFrom,
189  Transport::shared_pointer const & transport, epics::pvData::int8 version, epics::pvData::int8 command,
190  std::size_t payloadSize, epics::pvData::ByteBuffer* payloadBuffer) OVERRIDE FINAL;
191 
192 private:
193  // Name of the magic "server" PV used to implement channelList() and server info
194  static const std::string SERVER_CHANNEL_NAME;
195 
196  void disconnect(Transport::shared_pointer const & transport);
197 };
198 
199 namespace detail {
200 class BlockingServerTCPTransportCodec;
201 }
202 
203 class ServerChannelRequesterImpl :
204  public ChannelRequester,
205  public TransportSender,
206  public std::tr1::enable_shared_from_this<ServerChannelRequesterImpl>
207 {
208  friend class ServerCreateChannelHandler;
209 public:
210  typedef std::tr1::shared_ptr<ServerChannelRequesterImpl> shared_pointer;
211  typedef std::tr1::shared_ptr<const ServerChannelRequesterImpl> const_shared_pointer;
212 protected:
213  ServerChannelRequesterImpl(Transport::shared_pointer const & transport,
214  const std::string channelName,
215  const pvAccessID cid);
216 public:
217  virtual ~ServerChannelRequesterImpl() {}
218  static ChannelRequester::shared_pointer create(ChannelProvider::shared_pointer const & provider,
219  Transport::shared_pointer const & transport, const std::string channelName,
220  const pvAccessID cid);
221  virtual void channelCreated(const epics::pvData::Status& status, Channel::shared_pointer const & channel) OVERRIDE FINAL;
222  virtual void channelStateChange(Channel::shared_pointer const & c, const Channel::ConnectionState isConnected) OVERRIDE FINAL;
223  virtual std::tr1::shared_ptr<const PeerInfo> getPeerInfo() OVERRIDE FINAL;
224  virtual std::string getRequesterName() OVERRIDE FINAL;
225  virtual void message(std::string const & message, epics::pvData::MessageType messageType) OVERRIDE FINAL;
226  virtual void send(epics::pvData::ByteBuffer* buffer, TransportSendControl* control) OVERRIDE FINAL;
227 private:
228  ServerChannel::weak_pointer _serverChannel;
229  std::tr1::weak_ptr<detail::BlockingServerTCPTransportCodec> _transport;
230  const std::string _channelName;
231  const pvAccessID _cid;
232  bool _created;
233  epics::pvData::Status _status;
234  epics::pvData::Mutex _mutex;
235 };
236 
237 /****************************************************************************************/
241 class ServerDestroyChannelHandler : public AbstractServerResponseHandler
242 {
243 public:
244  ServerDestroyChannelHandler(ServerContextImpl::shared_pointer const & context) :
245  AbstractServerResponseHandler(context, "Destroy channel request") {
246  }
247  virtual ~ServerDestroyChannelHandler() {}
248 
249  virtual void handleResponse(osiSockAddr* responseFrom,
250  Transport::shared_pointer const & transport, epics::pvData::int8 version, epics::pvData::int8 command,
251  std::size_t payloadSize, epics::pvData::ByteBuffer* payloadBuffer) OVERRIDE FINAL;
252 };
253 
254 
255 class ServerDestroyChannelHandlerTransportSender : public TransportSender
256 {
257 public:
258  ServerDestroyChannelHandlerTransportSender(pvAccessID cid, pvAccessID sid): _cid(cid), _sid(sid) {
259  }
260 
261  virtual ~ServerDestroyChannelHandlerTransportSender() {}
262  virtual void send(epics::pvData::ByteBuffer* buffer, TransportSendControl* control) OVERRIDE FINAL {
263  control->startMessage((epics::pvData::int8)CMD_DESTROY_CHANNEL, 2*sizeof(epics::pvData::int32)/sizeof(epics::pvData::int8));
264  buffer->putInt(_sid);
265  buffer->putInt(_cid);
266  }
267 
268 private:
269  pvAccessID _cid;
270  pvAccessID _sid;
271 };
272 
273 /****************************************************************************************/
277 class ServerGetHandler : public AbstractServerResponseHandler
278 {
279 public:
280  ServerGetHandler(ServerContextImpl::shared_pointer const & context) :
281  AbstractServerResponseHandler(context, "Get request") {
282  }
283  virtual ~ServerGetHandler() {}
284 
285  virtual void handleResponse(osiSockAddr* responseFrom,
286  Transport::shared_pointer const & transport, epics::pvData::int8 version, epics::pvData::int8 command,
287  std::size_t payloadSize, epics::pvData::ByteBuffer* payloadBuffer) OVERRIDE FINAL;
288 };
289 
290 class ServerChannelGetRequesterImpl :
291  public BaseChannelRequester,
292  public ChannelGetRequester,
293  public std::tr1::enable_shared_from_this<ServerChannelGetRequesterImpl>
294 {
295 public:
296  typedef std::tr1::shared_ptr<ServerChannelGetRequesterImpl> shared_pointer;
297  typedef std::tr1::shared_ptr<const ServerChannelGetRequesterImpl> const_shared_pointer;
298 protected:
299  ServerChannelGetRequesterImpl(ServerContextImpl::shared_pointer const & context,
300  std::tr1::shared_ptr<ServerChannel> const & channel, const pvAccessID ioid,
301  Transport::shared_pointer const & transport);
302  void activate(epics::pvData::PVStructure::shared_pointer const & pvRequest);
303 public:
304  static ChannelGetRequester::shared_pointer create(ServerContextImpl::shared_pointer const & context,
305  std::tr1::shared_ptr<ServerChannel> const & channel, const pvAccessID ioid,
306  Transport::shared_pointer const & transport,
307  epics::pvData::PVStructure::shared_pointer const & pvRequest);
308  virtual ~ServerChannelGetRequesterImpl() {}
309  virtual void channelGetConnect(const epics::pvData::Status& status, ChannelGet::shared_pointer const & channelGet,
310  epics::pvData::Structure::const_shared_pointer const & structure) OVERRIDE FINAL;
311  virtual void getDone(const epics::pvData::Status& status, ChannelGet::shared_pointer const & channelGet,
312  epics::pvData::PVStructure::shared_pointer const & pvStructure,
313  epics::pvData::BitSet::shared_pointer const & bitSet) OVERRIDE FINAL;
314  virtual void destroy() OVERRIDE FINAL;
315 
316  ChannelGet::shared_pointer getChannelGet();
317  virtual std::tr1::shared_ptr<ChannelRequest> getOperation() OVERRIDE FINAL { return getChannelGet(); }
318 
319  virtual void send(epics::pvData::ByteBuffer* buffer, TransportSendControl* control) OVERRIDE FINAL;
320 private:
321  // Note: this forms a reference loop, which is broken in destroy()
322  ChannelGet::shared_pointer _channelGet;
323  epics::pvData::PVStructure::shared_pointer _pvStructure;
324  epics::pvData::BitSet::shared_pointer _bitSet;
325  epics::pvData::Status _status;
326 };
327 
328 
329 /****************************************************************************************/
333 class ServerPutHandler : public AbstractServerResponseHandler
334 {
335 public:
336  ServerPutHandler(ServerContextImpl::shared_pointer context) :
337  AbstractServerResponseHandler(context, "Put request") {
338  }
339  virtual ~ServerPutHandler() {}
340 
341  virtual void handleResponse(osiSockAddr* responseFrom,
342  Transport::shared_pointer const & transport, epics::pvData::int8 version, epics::pvData::int8 command,
343  std::size_t payloadSize, epics::pvData::ByteBuffer* payloadBuffer) OVERRIDE FINAL;
344 };
345 
346 class ServerChannelPutRequesterImpl :
347  public BaseChannelRequester,
348  public ChannelPutRequester,
349  public std::tr1::enable_shared_from_this<ServerChannelPutRequesterImpl>
350 {
351 public:
352  typedef std::tr1::shared_ptr<ServerChannelPutRequesterImpl> shared_pointer;
353  typedef std::tr1::shared_ptr<const ServerChannelPutRequesterImpl> const_shared_pointer;
354 protected:
355  ServerChannelPutRequesterImpl(ServerContextImpl::shared_pointer const & context,
356  std::tr1::shared_ptr<ServerChannel> const & channel, const pvAccessID ioid,
357  Transport::shared_pointer const & transport);
358  void activate(epics::pvData::PVStructure::shared_pointer const & pvRequest);
359 public:
360  static ChannelPutRequester::shared_pointer create(ServerContextImpl::shared_pointer const & context,
361  std::tr1::shared_ptr<ServerChannel> const & channel, const pvAccessID ioid,
362  Transport::shared_pointer const & transport,epics::pvData::PVStructure::shared_pointer const & pvRequest);
363 
364  virtual ~ServerChannelPutRequesterImpl() {}
365  virtual void channelPutConnect(const epics::pvData::Status& status, ChannelPut::shared_pointer const & channelPut,
366  epics::pvData::Structure::const_shared_pointer const & structure) OVERRIDE FINAL;
367  virtual void putDone(const epics::pvData::Status& status, ChannelPut::shared_pointer const & channelPut) OVERRIDE FINAL;
368  virtual void getDone(const epics::pvData::Status& status, ChannelPut::shared_pointer const & channelPut,
369  epics::pvData::PVStructure::shared_pointer const & pvStructure,
370  epics::pvData::BitSet::shared_pointer const & bitSet) OVERRIDE FINAL;
371  virtual void destroy() OVERRIDE FINAL;
372 
373  ChannelPut::shared_pointer getChannelPut();
374  virtual std::tr1::shared_ptr<ChannelRequest> getOperation() OVERRIDE FINAL { return getChannelPut(); }
375 
376  epics::pvData::BitSet::shared_pointer getPutBitSet();
377  epics::pvData::PVStructure::shared_pointer getPutPVStructure();
378  void send(epics::pvData::ByteBuffer* buffer, TransportSendControl* control) OVERRIDE FINAL;
379 private:
380  // Note: this forms a reference loop, which is broken in destroy()
381  ChannelPut::shared_pointer _channelPut;
382  epics::pvData::BitSet::shared_pointer _bitSet;
383  epics::pvData::PVStructure::shared_pointer _pvStructure;
384  epics::pvData::Status _status;
385 };
386 
387 /****************************************************************************************/
391 class ServerPutGetHandler : public AbstractServerResponseHandler
392 {
393 public:
394  ServerPutGetHandler(ServerContextImpl::shared_pointer const & context) :
395  AbstractServerResponseHandler(context, "Put-get request") {
396  }
397 
398  virtual ~ServerPutGetHandler() {}
399  virtual void handleResponse(osiSockAddr* responseFrom,
400  Transport::shared_pointer const & transport, epics::pvData::int8 version, epics::pvData::int8 command,
401  std::size_t payloadSize, epics::pvData::ByteBuffer* payloadBuffer) OVERRIDE FINAL;
402 };
403 
404 class ServerChannelPutGetRequesterImpl :
405  public BaseChannelRequester,
406  public ChannelPutGetRequester,
407  public std::tr1::enable_shared_from_this<ServerChannelPutGetRequesterImpl>
408 {
409 public:
410  typedef std::tr1::shared_ptr<ServerChannelPutGetRequesterImpl> shared_pointer;
411  typedef std::tr1::shared_ptr<const ServerChannelPutGetRequesterImpl> const_shared_pointer;
412 protected:
413  ServerChannelPutGetRequesterImpl(ServerContextImpl::shared_pointer const & context,
414  std::tr1::shared_ptr<ServerChannel> const & channel, const pvAccessID ioid,
415  Transport::shared_pointer const & transport);
416  void activate(epics::pvData::PVStructure::shared_pointer const & pvRequest);
417 public:
418  static ChannelPutGetRequester::shared_pointer create(ServerContextImpl::shared_pointer const & context,
419  std::tr1::shared_ptr<ServerChannel> const & channel, const pvAccessID ioid,
420  Transport::shared_pointer const & transport,epics::pvData::PVStructure::shared_pointer const & pvRequest);
421  virtual ~ServerChannelPutGetRequesterImpl() {}
422 
423  virtual void channelPutGetConnect(const epics::pvData::Status& status, ChannelPutGet::shared_pointer const & channelPutGet,
424  epics::pvData::Structure::const_shared_pointer const & putStructure,
425  epics::pvData::Structure::const_shared_pointer const & getStructure) OVERRIDE FINAL;
426  virtual void getGetDone(const epics::pvData::Status& status, ChannelPutGet::shared_pointer const & channelPutGet,
427  epics::pvData::PVStructure::shared_pointer const & pvStructure,
428  epics::pvData::BitSet::shared_pointer const & bitSet) OVERRIDE FINAL;
429  virtual void getPutDone(const epics::pvData::Status& status, ChannelPutGet::shared_pointer const & channelPutGet,
430  epics::pvData::PVStructure::shared_pointer const & pvStructure,
431  epics::pvData::BitSet::shared_pointer const & bitSet) OVERRIDE FINAL;
432  virtual void putGetDone(const epics::pvData::Status& status, ChannelPutGet::shared_pointer const & channelPutGet,
433  epics::pvData::PVStructure::shared_pointer const & pvStructure,
434  epics::pvData::BitSet::shared_pointer const & bitSet) OVERRIDE FINAL;
435  virtual void destroy() OVERRIDE FINAL;
436 
437  ChannelPutGet::shared_pointer getChannelPutGet();
438  virtual std::tr1::shared_ptr<ChannelRequest> getOperation() OVERRIDE FINAL { return getChannelPutGet(); }
439 
440  epics::pvData::PVStructure::shared_pointer getPutGetPVStructure();
441  epics::pvData::BitSet::shared_pointer getPutGetBitSet();
442 
443  virtual void send(epics::pvData::ByteBuffer* buffer, TransportSendControl* control) OVERRIDE FINAL;
444 private:
445  // Note: this forms a reference loop, which is broken in destroy()
446  ChannelPutGet::shared_pointer _channelPutGet;
447  epics::pvData::PVStructure::shared_pointer _pvPutStructure;
448  epics::pvData::BitSet::shared_pointer _pvPutBitSet;
449  epics::pvData::PVStructure::shared_pointer _pvGetStructure;
450  epics::pvData::BitSet::shared_pointer _pvGetBitSet;
451  epics::pvData::Status _status;
452 };
453 
454 
455 /****************************************************************************************/
459 class ServerMonitorHandler : public AbstractServerResponseHandler
460 {
461 public:
462  ServerMonitorHandler(ServerContextImpl::shared_pointer const & context) :
463  AbstractServerResponseHandler(context, "Monitor request") {
464  }
465  virtual ~ServerMonitorHandler() {}
466 
467  virtual void handleResponse(osiSockAddr* responseFrom,
468  Transport::shared_pointer const & transport, epics::pvData::int8 version, epics::pvData::int8 command,
469  std::size_t payloadSize, epics::pvData::ByteBuffer* payloadBuffer) OVERRIDE FINAL;
470 };
471 
472 
473 class ServerMonitorRequesterImpl :
474  public BaseChannelRequester,
475  public MonitorRequester,
476  public std::tr1::enable_shared_from_this<ServerMonitorRequesterImpl>
477 {
478 public:
479  typedef std::tr1::shared_ptr<ServerMonitorRequesterImpl> shared_pointer;
480  typedef std::tr1::shared_ptr<const ServerMonitorRequesterImpl> const_shared_pointer;
481 protected:
482  ServerMonitorRequesterImpl(ServerContextImpl::shared_pointer const & context,
483  std::tr1::shared_ptr<ServerChannel> const & channel, const pvAccessID ioid,
484  Transport::shared_pointer const & transport);
485  void activate(epics::pvData::PVStructure::shared_pointer const & pvRequest);
486 public:
487  static shared_pointer create(ServerContextImpl::shared_pointer const & context,
488  std::tr1::shared_ptr<ServerChannel> const & channel, const pvAccessID ioid,
489  Transport::shared_pointer const & transport,epics::pvData::PVStructure::shared_pointer const & pvRequest);
490  virtual ~ServerMonitorRequesterImpl() {}
491 
492  virtual void monitorConnect(const epics::pvData::Status& status,
493  Monitor::shared_pointer const & monitor,
494  epics::pvData::StructureConstPtr const & structure) OVERRIDE FINAL;
495  virtual void unlisten(Monitor::shared_pointer const & monitor) OVERRIDE FINAL;
496  virtual void monitorEvent(Monitor::shared_pointer const & monitor) OVERRIDE FINAL;
497  virtual void destroy() OVERRIDE FINAL;
498 
499  Monitor::shared_pointer getChannelMonitor();
500  virtual std::tr1::shared_ptr<ChannelRequest> getOperation() OVERRIDE FINAL { return std::tr1::shared_ptr<ChannelRequest>(); }
501 
502  virtual void send(epics::pvData::ByteBuffer* buffer, TransportSendControl* control) OVERRIDE FINAL;
503  void ack(size_t cnt);
504 private:
505  // Note: this forms a reference loop, which is broken in destroy()
506  Monitor::shared_pointer _channelMonitor;
507  epics::pvData::StructureConstPtr _structure;
508  epics::pvData::Status _status;
509  // when _pipeline==true
510  // _window_open + _window_closed.size() are together the congestion control window.
511  // _window_open are the number of elements which we can send w/o further ack's
512  size_t _window_open;
513  // The elements we have sent, but have not been acknowledged
515  window_t _window_closed;
516  bool _unlisten;
517  bool _pipeline; // const after activate()
518 };
519 
520 
521 /****************************************************************************************/
525 class ServerArrayHandler : public AbstractServerResponseHandler
526 {
527 public:
528  ServerArrayHandler(ServerContextImpl::shared_pointer const & context) :
529  AbstractServerResponseHandler(context, "Array request") {
530  }
531  virtual ~ServerArrayHandler() {}
532 
533  virtual void handleResponse(osiSockAddr* responseFrom,
534  Transport::shared_pointer const & transport, epics::pvData::int8 version, epics::pvData::int8 command,
535  std::size_t payloadSize, epics::pvData::ByteBuffer* payloadBuffer) OVERRIDE FINAL;
536 };
537 
538 class ServerChannelArrayRequesterImpl :
539  public BaseChannelRequester,
540  public ChannelArrayRequester,
541  public std::tr1::enable_shared_from_this<ServerChannelArrayRequesterImpl>
542 {
543 public:
544  typedef std::tr1::shared_ptr<ServerChannelArrayRequesterImpl> shared_pointer;
545  typedef std::tr1::shared_ptr<const ServerChannelArrayRequesterImpl> const_shared_pointer;
546 protected:
547  ServerChannelArrayRequesterImpl(ServerContextImpl::shared_pointer const & context,
548  std::tr1::shared_ptr<ServerChannel> const & channel, const pvAccessID ioid,
549  Transport::shared_pointer const & transport);
550  void activate(epics::pvData::PVStructure::shared_pointer const & pvRequest);
551 public:
552  static ChannelArrayRequester::shared_pointer create(ServerContextImpl::shared_pointer const & context,
553  std::tr1::shared_ptr<ServerChannel> const & channel, const pvAccessID ioid,
554  Transport::shared_pointer const & transport,epics::pvData::PVStructure::shared_pointer const & pvRequest);
555  virtual ~ServerChannelArrayRequesterImpl() {}
556 
557  virtual void channelArrayConnect(const epics::pvData::Status& status,
558  ChannelArray::shared_pointer const & channelArray,
559  epics::pvData::Array::const_shared_pointer const & array) OVERRIDE FINAL;
560  virtual void getArrayDone(const epics::pvData::Status& status,
561  ChannelArray::shared_pointer const & channelArray,
562  epics::pvData::PVArray::shared_pointer const & pvArray) OVERRIDE FINAL;
563  virtual void putArrayDone(const epics::pvData::Status& status,
564  ChannelArray::shared_pointer const & channelArray) OVERRIDE FINAL;
565  virtual void setLengthDone(const epics::pvData::Status& status,
566  ChannelArray::shared_pointer const & channelArray) OVERRIDE FINAL;
567  virtual void getLengthDone(const epics::pvData::Status& status,
568  ChannelArray::shared_pointer const & channelArray,
569  std::size_t length) OVERRIDE FINAL;
570  virtual void destroy() OVERRIDE FINAL;
571 
572  ChannelArray::shared_pointer getChannelArray();
573  virtual std::tr1::shared_ptr<ChannelRequest> getOperation() OVERRIDE FINAL { return getChannelArray(); }
574 
575  epics::pvData::PVArray::shared_pointer getPVArray();
576  virtual void send(epics::pvData::ByteBuffer* buffer, TransportSendControl* control) OVERRIDE FINAL;
577 
578 private:
579  // Note: this forms a reference loop, which is broken in destroy()
580  ChannelArray::shared_pointer _channelArray;
581  epics::pvData::PVArray::shared_pointer _pvArray;
582 
583  std::size_t _length;
584  epics::pvData::Status _status;
585 };
586 
587 /****************************************************************************************/
591 class ServerDestroyRequestHandler : public AbstractServerResponseHandler
592 {
593 public:
594  ServerDestroyRequestHandler(ServerContextImpl::shared_pointer const & context) :
595  AbstractServerResponseHandler(context, "Destroy request") {
596  }
597  virtual ~ServerDestroyRequestHandler() {}
598 
599  virtual void handleResponse(osiSockAddr* responseFrom,
600  Transport::shared_pointer const & transport, epics::pvData::int8 version, epics::pvData::int8 command,
601  std::size_t payloadSize, epics::pvData::ByteBuffer* payloadBuffer) OVERRIDE FINAL;
602 private:
603 
604  void failureResponse(Transport::shared_pointer const & transport, pvAccessID ioid, const epics::pvData::Status& errorStatus);
605 };
606 
607 
608 /****************************************************************************************/
612 class ServerCancelRequestHandler : public AbstractServerResponseHandler
613 {
614 public:
615  ServerCancelRequestHandler(ServerContextImpl::shared_pointer const & context) :
616  AbstractServerResponseHandler(context, "Cancel request") {
617  }
618  virtual ~ServerCancelRequestHandler() {}
619 
620  virtual void handleResponse(osiSockAddr* responseFrom,
621  Transport::shared_pointer const & transport, epics::pvData::int8 version, epics::pvData::int8 command,
622  std::size_t payloadSize, epics::pvData::ByteBuffer* payloadBuffer) OVERRIDE FINAL;
623 private:
624 
625  void failureResponse(Transport::shared_pointer const & transport, pvAccessID ioid, const epics::pvData::Status& errorStatus);
626 };
627 
628 
629 /****************************************************************************************/
633 class ServerProcessHandler : public AbstractServerResponseHandler
634 {
635 public:
636  ServerProcessHandler(ServerContextImpl::shared_pointer const & context) :
637  AbstractServerResponseHandler(context, "Process request") {
638  }
639  virtual ~ServerProcessHandler() {}
640 
641  virtual void handleResponse(osiSockAddr* responseFrom,
642  Transport::shared_pointer const & transport, epics::pvData::int8 version, epics::pvData::int8 command,
643  std::size_t payloadSize, epics::pvData::ByteBuffer* payloadBuffer) OVERRIDE FINAL;
644 };
645 
646 class ServerChannelProcessRequesterImpl :
647  public BaseChannelRequester,
649  public std::tr1::enable_shared_from_this<ServerChannelProcessRequesterImpl>
650 {
651 public:
652  typedef std::tr1::shared_ptr<ServerChannelProcessRequesterImpl> shared_pointer;
653  typedef std::tr1::shared_ptr<const ServerChannelProcessRequesterImpl> const_shared_pointer;
654 protected:
655  ServerChannelProcessRequesterImpl(ServerContextImpl::shared_pointer const & context,
656  std::tr1::shared_ptr<ServerChannel> const & channel, const pvAccessID ioid,
657  Transport::shared_pointer const & transport);
658  void activate(epics::pvData::PVStructure::shared_pointer const & pvRequest);
659 public:
660  static ChannelProcessRequester::shared_pointer create(ServerContextImpl::shared_pointer const & context,
661  std::tr1::shared_ptr<ServerChannel> const & channel, const pvAccessID ioid,
662  Transport::shared_pointer const & transport, epics::pvData::PVStructure::shared_pointer const & pvRequest);
663  virtual ~ServerChannelProcessRequesterImpl() {}
664 
665  virtual void channelProcessConnect(const epics::pvData::Status& status, ChannelProcess::shared_pointer const & channelProcess) OVERRIDE FINAL;
666  virtual void processDone(const epics::pvData::Status& status, ChannelProcess::shared_pointer const & channelProcess) OVERRIDE FINAL;
667  virtual void destroy() OVERRIDE FINAL;
668 
669  ChannelProcess::shared_pointer getChannelProcess();
670  virtual std::tr1::shared_ptr<ChannelRequest> getOperation() OVERRIDE FINAL { return getChannelProcess(); }
671 
672  virtual void send(epics::pvData::ByteBuffer* buffer, TransportSendControl* control) OVERRIDE FINAL;
673 
674 private:
675  // Note: this forms a reference loop, which is broken in destroy()
676  ChannelProcess::shared_pointer _channelProcess;
677  epics::pvData::Status _status;
678 };
679 
680 /****************************************************************************************/
684 class ServerGetFieldHandler : public AbstractServerResponseHandler
685 {
686 public:
687  ServerGetFieldHandler(ServerContextImpl::shared_pointer const & context) :
688  AbstractServerResponseHandler(context, "Get field request") {
689  }
690  virtual ~ServerGetFieldHandler() {}
691 
692  virtual void handleResponse(osiSockAddr* responseFrom,
693  Transport::shared_pointer const & transport, epics::pvData::int8 version, epics::pvData::int8 command,
694  std::size_t payloadSize, epics::pvData::ByteBuffer* payloadBuffer) OVERRIDE FINAL;
695 private:
696  void getFieldFailureResponse(Transport::shared_pointer const & transport, const pvAccessID ioid, const epics::pvData::Status& errorStatus);
697 };
698 
699 class ServerGetFieldRequesterImpl :
700  public BaseChannelRequester,
701  public GetFieldRequester,
702  public std::tr1::enable_shared_from_this<ServerGetFieldRequesterImpl>
703 {
704 public:
705  typedef std::tr1::shared_ptr<ServerGetFieldRequesterImpl> shared_pointer;
706  typedef std::tr1::shared_ptr<const ServerGetFieldRequesterImpl> const_shared_pointer;
707 
708  ServerGetFieldRequesterImpl(ServerContextImpl::shared_pointer const & context,
709  std::tr1::shared_ptr<ServerChannel> const & channel, const pvAccessID ioid,
710  Transport::shared_pointer const & transport);
711 
712  virtual std::tr1::shared_ptr<ChannelRequest> getOperation() OVERRIDE FINAL { return std::tr1::shared_ptr<ChannelRequest>(); }
713 
714  virtual ~ServerGetFieldRequesterImpl() {}
715  virtual void getDone(const epics::pvData::Status& status, epics::pvData::FieldConstPtr const & field) OVERRIDE FINAL;
716  virtual void destroy() OVERRIDE FINAL;
717  virtual void send(epics::pvData::ByteBuffer* buffer, TransportSendControl* control) OVERRIDE FINAL;
718 private:
719  bool done;
720  epics::pvData::Status _status;
721  epics::pvData::FieldConstPtr _field;
722 };
723 
724 class ServerGetFieldHandlerTransportSender : public TransportSender
725 {
726 public:
727  ServerGetFieldHandlerTransportSender(const pvAccessID ioid,const epics::pvData::Status& status, Transport::shared_pointer const & /*transport*/):
728  _ioid(ioid), _status(status) {
729 
730  }
731  virtual ~ServerGetFieldHandlerTransportSender() {}
732 
733  virtual void send(epics::pvData::ByteBuffer* buffer, TransportSendControl* control) OVERRIDE FINAL {
734  control->startMessage((epics::pvData::int8)CMD_GET_FIELD, sizeof(epics::pvData::int32)/sizeof(epics::pvData::int8));
735  buffer->putInt(_ioid);
736  _status.serialize(buffer, control);
737  }
738 
739 private:
740  const pvAccessID _ioid;
741  const epics::pvData::Status _status;
742 };
743 
744 
745 
746 /****************************************************************************************/
750 class ServerRPCHandler : public AbstractServerResponseHandler
751 {
752 public:
753  ServerRPCHandler(ServerContextImpl::shared_pointer const & context) :
754  AbstractServerResponseHandler(context, "RPC request") {
755  }
756  virtual ~ServerRPCHandler() {}
757 
758  virtual void handleResponse(osiSockAddr* responseFrom,
759  Transport::shared_pointer const & transport, epics::pvData::int8 version, epics::pvData::int8 command,
760  std::size_t payloadSize, epics::pvData::ByteBuffer* payloadBuffer) OVERRIDE FINAL;
761 };
762 
763 class ServerChannelRPCRequesterImpl :
764  public BaseChannelRequester,
765  public ChannelRPCRequester,
766  public std::tr1::enable_shared_from_this<ServerChannelRPCRequesterImpl>
767 {
768 public:
769  typedef std::tr1::shared_ptr<ServerChannelRPCRequesterImpl> shared_pointer;
770  typedef std::tr1::shared_ptr<const ServerChannelRPCRequesterImpl> const_shared_pointer;
771 protected:
772  ServerChannelRPCRequesterImpl(ServerContextImpl::shared_pointer const & context,
773  std::tr1::shared_ptr<ServerChannel> const & channel, const pvAccessID ioid,
774  Transport::shared_pointer const & transport);
775  void activate(epics::pvData::PVStructure::shared_pointer const & pvRequest);
776 public:
777  static ChannelRPCRequester::shared_pointer create(ServerContextImpl::shared_pointer const & context,
778  std::tr1::shared_ptr<ServerChannel> const & channel, const pvAccessID ioid,
779  Transport::shared_pointer const & transport,epics::pvData::PVStructure::shared_pointer const & pvRequest);
780  virtual ~ServerChannelRPCRequesterImpl() {}
781 
782  virtual void channelRPCConnect(const epics::pvData::Status& status, ChannelRPC::shared_pointer const & channelRPC) OVERRIDE FINAL;
783  virtual void requestDone(const epics::pvData::Status& status,
784  ChannelRPC::shared_pointer const & channelRPC,
785  epics::pvData::PVStructure::shared_pointer const & pvResponse) OVERRIDE FINAL;
786  virtual void destroy() OVERRIDE FINAL;
790  ChannelRPC::shared_pointer getChannelRPC();
791  virtual std::tr1::shared_ptr<ChannelRequest> getOperation() OVERRIDE FINAL { return getChannelRPC(); }
792 
793  virtual void send(epics::pvData::ByteBuffer* buffer, TransportSendControl* control) OVERRIDE FINAL;
794 private:
795  // Note: this forms a reference loop, which is broken in destroy()
796  ChannelRPC::shared_pointer _channelRPC;
797  epics::pvData::PVStructure::shared_pointer _pvResponse;
798  epics::pvData::Status _status;
799 };
800 
801 
806 public:
807  ServerResponseHandler(ServerContextImpl::shared_pointer const & context);
808 
809  virtual ~ServerResponseHandler() {}
810 
811  virtual void handleResponse(osiSockAddr* responseFrom,
812  Transport::shared_pointer const & transport, epics::pvData::int8 version, epics::pvData::int8 command,
813  std::size_t payloadSize, epics::pvData::ByteBuffer* payloadBuffer) OVERRIDE FINAL;
814 private:
815  ServerBadResponse handle_bad;
816 
817  ServerNoopResponse handle_beacon;
818  ServerConnectionValidationHandler handle_validation;
819  ServerEchoHandler handle_echo;
820  ServerSearchHandler handle_search;
821  AuthNZHandler handle_authnz;
822  ServerCreateChannelHandler handle_create;
823  ServerDestroyChannelHandler handle_destroy;
824  ServerGetHandler handle_get;
825  ServerPutHandler handle_put;
826  ServerPutGetHandler handle_putget;
827  ServerMonitorHandler handle_monitor;
828  ServerArrayHandler handle_array;
829  ServerDestroyRequestHandler handle_close;
830  ServerProcessHandler handle_process;
831  ServerGetFieldHandler handle_getfield;
832  ServerRPCHandler handle_rpc;
833  ServerCancelRequestHandler handle_cancel;
837  std::vector<ResponseHandler*> m_handlerTable;
838 
839 };
840 
841 }
842 }
843 
844 #endif /* RESPONSEHANDLERS_H_ */
Requester for ChannelPut.
Definition: pvAccess.h:635
ConnectionState
Channel connection status.
Definition: pvAccess.h:906
Connection validation message handler.
virtual void handleResponse(osiSockAddr *responseFrom, Transport::shared_pointer const &transport, epics::pvData::int8 version, epics::pvData::int8 command, std::size_t payloadSize, epics::pvData::ByteBuffer *payloadBuffer)
Handle response.
Requester for ChannelPutGet.
Definition: pvAccess.h:718
Interface defining response handler.
Definition: remote.h:313
constexpr __tuple_element_t< __i, tuple< _Elements... > > & get(tuple< _Elements... > &__t) noexcept
Requester for channelProcess.
Definition: pvAccess.h:569
virtual void handleResponse(osiSockAddr *responseFrom, Transport::shared_pointer const &transport, epics::pvData::int8 version, epics::pvData::int8 command, std::size_t payloadSize, epics::pvData::ByteBuffer *payloadBuffer)
Handle response.
Callback implemented by monitor clients.
Definition: pvAccess.h:249
virtual void handleResponse(osiSockAddr *responseFrom, Transport::shared_pointer const &transport, epics::pvData::int8 version, epics::pvData::int8 command, std::size_t payloadSize, epics::pvData::ByteBuffer *payloadBuffer)
Handle response.
Completion notification for Channel::getField()
Definition: pvAccess.h:853
Destroy channel request handler.
virtual void handleResponse(osiSockAddr *responseFrom, Transport::shared_pointer const &transport, epics::pvData::int8 version, epics::pvData::int8 command, std::size_t payloadSize, epics::pvData::ByteBuffer *payloadBuffer)
Handle response.
Interface defining transport sender (instance sending data over transport).
Definition: remote.h:139
Requester for channelGet.
Definition: pvAccess.h:511
Search channel request handler.
PVAS request handler - main handler which dispatches requests to appropriate handlers.
The Requester for a ChannelArray.
Definition: pvAccess.h:332
Notifications associated with Channel::createChannelRPC()
Definition: pvAccess.h:813
Create channel request handler.