|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // f32\sfat32\inc\sl_dir_cache.h |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 #ifndef SL_DIR_CACHE_H |
|
24 #define SL_DIR_CACHE_H |
|
25 |
|
26 #include "sf_memory_man.h" |
|
27 #include "sf_memory_client.h" |
|
28 #include "sl_cache.h" |
|
29 #include <e32hashtab.h> |
|
30 |
|
31 //--------------------------------------------------------------------------------------------------------------------------------- |
|
32 class CDynamicDirCache; |
|
33 |
|
34 |
|
35 /** |
|
36 The dynamic directory cache page class |
|
37 */ |
|
38 class TDynamicDirCachePage |
|
39 { |
|
40 public: |
|
41 enum TPageType |
|
42 { |
|
43 EUnknown, |
|
44 ELocked, |
|
45 EUnlocked, |
|
46 EActivePage, |
|
47 }; |
|
48 |
|
49 public: |
|
50 ~TDynamicDirCachePage(); |
|
51 static TDynamicDirCachePage* NewL(CDynamicDirCache* aOwnerCache, TInt64 aStartMedPos, TUint8* aStartRamAddr); |
|
52 |
|
53 inline void SetLocked(TBool); |
|
54 inline TBool IsLocked() const; |
|
55 inline TUint8* StartPtr() const; |
|
56 inline void SetStartPtr(TUint8* aPtr); |
|
57 inline void SetValid(TBool aIsValid); |
|
58 inline TBool IsValid() const; |
|
59 inline void SetPageType(TPageType aType); |
|
60 inline TPageType PageType(); |
|
61 |
|
62 inline TUint32 PageSizeInBytes() const; |
|
63 inline TUint32 PageSizeInSegs() const; |
|
64 |
|
65 inline void SetPos(TInt64 aPos); |
|
66 inline void ResetPos(); |
|
67 inline TInt64 StartPos() const; |
|
68 |
|
69 inline TUint8* PtrInPage(TInt64 aPos) const; |
|
70 inline TBool PosCachedInPage(TInt64 aPos) const; |
|
71 |
|
72 inline void Deque(); |
|
73 |
|
74 private: |
|
75 // declared to disable copying and assignment |
|
76 TDynamicDirCachePage& operator=(const TDynamicDirCachePage&); |
|
77 TDynamicDirCachePage(const TDynamicDirCachePage&); |
|
78 |
|
79 // private constructor, as this class is not supposed to be created on stack |
|
80 TDynamicDirCachePage(CDynamicDirCache* aOwnerCache, TInt64 aStartMedPos, TUint8* aStartRamAddr); |
|
81 |
|
82 public: |
|
83 TDblQueLink iLink; ///< the embedded link object, see TCachePageList |
|
84 TInt64 iStartMedPos; ///< the starting media address that this page caches |
|
85 TUint8* iStartRamAddr; ///< the starting ram address that thsi page lives |
|
86 CDynamicDirCache* iOwnerCache; ///< pointer to the cache that owns this page |
|
87 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 |
|
89 TPageType iType; ///< page type, see TPageType |
|
90 }; |
|
91 |
|
92 /** |
|
93 The lookup table entry class |
|
94 @see CDynamicDirCache |
|
95 */ |
|
96 class TLookupEntry |
|
97 { |
|
98 public: |
|
99 TLookupEntry(): iPos(0), iRange(0), iPage(NULL) {}; |
|
100 TLookupEntry(TInt64 aPos, TUint32 aRange, TDynamicDirCachePage* aPage): iPos(aPos), iRange(aRange), iPage(aPage) {}; |
|
101 public: |
|
102 TInt64 iPos; |
|
103 TUint32 iRange; |
|
104 TDynamicDirCachePage* iPage; |
|
105 }; |
|
106 |
|
107 //--------------------------------------------------------------------------------------------------------------------------------- |
|
108 typedef TDblQue<TDynamicDirCachePage> TCachePageList; |
|
109 /** |
|
110 Dynamic directory cache. |
|
111 For now it is directly derived from MWTCacheInterface. |
|
112 Provides caching FAT directory data. |
|
113 */ |
|
114 class CDynamicDirCache : public CBase, public MWTCacheInterface |
|
115 { |
|
116 public: |
|
117 ~CDynamicDirCache(); |
|
118 static CDynamicDirCache* NewL(TFatDriveInterface& aDrive, TUint32 aMinPageNum, TUint32 aMaxPageNum, TUint32 aPageSizeLog2, const TDesC& aClientName); |
|
119 |
|
120 //-- overloads from the base class |
|
121 void ReadL (TInt64 aPos, TInt aLength, TDes8& aDes); |
|
122 void WriteL(TInt64 aPos, const TDesC8& aDes); |
|
123 void InvalidateCache(void); |
|
124 void InvalidateCachePage(TUint64 aPos); |
|
125 |
|
126 TUint32 PosCached(const TInt64& aPosToSearch, TInt64& aCachedPosStart); |
|
127 TUint32 CacheSizeInBytes() const; |
|
128 TInt Control(TUint32 aFunction, TUint32 aParam1, TAny* aParam2); |
|
129 void SetCacheBasePos(TInt64 aBasePos); |
|
130 void MakePageMRU(TInt64 aPos); |
|
131 TUint32 PageSizeInBytesLog2() const; |
|
132 |
|
133 TUint32 PageSizeInSegs() const; |
|
134 |
|
135 // Debugging functions |
|
136 void Dump(); |
|
137 void Info() const; |
|
138 |
|
139 protected: |
|
140 CDynamicDirCache(TFatDriveInterface& aDrive, TUint32 aMinSizeInBytes, TUint32 aMaxSizeInBytes, TUint32 aPageSizeInBytesLog2); |
|
141 void ConstructL(const TDesC& aClientName); |
|
142 |
|
143 void ReadDataFromSinglePageL(TInt64 aPos, TInt aLength, TDes8& aDes); |
|
144 void WriteDataOntoSinglePageL(TInt64 aPos, const TUint8* aData, TUint32 aDataLen); |
|
145 TDynamicDirCachePage* FindPageByPos(TInt64 aPos); |
|
146 TDynamicDirCachePage* UpdateActivePageL(TInt64 aPos); |
|
147 TDynamicDirCachePage* AllocateAndLockNewPageL(TInt64 aStartMedPos); |
|
148 TUint8* LockPage(TDynamicDirCachePage* aPage); |
|
149 TInt UnlockPage(TDynamicDirCachePage* aPage); |
|
150 TInt DecommitPage(TDynamicDirCachePage* aPage); |
|
151 inline TInt64 CalcPageStartPos(TInt64 aPos) const; |
|
152 void CheckThresholds(); |
|
153 inline TBool CacheIsFull() const; |
|
154 inline TUint32 MaxCacheSizeInPages() const; |
|
155 TInt DeQueue(TDynamicDirCachePage* aPage); |
|
156 TInt AddFirstOntoQueue(TDynamicDirCachePage* aPage, TDynamicDirCachePage::TPageType aType); |
|
157 TInt LookupTblRemove(TInt64 aPagePos); |
|
158 TInt LookupTblAdd(TDynamicDirCachePage* aPage); |
|
159 TDynamicDirCachePage* LookupTblFind(TInt64 aPos); |
|
160 TInt ResetPagePos(TDynamicDirCachePage* aPage); |
|
161 void MakePageLastLocked(TDynamicDirCachePage* aPage); |
|
162 |
|
163 private: |
|
164 TUint32 iPageSizeLog2; ///< log2 value of cache pages size in bytes |
|
165 TUint32 iMinCacheSizeInBytes; ///< minimum cache data size |
|
166 TUint32 iMaxCacheSizeInBytes; ///< maximum cache data size |
|
167 TUint32 iMinSizeInPages; ///< minimum cache page number |
|
168 TUint32 iMaxSizeInPages; ///< maximum cache page number |
|
169 TUint32 iPageSizeInBytes; ///< cache page size in bytes |
|
170 TInt64 iCacheBasePos; ///< cache pages base position, used to align them at cluster size |
|
171 |
|
172 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 |
|
174 |
|
175 TDynamicDirCachePage* iActivePage; ///< a unique page in cache, used to read new page before make it MRU or have it replaced |
|
176 |
|
177 // data structures for LRU page list |
|
178 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 |
|
180 TUint32 iLockedQCount; |
|
181 TUint32 iUnlockedQCount; |
|
182 |
|
183 // data structures for look up table |
|
184 THashFunction32<TLookupEntry> iHashFunction; |
|
185 TIdentityRelation<TLookupEntry> iIdentityFunction; |
|
186 RHashSet<TLookupEntry> iLookupTable; ///< a lookup table that used to speed up page look up |
|
187 |
|
188 CCacheMemoryClient* iCacheMemoryClient; ///< interface to cache memory manager |
|
189 }; |
|
190 |
|
191 #include"sl_dir_cache.inl" |
|
192 |
|
193 #endif //SL_DIR_CACHE_H |
|
194 |
|
195 |
|
196 |
|
197 |