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