Remote Call Framework 3.2
ClientTransport.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2020, 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.2
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 
98  void setMaxOutgoingMessageLength(std::size_t maxMessageLength);
99 
101  std::size_t getMaxOutgoingMessageLength() const;
102 
104  std::size_t getLastRequestSize();
105 
107  std::size_t getLastResponseSize();
108 
110  std::uint64_t getRunningTotalBytesSent();
111 
113  std::uint64_t getRunningTotalBytesReceived();
114 
116  void resetRunningTotals();
117 
118  // *** SWIG END ***
119 
120  void setClientProgressPtr(ClientProgressPtr clientProgressPtr);
121 
122  virtual
123  std::unique_ptr<ClientTransport> clone() const = 0;
124 
125  virtual
126  EndpointPtr getEndpointPtr() const = 0;
127 
128  virtual
129  int send(
130  ClientTransportCallback & clientStub,
131  const std::vector<ByteBuffer> & data,
132  unsigned int timeoutMs) = 0;
133 
134  virtual
135  int receive(
136  ClientTransportCallback & clientStub,
137  ByteBuffer & byteBuffer,
138  unsigned int timeoutMs) = 0;
139 
140  virtual
141  bool isConnected() = 0;
142 
143  virtual
144  void connect(
145  ClientTransportCallback & clientStub,
146  unsigned int timeoutMs) = 0;
147 
148  virtual
149  void disconnect(
150  unsigned int timeoutMs = 0) = 0;
151 
152  virtual
153  void setTransportFilters(
154  const std::vector<FilterPtr> & filters) = 0;
155 
156  virtual
157  void getTransportFilters(
158  std::vector<FilterPtr> & filters) = 0;
159 
160  virtual
161  void getWireFilters(
162  std::vector<FilterPtr> & filters);
163 
164  RcfSessionWeakPtr getRcfSession();
165  void setRcfSession(RcfSessionWeakPtr rcfSessionWeakPtr);
166 
167  void setAsync(bool async);
168 
169  virtual void cancel();
170 
171  virtual void setTimer(
172  std::uint32_t timeoutMs,
173  ClientTransportCallback * pClientStub = NULL) = 0;
174 
175  virtual void associateWithIoService(AsioIoService & ioService);
176  virtual bool isAssociatedWithIoService();
177 
178  virtual bool supportsTransportFilters();
179 
180  virtual void getProgressInfo(RemoteCallProgressInfo & info);
181 
182  private:
183  std::size_t mMaxMessageLength;
184  std::size_t mMaxOutgoingMessageLength;
185  RcfSessionWeakPtr mRcfSessionWeakPtr;
186 
187  protected:
188  std::size_t mLastRequestSize;
189  std::size_t mLastResponseSize;
190 
191  std::uint64_t mRunningTotalBytesSent;
192  std::uint64_t mRunningTotalBytesReceived;
193 
194  ClientProgressPtr mClientProgressPtr;
195 
196  bool mAsync;
197 
198  friend class ClientStub;
199  };
200 
201 
202 } // namespace RCF
203 
204 #endif // ! INCLUDE_RCF_CLIENTTRANSPORT_HPP
Describes the status of a remote call while in progress. See RCF::ClientStub::setRemoteCallProgressCa...
Definition: ClientProgress.hpp:32
Controls the client side of a RCF connection.
Definition: ClientStub.hpp:83
std::shared_ptr< Endpoint > EndpointPtr
Reference counted wrapper for RCF::Endpoint.
Definition: RcfFwd.hpp:118
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