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