internetradio2.0/cachemgmtinc/ircachemgmt.h
changeset 0 09774dfdd46b
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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18  
       
    19 #ifndef CIRCACHEMGMT_H
       
    20 #define CIRCACHEMGMT_H
       
    21 
       
    22 #include <d32dbms.h>
       
    23 
       
    24 
       
    25 const TInt KMAXHEADER = 255;
       
    26 
       
    27 class CIRBrowseCatagoryItems;
       
    28 class CIRBrowseChannelItems;
       
    29 class CIRCacheCleanup;
       
    30 class CIRHttpResponseData;
       
    31 class CIRIsdsPreset;
       
    32 class CIROTAUpdate;
       
    33 class CIRSettings;
       
    34 class MIRCacheObserver;
       
    35 
       
    36 class CIRCacheMgmt : public CObject
       
    37   	{
       
    38   	
       
    39 public:
       
    40 
       
    41 	/**
       
    42 	*CIRCacheMgmt::OpenL()
       
    43 	*Standard two phased construction
       
    44 	*calls ConstructL()
       
    45 	*@param MIRCacheObserver &
       
    46 	*@return CIRCacheMgmt*
       
    47 	*/
       
    48 	IMPORT_C static CIRCacheMgmt* OpenL(MIRCacheObserver &aObserver);
       
    49 
       
    50     /**
       
    51      * Adds a cache observer
       
    52      *
       
    53      * @param aObserver The observer to be added
       
    54      */
       
    55     IMPORT_C void AddObserverL( MIRCacheObserver* aObserver );
       
    56     
       
    57     /**
       
    58     * Removes a cache observer
       
    59     *
       
    60     * @param aObserver The observer to be removed
       
    61     */
       
    62     IMPORT_C void RemoveObserver( MIRCacheObserver* aObserver );
       
    63 	
       
    64 	/**
       
    65 	*CIRCacheMgmt::CheckCache()
       
    66 	*API Exposed to Isds Client to check and get the cached items.
       
    67 	*@ aType the type of items i.e category,channel or preset. aName is the file name(type,CategoryId,PresetId
       
    68 	*@return TInt,1 for a cache hit,0 for cache miss,-1 for invalid cache
       
    69 	*
       
    70 	*/
       
    71 	IMPORT_C void CheckCacheL(TInt aType,const TDesC& aName,TBool aForceGet,TInt& aReturn);
       
    72 
       
    73 	/**
       
    74 	*CIRCacheMgmt::CheckValidity()
       
    75 	*Checks the freshness of the cache
       
    76 	*@param universal time of file creation
       
    77 	*@return TBool 1 if fresh,0 if stale
       
    78 	*/ 
       
    79 	TBool CheckValidity(const TTime &aCreateTime,TInt aTrustPeriod) const;
       
    80 
       
    81 	
       
    82 	/**
       
    83 	*CIRCacheMgmt::CacheCategoryItems()
       
    84 	*Caches the category array of data.By externalizing it into a file.
       
    85 	*@param aPtrCategory the object array,aName the file name from which the information is to be written
       
    86 	*/ 
       
    87 	IMPORT_C  void CacheCategoryItemsL(CArrayPtrFlat<CIRBrowseCatagoryItems>& aPtrCategory,
       
    88 			const TDesC& aFilePath,const CIRHttpResponseData& aResponseHeaders);
       
    89 
       
    90 	/**
       
    91 	*CIRCacheMgmt::CacheChannelItems()
       
    92 	*Caches the channel objects array of data.By externalizing it into a file.
       
    93 	*@param aPtrChannel the object array,aName the file name from which the information is to be written
       
    94 	*/
       
    95 	IMPORT_C  void CacheChannelItemsL(CArrayPtrFlat<CIRBrowseChannelItems>& aPtrChannel,
       
    96 		const TDesC& aFilePath,const CIRHttpResponseData& aResponseHeaders);
       
    97 
       
    98 	/**
       
    99 	*CIRCacheMgmt::CachePresetItem()
       
   100 	*Caches the preset objects .By externalizing it into a file.
       
   101 	*Multiple presets can be cached.
       
   102 	*@param aPreset preset object,aName the file name from which the information is to be written
       
   103 	*/
       
   104 	IMPORT_C  void CachePresetItemL(
       
   105 		CArrayPtrFlat<CIRIsdsPreset>& aPtrPresets,
       
   106 		const TDesC& aName,const CIRHttpResponseData& aResponseHeaders);
       
   107 
       
   108 	/**
       
   109 	*Function : CIRCacheMgmt::CacheOtaInfoL()
       
   110 	* Caches the OTA information  .By externalizing it into a db.
       
   111 	*@param aOta otainfo object,aName the file name from which the information is to be written
       
   112 	*/
       
   113 	IMPORT_C void CacheOtaInfoL(const CIROTAUpdate& aOta,const TDesC& aName,
       
   114 								const CIRHttpResponseData& aResponseHeaders);
       
   115 								
       
   116 								
       
   117 	////////////////////////////////////////////////////////////////////////
       
   118 	// CacheLogoL() API is added newly for logo cache management          //
       
   119 	////////////////////////////////////////////////////////////////////////							
       
   120 	/**
       
   121 	*CIRCacheMgmt::CacheLogoL()
       
   122 	* Caches the logo data for a given logo url.
       
   123 	*@param aData --- logo data
       
   124 	*@param aUrl  --- logo url
       
   125 	*/								
       
   126 	IMPORT_C void CacheLogoL(const TDesC8& aData, const TDesC& aUrl,
       
   127 	                         const CIRHttpResponseData& aResponseHeaders);
       
   128 								
       
   129 								
       
   130 	/**
       
   131 	*CIRCacheMgmt::UpdateTrustPeriodL()
       
   132 	*Modifies the Trust period that comes with the 304 Not Modified responces from isds
       
   133 	*@ aType the type of items i.e category,channel or preset. aName is the file name(type,CategoryId,PresetId
       
   134 	*/		
       
   135 	IMPORT_C void UpdateTrustPeriodL(TInt aType, const TDesC& aName,
       
   136 						 CIRHttpResponseData& aResponseHeaders);
       
   137 
       
   138    	/**
       
   139 	*CIRCacheMgmt::RemoveOtaInfoL()	
       
   140 	*removes any cached ota response in case it is invalid
       
   141 	*/
       
   142 	IMPORT_C void RemoveOtaInfoL();
       
   143     
       
   144 	/**
       
   145 	*CIRCacheMgmt::CheckSizeL()
       
   146 	*checks the current size of cache against the max cache limit
       
   147 	*/	
       
   148 	void CheckSizeL();
       
   149 	/**
       
   150 	*CIRCacheMgmt::RemoveOldUnusedDataL()
       
   151 	*removes all unused data to bring the cache under the max cache size
       
   152 	*/	
       
   153 	void RemoveOldUnusedDataL();
       
   154 	/**
       
   155 	*CIRCacheMgmt::CacheSize()
       
   156 	*@return the cache size
       
   157 	*/	
       
   158 	TInt CacheSize();
       
   159 private:
       
   160 
       
   161 	/**
       
   162 	*CIRCacheMgmt::CIRCacheMgmt()
       
   163 	*Standard C++ constructor
       
   164 	*@param MIRCacheObserver &
       
   165 	*@return NA
       
   166 	*sets the trust period to 24hrs(default)
       
   167 	*/
       
   168 	CIRCacheMgmt(MIRCacheObserver &aObserver);
       
   169 		
       
   170 	/**
       
   171 	*CIRCacheMgmt::ConstructL()
       
   172 	*Standard two phased construction
       
   173 	*@param void
       
   174 	*@return void
       
   175 	*creates the folder paths if nonexistant
       
   176 	*/
       
   177 	void ConstructL();
       
   178 	
       
   179 	/**
       
   180 	*CIRCacheMgmt::~CIRCacheMgmt()
       
   181 	*Standard C++ destructor
       
   182 	*@param NA
       
   183 	*@return NA
       
   184 	*/
       
   185 	~CIRCacheMgmt();
       
   186 	
       
   187 	/**
       
   188 	*CIRCacheMgmt::CreateCacheTableL()
       
   189 	*Creates the cache table
       
   190 	*CacheTable
       
   191 	* -----------------------------------------------------------------------------------------------
       
   192 	*| RowIndex|DataType|DataId|TrustPeriod|LastModified  |LastAccessed|Created|ItemCount|CachedData|
       
   193 	*------------------------------------------------------------------------------------------------
       
   194 	*| auto    |TInt    |TDesC |TInt       |TDesC/DateTime|TTime       |Time   |TInt     | Streamed |
       
   195 	*|increment|0,1,2 !0| !0   |  !0       |              |            |       |         | Data     |
       
   196 	*------------------------------------------------------------------------------------------------
       
   197 	*/
       
   198 	void CreateCacheTableL();
       
   199 		
       
   200 	/**
       
   201 	*CIRCacheMgmt::CreateCacheIndexL()
       
   202 	*creates the indices for cache table
       
   203 	*/
       
   204 	void CreateCacheIndexL();
       
   205 	
       
   206 	void FetchCacheIfAvailableL(TInt aType,const TDesC& aId,TBool aForceGet,TInt& aReturnVal);
       
   207 	void FetchCachedDataL(TInt aType,TInt aCountItems,RDbView& aCacheView);
       
   208 	
       
   209 	void CloseDb();
       
   210 	TInt OpenCacheDb();
       
   211 	TInt CreateDb();
       
   212 	void CreateDbConditionalL();		
       
   213 	/**	
       
   214 	*CIRCacheMgmt::UpdateLastAccessedTime()	
       
   215 	*updates the last accessed field to aid in deletion of old data
       
   216 	*@param RDbView&,the view for which the update has to be made
       
   217 	*/
       
   218 	void UpdateLastAccessedTimeL(RDbView &aCacheView);
       
   219 	
       
   220 public:
       
   221 	//!Enumeration for type identification
       
   222 	enum TIRTypes
       
   223 		{
       
   224 		ECatagory = 0,
       
   225 		EChannels,
       
   226 		EPresets,
       
   227 		EOtaInfo,
       
   228 		ELogo		//added for logo cache management
       
   229 		};
       
   230 		
       
   231 	//!Enumeration for return types	    
       
   232 	enum TIRCacheStatus
       
   233 		{
       
   234 		ECacheNotValid = -1,
       
   235 		ENotCached,
       
   236 		ECacheUseable
       
   237 		};
       
   238 		
       
   239 	//! trust period for cache(24hrs by default)
       
   240 	TTimeIntervalSeconds iTrustPeriod;
       
   241 	
       
   242 	// Array of Pointers to PresetClass
       
   243 	//used to return an array of cached presets to the UI
       
   244 	CArrayPtrFlat<CIRIsdsPreset>* iPtrPreset;
       
   245 	
       
   246 	//! Array of Pointers to CategoryClass	
       
   247 	CArrayPtrFlat<CIRBrowseCatagoryItems>* iPtrCategory;
       
   248 	
       
   249 	//! Array of Pointers to BrowseCategoryClass
       
   250 	CArrayPtrFlat<CIRBrowseChannelItems>* iPtrChannel;
       
   251 	
       
   252 	//ota info holding object
       
   253 	CIROTAUpdate* iOTA;
       
   254 	//!Observer class for cache
       
   255 	MIRCacheObserver& iCacheObserver;
       
   256 	
       
   257 	//To store the logo data which is retrieved from the cache
       
   258 	RBuf8 iLogoData;
       
   259 	
       
   260 	//!time stamp string in HTTP format,used if cache is stale
       
   261  	TTime iLastModified;
       
   262  	
       
   263  	//ETag header assaociated witht the logo data
       
   264  	TBuf8< KMAXHEADER > iETag;
       
   265 	
       
   266 private:
       
   267 	/** 
       
   268      * Array of cache observers
       
   269      */
       
   270     RPointerArray<MIRCacheObserver> iCacheObservers;
       
   271     RDbNamedDatabase iCacheDb;
       
   272     TBool iOpen;
       
   273     //! fileserver session
       
   274 	RFs iFsSession;
       
   275 	TFileName iDatabaseFileName;
       
   276 	//central repository settings handle
       
   277 	CIRSettings* iSettings;
       
   278 	CIRCacheCleanup* iCleanup;
       
   279 	TInt iCacheDbSize;
       
   280 	};
       
   281 #endif //CIRCACHEMGMT_H