pvAccessCPP  7.1.7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
remote.h
1 
7 #ifndef REMOTE_H_
8 #define REMOTE_H_
9 
10 #ifdef epicsExportSharedSymbols
11 # define remoteEpicsExportSharedSymbols
12 # undef epicsExportSharedSymbols
13 #endif
14 
15 #include <map>
16 #include <string>
17 
18 #include <osiSock.h>
19 
20 #include <pv/serialize.h>
21 #include <pv/pvType.h>
22 #include <pv/byteBuffer.h>
23 #include <pv/timer.h>
24 #include <pv/pvData.h>
25 #include <pv/sharedPtr.h>
26 
27 #ifdef remoteEpicsExportSharedSymbols
28 # define epicsExportSharedSymbols
29 # undef remoteEpicsExportSharedSymbols
30 #endif
31 
32 #include <pv/pvaConstants.h>
33 #include <pv/configuration.h>
34 #include <pv/fairQueue.h>
35 #include <pv/pvaDefs.h>
36 
38 #include <pv/pvAccess.h>
39 
40 namespace epics {
41 namespace pvAccess {
42 
43 class TransportRegistry;
44 class ClientChannelImpl;
45 
46 enum QoS {
50  QOS_DEFAULT = 0x00,
62  QOS_PROCESS = 0x04,
66  QOS_INIT = 0x08,
70  QOS_DESTROY = 0x10,
74  QOS_SHARE = 0x20,
78  QOS_GET = 0x40,
82  QOS_GET_PUT = 0x80
83 };
84 
85 enum ApplicationCommands {
86  CMD_BEACON = 0,
87  CMD_CONNECTION_VALIDATION = 1,
88  CMD_ECHO = 2,
89  CMD_SEARCH = 3,
90  CMD_SEARCH_RESPONSE = 4,
91  CMD_AUTHNZ = 5,
92  CMD_ACL_CHANGE = 6,
93  CMD_CREATE_CHANNEL = 7,
94  CMD_DESTROY_CHANNEL = 8,
95  CMD_CONNECTION_VALIDATED = 9,
96  CMD_GET = 10,
97  CMD_PUT = 11,
98  CMD_PUT_GET = 12,
99  CMD_MONITOR = 13,
100  CMD_ARRAY = 14,
101  CMD_DESTROY_REQUEST = 15,
102  CMD_PROCESS = 16,
103  CMD_GET_FIELD = 17,
104  CMD_MESSAGE = 18,
105  CMD_MULTIPLE_DATA = 19,
106  CMD_RPC = 20,
107  CMD_CANCEL_REQUEST = 21,
108  CMD_ORIGIN_TAG = 22
109 };
110 
111 enum ControlCommands {
112  CMD_SET_MARKER = 0,
113  CMD_ACK_MARKER = 1,
114  CMD_SET_ENDIANESS = 2
115 };
116 
117 void hackAroundRTEMSSocketInterrupt();
118 
122 class TransportSendControl : public epics::pvData::SerializableControl {
123 public:
124  POINTER_DEFINITIONS(TransportSendControl);
125 
126  virtual ~TransportSendControl() {}
127 
128  virtual void startMessage(epics::pvData::int8 command, std::size_t ensureCapacity, epics::pvData::int32 payloadSize = 0) = 0;
129  virtual void endMessage() = 0;
130 
131  virtual void flush(bool lastMessageCompleted) = 0;
132 
133  virtual void setRecipient(osiSockAddr const & sendTo) = 0;
134 };
135 
139 class TransportSender : public Lockable, public fair_queue<TransportSender>::entry {
140 public:
141  POINTER_DEFINITIONS(TransportSender);
142 
143  TransportSender() :bytesTX(0u), bytesRX(0u) {}
144  virtual ~TransportSender() {}
145 
154  virtual void send(epics::pvData::ByteBuffer* buffer, TransportSendControl* control) = 0;
155 
156  size_t bytesTX;
157  size_t bytesRX;
158 };
159 
160 class ClientChannelImpl;
161 class SecuritySession;
162 
166 class epicsShareClass Transport : public epics::pvData::DeserializableControl {
167 public:
168  POINTER_DEFINITIONS(Transport);
169 
170  static size_t num_instances;
171 
172  Transport();
173  virtual ~Transport();
174 
180  virtual bool acquire(std::tr1::shared_ptr<ClientChannelImpl> const & client) = 0;
181 
186  virtual void release(pvAccessID clientId) = 0;
187 
192  virtual std::string getType() const = 0;
193 
194  virtual const osiSockAddr& getRemoteAddress() const = 0;
195 
196  virtual const std::string& getRemoteName() const = 0;
197 
198  // TODO getContext?
199 
204  virtual std::size_t getReceiveBufferSize() const = 0;
205 
210  virtual epics::pvData::int16 getPriority() const = 0;
211 
216  virtual void setRemoteTransportReceiveBufferSize(std::size_t receiveBufferSize) = 0;
217 
222  virtual void setRemoteTransportSocketReceiveBufferSize(std::size_t socketReceiveBufferSize) = 0;
223 
228  // TODO enum
229  virtual void setByteOrder(int byteOrder) = 0;
230 
235  virtual void enqueueSendRequest(TransportSender::shared_pointer const & sender) = 0;
236 
240  virtual void flushSendQueue() = 0;
241 
246  virtual void verified(epics::pvData::Status const & status) = 0;
247 
252  virtual bool verify(epics::pvData::int32 timeoutMs) = 0;
253 
257  virtual void close() = 0;
258 
260  virtual void waitJoin() {}
261 
266  virtual bool isClosed() = 0;
267 
272  virtual void authNZMessage(epics::pvData::PVStructure::shared_pointer const & data) = 0;
273 
274  size_t _totalBytesSent;
275  size_t _totalBytesRecv;
276 };
277 
278 class Channel;
279 class SecurityPlugin;
280 class AuthenticationRegistry;
281 
285 class Context {
286 public:
287  POINTER_DEFINITIONS(Context);
288 
289  virtual ~Context() {}
290 
291  virtual epics::pvData::Timer::shared_pointer getTimer() = 0;
292 
293  virtual TransportRegistry* getTransportRegistry() = 0;
294 
295 
296 
297 
298  virtual Configuration::const_shared_pointer getConfiguration() = 0;
299 
303 
304  virtual void newServerDetected() = 0;
305 
306  virtual std::tr1::shared_ptr<Channel> getChannel(pvAccessID id) = 0;
307  virtual Transport::shared_pointer getSearchTransport() = 0;
308 };
309 
314 public:
315  POINTER_DEFINITIONS(ResponseHandler);
316 
317  static size_t num_instances;
318 
319  ResponseHandler(Context* context, const std::string& description);
320  virtual ~ResponseHandler();
321 
332  virtual void
333  handleResponse(osiSockAddr* responseFrom, Transport::shared_pointer const & transport,
334  epics::pvData::int8 version, epics::pvData::int8 command, std::size_t payloadSize,
335  epics::pvData::ByteBuffer* payloadBuffer);
336 
337 protected:
342 
346  epics::pvData::int32 _debugLevel;
347 };
348 
354 public:
355  POINTER_DEFINITIONS(ResponseRequest);
356 
357  virtual ~ResponseRequest() {}
358 
363  virtual pvAccessID getIOID() const = 0;
364 
368  virtual void timeout() = 0;
369 
373  virtual void cancel() = 0;
374 
379  virtual void reportStatus(Channel::ConnectionState status) = 0;
380 
386  virtual std::tr1::shared_ptr<ChannelBaseRequester> getRequester() = 0;
387 
394  virtual void response(Transport::shared_pointer const & transport, epics::pvData::int8 version, epics::pvData::ByteBuffer* payloadBuffer) = 0;
395 
396 };
397 
398 
399 }
400 }
401 
402 #endif /* REMOTE_H_ */
virtual pvAccessID getIOID() const =0
Get I/O ID.
virtual void timeout()=0
Timeout notification.
ConnectionState
Channel connection status.
Definition: pvAccess.h:906
Interface defining transport (connection).
Definition: remote.h:166
Not public IF, used by Transports, etc.
Definition: remote.h:285
Interface defining transport send control.
Definition: remote.h:122
Process option.
Definition: remote.h:62
Interface defining response handler.
Definition: remote.h:313
Require reply (acknowledgment for reliable operation).
Definition: remote.h:54
std::string _description
Response hanlder description.
Definition: remote.h:341
Destroy option.
Definition: remote.h:70
virtual std::tr1::shared_ptr< ChannelBaseRequester > getRequester()=0
used by MessageHandler and reportChannelStateChange().
Best-effort option (no reply).
Definition: remote.h:58
Initialize option.
Definition: remote.h:66
epics::pvData::int32 _debugLevel
Debug flag.
Definition: remote.h:346
virtual void send(epics::pvData::ByteBuffer *buffer, TransportSendControl *control)=0
Called by transport.
Default behavior.
Definition: remote.h:50
virtual void response(Transport::shared_pointer const &transport, epics::pvData::int8 version, epics::pvData::ByteBuffer *payloadBuffer)=0
Notification response.
virtual void waitJoin()
Call after close() to wait for any worker threads to exit.
Definition: remote.h:260
virtual void newServerDetected()=0
due to ClientContextImpl
Interface defining transport sender (instance sending data over transport).
Definition: remote.h:139
Share data option.
Definition: remote.h:74
virtual void cancel()=0
Cancel response request (always to be called to complete/destroy).
A request that expects an response.
Definition: remote.h:353
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.
virtual void reportStatus(Channel::ConnectionState status)=0
Report status to clients (e.g.