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