|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifndef __ACTIVESOCKET_H__ |
|
17 #define __ACTIVESOCKET_H__ |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <wapmessage.h> |
|
21 #include "WapSwsTimeOut.h" |
|
22 |
|
23 |
|
24 class CActiveSocketSMS; |
|
25 class CActiveSocketUDP; |
|
26 class MProgressNotify; |
|
27 |
|
28 enum TWapMessageState |
|
29 { |
|
30 /** |
|
31 The state that is no outstanding request. |
|
32 */ |
|
33 EIdle, |
|
34 /** |
|
35 The state that the messaging API client is requesting data length |
|
36 */ |
|
37 ERequestingLength, |
|
38 /** |
|
39 The state the the messaging API client is requesting data |
|
40 */ |
|
41 ERequestingData, |
|
42 /** |
|
43 The state that the data size is ready to be read |
|
44 */ |
|
45 EPendingLength, |
|
46 /** |
|
47 The state that the messaging API client got the data length |
|
48 */ |
|
49 EGotLength, |
|
50 /** |
|
51 The state that the received data is ready to be read |
|
52 */ |
|
53 EPendingData, |
|
54 /** |
|
55 The state the data is being reading, but not finished |
|
56 */ |
|
57 EReading, |
|
58 /** |
|
59 The state that there are more data to be received from ESock (PRT 1.5) |
|
60 */ |
|
61 EContinuous |
|
62 }; |
|
63 enum TWapMessageType |
|
64 { |
|
65 /** |
|
66 Wsp message |
|
67 */ |
|
68 EWapWsp, |
|
69 /** |
|
70 Wdp message |
|
71 */ |
|
72 EWapWdp |
|
73 }; |
|
74 enum TWapActiveSocketState |
|
75 { |
|
76 /** |
|
77 No outstanding request state |
|
78 */ |
|
79 ESocketIdle, |
|
80 /** |
|
81 Waiting for the PDU length state |
|
82 */ |
|
83 ESocketWaitingForLength, |
|
84 /** |
|
85 Waiting for the PDU data state |
|
86 */ |
|
87 ESocketWaitingForData |
|
88 }; |
|
89 enum TWapNotificationEvent |
|
90 { |
|
91 /** |
|
92 The event that PDU length is ready. |
|
93 */ |
|
94 EPduLengthReceived, |
|
95 /** |
|
96 The event thst PDU us ready |
|
97 */ |
|
98 EPduReceived |
|
99 }; |
|
100 |
|
101 class TWapNotificationInfo |
|
102 { |
|
103 public: |
|
104 inline TWapNotificationInfo(Wap::TBearer aBearer, TInt aError); |
|
105 Wap::TBearer iBearer; |
|
106 TInt iError; |
|
107 }; |
|
108 |
|
109 inline TWapNotificationInfo::TWapNotificationInfo(Wap::TBearer aBearer, TInt aError): |
|
110 iBearer(aBearer), iError(aError) |
|
111 { |
|
112 } |
|
113 |
|
114 typedef TPckgBuf<TWapNotificationInfo> TWapNotificationInfoBuf; |
|
115 |
|
116 const TUint KMaxUdpBearerDataBufferLength=1024; |
|
117 |
|
118 class CWapMessageRecord: public CBase |
|
119 /** |
|
120 The Base class to represent the received WSP and WDP PDU |
|
121 @internalComponent |
|
122 @released |
|
123 @since v8.0 |
|
124 */ |
|
125 { |
|
126 public: |
|
127 static CWapMessageRecord* NewL(TWapMessageType aType); |
|
128 virtual ~CWapMessageRecord(); |
|
129 TWapMessageState GetDataState(); |
|
130 void SetDataState(TWapMessageState aStatus); |
|
131 void CreatePduBufferL(TBool aFixLengthFlag); |
|
132 TPckgBuf<TUint32>* GetPduSizeRef(); |
|
133 void SetPduSize(TUint32 aLength); |
|
134 TUint32 GetPduSize(); |
|
135 HBufC8*& GetPduPtr(); |
|
136 /** |
|
137 To read the received Wdp pdu |
|
138 @internalComponent |
|
139 @released |
|
140 @since v8.0 |
|
141 @param aBuffer(out) the buffer to contain the received wdp pdu |
|
142 @param aTruncated(out) the flag to represent if the data is truncated or not |
|
143 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
144 */ |
|
145 virtual TInt GetPduData(TDes8& aBuffer, TBool& aTruncated)=0; |
|
146 /** |
|
147 To unpack the received wdp pdu to wsp message. |
|
148 @internalComponent |
|
149 @released |
|
150 @since v8.0 |
|
151 */ |
|
152 virtual void UnpackPduToWspDataL()=0; |
|
153 /** |
|
154 To read the wsp message from the buffer |
|
155 @internalComponent |
|
156 @released |
|
157 @since v8.0 |
|
158 @param aWspHeader(out) the buffer to contain the wsp header |
|
159 @param aWspBody(out) the buffer to contain the wsp body |
|
160 @param iTransactionId(out) the received transaction ID |
|
161 @param aWspStatus(out) the received wsp status |
|
162 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
163 */ |
|
164 virtual TInt GetWspData(TDes8& aWspHeader, TDes8& aWspBody, TUint8& aTransactionId, TWSPStatus& aWspStatus)=0; |
|
165 virtual void CleanUpData(); |
|
166 public: |
|
167 /**The received WDP PDU Data buffer |
|
168 */ |
|
169 HBufC8* iPdu; |
|
170 /**The received WDP PDU length buffer |
|
171 */ |
|
172 TPckgBuf<TUint32> iDataLength; |
|
173 |
|
174 protected: |
|
175 CWapMessageRecord(); |
|
176 /**The state of the received the WSP or WDP data |
|
177 */ |
|
178 TWapMessageState iState; |
|
179 }; |
|
180 |
|
181 class CWspMessageRecord: public CWapMessageRecord |
|
182 /** |
|
183 The class to represent the received WSP PDU |
|
184 @internalComponent |
|
185 @released |
|
186 @since v8.0 |
|
187 */ |
|
188 { |
|
189 public: |
|
190 CWspMessageRecord(); |
|
191 ~CWspMessageRecord(); |
|
192 void UnpackPduToWspDataL(); |
|
193 TInt GetWspData(TDes8& aWspHeader, TDes8& aWspBody, TUint8& aTransactionId, TWSPStatus& aWspStatus); |
|
194 TInt GetPduData(TDes8& aBuffer, TBool& aTruncated); |
|
195 void CleanUpData(); |
|
196 private: |
|
197 /** |
|
198 The buffer for received Wsp header. |
|
199 */ |
|
200 HBufC8* iWspHeader; |
|
201 /** |
|
202 The buffer for received Wsp body. |
|
203 */ |
|
204 HBufC8* iWspBody; |
|
205 /** |
|
206 The received the transaction Id. |
|
207 */ |
|
208 TUint8 iTransactionId; |
|
209 /** |
|
210 The received WSP layer status |
|
211 */ |
|
212 TWSPStatus iWspStatus; |
|
213 /** |
|
214 The offset of the header for next reading |
|
215 */ |
|
216 TInt iHeaderOffset; |
|
217 /** |
|
218 The offset of the body for next reading |
|
219 */ |
|
220 TInt iBodyOffset; |
|
221 }; |
|
222 |
|
223 class CWdpMessageRecord: public CWapMessageRecord |
|
224 /** |
|
225 The class to represent the received WDP PDU |
|
226 @internalComponent |
|
227 @released |
|
228 @since v8.0 |
|
229 */ |
|
230 { |
|
231 public: |
|
232 CWdpMessageRecord(); |
|
233 ~CWdpMessageRecord(); |
|
234 void UnpackPduToWspDataL(); |
|
235 TInt GetWspData(TDes8& aWspHeader, TDes8& aWspBody, TUint8& aTransactionId, TWSPStatus& aWspStatus); |
|
236 TInt GetPduData(TDes8& aBuffer, TBool& aTruncated); |
|
237 void CleanUpData(); |
|
238 private: |
|
239 /** |
|
240 The offset of the pdu for next reading |
|
241 */ |
|
242 TUint32 iPduOffset; |
|
243 }; |
|
244 |
|
245 class CActiveSocket: public CActive |
|
246 /** |
|
247 The base class for the different bearer classes. |
|
248 @internalComponent |
|
249 @released |
|
250 @since v8.0 |
|
251 */ |
|
252 { |
|
253 public: |
|
254 static void NewL(RSocketServ& aSocketServ, RPointerArray<CActiveSocket>& aActiveSockets, Wap::TBearer aBearer, TWapMessageType aType, MProgressNotify* aNotify, Wap::TPort aLocalPort, RConnection* aConnection=NULL); |
|
255 static void NewL(RSocketServ& aSocketServ, RPointerArray<CActiveSocket>& aActiveSockets, Wap::TBearer aBearer, TWapMessageType aType, MProgressNotify* aNotify, const TSockAddr& aRemoteAddr, RConnection* aConnection=NULL); |
|
256 virtual ~CActiveSocket(); |
|
257 virtual void ConstructL(TWapMessageType aType); |
|
258 /** |
|
259 Read the received Wdp pdu length. |
|
260 @internalComponent |
|
261 @released |
|
262 @since v8.0 |
|
263 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
264 */ |
|
265 virtual TInt AwaitRecvDataSize() = 0; |
|
266 /** |
|
267 Read the received Wdp pdu. |
|
268 @internalComponent |
|
269 @released |
|
270 @since v8.0 |
|
271 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
272 */ |
|
273 virtual TInt Receive() = 0; |
|
274 TSockAddr& GetLocalAddress(); |
|
275 TInt GetLocalPort(Wap::TPort& aLocalPort); |
|
276 TInt GetRemoteAddress(HBufC8*& aAddr); |
|
277 TSockAddr& GetRemoteAddress(); |
|
278 |
|
279 TWapMessageState GetDataState(); |
|
280 void SetDataState(TWapMessageState aState); |
|
281 TUint32 GetPduSize(); |
|
282 TInt GetPduData(TDes8& aBuffer, TBool& aTruncated); |
|
283 TInt GetWspData(TDes8& aWspHeader, TDes8& aWspBody, TUint8& aTransactionId, TWSPStatus& aStatus); |
|
284 void UnpackPduToWspDataL(); |
|
285 Wap::TBearer GetBearerType(); |
|
286 RSocket& Socket(); |
|
287 void CleanUpData(); |
|
288 |
|
289 public: |
|
290 /**The RSocket instance to send and receive WDP PDU. |
|
291 */ |
|
292 RSocket iSocket; |
|
293 /**The remote address for the last received message |
|
294 */ |
|
295 TSockAddr iRemoteAddr; |
|
296 /**The local address for the last received message |
|
297 */ |
|
298 TSockAddr iLocalAddr; |
|
299 |
|
300 protected: |
|
301 CActiveSocket(RSocketServ& aSocketServ, Wap::TBearer aBearerType, MProgressNotify* aNotify, Wap::TPort aLocalPort); |
|
302 CActiveSocket(RSocketServ& aSocketServ, Wap::TBearer aBearerType, MProgressNotify* aNotify, const TSockAddr& aRemoteAddr, Wap::TPort aLocalPort); |
|
303 |
|
304 protected: |
|
305 /**The data buffer to receive WDP or WSP message |
|
306 */ |
|
307 CWapMessageRecord* iMessageRecord; |
|
308 /**The RSocketServ reference from WAP message API |
|
309 */ |
|
310 RSocketServ& iSocketServ; |
|
311 /**The Bearer type |
|
312 */ |
|
313 Wap::TBearer iBearerType; |
|
314 /**The port number for the last received message |
|
315 */ |
|
316 Wap::TPort iLocalPort; |
|
317 /**The state of the bearer |
|
318 */ |
|
319 TWapActiveSocketState iSocketState; |
|
320 /** |
|
321 The instance that to be notified when data is received |
|
322 */ |
|
323 MProgressNotify* iNotify; |
|
324 /** |
|
325 Buffer for the first read from ESock |
|
326 */ |
|
327 TPtr8 iBuf; |
|
328 /** |
|
329 Reported remaining length for PRT 1.5 |
|
330 */ |
|
331 TSockXfrLength iRxlength; |
|
332 /** |
|
333 Buffer for continious read from ESock |
|
334 */ |
|
335 TPtr8 iBufCon; |
|
336 }; |
|
337 |
|
338 class CActiveSocketSMS : public CActiveSocket |
|
339 /** |
|
340 The class represent the SMS bearer. It will open a RSocket over WapSMS protocol, send and |
|
341 receive WDP PDU. |
|
342 @internalComponent |
|
343 @released |
|
344 @since v8.0 |
|
345 */ |
|
346 { |
|
347 public: |
|
348 CActiveSocketSMS(RSocketServ& aSocketServ, MProgressNotify* aNotify, Wap::TBearer aBearer, Wap::TPort aLocalPort); |
|
349 CActiveSocketSMS(RSocketServ& aSocketServ, MProgressNotify* aNotify, Wap::TBearer aBearer, const TSockAddr& aRemoteAddr); |
|
350 virtual ~CActiveSocketSMS(); |
|
351 TInt AwaitRecvDataSize(); |
|
352 TInt Receive(); |
|
353 void ConstructL(TWapMessageType aType); |
|
354 private: |
|
355 void RunL(); |
|
356 void DoCancel(); |
|
357 }; |
|
358 |
|
359 class CActiveSocketUDP : public CActiveSocket |
|
360 /** |
|
361 The class represent the UDP bearer. It will open a RSocket over UDP protocol, send and |
|
362 receive WDP PDU. It is not supported in released v8.0. |
|
363 @internalComponent |
|
364 @released |
|
365 @since v8.0 |
|
366 */ |
|
367 { |
|
368 public: |
|
369 CActiveSocketUDP(RSocketServ& aSocketServ, MProgressNotify* aNotify, Wap::TBearer aBearer, Wap::TPort aLocalPort, RConnection* aConnection); |
|
370 CActiveSocketUDP(RSocketServ& aSocketServ, MProgressNotify* aNotify, Wap::TBearer aBearer, const TSockAddr& aRemoteAddr, RConnection* aConnection); |
|
371 virtual ~CActiveSocketUDP(); |
|
372 TInt AwaitRecvDataSize(); |
|
373 TInt Receive(); |
|
374 void ConstructL(TWapMessageType aType); |
|
375 private: |
|
376 void RunL(); |
|
377 void DoCancel(); |
|
378 /** |
|
379 The RConnection shared with the WAP message API client. |
|
380 */ |
|
381 RConnection* iConnection; |
|
382 }; |
|
383 |
|
384 #endif // __ACTIVESOCKET_H__ |
|
385 |