|
1 /* |
|
2 * Copyright (c) 2002-2007 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: |
|
15 * Class implementing transaction within WAP session |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #ifndef MMSTRANSACTION_H |
|
22 #define MMSTRANSACTION_H |
|
23 |
|
24 // INCLUDES |
|
25 #include "mmsoperationtimer.h" |
|
26 #include "mmstransportobserver.h" |
|
27 #include "mmsbearerstatus.h" |
|
28 |
|
29 #include <e32base.h> |
|
30 #include <mentact.h> // CMsgActive |
|
31 #include <thttpevent.h> |
|
32 #include <mhttptransactioncallback.h> |
|
33 #include <mhttpdatasupplier.h> |
|
34 |
|
35 // CONSTANTS |
|
36 |
|
37 // MACROS |
|
38 |
|
39 // DATA TYPES |
|
40 |
|
41 // FUNCTION PROTOTYPES |
|
42 |
|
43 // FORWARD DECLARATIONS |
|
44 class MMmsCodecDataSupplier; |
|
45 class MMmsCodecDataSink; |
|
46 |
|
47 // CLASS DECLARATION |
|
48 |
|
49 /** |
|
50 * Class implementing transaction within WAP session |
|
51 */ |
|
52 NONSHARABLE_CLASS( CMmsTransaction ):public CMsgActive, |
|
53 public MMmsTransportObserver, |
|
54 public MHTTPTransactionCallback, |
|
55 public MHTTPDataSupplier |
|
56 { |
|
57 public: // Constructors and destructor |
|
58 |
|
59 /** |
|
60 * Two-phased constructor. |
|
61 */ |
|
62 static CMmsTransaction* NewL(); |
|
63 |
|
64 /** |
|
65 * Destructor. |
|
66 */ |
|
67 virtual ~CMmsTransaction(); |
|
68 |
|
69 public: // New functions |
|
70 |
|
71 /** |
|
72 * Start the state machine. |
|
73 * @param aHTTPSession Reference to HTTP session running in client |
|
74 * @param aTransferControl Object used to detect if transfer is cancelled |
|
75 * @param aUri Address to MMSC with message id |
|
76 * @param aMethod The type of transaction (POST/GET) |
|
77 * @param aMessageBuffer An IN/OUT parameter. Includes the data to be sent to |
|
78 * to WAP GW. If there should be data to be returned, this includes it. |
|
79 * @param aTransactionTimer Timer for transaction |
|
80 * @param aMaxReceiveSize upper limit for accepted message. 0 = anything goes. |
|
81 * @param aExpectedReceiveSize tells how large buffer will be allocated for the data |
|
82 * @param aDataSupplier The class that will serve as data supplier |
|
83 * for chunked transfer. |
|
84 * @param aDataSink The class that will serve as data sink for chunked receive |
|
85 * @param aStatus Status of calling active object |
|
86 */ |
|
87 void ExecuteL( |
|
88 RHTTPSession& aSession, |
|
89 CMmsBearerStatus& aTransferControl, |
|
90 const TDesC& aUri, |
|
91 const TInt aMethod, |
|
92 CBufFlat& aMessageBuffer, |
|
93 const TInt aTransactionTimer, |
|
94 TInt32 aMaxReceiveSize, |
|
95 TInt32 aExpectedReceiveSize, |
|
96 MMmsCodecDataSupplier& aDataSupplier, |
|
97 MMmsCodecDataSink& aDataSink, |
|
98 TRequestStatus& aStatus ); |
|
99 |
|
100 |
|
101 public: // Functions from base classes |
|
102 |
|
103 // from MHTTPTransactionCallback |
|
104 /** Called when the filter's registration conditions are satisfied for |
|
105 * events that occur on a transaction. |
|
106 * Note that this function is not allowed to leave if called with |
|
107 * certain events. @see THTTPEvent |
|
108 * @param aTransaction The transaction that the event has occurred on. |
|
109 * @param aEvent The event that has occurred. |
|
110 * @exception Any Leaves must be handled by the appropriate MHFRunError. |
|
111 */ |
|
112 void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent); |
|
113 |
|
114 /** Called when RunL leaves from a transaction event. This works in the same |
|
115 * way as CActve::RunError; return KErrNone if you have handled the error. |
|
116 * If you don't completely handle the error, a panic will occur. |
|
117 * @param aError The leave code that RunL left with. |
|
118 * @param aTransaction The transaction that was being processed. |
|
119 * @param aEvent The Event that was being processed. |
|
120 * @return KErrNone if the error has been cancelled or the code |
|
121 * of the continuing error otherwise. |
|
122 */ |
|
123 TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent); |
|
124 |
|
125 // from MHTTPDataSupplier |
|
126 /** Obtain a data part from the supplier. The data is guaranteed |
|
127 * to survive until a call is made to ReleaseData(). |
|
128 * @param aDataPart - the data part |
|
129 * @return ETrue if this is the last part. EFalse otherwise |
|
130 */ |
|
131 TBool GetNextDataPart(TPtrC8& aDataPart); |
|
132 |
|
133 /** Release the current data part being held at the data |
|
134 * supplier. This call indicates to the supplier that the part |
|
135 * is no longer needed, and another one can be supplied, if |
|
136 * appropriate. |
|
137 */ |
|
138 void ReleaseData(); |
|
139 |
|
140 /** Obtain the overall size of the data being supplied, if known |
|
141 * to the supplier. Where a body of data is supplied in several |
|
142 * parts this size will be the sum of all the part sizes. If |
|
143 * the size is not known, KErrNotFound is returned; in this case |
|
144 * the client must use the return code of GetNextDataPart to find |
|
145 * out when the data is complete. |
|
146 * @return A size in bytes, or KErrNotFound if the size is not known. |
|
147 */ |
|
148 TInt OverallDataSize(); |
|
149 |
|
150 /** Reset the data supplier. This indicates to the data supplier that it should |
|
151 * return to the first part of the data. This could be used in a situation where |
|
152 * the data consumer has encountered an error and needs the data to be supplied |
|
153 * afresh. Even if the last part has been supplied (i.e. GetNextDataPart has |
|
154 * returned ETrue), the data supplier should reset to the first part. |
|
155 * If the supplier cannot reset it should return an error code; otherwise it should |
|
156 * return KErrNone, where the reset will be assumed to have succeeded |
|
157 */ |
|
158 TInt Reset(); |
|
159 |
|
160 // from MMmsTransportObserver |
|
161 /** |
|
162 * Callback function for CMmsOperationtimer to notify |
|
163 * about timer expiration |
|
164 */ |
|
165 void TimerExpired(); |
|
166 |
|
167 /** |
|
168 * Callback function for CMmsBearerStatus to notify |
|
169 * about gprs suspend |
|
170 */ |
|
171 void GprsSuspended(); |
|
172 |
|
173 /** |
|
174 * Callback function for CMmsBearerStatus to notify |
|
175 * about gprs resume |
|
176 */ |
|
177 void GprsResumed(); |
|
178 |
|
179 /** |
|
180 * Callback function for CMmsBearerStatus to notify |
|
181 * about gprs resume |
|
182 */ |
|
183 void TransferCancelled(); |
|
184 |
|
185 |
|
186 protected: // New functions |
|
187 |
|
188 protected: // Functions from base classes |
|
189 |
|
190 /** |
|
191 * From CActive |
|
192 */ |
|
193 void DoCancel(); |
|
194 |
|
195 /** |
|
196 * From CMsgActive: Active object completion |
|
197 * We must override this because the CMmsOperationTimer |
|
198 * and GPRS suspend information is delivered as an error. |
|
199 * This class DoRunL is not called if iStatus is error. |
|
200 */ |
|
201 void RunL(); |
|
202 |
|
203 /** |
|
204 * From CMsgActive |
|
205 */ |
|
206 void DoRunL(); |
|
207 |
|
208 private: |
|
209 |
|
210 /** |
|
211 * C++ default constructor. |
|
212 */ |
|
213 CMmsTransaction(); |
|
214 |
|
215 /** |
|
216 * By default Symbian OS constructor is private. |
|
217 */ |
|
218 void ConstructL(); |
|
219 |
|
220 /** |
|
221 * From CMsgActive: Complete current operation. |
|
222 * Cancel all active operations (timer, bearer status) |
|
223 * @param aError Error code received by RunL |
|
224 */ |
|
225 void DoComplete( TInt& aError ); |
|
226 |
|
227 /** |
|
228 * Select next state for state machine |
|
229 */ |
|
230 void SelectNextState(); |
|
231 |
|
232 /** |
|
233 * Switch states |
|
234 */ |
|
235 void ChangeStateL(); |
|
236 |
|
237 /** |
|
238 * Send transaction request (POST/GET) to WAP GW |
|
239 */ |
|
240 void MakeTransactionL(); |
|
241 |
|
242 /** |
|
243 * Finalizing procedures |
|
244 */ |
|
245 void FinishL(); |
|
246 |
|
247 /** |
|
248 * Sets a transaction header |
|
249 * @param aHeaders the header collection where the new header is inserted |
|
250 * @param aHdrField enumeration of the header field |
|
251 * @param aHdsValue the string value of the header to be set |
|
252 */ |
|
253 void SetHeaderL( RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue ); |
|
254 |
|
255 /** |
|
256 * Sets the 'Host' transaction header |
|
257 * @param aHeaders the header collection where the new header is inserted |
|
258 */ |
|
259 void SetHostHeaderL( RHTTPHeaders aHeaders ); |
|
260 |
|
261 public: // Data |
|
262 |
|
263 protected: // Data |
|
264 |
|
265 private: // Data |
|
266 |
|
267 enum TMmsTransactionStates |
|
268 { |
|
269 EMmsIdle, |
|
270 EMmsSendingTransactionRequest, |
|
271 EMmsFinished |
|
272 }; |
|
273 |
|
274 TInt iState; |
|
275 TInt iError; |
|
276 HBufC* iUri; // URI |
|
277 CBufFlat* iBuffer; |
|
278 TInt iMethod; |
|
279 RHTTPSession* iHTTPSession; // transport session |
|
280 THTTPEvent iEvent; |
|
281 RHTTPTransaction iTransaction; // transaction |
|
282 // This is owned by caller |
|
283 CMmsOperationTimer* iTimer; |
|
284 CMmsBearerStatus* iTransferControl; |
|
285 TInt iTransactionTimeout; |
|
286 TBool iRetryCount; |
|
287 TBool iRequestOngoing; |
|
288 TBool iSuspendOccurred; |
|
289 TBool iGotBodyData; |
|
290 TBool iDataChunkNumber; |
|
291 TInt iMaxReceiveSize; // used in case we don't allow big messages |
|
292 TInt iExpectedReceiveSize; // used for reserving correct size receive buffer |
|
293 TBool iTransactionOpened; // tells if transaction created successfully |
|
294 TBool iGotResponseHeaders; // did we get response headers |
|
295 // pointer to the class that will serve as data supplier for chunked transfer. |
|
296 // pointer is owned by caller - we don't delete it |
|
297 MMmsCodecDataSupplier* iDataSupplier; |
|
298 // pointer to the class that will serve as data sink for chunked receive. |
|
299 // pointer is owned by caller - we don't delete it |
|
300 MMmsCodecDataSink* iDataSink; |
|
301 TBool iLastChunk; // keep track if we already got last chunk |
|
302 TInt iCumulativeSize; // the amound of data received or sent so far |
|
303 TInt iChunkSize; // remember last chunk |
|
304 // The size the buffer can be expanded to in chunked mode. |
|
305 // When buffer reaches this size the contents must be sent for decoding. |
|
306 TInt iBufferSize; |
|
307 // Position where the data will be written into buffer. There may be some old |
|
308 // unhandled data left. |
|
309 TInt iPosition; |
|
310 |
|
311 |
|
312 public: // Friend classes |
|
313 protected: // Friend classes |
|
314 private: // Friend classes |
|
315 |
|
316 }; |
|
317 |
|
318 #endif // MMSTRANSACTION_H |
|
319 |
|
320 // End of File |