RCFProto
 All Classes Functions Typedefs
ClientTransport.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2013, 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: 2.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 <memory>
23 #include <string>
24 #include <vector>
25 
26 #include <boost/cstdint.hpp>
27 #include <boost/weak_ptr.hpp>
28 
29 #include <RCF/AsioFwd.hpp>
30 #include <RCF/Enums.hpp>
31 #include <RCF/Filter.hpp>
32 #include <RCF/ByteBuffer.hpp>
33 #include <RCF/Export.hpp>
34 
35 namespace RCF {
36 
37  class Endpoint;
38  typedef boost::shared_ptr<Endpoint> EndpointPtr;
39 
40  class RcfServer;
41 
42  class OverlappedAmi;
43  typedef boost::shared_ptr<OverlappedAmi> OverlappedAmiPtr;
44 
45  class ClientStub;
46  class RcfSession;
47  typedef boost::weak_ptr<RcfSession> RcfSessionWeakPtr;
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 
72  class RCF_EXPORT ClientTransport
73  {
74  public:
76  ClientTransport(const ClientTransport & rhs);
77 
78  virtual ~ClientTransport()
79  {}
80 
81  // *** SWIG BEGIN ***
82 
84  virtual TransportType getTransportType() = 0;
85 
88  void setMaxIncomingMessageLength(std::size_t maxMessageLength);
89 
91  std::size_t getMaxIncomingMessageLength() const;
92 
94  std::size_t getLastRequestSize();
95 
97  std::size_t getLastResponseSize();
98 
100  boost::uint64_t getRunningTotalBytesSent();
101 
103  boost::uint64_t getRunningTotalBytesReceived();
104 
106  void resetRunningTotals();
107 
108  // *** SWIG END ***
109 
110 
111 
112  virtual
113  std::auto_ptr<ClientTransport> clone() const = 0;
114 
115  virtual
116  EndpointPtr getEndpointPtr() const = 0;
117 
118  virtual
119  int send(
120  ClientTransportCallback & clientStub,
121  const std::vector<ByteBuffer> & data,
122  unsigned int timeoutMs) = 0;
123 
124  virtual
125  int receive(
126  ClientTransportCallback & clientStub,
127  ByteBuffer & byteBuffer,
128  unsigned int timeoutMs) = 0;
129 
130  virtual
131  bool isConnected() = 0;
132 
133  virtual
134  void connect(
135  ClientTransportCallback & clientStub,
136  unsigned int timeoutMs) = 0;
137 
138  virtual
139  void disconnect(
140  unsigned int timeoutMs = 0) = 0;
141 
142  virtual
143  void setTransportFilters(
144  const std::vector<FilterPtr> & filters) = 0;
145 
146  virtual
147  void getTransportFilters(
148  std::vector<FilterPtr> & filters) = 0;
149 
150  // Deprecated - use setMaxIncomingMessageLength()/getMaxIncomingMessageLength() instead.
151  void setMaxMessageLength(std::size_t maxMessageLength);
152  std::size_t getMaxMessageLength() const;
153 
154 
155  RcfSessionWeakPtr getRcfSession();
156  void setRcfSession(RcfSessionWeakPtr rcfSessionWeakPtr);
157 
158 
159  void setAsync(bool async);
160 
161  virtual void cancel();
162 
163  virtual void setTimer(
164  boost::uint32_t timeoutMs,
165  ClientTransportCallback * pClientStub = NULL) = 0;
166 
167  virtual void associateWithIoService(AsioIoService & ioService);
168  virtual bool isAssociatedWithIoService();
169 
170  virtual bool supportsTransportFilters()
171  {
172  return true;
173  }
174 
175  private:
176  std::size_t mMaxMessageLength;
177  RcfSessionWeakPtr mRcfSessionWeakPtr;
178 
179  protected:
180  std::size_t mLastRequestSize;
181  std::size_t mLastResponseSize;
182 
183  boost::uint64_t mRunningTotalBytesSent;
184  boost::uint64_t mRunningTotalBytesReceived;
185 
186  bool mAsync;
187 
188  friend class ClientStub;
189  };
190 
191  typedef boost::shared_ptr<ClientTransport> ClientTransportPtr;
192 
193  typedef std::auto_ptr<ClientTransport> ClientTransportAutoPtr;
194 
195  typedef boost::shared_ptr< ClientTransportAutoPtr > ClientTransportAutoPtrPtr;
196 
197 } // namespace RCF
198 
199 #endif // ! INCLUDE_RCF_CLIENTTRANSPORT_HPP