|
1 /* |
|
2 * Copyright (c) 2006-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: Header of IRLogoDownloadEngine.cpp |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef IRLOGODOWNLOADENGINE_H |
|
20 #define IRLOGODOWNLOADENGINE_H |
|
21 |
|
22 #include <mhttpdatasupplier.h> |
|
23 #include <mhttptransactioncallback.h> |
|
24 #include <rhttptransaction.h> |
|
25 #include <rhttpsession.h> |
|
26 #include <rhttpheaders.h> |
|
27 #include <http.h> |
|
28 #include <es_sock.h> |
|
29 |
|
30 #include "irisdspreset.h" |
|
31 #include "mlogodownloadobserver.h" |
|
32 #include "ircacheobserver.h" |
|
33 #include "iractivenetworkobserver.h" |
|
34 |
|
35 |
|
36 //Used to specify the maximum header-field value length |
|
37 const TInt KMAXHEADERLENGTHS = 255; |
|
38 |
|
39 //Forward Declarations |
|
40 class RHTTPSession; |
|
41 class RHTTPTransaction; |
|
42 class CIRIsdsPreset; |
|
43 class CIRNetworkController; |
|
44 class MLogoDownloadObserver; |
|
45 class CIRCacheMgmt; //for logo cache mgmt |
|
46 class CIRHttpResponseData; |
|
47 class MIRActiveNetworkObserver;//for network up and downs |
|
48 |
|
49 |
|
50 |
|
51 /** |
|
52 * class CIRLogoDownlaodEngine |
|
53 */ |
|
54 class CIRLogoDownloadEngine : public CBase, |
|
55 public MHTTPTransactionCallback, |
|
56 public MHTTPDataSupplier, |
|
57 public MIRCacheObserver, |
|
58 public MIRActiveNetworkObserver |
|
59 { |
|
60 public: |
|
61 |
|
62 /** |
|
63 * enum TState |
|
64 * status of the transaction |
|
65 */ |
|
66 enum TState |
|
67 { |
|
68 EIdle, |
|
69 ESendingEvent |
|
70 }; |
|
71 |
|
72 /** |
|
73 * CIRLogoDownloadEngine* NewL() |
|
74 * Creates instance of CIRLogoDownloadEngine. |
|
75 */ |
|
76 IMPORT_C static CIRLogoDownloadEngine* NewL(); |
|
77 |
|
78 |
|
79 /** |
|
80 * SendRequestL(CIRIsdsPreset* aPreset) |
|
81 * API is called from the SearchResultsView for to download logo |
|
82 */ |
|
83 IMPORT_C void SendRequestL( CIRIsdsPreset* aPreset, TInt aXValue = 0, |
|
84 TInt aYValue = 0 ); |
|
85 |
|
86 /** |
|
87 * SendRequestL() |
|
88 * API is called from the NowPlayingView for to download logo |
|
89 */ |
|
90 IMPORT_C void SendRequestL( CIRIsdsPreset* aPreset, |
|
91 MLogoDownloadObserver* aLogoHandle, TInt aNPVReq = 1, |
|
92 TInt aXValue = 0, TInt aYValue = 0 ); |
|
93 |
|
94 /** |
|
95 * IsLogoCachedL() |
|
96 * |
|
97 */ |
|
98 IMPORT_C TBool IsLogoCachedL( CIRIsdsPreset* aPreset, TInt aXValue = 0, |
|
99 TInt aYValue = 0 ); |
|
100 |
|
101 /** |
|
102 * CancelTransaction() |
|
103 * cancels the current transaction |
|
104 */ |
|
105 IMPORT_C void CancelTransaction(); |
|
106 |
|
107 /** |
|
108 * TBool IsRunning() const |
|
109 * To know the status of downloading logo |
|
110 */ |
|
111 IMPORT_C TBool IsRunning() const; |
|
112 |
|
113 /** |
|
114 * ~CIRLogoDownloadEngine() |
|
115 * Destructs instance of CIRLogoDownloadEngine |
|
116 */ |
|
117 IMPORT_C ~CIRLogoDownloadEngine(); |
|
118 |
|
119 /** |
|
120 * void SendPresetWithLogoL() |
|
121 * sends the preset with logo to the requestors |
|
122 */ |
|
123 IMPORT_C void SendPresetWithLogoL(); |
|
124 |
|
125 /** |
|
126 * GetCacheLogoL(TDesC& aUrl,TInt& aStatus) |
|
127 * takes the url as a parameter and returns the logo data which is in cache |
|
128 * this API is called form the search results for to display logo on the view |
|
129 */ |
|
130 IMPORT_C void GetCacheLogoL( const TDesC& aUrl, TInt& aStatus ); |
|
131 |
|
132 /** |
|
133 * TDesC8& SendCacheLogo() |
|
134 * sends the logo which is cached |
|
135 */ |
|
136 IMPORT_C TDesC8& SendCacheLogo(); |
|
137 |
|
138 |
|
139 |
|
140 /** |
|
141 * void FetchLogoDataL(CIRIsdsPreset* aPreset) |
|
142 * API is used to download logo from isds/internet |
|
143 * called in the API SendRequestL(CIRIsdsPreset* aPreset) |
|
144 */ |
|
145 void FetchLogoDataL( CIRIsdsPreset* aPreset ); |
|
146 |
|
147 /** |
|
148 * void FetchLogoDataL() |
|
149 * API is used to download logo from isds/internet |
|
150 * called in the API SendRequestL() |
|
151 */ |
|
152 void FetchLogoDataL( CIRIsdsPreset* aPreset, |
|
153 MLogoDownloadObserver* aLogoHandle, TInt aNPVReq ); |
|
154 |
|
155 /** |
|
156 * void ManagePresetArrayIndexL() |
|
157 * To update the iPresetArray current index |
|
158 */ |
|
159 void ManagePresetArrayIndexL(); |
|
160 |
|
161 /** |
|
162 * void ManageCachePresetArrayIndexL() |
|
163 * To update the iCachePresetArray current index |
|
164 */ |
|
165 void ManageCachePresetArrayIndexL(); |
|
166 |
|
167 /** |
|
168 * void CacheError() |
|
169 * Called from cachemgmt in case of an error |
|
170 * callback API from MIRCacheObserver |
|
171 */ |
|
172 void CacheError(); |
|
173 |
|
174 /** |
|
175 * void CacheFailed() |
|
176 * Called from cachemgmt in case of cache failure |
|
177 * callback API from MIRCacheObserver |
|
178 */ |
|
179 void CacheFailed(); |
|
180 |
|
181 /** |
|
182 * void CacheInvalid() |
|
183 * Called from cachemgmt in case cache is invalid |
|
184 * callback API from MIRCacheObserver |
|
185 */ |
|
186 void CacheInvalid(); |
|
187 |
|
188 /** |
|
189 * void CachedStructureL() |
|
190 * Called from cachemgmt data retrival is successful |
|
191 *@param aChoice,it gives the data type of the cache |
|
192 * callback API from MIRCacheObserver |
|
193 */ |
|
194 void CachedStructureL( TInt aChoice ); |
|
195 |
|
196 /** |
|
197 * ReleaseResources(); |
|
198 * Releases the resources held by logo download engine |
|
199 */ |
|
200 void ReleaseResources(); |
|
201 |
|
202 //from MIRActiveNetworkObserver |
|
203 /** |
|
204 * Notified by network controller when network is active |
|
205 * to reissue the request |
|
206 * NotifyActiveNetworkObserversL() |
|
207 */ |
|
208 void NotifyActiveNetworkObserversL(TIRNetworkEvent aEvent); |
|
209 |
|
210 /** |
|
211 * Notifies all observers whose network request is active |
|
212 * to reset the pending request status |
|
213 * ResetPendingRequests() |
|
214 */ |
|
215 void ResetPendingRequests( TBool aValue ); |
|
216 |
|
217 private: |
|
218 |
|
219 /** |
|
220 * void ConstructL() |
|
221 * 2nd phase construction |
|
222 */ |
|
223 void ConstructL(); |
|
224 |
|
225 /** |
|
226 * CIRLogoDownloadEngine() |
|
227 * Standard C++ constructor |
|
228 */ |
|
229 CIRLogoDownloadEngine(); |
|
230 |
|
231 /** |
|
232 * void SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue) const |
|
233 * to set the headers of the http transaction |
|
234 */ |
|
235 void SetHeaderL( RHTTPHeaders aHeaders, TInt aHdrField, |
|
236 const TDesC8& aHdrValue ) const; |
|
237 |
|
238 /** |
|
239 * void IssueLogoDownloadRequest() |
|
240 * submits the transaction for to download the logo |
|
241 */ |
|
242 void IssueLogoDownloadRequestL(); |
|
243 |
|
244 /** |
|
245 * void CheckCacheForLogoL() |
|
246 * checks the logo in the cache |
|
247 */ |
|
248 void CheckCacheForLogoL( TInt aValue ); |
|
249 |
|
250 /** |
|
251 * void MHFRunL() |
|
252 * from MHTTPTransactionCallback |
|
253 */ |
|
254 void MHFRunL( RHTTPTransaction aTransaction, const THTTPEvent& aEvent ); |
|
255 |
|
256 /** |
|
257 * TInt MHFRunError() |
|
258 * //from MHTTPTransactionCallback |
|
259 */ |
|
260 TInt MHFRunError( TInt aError, RHTTPTransaction aTransaction, |
|
261 const THTTPEvent& aEvent ); |
|
262 |
|
263 /** |
|
264 * void ReleaseData() |
|
265 * from MHTTPDataSupplier |
|
266 */ |
|
267 void ReleaseData(); |
|
268 |
|
269 /** |
|
270 * TBool GetNextDataPart() |
|
271 * from MHTTPDataSupplier |
|
272 */ |
|
273 TBool GetNextDataPart( TPtrC8& aDataPart ); |
|
274 |
|
275 /** |
|
276 * TInt Reset() |
|
277 * from MHTTPDataSupplier |
|
278 */ |
|
279 TInt Reset(); |
|
280 |
|
281 /** |
|
282 * TInt OverallDataSize() |
|
283 * from MHTTPDataSupplier |
|
284 */ |
|
285 TInt OverallDataSize(); |
|
286 |
|
287 /** |
|
288 * CIRLogoDownloadEngine::ExtractResponseHeadersL() |
|
289 * Used to Extract the response headers. |
|
290 * @param aTransaction HTTP Transaction object |
|
291 */ |
|
292 void ExtractResponseHeadersL( const RHTTPTransaction& aTransaction ); |
|
293 |
|
294 /** |
|
295 * CIRLogoDownloadEngine::HttpHeaderReceived() |
|
296 * indicate that an HTTP header is received. |
|
297 * @param aHeaderData Reference to the Header Info |
|
298 */ |
|
299 virtual void HttpHeaderReceived( const TDesC8 &aHeaderData ); |
|
300 |
|
301 /** |
|
302 * CIRLogoDownloadEngine::ExtractHeaderValue() |
|
303 * Used to build the CIRHttpResponseData |
|
304 */ |
|
305 void ExtractHeaderValue( const TDesC8& aHeaderData, |
|
306 const TDesC8& aHeaderName, const TDesC8& aDelimeter, |
|
307 TDes8& aHolder ) const; |
|
308 |
|
309 /** |
|
310 * CIRLogoDownloadEngine::HttpDateHeaderReceived() |
|
311 * Used to build the CIRHttpResponseData members |
|
312 */ |
|
313 void HttpDateHeaderReceived( const TDesC8 &aHeader, const TTime& aTime ); |
|
314 |
|
315 private: |
|
316 |
|
317 /** |
|
318 * pointer to the logo observer object |
|
319 */ |
|
320 MLogoDownloadObserver* iLogoHandle; |
|
321 |
|
322 /** |
|
323 * pointer to the logo observer object |
|
324 */ |
|
325 MLogoDownloadObserver* iTempLogoHandle; |
|
326 |
|
327 /** |
|
328 * pointer to the logo observer object |
|
329 */ |
|
330 MLogoDownloadObserver* iCacheTempLogoHandle; |
|
331 |
|
332 /** |
|
333 * pointer to the preset object |
|
334 * temporary preset in the logo downloading usecase |
|
335 */ |
|
336 CIRIsdsPreset* iTempPreset; |
|
337 |
|
338 /** |
|
339 * pointer to the preset object |
|
340 * temporary preset in the cache checking usecase |
|
341 */ |
|
342 CIRIsdsPreset* iCacheTempPreset; |
|
343 |
|
344 /** |
|
345 * pointer to the preset object |
|
346 * preset used to conver CIRPreset to CIRIsdsPreset |
|
347 */ |
|
348 CIRIsdsPreset* iCopyPreset; |
|
349 |
|
350 /** |
|
351 * Network controller handle pointer |
|
352 */ |
|
353 CIRNetworkController *iIRNetworkControllerHandle; |
|
354 |
|
355 /** |
|
356 * Preset Array for downloading logo |
|
357 */ |
|
358 CArrayPtrFlat<CIRIsdsPreset>* iPresetArray; |
|
359 |
|
360 /** |
|
361 * Preset Array for checking cache |
|
362 */ |
|
363 CArrayPtrFlat<CIRIsdsPreset>* iCachePresetArray; |
|
364 |
|
365 /** |
|
366 * MLogoDownloadObserver array for downloading logo |
|
367 */ |
|
368 CArrayPtrFlat<MLogoDownloadObserver>* iObserverArray; |
|
369 |
|
370 /** |
|
371 * MLogoDownloadObserver array for checking cache |
|
372 */ |
|
373 CArrayPtrFlat<MLogoDownloadObserver>* iCacheObserverArray; |
|
374 |
|
375 /** |
|
376 * To keep track whether the req came for Favorites or NPV(downloading logo) |
|
377 */ |
|
378 CArrayFixFlat<TInt>* iReqFromArray; |
|
379 |
|
380 /** |
|
381 * To keep track whether the req came for Favorites or NPV(checking cache) |
|
382 */ |
|
383 CArrayFixFlat<TInt>* iCacheReqFromArray; |
|
384 |
|
385 /** |
|
386 * Separate session for the logo downloading |
|
387 */ |
|
388 RHTTPSession iLogoSession; |
|
389 |
|
390 /** |
|
391 * http transaction |
|
392 */ |
|
393 RHTTPTransaction iTransaction; |
|
394 |
|
395 /** |
|
396 * for the transactions with cache mgmt |
|
397 */ |
|
398 CIRCacheMgmt *iCache; |
|
399 |
|
400 /** |
|
401 * Pointer to Response header data |
|
402 */ |
|
403 CIRHttpResponseData* iResponseHeaders; |
|
404 |
|
405 /** |
|
406 * boolean for to know the status of the downloading logo |
|
407 */ |
|
408 TBool iRunning; |
|
409 |
|
410 /** |
|
411 * body of the transaction request |
|
412 */ |
|
413 TDesC8* iReqBody; |
|
414 |
|
415 /** |
|
416 * body of the transaction response |
|
417 */ |
|
418 HBufC8* iRespBody; |
|
419 |
|
420 /** |
|
421 * size of the response body |
|
422 */ |
|
423 TInt iRespBodySize; |
|
424 |
|
425 /** |
|
426 * state of the transaction |
|
427 */ |
|
428 TState iState; |
|
429 |
|
430 /** |
|
431 * status, from which the preset has modified |
|
432 */ |
|
433 TBool iPresetModifiedStatus; |
|
434 |
|
435 /** |
|
436 * iPresetArray position |
|
437 */ |
|
438 TInt iPresetArrayPos; |
|
439 |
|
440 /** |
|
441 * position of the iReqFromArray |
|
442 */ |
|
443 TInt iReqFromArrayPos; |
|
444 |
|
445 /** |
|
446 * position of the iObserverArray |
|
447 */ |
|
448 TInt iObserverArrayPos; |
|
449 |
|
450 /** |
|
451 * position of the iCachePresetArray |
|
452 */ |
|
453 TInt iCachePresetArrayPos; |
|
454 |
|
455 /** |
|
456 * position of the iCacheReqFromArray |
|
457 */ |
|
458 TInt iCacheReqFromArrayPos; |
|
459 |
|
460 /** |
|
461 * position of the iCacheObserverArray |
|
462 */ |
|
463 TInt iCacheObserverArrayPos; |
|
464 |
|
465 /** |
|
466 * status of cache request |
|
467 */ |
|
468 TInt iCacheReqFrom; |
|
469 |
|
470 /** |
|
471 * temporary variable for the status of request |
|
472 */ |
|
473 TInt iTempReqFrom; |
|
474 |
|
475 /** |
|
476 * boolean to verify first time or not |
|
477 */ |
|
478 TBool iFirstTime; |
|
479 |
|
480 /** |
|
481 * ETrue if logo is available in cache |
|
482 */ |
|
483 TBool iLogoCached; |
|
484 |
|
485 /** |
|
486 * boolean for forcibly getting the logo from cache |
|
487 */ |
|
488 TBool iForceGet; |
|
489 |
|
490 /** |
|
491 * boolean for to track whether the cache request has made or not |
|
492 */ |
|
493 TBool iCacheReqMade; |
|
494 |
|
495 /** |
|
496 * response from the cache for the availability of logo(CacheNotValid,NotCached,CacheUseable) |
|
497 */ |
|
498 TInt iResult; |
|
499 |
|
500 /** |
|
501 * status on cache checking |
|
502 */ |
|
503 TBool iCheckingCache; |
|
504 |
|
505 /** |
|
506 * integer for the status of sending the logo |
|
507 */ |
|
508 TInt iSendingLogo; |
|
509 |
|
510 /** |
|
511 * Using for temporarily till the isds provides urls |
|
512 */ |
|
513 TInt iImageIndex; |
|
514 |
|
515 /** |
|
516 * this is used while making a conditional GET request |
|
517 */ |
|
518 TTime iLastModifiedTime; |
|
519 |
|
520 /** |
|
521 * this is used while making a conditional GET request |
|
522 */ |
|
523 TBuf8<KMAXHEADERLENGTHS> iETag; |
|
524 |
|
525 /** |
|
526 * this is used to track whether the request is conditional GET or non-conditional GET |
|
527 */ |
|
528 TBool iIsConditionalGET; |
|
529 |
|
530 /** |
|
531 * Status of the logo download in the network up and down scenarios |
|
532 */ |
|
533 TBool iLogoRequestPending; |
|
534 |
|
535 /** |
|
536 * status of the response code |
|
537 */ |
|
538 TInt iRespCode; |
|
539 }; |
|
540 |
|
541 #endif // IRLOGODOWNLOADENGINE_H |