Remote Call Framework 3.0
ClientTransport.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2018, Delta V Software. All rights reserved.
6 // http://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF
12 // under GPL terms.
13 //
14 // Version: 3.0
15 // Contact: support <at> deltavsoft.com
16 //
17 //******************************************************************************
18 
19 #ifndef INCLUDE_RCF_CLIENTTRANSPORT_HPP
20 #define INCLUDE_RCF_CLIENTTRANSPORT_HPP
21 
22 #include <cstdint>
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 #include <RCF/AsioFwd.hpp>
28 #include <RCF/Export.hpp>
29 #include <RCF/RcfFwd.hpp>
30 
31 namespace RCF {
32 
33  class RcfServer;
34 
35  class OverlappedAmi;
36  typedef std::shared_ptr<OverlappedAmi> OverlappedAmiPtr;
37 
38  class ClientStub;
39  class RcfSession;
40  typedef std::weak_ptr<RcfSession> RcfSessionWeakPtr;
41 
42  class ByteBuffer;
43 
44  class Filter;
45  typedef std::shared_ptr<Filter> FilterPtr;
46 
47  class ClientProgress;
48  typedef std::shared_ptr<ClientProgress> ClientProgressPtr;
49 
50  class RCF_EXPORT ClientTransportCallback
51  {
52  public:
53  ClientTransportCallback() : mpAsyncDispatcher() {}
54  virtual ~ClientTransportCallback() {}
55  virtual void onConnectCompleted(bool alreadyConnected = false) = 0;
56  virtual void onSendCompleted() = 0;
57  virtual void onReceiveCompleted() = 0;
58  virtual void onTimerExpired() = 0;
59  virtual void onError(const std::exception &e) = 0;
60 
61  void setAsyncDispatcher(RcfServer & server);
62  RcfServer * getAsyncDispatcher();
63 
64  virtual bool isClientStub() const { return false; }
65 
66  private:
67  RcfServer * mpAsyncDispatcher;
68  };
69 
70  class ClientStub;
71 
72  enum TransportType;
73 
75  class RCF_EXPORT ClientTransport
76  {
77  public:
79  ClientTransport(const ClientTransport & rhs);
80 
81  virtual ~ClientTransport()
82  {}
83 
84  // *** SWIG BEGIN ***
85 
87  virtual TransportType getTransportType() = 0;
88 
91  void setMaxIncomingMessageLength(std::size_t maxMessageLength);
92 
94  std::size_t getMaxIncomingMessageLength() const;
95 
97  std::size_t getLastRequestSize();
98 
100  std::size_t getLastResponseSize();
101 
103  std::uint64_t getRunningTotalBytesSent();
104 
106  std::uint64_t getRunningTotalBytesReceived();
107 
109  void resetRunningTotals();
110 
111  // *** SWIG END ***
112 
113  void setClientProgressPtr(ClientProgressPtr clientProgressPtr);
114 
115  virtual
116  std::unique_ptr<ClientTransport> clone() const = 0;
117 
118  virtual
119  EndpointPtr getEndpointPtr() const = 0;
120 
121  virtual
122  int send(
123  ClientTransportCallback & clientStub,
124  const std::vector<ByteBuffer> & data,
125  unsigned int timeoutMs) = 0;
126 
127  virtual
128  int receive(
129  ClientTransportCallback & clientStub,
130  ByteBuffer & byteBuffer,
131  unsigned int timeoutMs) = 0;
132 
133  virtual
134  bool isConnected() = 0;
135 
136  virtual
137  void connect(
138  ClientTransportCallback & clientStub,
139  unsigned int timeoutMs) = 0;
140 
141  virtual
142  void disconnect(
143  unsigned int timeoutMs = 0) = 0;
144 
145  virtual
146  void setTransportFilters(
147  const std::vector<FilterPtr> & filters) = 0;
148 
149  virtual
150  void getTransportFilters(
151  std::vector<FilterPtr> & filters) = 0;
152 
153  virtual
154  void getWireFilters(
155  std::vector<FilterPtr> & filters);
156 
157  RcfSessionWeakPtr getRcfSession();
158  void setRcfSession(RcfSessionWeakPtr rcfSessionWeakPtr);
159 
160  void setAsync(bool async);
161 
162  virtual void cancel();
163 
164  virtual void setTimer(
165  std::uint32_t timeoutMs,
166  ClientTransportCallback * pClientStub = NULL) = 0;
167 
168  virtual void associateWithIoService(AsioIoService & ioService);
169  virtual bool isAssociatedWithIoService();
170 
171  virtual bool supportsTransportFilters()
172  {
173  return true;
174  }
175 
176  private:
177  std::size_t mMaxMessageLength;
178  RcfSessionWeakPtr mRcfSessionWeakPtr;
179 
180  protected:
181  std::size_t mLastRequestSize;
182  std::size_t mLastResponseSize;
183 
184  std::uint64_t mRunningTotalBytesSent;
185  std::uint64_t mRunningTotalBytesReceived;
186 
187  ClientProgressPtr mClientProgressPtr;
188 
189  bool mAsync;
190 
191  friend class ClientStub;
192  };
193 
194 
195 } // namespace RCF
196 
197 #endif // ! INCLUDE_RCF_CLIENTTRANSPORT_HPP
Controls the client side of a RCF connection.
Definition: ClientStub.hpp:69
std::shared_ptr< Endpoint > EndpointPtr
Reference counted wrapper for RCF::Endpoint.
Definition: RcfFwd.hpp:117
Base class for all client transports.
Definition: ClientTransport.hpp:75
Definition: ByteBuffer.hpp:40
Definition: AmiIoHandler.hpp:24
TransportType
Describes the transport types used by a RCF connection.
Definition: Enums.hpp:34