author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 31 Aug 2010 16:34:26 +0300 | |
branch | RCL_3 |
changeset 43 | c1f20ce4abcf |
parent 2 | 4122176ea935 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1996-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_cache.h |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
/** |
|
19 |
@file |
|
20 |
@internalTechnology |
|
21 |
*/ |
|
22 |
||
2
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
23 |
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
24 |
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
25 |
//!! |
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
26 |
//!! WARNING!! DO NOT edit this file !! '\sfat' component is obsolete and is not being used. '\sfat32'replaces it |
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
27 |
//!! |
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
28 |
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
29 |
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
30 |
|
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
31 |
|
0 | 32 |
#ifndef SL_CACHE_H |
33 |
#define SL_CACHE_H |
|
34 |
||
35 |
||
36 |
//--------------------------------------------------------------------------------------------------------------------------------- |
|
37 |
//-- dedicated FAT directory cache related stuff |
|
38 |
||
39 |
//-- if defined, a dedicated cache will be used for FAT directories |
|
40 |
#define ENABLE_DEDICATED_DIR_CACHE |
|
41 |
||
42 |
//--------------------------------------------------------------------------------------------------------------------------------- |
|
43 |
||
44 |
||
45 |
/** |
|
46 |
An abstract interface to the media Write-Through cache |
|
47 |
*/ |
|
48 |
class MWTCacheInterface |
|
49 |
{ |
|
50 |
public: |
|
51 |
||
2
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
52 |
/** Enums for control functions. See Control() */ |
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
53 |
enum TControl |
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
54 |
{ |
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
55 |
EDisableCache = 0, ///< disable/enable cache, can be used for debug purposes |
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
56 |
EDumpCache = 1, ///< print full cache content, can be used for debug purposes |
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
57 |
ECacheInfo = 2, ///< print cache info, can be used for debug purposes |
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
58 |
}; |
0 | 59 |
|
60 |
virtual ~MWTCacheInterface() {} |
|
61 |
||
62 |
/** the same meaning and parameters as in CRawDisk::ReadL */ |
|
63 |
virtual void ReadL(TInt64 aPos, TInt aLength, TDes8& aDes)=0; |
|
64 |
||
65 |
/** the same meaning and parameters as in CRawDisk::WriteL */ |
|
66 |
virtual void WriteL(TInt64 aPos,const TDesC8& aDes)=0; |
|
67 |
||
68 |
/** Invalidates whole directory cache*/ |
|
69 |
virtual void InvalidateCache(void)=0; |
|
70 |
||
71 |
/** invalidate a single cache page if the aPos is cached*/ |
|
72 |
virtual void InvalidateCachePage(TUint64 aPos)=0; |
|
73 |
||
74 |
/** |
|
75 |
Finds out if the media position "aPosToSearch" is in the cache and returns cache page information in this case. |
|
76 |
||
77 |
@param aPosToSearch linear media position to lookup in the cache |
|
78 |
@param aCachedPosStart if "aPosToSearch" is cached, here will be media position of this page start |
|
79 |
||
80 |
@return 0 if aPosToSearch isn't cached, otherwise cache page size in bytes (see also aCachedPosStart). |
|
81 |
*/ |
|
82 |
virtual TUint32 PosCached(const TInt64& aPosToSearch, TInt64& aCachedPosStart) = 0; |
|
83 |
||
84 |
/** |
|
85 |
@return size of the cache in bytes. Can be 0. |
|
86 |
*/ |
|
87 |
virtual TUint32 CacheSizeInBytes() const = 0; |
|
88 |
||
89 |
/** |
|
90 |
Make the page indexed by aPos the MRU page in the cache. |
|
91 |
Assumes cache evicts pages according to LRU algorithm. |
|
92 |
*/ |
|
93 |
virtual void MakePageMRU(TInt64 aPos) = 0; |
|
94 |
||
95 |
/** |
|
96 |
@return log2 number of the size of the cache in bytes. |
|
97 |
*/ |
|
98 |
virtual TUint32 PageSizeInBytesLog2() const = 0; |
|
99 |
||
100 |
/** |
|
101 |
Control method. |
|
102 |
||
103 |
@param aFunction control function |
|
104 |
@param aParam1 just arbitrary parameter |
|
105 |
@param aParam2 just arbitrary parameter |
|
106 |
@return Standard error code. |
|
107 |
*/ |
|
108 |
virtual TInt Control(TUint32 aFunction, TUint32 aParam1, TAny* aParam2)=0; |
|
109 |
||
110 |
/** |
|
111 |
Set cache base position at aBasePos |
|
112 |
@param aBasePos base position of the cache pages. Affects pages alignment. |
|
113 |
*/ |
|
114 |
virtual void SetCacheBasePos(TInt64 aBasePos)=0; |
|
115 |
||
116 |
}; |
|
117 |
||
118 |
//--------------------------------------------------------------------------------------------------------------------------------- |
|
119 |
||
120 |
/** |
|
121 |
This class represents the media Write-Through cache page |
|
122 |
*/ |
|
123 |
class CWTCachePage |
|
124 |
{ |
|
125 |
public: |
|
126 |
||
127 |
static CWTCachePage* NewL(TUint32 aPageSizeLog2); |
|
128 |
void ConstructL(TUint32 aPageSizeLog2); |
|
129 |
||
130 |
~CWTCachePage(); |
|
131 |
||
132 |
inline TBool PosCached(TInt64 aPos) const; |
|
133 |
inline TUint32 PosInCachePage(TInt64 aPos) const; |
|
134 |
inline TUint8* PtrInCachePage(TInt64 aPos) const; |
|
135 |
inline TUint32 PageSize() const; |
|
136 |
||
137 |
protected: |
|
138 |
||
139 |
CWTCachePage(); |
|
140 |
CWTCachePage(const CWTCachePage&); |
|
141 |
CWTCachePage& operator=(const CWTCachePage&); |
|
142 |
||
143 |
public: |
|
144 |
||
145 |
TInt32 iValid; ///< 0 if the page doesn't contain valid data |
|
146 |
TInt64 iStartPos; ///< cache page base media position |
|
147 |
RBuf8 iData; ///< page Data |
|
148 |
}; |
|
149 |
||
150 |
//--------------------------------------------------------------------------------------------------------------------------------- |
|
151 |
||
152 |
/** |
|
153 |
Media Write-through cache. |
|
154 |
*/ |
|
155 |
class CMediaWTCache : public CBase, public MWTCacheInterface |
|
156 |
{ |
|
157 |
public: |
|
158 |
~CMediaWTCache(); |
|
159 |
||
160 |
static CMediaWTCache* NewL(TFatDriveInterface& aDrive, TUint32 aNumPages, TUint32 aPageSizeLog2); |
|
161 |
||
162 |
void ConstructL(TUint32 aNumPages, TUint32 aPageSizeLog2); |
|
163 |
||
164 |
//-- overloads from the base class |
|
165 |
void ReadL (TInt64 aPos,TInt aLength,TDes8& aDes); |
|
166 |
void WriteL(TInt64 aPos,const TDesC8& aDes); |
|
167 |
void InvalidateCache(void); |
|
168 |
void InvalidateCachePage(TUint64 aPos); |
|
169 |
||
170 |
||
171 |
TUint32 PosCached(const TInt64& aPosToSearch, TInt64& aCachedPosStart); |
|
172 |
TUint32 CacheSizeInBytes() const; |
|
2
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
173 |
void MakePageMRU(TInt64 aPos); |
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
174 |
TUint32 PageSizeInBytesLog2() const; |
0 | 175 |
TInt Control(TUint32 aFunction, TUint32 aParam1, TAny* aParam2); |
176 |
inline void SetCacheBasePos(TInt64 aBasePos); |
|
177 |
//-- |
|
178 |
||
179 |
protected: |
|
180 |
CMediaWTCache(); |
|
181 |
CMediaWTCache(TFatDriveInterface& aDrive); |
|
182 |
||
183 |
inline TInt64 CalcPageStartPos(TInt64 aPos) const; |
|
184 |
inline TUint32 PageSize() const; |
|
185 |
||
186 |
void MakePageLRU(TInt aPageNo); |
|
187 |
||
188 |
TInt FindPageByPos(TInt64 aPos) const; |
|
189 |
TUint32 GrabPage() const; |
|
190 |
TUint32 GrabReadPageL(TInt64 aPos); |
|
191 |
TUint32 FindOrGrabReadPageL(TInt64 aPos); |
|
192 |
||
193 |
protected: |
|
194 |
TFatDriveInterface& iDrive; ///< reference to the driver for media access |
|
195 |
TUint32 iPageSizeLog2; ///< Log2 (cache page size) |
|
196 |
mutable TBool iAllPagesValid;///< ETrue if all cache pages have valid data |
|
197 |
TInt64 iCacheBasePos; ///< Cache pages base position, used to align them at cluster size |
|
198 |
RPointerArray<CWTCachePage> iPages; ///< array of pointers to the cache pages. Used for organising LRU list |
|
199 |
TUint32 iCacheDisabled :1; ///< if not 0 the cache is disabled totally and all reads and writes go via TFatDriveInterface directly |
|
200 |
}; |
|
201 |
||
202 |
||
203 |
||
204 |
||
205 |
#include"sl_cache.inl" |
|
206 |
||
207 |
#endif //SL_CACHE_H |
|
208 |
||
209 |
||
210 |
||
211 |