userlibandfileserver/fileserver/sfat/sl_dir_cache.h
changeset 15 4122176ea935
parent 0 a41df078684a
equal deleted inserted replaced
0:a41df078684a 15:4122176ea935
    18 /**
    18 /**
    19  @file
    19  @file
    20  @internalTechnology
    20  @internalTechnology
    21 */
    21 */
    22 
    22 
       
    23 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       
    24 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       
    25 //!!
       
    26 //!! WARNING!! DO NOT edit this file !! '\sfat' component is obsolete and is not being used. '\sfat32'replaces it
       
    27 //!!
       
    28 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       
    29 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       
    30 
       
    31 
    23 #ifndef SL_DIR_CACHE_H
    32 #ifndef SL_DIR_CACHE_H
    24 #define SL_DIR_CACHE_H
    33 #define SL_DIR_CACHE_H
    25 
    34 
    26 #include "sf_memory_man.h"
    35 #include "sf_memory_man.h"
    27 #include "sf_memory_client.h"
    36 #include "sf_memory_client.h"
    28 #include "sl_cache.h"
    37 #include "sl_cache.h"
    29 #include <e32hashtab.h>
    38 #include <e32hashtab.h>
    30 
    39 
    31 //---------------------------------------------------------------------------------------------------------------------------------
    40 //---------------------------------------------------------------------------------------------------------------------------------
    32 class 	CDynamicDirCache;
    41 class   CDynamicDirCache;
    33 
    42 
    34 
    43 
    35 /**
    44 /**
    36 The dynamic directory cache page class
    45 The dynamic directory cache page class
    37 */
    46 */
    38 class TDynamicDirCachePage
    47 class TDynamicDirCachePage
    39     {
    48     {
    40 public:
    49 public:
    41 	enum TPageType
    50     enum TPageType
    42 		{
    51         {
    43 		EUnknown,
    52         EUnknown,
    44 		ELocked,
    53         ELocked,
    45 		EUnlocked,
    54         EUnlocked,
    46 		EActivePage,
    55         EActivePage,
    47 		};
    56         };
    48 
    57 
    49 public:
    58 public:
    50 	~TDynamicDirCachePage();
    59     ~TDynamicDirCachePage();
    51 	static TDynamicDirCachePage* NewL(CDynamicDirCache* aOwnerCache, TInt64 aStartMedPos, TUint8* aStartRamAddr);
    60     static TDynamicDirCachePage* NewL(CDynamicDirCache* aOwnerCache, TInt64 aStartMedPos, TUint8* aStartRamAddr);
    52 	
    61     
    53 	inline void	SetLocked(TBool);
    62     inline void SetLocked(TBool);
    54 	inline TBool	IsLocked() const;
    63     inline TBool    IsLocked() const;
    55 	inline TUint8*	StartPtr()	const;
    64     inline TUint8*  StartPtr()  const;
    56 	inline void 	SetStartPtr(TUint8* aPtr);
    65     inline void     SetStartPtr(TUint8* aPtr);
    57 	inline void	SetValid(TBool aIsValid);
    66     inline void SetValid(TBool aIsValid);
    58 	inline TBool	IsValid()	const;
    67     inline TBool    IsValid()   const;
    59 	inline void	SetPageType(TPageType aType);
    68     inline void SetPageType(TPageType aType);
    60 	inline TPageType PageType();
    69     inline TPageType PageType();
    61 
    70 
    62 	inline TUint32	PageSizeInBytes() const;
    71     inline TUint32  PageSizeInBytes() const;
    63     inline TUint32	PageSizeInSegs() const;
    72     inline TUint32  PageSizeInSegs() const;
    64 
    73 
    65     inline void	SetPos(TInt64 aPos);
    74     inline void SetPos(TInt64 aPos);
    66     inline void	ResetPos();
    75     inline void ResetPos();
    67 	inline TInt64	StartPos()	const;
    76     inline TInt64   StartPos()  const;
    68 
    77 
    69 	inline TUint8*	PtrInPage(TInt64 aPos) const;
    78     inline TUint8*  PtrInPage(TInt64 aPos) const;
    70 	inline TBool	PosCachedInPage(TInt64 aPos) const;
    79     inline TBool    PosCachedInPage(TInt64 aPos) const;
    71 
    80 
    72 	inline void	Deque();
    81     inline void Deque();
    73 
    82 
    74 private:
    83 private:
    75 	// declared to disable copying and assignment
    84     // declared to disable copying and assignment
    76 	TDynamicDirCachePage& operator=(const TDynamicDirCachePage&);
    85     TDynamicDirCachePage& operator=(const TDynamicDirCachePage&);
    77 	TDynamicDirCachePage(const TDynamicDirCachePage&);
    86     TDynamicDirCachePage(const TDynamicDirCachePage&);
    78 
    87 
    79 	// private constructor, as this class is not supposed to be created on stack
    88     // private constructor, as this class is not supposed to be created on stack
    80 	TDynamicDirCachePage(CDynamicDirCache* aOwnerCache, TInt64 aStartMedPos, TUint8* aStartRamAddr);
    89     TDynamicDirCachePage(CDynamicDirCache* aOwnerCache, TInt64 aStartMedPos, TUint8* aStartRamAddr);
    81 
    90 
    82 public:
    91 public:
    83 	TDblQueLink			iLink;			///< the embedded link object, see TCachePageList
    92     TDblQueLink         iLink;          ///< the embedded link object, see TCachePageList
    84     TInt64  			iStartMedPos;	///< the starting media address that this page caches
    93     TInt64              iStartMedPos;   ///< the starting media address that this page caches
    85     TUint8*				iStartRamAddr;	///< the starting ram address that thsi page lives
    94     TUint8*             iStartRamAddr;  ///< the starting ram address that thsi page lives
    86     CDynamicDirCache* 	iOwnerCache;	///< pointer to the cache that owns this page
    95     CDynamicDirCache*   iOwnerCache;    ///< pointer to the cache that owns this page
    87     TBool				iValid 	:1;		///< flag to indicate the validity of the page content
    96     TBool               iValid  :1;     ///< flag to indicate the validity of the page content
    88 	TBool				iLocked :1;		///< flag to indicate if the page is locked or not
    97     TBool               iLocked :1;     ///< flag to indicate if the page is locked or not
    89 	TPageType			iType;			///< page type, see TPageType
    98     TPageType           iType;          ///< page type, see TPageType
    90     };
    99     };
    91 
   100 
    92 /**
   101 /**
    93 The lookup table entry class
   102 The lookup table entry class
    94 @see	CDynamicDirCache
   103 @see    CDynamicDirCache
    95 */
   104 */
    96 class TLookupEntry
   105 class TLookupEntry
    97 	{
   106     {
    98 	public:
   107     public:
    99 		TLookupEntry(): iPos(0), iRange(0), iPage(NULL) {};
   108         TLookupEntry(): iPos(0), iRange(0), iPage(NULL) {};
   100 		TLookupEntry(TInt64 aPos, TUint32 aRange, TDynamicDirCachePage* aPage): iPos(aPos), iRange(aRange), iPage(aPage) {};
   109         TLookupEntry(TInt64 aPos, TUint32 aRange, TDynamicDirCachePage* aPage): iPos(aPos), iRange(aRange), iPage(aPage) {};
   101 	public:
   110     public:
   102 		TInt64 					iPos;
   111         TInt64                  iPos;
   103 		TUint32					iRange;
   112         TUint32                 iRange;
   104 		TDynamicDirCachePage* 	iPage;
   113         TDynamicDirCachePage*   iPage;
   105 	};
   114     };
   106 
   115 
   107 //---------------------------------------------------------------------------------------------------------------------------------
   116 //---------------------------------------------------------------------------------------------------------------------------------
   108 typedef TDblQue<TDynamicDirCachePage> TCachePageList;
   117 typedef TDblQue<TDynamicDirCachePage> TCachePageList;
   109 /**
   118 /**
   110 Dynamic directory cache.
   119 Dynamic directory cache.
   112 Provides caching FAT directory data.
   121 Provides caching FAT directory data.
   113 */
   122 */
   114 class CDynamicDirCache : public CBase, public MWTCacheInterface
   123 class CDynamicDirCache : public CBase, public MWTCacheInterface
   115     {
   124     {
   116 public:
   125 public:
   117 	~CDynamicDirCache();
   126     ~CDynamicDirCache();
   118 	static CDynamicDirCache* NewL(TFatDriveInterface& aDrive, TUint32 aMinPageNum, TUint32 aMaxPageNum, TUint32 aPageSizeLog2, const TDesC& aClientName);
   127     static CDynamicDirCache* NewL(TFatDriveInterface& aDrive, TUint32 aMinPageNum, TUint32 aMaxPageNum, TUint32 aPageSizeLog2, const TDesC& aClientName);
   119 
   128 
   120 	//-- overloads from the base class
   129     //-- overloads from the base class
   121 	void    ReadL (TInt64 aPos, TInt aLength, TDes8& aDes);
   130     void    ReadL (TInt64 aPos, TInt aLength, TDes8& aDes);
   122 	void    WriteL(TInt64 aPos, const TDesC8& aDes);
   131     void    WriteL(TInt64 aPos, const TDesC8& aDes);
   123 	void    InvalidateCache(void);
   132     void    InvalidateCache(void);
   124     void    InvalidateCachePage(TUint64 aPos);
   133     void    InvalidateCachePage(TUint64 aPos);
   125 
   134 
   126 	TUint32 PosCached(const TInt64& aPosToSearch, TInt64& aCachedPosStart);
   135     TUint32 PosCached(const TInt64& aPosToSearch, TInt64& aCachedPosStart);
   127 	TUint32 CacheSizeInBytes()  const;
   136     TUint32 CacheSizeInBytes()  const;
   128 	TInt    Control(TUint32 aFunction, TUint32 aParam1, TAny* aParam2);
   137     TInt    Control(TUint32 aFunction, TUint32 aParam1, TAny* aParam2);
   129 	void 	SetCacheBasePos(TInt64 aBasePos);
   138     void    SetCacheBasePos(TInt64 aBasePos);
   130 	void 	MakePageMRU(TInt64 aPos);
   139     void    MakePageMRU(TInt64 aPos);
   131 	TUint32	PageSizeInBytesLog2() const;
   140     TUint32 PageSizeInBytesLog2() const;
   132 	
   141     
   133 	TUint32 PageSizeInSegs() const;
   142     TUint32 PageSizeInSegs() const;
   134 
   143 
   135     // Debugging functions
   144     // Debugging functions
   136 	void Dump();
   145     void Dump();
   137 	void Info() const;
   146     void Info() const;
   138 
   147 
   139 protected:
   148 protected:
   140 	CDynamicDirCache(TFatDriveInterface& aDrive, TUint32 aMinSizeInBytes, TUint32 aMaxSizeInBytes, TUint32 aPageSizeInBytesLog2);
   149     CDynamicDirCache(TFatDriveInterface& aDrive, TUint32 aMinSizeInBytes, TUint32 aMaxSizeInBytes, TUint32 aPageSizeInBytesLog2);
   141 	void ConstructL(const TDesC& aClientName);
   150     void ConstructL(const TDesC& aClientName);
   142 
   151 
   143 	void ReadDataFromSinglePageL(TInt64 aPos, TInt aLength, TDes8& aDes);
   152     void ReadDataFromSinglePageL(TInt64 aPos, TInt aLength, TDes8& aDes);
   144 	void WriteDataOntoSinglePageL(TInt64 aPos, const TUint8* aData, TUint32 aDataLen);
   153     void WriteDataOntoSinglePageL(TInt64 aPos, const TUint8* aData, TUint32 aDataLen);
   145 	TDynamicDirCachePage* FindPageByPos(TInt64 aPos);
   154     TDynamicDirCachePage* FindPageByPos(TInt64 aPos);
   146 	TDynamicDirCachePage* UpdateActivePageL(TInt64 aPos);
   155     TDynamicDirCachePage* UpdateActivePageL(TInt64 aPos);
   147 	TDynamicDirCachePage* AllocateAndLockNewPageL(TInt64 aStartMedPos);
   156     TDynamicDirCachePage* AllocateAndLockNewPageL(TInt64 aStartMedPos);
   148 	TUint8* LockPage(TDynamicDirCachePage* aPage);
   157     TUint8* LockPage(TDynamicDirCachePage* aPage);
   149 	TInt 	UnlockPage(TDynamicDirCachePage* aPage);
   158     TInt    UnlockPage(TDynamicDirCachePage* aPage);
   150 	TInt 	DecommitPage(TDynamicDirCachePage* aPage);
   159     TInt    DecommitPage(TDynamicDirCachePage* aPage);
   151 	inline TInt64  CalcPageStartPos(TInt64 aPos) const;
   160     inline TInt64  CalcPageStartPos(TInt64 aPos) const;
   152 	void CheckThresholds();
   161     void CheckThresholds();
   153 	inline TBool CacheIsFull() const;
   162     inline TBool CacheIsFull() const;
   154 	inline TUint32 MaxCacheSizeInPages() const;
   163     inline TUint32 MaxCacheSizeInPages() const;
   155 	TInt DeQueue(TDynamicDirCachePage* aPage);
   164     TInt DeQueue(TDynamicDirCachePage* aPage);
   156 	TInt AddFirstOntoQueue(TDynamicDirCachePage* aPage, TDynamicDirCachePage::TPageType aType);
   165     TInt AddFirstOntoQueue(TDynamicDirCachePage* aPage, TDynamicDirCachePage::TPageType aType);
   157 	TInt LookupTblRemove(TInt64 aPagePos);
   166     TInt LookupTblRemove(TInt64 aPagePos);
   158 	TInt LookupTblAdd(TDynamicDirCachePage* aPage);
   167     TInt LookupTblAdd(TDynamicDirCachePage* aPage);
   159 	TDynamicDirCachePage* LookupTblFind(TInt64 aPos);
   168     TDynamicDirCachePage* LookupTblFind(TInt64 aPos);
   160 	TInt ResetPagePos(TDynamicDirCachePage* aPage);
   169     TInt ResetPagePos(TDynamicDirCachePage* aPage);
   161 	void MakePageLastLocked(TDynamicDirCachePage* aPage);
   170     void MakePageLastLocked(TDynamicDirCachePage* aPage);
   162 	
   171     
   163 private:
   172 private:
   164 	TUint32				iPageSizeLog2;		///< log2 value of cache pages size in bytes
   173     TUint32             iPageSizeLog2;      ///< log2 value of cache pages size in bytes
   165 	TUint32				iMinCacheSizeInBytes;	///< minimum cache data size
   174     TUint32             iMinCacheSizeInBytes;   ///< minimum cache data size
   166 	TUint32				iMaxCacheSizeInBytes;	///< maximum cache data size
   175     TUint32             iMaxCacheSizeInBytes;   ///< maximum cache data size
   167 	TUint32				iMinSizeInPages;	///< minimum cache page number
   176     TUint32             iMinSizeInPages;    ///< minimum cache page number
   168 	TUint32				iMaxSizeInPages;	///< maximum cache page number
   177     TUint32             iMaxSizeInPages;    ///< maximum cache page number
   169 	TUint32             iPageSizeInBytes;	///< cache page size in bytes
   178     TUint32             iPageSizeInBytes;   ///< cache page size in bytes
   170 	TInt64              iCacheBasePos; 		///< cache pages base position, used to align them at cluster size
   179     TInt64              iCacheBasePos;      ///< cache pages base position, used to align them at cluster size
   171 
   180 
   172 	TFatDriveInterface& iDrive;        		///< reference to the driver for media access
   181     TFatDriveInterface& iDrive;             ///< reference to the driver for media access
   173 	TUint32             iCacheDisabled : 1; ///< if not 0 the cache is disabled totally and all reads and writes go via TFatDriveInterface directly
   182     TUint32             iCacheDisabled : 1; ///< if not 0 the cache is disabled totally and all reads and writes go via TFatDriveInterface directly
   174 
   183 
   175 	TDynamicDirCachePage* 	iActivePage;	///< a unique page in cache, used to read new page before make it MRU or have it replaced
   184     TDynamicDirCachePage*   iActivePage;    ///< a unique page in cache, used to read new page before make it MRU or have it replaced
   176 	
   185     
   177 	// data structures for LRU page list	
   186     // data structures for LRU page list    
   178 	TCachePageList 	iLockedQ;				///< the locked queue that manages all locked pages, limited by minimum page number
   187     TCachePageList  iLockedQ;               ///< the locked queue that manages all locked pages, limited by minimum page number
   179 	TCachePageList 	iUnlockedQ;				///< the unlocked queue that manages all locked pages, limited by maximum page number - minimum page number
   188     TCachePageList  iUnlockedQ;             ///< the unlocked queue that manages all locked pages, limited by maximum page number - minimum page number
   180 	TUint32			iLockedQCount;
   189     TUint32         iLockedQCount;
   181 	TUint32			iUnlockedQCount;
   190     TUint32         iUnlockedQCount;
   182 
   191 
   183 	// data structures for look up table
   192     // data structures for look up table
   184 	THashFunction32<TLookupEntry> 	iHashFunction;
   193     THashFunction32<TLookupEntry>   iHashFunction;
   185 	TIdentityRelation<TLookupEntry>	iIdentityFunction;
   194     TIdentityRelation<TLookupEntry> iIdentityFunction;
   186 	RHashSet<TLookupEntry> 			iLookupTable;	///< a lookup table that used to speed up page look up
   195     RHashSet<TLookupEntry>          iLookupTable;   ///< a lookup table that used to speed up page look up
   187 
   196 
   188 	CCacheMemoryClient*	iCacheMemoryClient;	///< interface to cache memory manager
   197     CCacheMemoryClient* iCacheMemoryClient; ///< interface to cache memory manager
   189     };
   198     };
   190 
   199 
   191 #include"sl_dir_cache.inl"
   200 #include"sl_dir_cache.inl"
   192 
   201 
   193 #endif //SL_DIR_CACHE_H
   202 #endif //SL_DIR_CACHE_H