sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32\sfat32\inc\sl_dir_cache.h sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sl@0: //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sl@0: //!! sl@0: //!! WARNING!! DO NOT edit this file !! '\sfat' component is obsolete and is not being used. '\sfat32'replaces it sl@0: //!! sl@0: //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sl@0: //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sl@0: sl@0: sl@0: #ifndef SL_DIR_CACHE_H sl@0: #define SL_DIR_CACHE_H sl@0: sl@0: #include "sf_memory_man.h" sl@0: #include "sf_memory_client.h" sl@0: #include "sl_cache.h" sl@0: #include sl@0: sl@0: //--------------------------------------------------------------------------------------------------------------------------------- sl@0: class CDynamicDirCache; sl@0: sl@0: sl@0: /** sl@0: The dynamic directory cache page class sl@0: */ sl@0: class TDynamicDirCachePage sl@0: { sl@0: public: sl@0: enum TPageType sl@0: { sl@0: EUnknown, sl@0: ELocked, sl@0: EUnlocked, sl@0: EActivePage, sl@0: }; sl@0: sl@0: public: sl@0: ~TDynamicDirCachePage(); sl@0: static TDynamicDirCachePage* NewL(CDynamicDirCache* aOwnerCache, TInt64 aStartMedPos, TUint8* aStartRamAddr); sl@0: sl@0: inline void SetLocked(TBool); sl@0: inline TBool IsLocked() const; sl@0: inline TUint8* StartPtr() const; sl@0: inline void SetStartPtr(TUint8* aPtr); sl@0: inline void SetValid(TBool aIsValid); sl@0: inline TBool IsValid() const; sl@0: inline void SetPageType(TPageType aType); sl@0: inline TPageType PageType(); sl@0: sl@0: inline TUint32 PageSizeInBytes() const; sl@0: inline TUint32 PageSizeInSegs() const; sl@0: sl@0: inline void SetPos(TInt64 aPos); sl@0: inline void ResetPos(); sl@0: inline TInt64 StartPos() const; sl@0: sl@0: inline TUint8* PtrInPage(TInt64 aPos) const; sl@0: inline TBool PosCachedInPage(TInt64 aPos) const; sl@0: sl@0: inline void Deque(); sl@0: sl@0: private: sl@0: // declared to disable copying and assignment sl@0: TDynamicDirCachePage& operator=(const TDynamicDirCachePage&); sl@0: TDynamicDirCachePage(const TDynamicDirCachePage&); sl@0: sl@0: // private constructor, as this class is not supposed to be created on stack sl@0: TDynamicDirCachePage(CDynamicDirCache* aOwnerCache, TInt64 aStartMedPos, TUint8* aStartRamAddr); sl@0: sl@0: public: sl@0: TDblQueLink iLink; ///< the embedded link object, see TCachePageList sl@0: TInt64 iStartMedPos; ///< the starting media address that this page caches sl@0: TUint8* iStartRamAddr; ///< the starting ram address that thsi page lives sl@0: CDynamicDirCache* iOwnerCache; ///< pointer to the cache that owns this page sl@0: TBool iValid :1; ///< flag to indicate the validity of the page content sl@0: TBool iLocked :1; ///< flag to indicate if the page is locked or not sl@0: TPageType iType; ///< page type, see TPageType sl@0: }; sl@0: sl@0: /** sl@0: The lookup table entry class sl@0: @see CDynamicDirCache sl@0: */ sl@0: class TLookupEntry sl@0: { sl@0: public: sl@0: TLookupEntry(): iPos(0), iRange(0), iPage(NULL) {}; sl@0: TLookupEntry(TInt64 aPos, TUint32 aRange, TDynamicDirCachePage* aPage): iPos(aPos), iRange(aRange), iPage(aPage) {}; sl@0: public: sl@0: TInt64 iPos; sl@0: TUint32 iRange; sl@0: TDynamicDirCachePage* iPage; sl@0: }; sl@0: sl@0: //--------------------------------------------------------------------------------------------------------------------------------- sl@0: typedef TDblQue TCachePageList; sl@0: /** sl@0: Dynamic directory cache. sl@0: For now it is directly derived from MWTCacheInterface. sl@0: Provides caching FAT directory data. sl@0: */ sl@0: class CDynamicDirCache : public CBase, public MWTCacheInterface sl@0: { sl@0: public: sl@0: ~CDynamicDirCache(); sl@0: static CDynamicDirCache* NewL(TFatDriveInterface& aDrive, TUint32 aMinPageNum, TUint32 aMaxPageNum, TUint32 aPageSizeLog2, const TDesC& aClientName); sl@0: sl@0: //-- overloads from the base class sl@0: void ReadL (TInt64 aPos, TInt aLength, TDes8& aDes); sl@0: void WriteL(TInt64 aPos, const TDesC8& aDes); sl@0: void InvalidateCache(void); sl@0: void InvalidateCachePage(TUint64 aPos); sl@0: sl@0: TUint32 PosCached(const TInt64& aPosToSearch, TInt64& aCachedPosStart); sl@0: TUint32 CacheSizeInBytes() const; sl@0: TInt Control(TUint32 aFunction, TUint32 aParam1, TAny* aParam2); sl@0: void SetCacheBasePos(TInt64 aBasePos); sl@0: void MakePageMRU(TInt64 aPos); sl@0: TUint32 PageSizeInBytesLog2() const; sl@0: sl@0: TUint32 PageSizeInSegs() const; sl@0: sl@0: // Debugging functions sl@0: void Dump(); sl@0: void Info() const; sl@0: sl@0: protected: sl@0: CDynamicDirCache(TFatDriveInterface& aDrive, TUint32 aMinSizeInBytes, TUint32 aMaxSizeInBytes, TUint32 aPageSizeInBytesLog2); sl@0: void ConstructL(const TDesC& aClientName); sl@0: sl@0: void ReadDataFromSinglePageL(TInt64 aPos, TInt aLength, TDes8& aDes); sl@0: void WriteDataOntoSinglePageL(TInt64 aPos, const TUint8* aData, TUint32 aDataLen); sl@0: TDynamicDirCachePage* FindPageByPos(TInt64 aPos); sl@0: TDynamicDirCachePage* UpdateActivePageL(TInt64 aPos); sl@0: TDynamicDirCachePage* AllocateAndLockNewPageL(TInt64 aStartMedPos); sl@0: TUint8* LockPage(TDynamicDirCachePage* aPage); sl@0: TInt UnlockPage(TDynamicDirCachePage* aPage); sl@0: TInt DecommitPage(TDynamicDirCachePage* aPage); sl@0: inline TInt64 CalcPageStartPos(TInt64 aPos) const; sl@0: void CheckThresholds(); sl@0: inline TBool CacheIsFull() const; sl@0: inline TUint32 MaxCacheSizeInPages() const; sl@0: TInt DeQueue(TDynamicDirCachePage* aPage); sl@0: TInt AddFirstOntoQueue(TDynamicDirCachePage* aPage, TDynamicDirCachePage::TPageType aType); sl@0: TInt LookupTblRemove(TInt64 aPagePos); sl@0: TInt LookupTblAdd(TDynamicDirCachePage* aPage); sl@0: TDynamicDirCachePage* LookupTblFind(TInt64 aPos); sl@0: TInt ResetPagePos(TDynamicDirCachePage* aPage); sl@0: void MakePageLastLocked(TDynamicDirCachePage* aPage); sl@0: sl@0: private: sl@0: TUint32 iPageSizeLog2; ///< log2 value of cache pages size in bytes sl@0: TUint32 iMinCacheSizeInBytes; ///< minimum cache data size sl@0: TUint32 iMaxCacheSizeInBytes; ///< maximum cache data size sl@0: TUint32 iMinSizeInPages; ///< minimum cache page number sl@0: TUint32 iMaxSizeInPages; ///< maximum cache page number sl@0: TUint32 iPageSizeInBytes; ///< cache page size in bytes sl@0: TInt64 iCacheBasePos; ///< cache pages base position, used to align them at cluster size sl@0: sl@0: TFatDriveInterface& iDrive; ///< reference to the driver for media access sl@0: TUint32 iCacheDisabled : 1; ///< if not 0 the cache is disabled totally and all reads and writes go via TFatDriveInterface directly sl@0: sl@0: TDynamicDirCachePage* iActivePage; ///< a unique page in cache, used to read new page before make it MRU or have it replaced sl@0: sl@0: // data structures for LRU page list sl@0: TCachePageList iLockedQ; ///< the locked queue that manages all locked pages, limited by minimum page number sl@0: TCachePageList iUnlockedQ; ///< the unlocked queue that manages all locked pages, limited by maximum page number - minimum page number sl@0: TUint32 iLockedQCount; sl@0: TUint32 iUnlockedQCount; sl@0: sl@0: // data structures for look up table sl@0: THashFunction32 iHashFunction; sl@0: TIdentityRelation iIdentityFunction; sl@0: RHashSet iLookupTable; ///< a lookup table that used to speed up page look up sl@0: sl@0: CCacheMemoryClient* iCacheMemoryClient; ///< interface to cache memory manager sl@0: }; sl@0: sl@0: #include"sl_dir_cache.inl" sl@0: sl@0: #endif //SL_DIR_CACHE_H sl@0: sl@0: sl@0: sl@0: