|
1 /* |
|
2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Including CTrReq : transport request buffer element. |
|
15 * Including CImpsSendReceive2: This is an adapter between WV engine core and transport dll. |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CImpsSendReceive2_H |
|
20 #define CImpsSendReceive2_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <f32file.h> |
|
24 #include "impscspsessionapi.h" |
|
25 #include "impsdatachannelapi.h" |
|
26 |
|
27 // DATA TYPES |
|
28 |
|
29 // Command types for connection monitor |
|
30 enum TImpsTransCmd |
|
31 { |
|
32 EImpsTransNone, |
|
33 EImpsTransOpenAP, |
|
34 EImpsTransCloseDelay, |
|
35 EImpsTransCloseAP, |
|
36 EImpsTransWaitOpen |
|
37 }; |
|
38 |
|
39 // Connection states |
|
40 enum TImpsConnectionState |
|
41 { |
|
42 EImpsOnline = 0, // active |
|
43 EImpsOffline, // suspend |
|
44 EImpsNoAP // lost or uninitialized |
|
45 }; |
|
46 |
|
47 // State machine |
|
48 enum TImpsTrState |
|
49 { |
|
50 EImpsTrInit = 0, |
|
51 EImpsTrAPOpening, |
|
52 EImpsTrAPOpen, |
|
53 EImpsTrClosing, |
|
54 EImpsTrClosingPDP, // close PDP context only, not bearer events. |
|
55 EImpsTrCloseDelayed, |
|
56 EImpsTrClosedPDP, |
|
57 EImpsTrOpeningPDP, |
|
58 EImpsTrDataOpen |
|
59 }; |
|
60 |
|
61 |
|
62 // FORWARD DECLARATIONS |
|
63 class CImpsConnManager; |
|
64 |
|
65 |
|
66 /** |
|
67 * transport request buffer element |
|
68 */ |
|
69 class CTrReq : public CBase |
|
70 { |
|
71 public: |
|
72 CTrReq( |
|
73 const TDesC& aTID, |
|
74 TInt aOpId ); |
|
75 virtual ~CTrReq(); |
|
76 void Destroy(); |
|
77 |
|
78 TInt iOpId; //lint !e1925 |
|
79 TBuf<KImpsMaxTID> iTID; //lint !e1925 // CSP TID |
|
80 TDblQueLink iLink; //lint !e1925 |
|
81 }; |
|
82 |
|
83 /** |
|
84 * This is an adapter between WV engine core and transport dll. |
|
85 */ |
|
86 class CImpsSendReceive2 : public CBase, public MImpsDataReceiver |
|
87 { |
|
88 public: // Constructors and destructor |
|
89 |
|
90 /** |
|
91 * Two-phased constructor. |
|
92 * @param aFs file server |
|
93 * @param aServer WV engine core |
|
94 * @param aOutputBuffer output buffer |
|
95 * @param aMimeType MIME content type to be added in HTTP headers. |
|
96 */ |
|
97 static CImpsSendReceive2* NewL( |
|
98 RFs& aFs, |
|
99 MImpsCSPSession& aServer, |
|
100 CBufFlat& aOutputBuffer, |
|
101 TDesC8& aMimeType ); |
|
102 |
|
103 /** |
|
104 * Destructor. |
|
105 */ |
|
106 virtual ~CImpsSendReceive2(); |
|
107 |
|
108 public: // New functions |
|
109 |
|
110 /** |
|
111 * Opens a session to WV SAP/HTTP proxy. |
|
112 * If already opened, error code in status is returned in leave. |
|
113 * @param aID operation id to identify the request. |
|
114 * Used in error situations. |
|
115 * Zero length id means that data channel is opened only. |
|
116 * @param aXmlLog if xml messages are written to log |
|
117 * +1 logging is on, +2 log also polling |
|
118 * @param aSAP WV SAP |
|
119 * @param aIAP CommDb IAP id |
|
120 * @param aDelayed ETrue if open AP must be delayed a little bit. |
|
121 */ |
|
122 void OpenL( |
|
123 const TDesC& aTID, |
|
124 TInt aXmlLog, |
|
125 const TDesC& aSAP, |
|
126 TInt aIAP, |
|
127 TBool aDelayed = EFalse ); |
|
128 |
|
129 /** |
|
130 * Closes the Data channel to WV SAP/HTTP proxy and AP |
|
131 */ |
|
132 void CloseTr(); |
|
133 |
|
134 /** |
|
135 * Closes the session to WV SAP/HTTP proxy. |
|
136 * Yields the control for active scheduler until performs the operation. |
|
137 * @return error code |
|
138 */ |
|
139 TInt Close2( ); |
|
140 |
|
141 /** |
|
142 * Close IAP only. GPRS state changes are still received thru |
|
143 * callback method. |
|
144 */ |
|
145 void ClosePDP(); |
|
146 |
|
147 /** |
|
148 * Open PDP and data channel only |
|
149 * @param aSAP WV SAP |
|
150 * @param aIAP CommDb IAP id |
|
151 */ |
|
152 void OpenPDPL( |
|
153 const TDesC& aSAP, |
|
154 TInt aIAP ); |
|
155 |
|
156 /** |
|
157 * Send a request and waits a response. |
|
158 * Cleans current entry from iRequList in error case so that |
|
159 * DeleteId is not needed. |
|
160 * @param aTID transaction id to identify the request. |
|
161 * Used in error situations. |
|
162 * @param aExpiryTime expiry time |
|
163 */ |
|
164 void SendAndWaitL( const TDesC& aTID, TInt aExpiryTime = 0 ); |
|
165 |
|
166 /** |
|
167 * Is the connection made |
|
168 */ |
|
169 TBool isConnected(); |
|
170 |
|
171 /** |
|
172 * Cancel transport transactions, affects Data Channel only |
|
173 */ |
|
174 void Cancel(); |
|
175 |
|
176 /** |
|
177 * Number of pending requests |
|
178 */ |
|
179 inline TInt NbrOfPending(); |
|
180 |
|
181 /** |
|
182 * Cancel a transaction |
|
183 * @param aTID transaction id to identify the request. |
|
184 */ |
|
185 void CancelTrans( const TDesC& aTID ); |
|
186 |
|
187 /** |
|
188 * Cancel a login transaction |
|
189 * This differs from CancelTrans so that this calls |
|
190 * CSP session's TransportErrorL callback with specific |
|
191 * error codes when ready. |
|
192 * @param aTID transaction id to identify the request. |
|
193 * @return ETrue if Login transaction was sent and Logout should be sent later. |
|
194 */ |
|
195 TBool CancelLoginTrans( const TDesC& aTID ); |
|
196 |
|
197 public: // Functions from base classes |
|
198 |
|
199 /** |
|
200 * InputBuffer accessor |
|
201 * @return input buffer to be used for raw 8-bit response data |
|
202 */ |
|
203 CBufFlat& InputBuffer(); |
|
204 |
|
205 /** |
|
206 * Callback for transport request response |
|
207 * This handles the responses to the SendL() method from MImpsSender |
|
208 * |
|
209 * NOTE: It is very important to bear in mind that the memory |
|
210 * area which the fourth parameter points to, MUST be |
|
211 * deallocated by the object that implements this abstract |
|
212 * interface! After the IMPS Data Channel component has |
|
213 * called this method, it is no longer responsible for |
|
214 * maintenance (including deallocation) of this chunk of |
|
215 * heap. Failure to free the memory area will result in |
|
216 * a serious memory leak and, consequently, a crash. |
|
217 * Also note that in many error cases, including a request |
|
218 * timing out, the pointer will be NULL as there is no data |
|
219 * to relay. |
|
220 * |
|
221 * @param TInt Operation-id given in SendL() method |
|
222 * @param TInt Internal error code, KErrNone if successful |
|
223 * @param TInt HTTP status code, 200 if successful |
|
224 * @param HBufC8** Pointer to the raw eight-bit CSP data; |
|
225 * must be deleted by the implementing class |
|
226 * after its contents are no longer needed |
|
227 */ |
|
228 virtual void TransportResponse( TInt aId, |
|
229 TInt aError, |
|
230 TInt aHttpStatus, |
|
231 HBufC8* aCspMessage ); |
|
232 |
|
233 /** |
|
234 * Observer for connection status change and completion of |
|
235 * open and close operations. |
|
236 * @param aConnectionState new state or command executed |
|
237 * @param aStatus error code for the command |
|
238 * @param aOperation True if operation response (open or close) |
|
239 * @param aAuthClose True if authoritatively closed |
|
240 */ |
|
241 void APStatusEvent( |
|
242 TImpsConnectionState aConnectionState, |
|
243 TInt aStatus, |
|
244 TBool aOperation, |
|
245 TBool aAuthClose = EFalse ); |
|
246 |
|
247 /** |
|
248 * Deletes members while active scheduler is still running |
|
249 */ |
|
250 void Destroy(); |
|
251 |
|
252 /** |
|
253 * Connection Manager accessor |
|
254 */ |
|
255 MMsgConnManager& ConnManagerHandleL(); |
|
256 |
|
257 protected: // New functions |
|
258 |
|
259 protected: // Functions from base classes |
|
260 |
|
261 private: |
|
262 |
|
263 /** |
|
264 * C++ default constructor. |
|
265 * @param aFs file server |
|
266 * @param aServer WV engine core |
|
267 * @param aInputBuffer input buffer |
|
268 * @param aOutputBuffer output buffer |
|
269 */ |
|
270 CImpsSendReceive2( |
|
271 RFs& aFs, |
|
272 MImpsCSPSession& aServer, |
|
273 CBufFlat& aOutputBuffer ); |
|
274 |
|
275 /** |
|
276 * Opens a session to WV SAP/HTTP proxy. |
|
277 * If already opened, error code in status is returned in leave. |
|
278 * Other parameters givnen in previous OpenL methos |
|
279 * @param aID operation id to identify the request. |
|
280 * @param aDelayed ETrue if open AP must be delayed a little bit |
|
281 */ |
|
282 void OpenL( const TDesC& aTID, TBool aDelayed ); |
|
283 |
|
284 /** |
|
285 * Generate unique transport operation-id |
|
286 */ |
|
287 inline void GenerateId(); |
|
288 |
|
289 /** |
|
290 * SAP address accessor |
|
291 * @return SAP address |
|
292 */ |
|
293 inline TPtrC SAP() const; |
|
294 |
|
295 /** |
|
296 * Create a request element for transport adapter |
|
297 * @param aTid transaction-id |
|
298 * @return new operation-id |
|
299 */ |
|
300 TInt AddIdL( const TDesC& aTid ); |
|
301 |
|
302 /** |
|
303 * Gives the transaction-id from operation-id |
|
304 * @param aId operation-id |
|
305 * @return transaction-id |
|
306 */ |
|
307 TPtrC OpidToTid( TInt aId ); |
|
308 |
|
309 /** |
|
310 * Gives operation-id from transaction-id |
|
311 * @param aId transaction-id |
|
312 * @return operation-id |
|
313 */ |
|
314 TInt TidToOpid( const TDesC& aId ); |
|
315 |
|
316 /** |
|
317 * Deletes the request element |
|
318 * @param aId operation-id |
|
319 * @return ETrue if found and deleted |
|
320 */ |
|
321 TBool DeleteId( TInt aId ); |
|
322 |
|
323 /** |
|
324 * Delete all request elements |
|
325 */ |
|
326 void DeleteAllIds(); |
|
327 |
|
328 /** |
|
329 * Callback for transport request response |
|
330 * @param aId operation-id given in send request, 0 means undefined |
|
331 * @param aError status code, KErrNone if successful |
|
332 * @param TInt HTTP status code, 200 if successful |
|
333 * @param HBufC8** Pointer to the raw eight-bit CSP data; |
|
334 * must be deleted by the implementing class |
|
335 * after its contents are no longer needed |
|
336 */ |
|
337 void DoTransportResponseL( |
|
338 TInt aId, |
|
339 TInt aError, |
|
340 TInt aHttpStatus, |
|
341 HBufC8** aCspPtr |
|
342 ); |
|
343 |
|
344 /** |
|
345 * Opens a connection and/or data channel |
|
346 * @param aCmd command |
|
347 * @param IAP, optional |
|
348 */ |
|
349 void Open2L( TInt aInt, TBool aDelayed ); |
|
350 |
|
351 /** |
|
352 * Is the DataChannel OK |
|
353 * @return ETrue if DataChannel open |
|
354 */ |
|
355 TBool DoIsConnectedL(); |
|
356 |
|
357 /** |
|
358 * By default constructor is private. |
|
359 * @param aMimeType MIME content type to be added in HTTP headers. |
|
360 */ |
|
361 void ConstructL( TDesC8& aMimeType ); |
|
362 |
|
363 // By default, prohibit copy constructor |
|
364 CImpsSendReceive2( const CImpsSendReceive2& ); |
|
365 // Prohibit assigment operator |
|
366 CImpsSendReceive2& operator= ( const CImpsSendReceive2& ); |
|
367 |
|
368 /** |
|
369 * Internal state change |
|
370 * @param aNew new status |
|
371 */ |
|
372 void NewTrState( TImpsTrState aNew ); |
|
373 |
|
374 /** |
|
375 * Handle response for our request to transport modules |
|
376 * @param aConnectionState new state or command executed |
|
377 * @param aStatus error code for the command |
|
378 */ |
|
379 void DoHandleRespL( |
|
380 TImpsConnectionState aConnectionState, |
|
381 TInt aStatus ); |
|
382 |
|
383 /** |
|
384 * Handle transport event handling |
|
385 * @param aConnectionState new state or command executed |
|
386 * @param True if authoratively closed, valid only in bearer-lost. |
|
387 */ |
|
388 void DoHandleTrEventL( |
|
389 TImpsConnectionState aConnectionState, TBool aAuthClose ); |
|
390 |
|
391 /** |
|
392 * Open data channel |
|
393 * @return error code |
|
394 */ |
|
395 TInt DoOpenDataCh(); |
|
396 |
|
397 |
|
398 private: // Data |
|
399 MImpsCSPSession& iServer; |
|
400 CBufFlat& iOutputBuffer; |
|
401 TBool iProxy; |
|
402 TBool iXmlLog; |
|
403 TInt iID; |
|
404 TInt iOpenId; // used for open/close method |
|
405 TParse iParse; |
|
406 RFs& iFs; |
|
407 TInt iIAP; |
|
408 MImpsSender* iSender; |
|
409 // Request queue |
|
410 TDblQue<CTrReq> iRequList; |
|
411 |
|
412 CImpsConnManager* iConnMan; |
|
413 HBufC* iSAP; // TCP/IP address |
|
414 // TImpsTransCmd iPendingCmd; |
|
415 TBuf8<50> iMimeType; |
|
416 TImpsTrState iTrState; |
|
417 }; |
|
418 |
|
419 inline TInt CImpsSendReceive2::NbrOfPending() |
|
420 { |
|
421 return iSender ? iSender->PendingRequests() : 0; |
|
422 } |
|
423 |
|
424 inline void CImpsSendReceive2::GenerateId( ) |
|
425 { |
|
426 iID++; |
|
427 } |
|
428 |
|
429 inline TPtrC CImpsSendReceive2::SAP() const |
|
430 { |
|
431 return iSAP ? TPtrC( *iSAP ) : TPtrC(); |
|
432 } |
|
433 |
|
434 |
|
435 |
|
436 #endif // INCLUDE_H |
|
437 |
|
438 // End of File |