RCFProto

- Main Page
- Classes
- Files

- File List

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 private:
64 RcfServer * mpAsyncDispatcher;
65 };
66
67 class ClientStub;
68
70 class RCF_EXPORT ClientTransport
71 {
72 public:
73 ClientTransport();
74 ClientTransport(const ClientTransport & rhs);
75
76 virtual ~ClientTransport()
77 {}
78
79 // *** SWIG BEGIN ***
80
82 virtual TransportType getTransportType() = 0;
83
86 void setMaxIncomingMessageLength(std::size_t maxMessageLength);
87
89 std::size_t getMaxIncomingMessageLength() const;
90
92 std::size_t getLastRequestSize();
93
95 std::size_t getLastResponseSize();
96
98 boost::uint64_t getRunningTotalBytesSent();
99
101 boost::uint64_t getRunningTotalBytesReceived();
102
104 void resetRunningTotals();
105
106 // *** SWIG END ***
107
108
109
110 virtual
111 std::auto_ptr<ClientTransport> clone() const = 0;
112
113 virtual
114 EndpointPtr getEndpointPtr() const = 0;
115
116 virtual
117 int send(
118 ClientTransportCallback & clientStub,
119 const std::vector<ByteBuffer> & data,
120 unsigned int timeoutMs) = 0;
121
122 virtual
123 int receive(
124 ClientTransportCallback & clientStub,
125 ByteBuffer & byteBuffer,
126 unsigned int timeoutMs) = 0;
127
128 virtual
129 bool isConnected() = 0;
130
131 virtual
132 void connect(
133 ClientTransportCallback & clientStub,
134 unsigned int timeoutMs) = 0;
135
136 virtual
137 void disconnect(
138 unsigned int timeoutMs = 0) = 0;
139
140 virtual
141 void setTransportFilters(
142 const std::vector<FilterPtr> & filters) = 0;
143
144 virtual
145 void getTransportFilters(
146 std::vector<FilterPtr> & filters) = 0;
147
148 // Deprecated - use setMaxIncomingMessageLength()/getMaxIncomingMessageLength() instead.
149 void setMaxMessageLength(std::size_t maxMessageLength);
150 std::size_t getMaxMessageLength() const;
151
152
153 RcfSessionWeakPtr getRcfSession();
154 void setRcfSession(RcfSessionWeakPtr rcfSessionWeakPtr);
155
156
157 void setAsync(bool async);
158
159 virtual void cancel();
160
161 virtual void setTimer(
162 boost::uint32_t timeoutMs,
163 ClientTransportCallback * pClientStub = NULL) = 0;
164
165 virtual void associateWithIoService(AsioIoService & ioService);
166 virtual bool isAssociatedWithIoService();
167
168 virtual bool isInProcess();
169 virtual void doInProcessCall(ClientStub & clientStub);
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 boost::uint64_t mRunningTotalBytesSent;
185 boost::uint64_t mRunningTotalBytesReceived;
186
187 bool mAsync;
188
189 friend class ClientStub;
190 };
191
192 typedef boost::shared_ptr<ClientTransport> ClientTransportPtr;
193
194 typedef std::auto_ptr<ClientTransport> ClientTransportAutoPtr;
195
196 typedef boost::shared_ptr< ClientTransportAutoPtr > ClientTransportAutoPtrPtr;
197
198 } // namespace RCF
199
200 #endif // ! INCLUDE_RCF_CLIENTTRANSPORT_HPP