|
1 /** @file |
|
2 * Copyright (c) 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: Base class for download / upload worker classes |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_CHTTPTRANSFERWORKER_H |
|
20 #define C_CHTTPTRANSFERWORKER_H |
|
21 |
|
22 |
|
23 // System include files |
|
24 #include <http/mhttptransactioncallback.h> |
|
25 #include <e32def.h> |
|
26 #include <e32cmn.h> |
|
27 #include <http.h> |
|
28 #include <e32base.h> |
|
29 #include <es_sock.h> |
|
30 #include <stringpool.h> |
|
31 |
|
32 // User include files |
|
33 #include "httptransferobserver.h" |
|
34 #include "httpfile.h" |
|
35 #include "httptransferbase.h" |
|
36 #include "httptransfertimerobserver.h" |
|
37 #include "upnpconnectionmanagerproxy.h" |
|
38 #include "httpnotifytimer.h" |
|
39 |
|
40 // Forward declarations |
|
41 class MHttpTransactionObserver; |
|
42 class CHttpTransferTimer; |
|
43 |
|
44 const TInt KSessionTimeout = 35; //35 sec |
|
45 |
|
46 /** |
|
47 * Virtual base class for CHttpDowloadWorker and CHttpUploadWorker. |
|
48 * |
|
49 * @lib httptransfer.lib |
|
50 * @since S60 v3.2 |
|
51 */ |
|
52 class CHttpTransferWorker : public CBase, |
|
53 public MHTTPTransactionCallback, |
|
54 public MHttpTransferTimerObserver |
|
55 { |
|
56 public: |
|
57 /** |
|
58 * State machine |
|
59 * |
|
60 * @since S60 v3.2 |
|
61 */ |
|
62 enum THttpWorkerState |
|
63 { |
|
64 // Waiting for start of the process |
|
65 EHttpWaitingForStart, |
|
66 |
|
67 // HTTP GET sent |
|
68 EHttpGetSent, |
|
69 |
|
70 // HTTP POST sent |
|
71 EHttpPostSent, |
|
72 |
|
73 // HTTP GET response received |
|
74 EHttpGetResponseReceived, |
|
75 |
|
76 // HTTP transaction finished |
|
77 EHttpTransactionIdle, |
|
78 |
|
79 // HTTP transaction canceled |
|
80 EHttpTransactionCanceled |
|
81 }; |
|
82 |
|
83 public: |
|
84 |
|
85 /** |
|
86 * Virtual destructor |
|
87 * |
|
88 * @since S60 v3.2 |
|
89 */ |
|
90 virtual ~CHttpTransferWorker(); |
|
91 |
|
92 /** |
|
93 * Connects the HTTP session |
|
94 * |
|
95 * @since S60 v3.2 |
|
96 */ |
|
97 void ConnectL(); |
|
98 |
|
99 /** |
|
100 * Sets file which should be transfered. |
|
101 * |
|
102 * @since S60 v3.2 |
|
103 * @param aFile New file |
|
104 */ |
|
105 void SetFileL( CHttpFile& aFile ); |
|
106 |
|
107 /** |
|
108 * Stops the transfer of the file |
|
109 * |
|
110 * @since S60 v3.2 |
|
111 */ |
|
112 virtual void CancelTransfer()=0; |
|
113 |
|
114 /** |
|
115 * Starts the processing of a file. |
|
116 * Asynchronous. |
|
117 * |
|
118 * @since S60 v3.2 |
|
119 */ |
|
120 virtual void StartProcessL(); |
|
121 |
|
122 /** |
|
123 * Sets tracking flag of the processed file to the value |
|
124 * of the aValue attribute. |
|
125 * |
|
126 * @since S60 v3.2 |
|
127 * @param aValue New value |
|
128 */ |
|
129 void TrackProgress( TBool aValue ); |
|
130 |
|
131 /** |
|
132 * Getter for key value of the processed file. |
|
133 * |
|
134 * @since S60 v3.2 |
|
135 * @return Value of the aKey attribute of the processed file. |
|
136 */ |
|
137 TAny* Key() const; |
|
138 |
|
139 /** |
|
140 * Getter for Uri |
|
141 * |
|
142 * @since S60 v3.2 |
|
143 * @return Value of the Uri |
|
144 */ |
|
145 const HBufC8* Uri() const; |
|
146 |
|
147 /** |
|
148 * Getter for Path |
|
149 * |
|
150 * @since S60 v3.2 |
|
151 * @return Value of the path |
|
152 */ |
|
153 const HBufC* Path() const; |
|
154 |
|
155 /** |
|
156 * Returns information if the process is on-going |
|
157 * |
|
158 * @since S60 v3.2 |
|
159 * @return True if process is on-going |
|
160 */ |
|
161 TBool ProcessOnGoing() const; |
|
162 |
|
163 /** |
|
164 * Returns information if the worker is waiting for start |
|
165 * |
|
166 * @since S60 v3.2 |
|
167 * @return True if is waiting |
|
168 */ |
|
169 TBool IsWaiting() const; |
|
170 |
|
171 /** |
|
172 * Sets headers |
|
173 * |
|
174 * @since S60 v3.2 |
|
175 * @param aHeaders Header |
|
176 * @param aHdrField The field of the header |
|
177 * @param aHdrValue Value of the header |
|
178 */ |
|
179 void SetHeaderL( RHTTPHeaders aHeaders, TInt aHdrField, |
|
180 const TDesC8& aHdrValue ); |
|
181 |
|
182 /** |
|
183 * Sets headers |
|
184 * |
|
185 * @since S60 v3.2 |
|
186 * @param aHeaders Header |
|
187 * @param aHdrField The field of the header |
|
188 * @param aHdrValue Value of the header |
|
189 */ |
|
190 void SetHeaderL( RHTTPHeaders aHeaders, |
|
191 const TDesC8& aHdrField, |
|
192 const TDesC8& aHdrValue ); |
|
193 |
|
194 /** |
|
195 * Returns a reference to the processed file. Returns NULL if |
|
196 * the processed file is not set. |
|
197 * |
|
198 * @since S60 v3.2 |
|
199 * @return A pointer to the processed file |
|
200 */ |
|
201 CHttpFile* ProcessedFile(); |
|
202 |
|
203 // from base class MHTTPTransactionCallback |
|
204 |
|
205 /** |
|
206 * Called by framework to notify about transaction events. |
|
207 * |
|
208 * @since S60 v3.2 |
|
209 * @param aTransaction Transaction, where the event occured. |
|
210 * @param aEvent Occured event. |
|
211 */ |
|
212 virtual void MHFRunL( RHTTPTransaction aTransaction, |
|
213 const THTTPEvent& aEvent )=0; |
|
214 |
|
215 /** |
|
216 * Called by framework when leave occurs in handling of transaction |
|
217 * event. |
|
218 * |
|
219 * @since S60 v3.2 |
|
220 * @param aError The leave code that occured. |
|
221 * @param aTransaction The transaction that was being processed |
|
222 * @param aEvent The event that was being processed |
|
223 * @return Error code |
|
224 */ |
|
225 virtual TInt MHFRunError( TInt aError, |
|
226 RHTTPTransaction aTransaction, |
|
227 const THTTPEvent& aEvent )=0; |
|
228 |
|
229 // from base class MHttpTransferTimerObserver |
|
230 |
|
231 /** |
|
232 * Call back for the timer |
|
233 * |
|
234 * @since S60 v3.2 |
|
235 */ |
|
236 void TimerCallback(); |
|
237 |
|
238 protected: |
|
239 /** |
|
240 * Second phase constructor |
|
241 * |
|
242 * @since S60 v3.2 |
|
243 */ |
|
244 void ConstructL(); |
|
245 |
|
246 protected: |
|
247 |
|
248 /** |
|
249 * Pointer to the transfer observer |
|
250 * Not own. |
|
251 */ |
|
252 MHttpTransferObserver* iObserver; |
|
253 |
|
254 /** |
|
255 * HTTP session |
|
256 */ |
|
257 RHTTPSession iSession; |
|
258 |
|
259 /** |
|
260 * String pool |
|
261 */ |
|
262 RStringPool iStringPool; |
|
263 |
|
264 /** |
|
265 * Connection |
|
266 */ |
|
267 CUpnpConnectionManagerProxy *iConnectionManagerProxy; |
|
268 |
|
269 /** |
|
270 * Filename |
|
271 * Own. |
|
272 */ |
|
273 HBufC* iFileName; |
|
274 |
|
275 /** |
|
276 * Handle to the file server session |
|
277 */ |
|
278 RFs iFsSession; |
|
279 |
|
280 /** |
|
281 * File |
|
282 */ |
|
283 RFile iFile; |
|
284 |
|
285 /** |
|
286 * File which is being processed. |
|
287 * Own. |
|
288 */ |
|
289 CHttpFile* iProcessedFile; |
|
290 |
|
291 |
|
292 /** |
|
293 * State machine |
|
294 */ |
|
295 THttpWorkerState iProcessState; |
|
296 |
|
297 /** |
|
298 * Buffer size |
|
299 */ |
|
300 TInt iBufferSize; |
|
301 |
|
302 /** |
|
303 * Socket server |
|
304 */ |
|
305 RSocketServ iSocketServer; |
|
306 |
|
307 /** |
|
308 * A HTTP Transaction. This encapsulates 1 HTTP request and |
|
309 * response. A Transaction is associated with a session, and must be |
|
310 * created using the session's CreateTransactionL method. |
|
311 */ |
|
312 RHTTPTransaction iHttpTransaction; |
|
313 |
|
314 /** |
|
315 * Worker observer |
|
316 * Not own. |
|
317 */ |
|
318 MHttpWorkerObserver* iCallback; |
|
319 |
|
320 /** |
|
321 * Timer. |
|
322 * Own. |
|
323 */ |
|
324 CHttpTransferTimer* iTimer; |
|
325 |
|
326 }; |
|
327 |
|
328 #endif // C_CHTTPTRANSFERWORKER_H |