author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 15 Sep 2010 13:42:27 +0300 | |
branch | RCL_3 |
changeset 268 | 345b1ca54e88 |
parent 257 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2006-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\sfile\sf_file_cache.h |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
/** |
|
19 |
@file |
|
20 |
@internalTechnology |
|
21 |
*/ |
|
22 |
||
23 |
||
24 |
#if !defined(__SF_FILE_CACHE_H__) |
|
25 |
#define __SF_FILE_CACHE_H__ |
|
26 |
||
27 |
#include "sf_cache_client.h" |
|
28 |
||
29 |
//#define _DEBUG_READ_AHEAD |
|
30 |
||
31 |
||
32 |
NONSHARABLE_CLASS(CFileCache) : public CFsDispatchObject |
|
33 |
{ |
|
34 |
public: |
|
35 |
static CFileCache* NewL(CFileShare& aShare); |
|
36 |
CFileCache* ReNewL(CFileShare& aShare); |
|
37 |
~CFileCache(); |
|
38 |
void Init(CFileShare& aShare); |
|
39 |
||
40 |
CMountCB& Mount() const; |
|
41 |
||
42 |
CFileCB* FileCB(); |
|
43 |
||
44 |
void ReadAhead(CFsMessageRequest& aMsgRequest, TUint aMode); |
|
45 |
void ResetReadAhead(); |
|
46 |
||
47 |
static TInt CompleteRead(CFsRequest* aMsgRequest); |
|
48 |
static TInt CompleteWrite(CFsRequest* aMsgRequest); |
|
49 |
TInt ReadBuffered(CFsMessageRequest& aMsgRequest, TUint aMode); |
|
50 |
TInt WriteBuffered(CFsMessageRequest& aMsgRequest, TUint aMode); |
|
51 |
||
52 |
inline TBool IsDirty() {return iDirtyDataOwner != NULL;} |
|
53 |
TInt FlushDirty(CFsRequest* aOldRequest = NULL); |
|
54 |
void Purge(TBool aPurgeDirty = EFalse); |
|
55 |
||
56 |
// from CFsObject |
|
57 |
void Close(); |
|
58 |
||
59 |
inline TInt64 Size64() const {return iSize64;} |
|
60 |
||
61 |
// Sets 64 bit (cached) file size |
|
62 |
void SetSize64(TInt64 aSize); |
|
63 |
||
64 |
TDrive& Drive() const; |
|
65 |
TUint32 NameHash() const; |
|
66 |
HBufC& FileNameF() const; |
|
67 |
||
68 |
void MarkFileClean(); |
|
69 |
||
70 |
private: |
|
71 |
void ConstructL(CFileShare& aShare); |
|
72 |
CFileCache(); |
|
73 |
||
74 |
void SetFileCacheFlags(CFileShare& aShare); |
|
75 |
||
76 |
TInt DoReadBuffered(CFsMessageRequest& aMsgRequest, TUint aMode, CFsClientMessageRequest*& aNewRequest); |
|
77 |
TInt DoWriteBuffered(CFsMessageRequest& aMsgRequest, CFsClientMessageRequest*& aNewRequest, TUint aMode); |
|
257 | 78 |
enum TFlushMode {EFlushSingle, EFlushAll}; |
248
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
79 |
TInt DoFlushDirty(CFsClientMessageRequest*& aNewRequest, CFsRequest* aOldRequest, TFlushMode aFlushMode); |
0 | 80 |
|
81 |
||
82 |
inline TInt SegmentSize() const; |
|
83 |
inline TInt SegmentSizeLog2() const; |
|
84 |
inline TInt64 SegmentSizeMask() const; |
|
85 |
||
86 |
inline void UpdateSharePosition(CFsMessageRequest& aMsgRequest, TMsgOperation& aCurrentOperation); |
|
87 |
||
88 |
static TInt CompleteFlushDirty(CFsRequest* aMsgRequest); |
|
89 |
TInt FlushDirtySm(CFsMessageRequest& aMsgRequest); |
|
90 |
||
91 |
TInt AllocateRequest(CFsClientMessageRequest*& aNewRequest, TBool aWrite, CSessionFs* aSession = NULL); |
|
92 |
||
93 |
void DoReadAhead(CFsMessageRequest& aMsgRequest, TUint aMode); |
|
94 |
||
95 |
void FileDirty(CFsMessageRequest& aMsgRequest); |
|
96 |
||
97 |
||
98 |
||
99 |
TInt HandleWriteDirtyError(TInt aError); |
|
100 |
void PropagateFlushErrorToAllFileShares(); |
|
101 |
||
102 |
static TInt ClosedTimerEvent(TAny* aFileCache); |
|
103 |
static TInt DirtyTimerEvent(TAny* aFileCache); |
|
104 |
||
105 |
TBool IsDriveThread(); |
|
106 |
||
107 |
private: |
|
108 |
||
109 |
CCacheClient* iCacheClient; |
|
110 |
||
111 |
TInt iMaxReadAheadLen; |
|
112 |
TInt iCacheSize; |
|
113 |
||
114 |
TInt32 iClosedFileKeepAliveTime; // in microseconds |
|
115 |
TInt32 iDirtyDataFlushTime; // in microseconds |
|
116 |
||
117 |
CFileCB* iFileCB; |
|
118 |
||
119 |
RFastLock iLock; |
|
120 |
||
121 |
TInt iFlushError; |
|
122 |
TBool iFlushBusy; |
|
123 |
||
124 |
CDriveThread* iDriveThread; |
|
125 |
TInt iDriveNum; |
|
126 |
||
127 |
// closed queue eject timer |
|
128 |
TThreadTimer iClosedTimer; |
|
129 |
||
130 |
// dirty data flush timer |
|
131 |
TThreadTimer iDirtyTimer; |
|
132 |
// The last session writing to this file. If non-NULL indicates cache contains dirty data |
|
133 |
CSessionFs* iDirtyDataOwner; |
|
134 |
||
135 |
// The size of the file. |
|
136 |
TInt64 iSize64; |
|
137 |
||
138 |
// The size of the file at the start of a write request |
|
139 |
TInt64 iInitialSize; |
|
140 |
||
141 |
// The full name of the file, including drive and extensions - Folded. This is "stolen" |
|
142 |
// from the owning CFileCB when the CFileCB destructor calls CFileCache::Close(). |
|
143 |
HBufC* iFileNameF; |
|
144 |
||
145 |
TUint32 iNameHash; |
|
146 |
||
147 |
TDrive* iDrive; |
|
148 |
||
149 |
CMountCB* iMount; |
|
150 |
||
151 |
// Read-ahead |
|
152 |
TInt iSequentialReads; |
|
153 |
TInt iReadAheadLen; |
|
154 |
TInt64 iReadAheadPos; |
|
155 |
TInt64 iLastReadPos; |
|
156 |
TInt iLastReadLen; |
|
157 |
TBool iFileCacheReadAsync; |
|
158 |
CFsClientMessageRequest* iReadAheadRequest; |
|
159 |
||
160 |
friend class TClosedFileUtils; |
|
161 |
friend class TFsFileWriteDirty; |
|
162 |
}; |
|
163 |
||
164 |
||
165 |
class TFileCacheSettings |
|
166 |
{ |
|
167 |
public: |
|
168 |
class TFileCacheConfig |
|
169 |
{ |
|
170 |
public: |
|
171 |
TFileCacheConfig(TInt aDrive); |
|
172 |
static TFileCacheFlags ConvertEnumToFlags(const TInt aFileCacheRead, const TInt aFileCacheReadAhead, const TInt aFileCacheWrite); |
|
173 |
public: |
|
174 |
TInt iDrive; |
|
175 |
TFileCacheFlags iFlags; |
|
176 |
||
177 |
TBool iFileCacheReadAsync; |
|
178 |
TInt32 iFairSchedulingLen; // in bytes |
|
179 |
TInt32 iCacheSize; // in bytes |
|
180 |
TInt32 iMaxReadAheadLen; // in bytes |
|
181 |
TInt32 iClosedFileKeepAliveTime; // in microseconds |
|
182 |
TInt32 iDirtyDataFlushTime; // in microseconds |
|
183 |
}; |
|
184 |
||
185 |
public: |
|
186 |
static TInt ReadPropertiesFile(TInt aDriveNumber); |
|
187 |
static void SetFlags(TInt aDrive, TFileCacheFlags alags); |
|
188 |
static TFileCacheFlags Flags(TInt aDrive); |
|
189 |
||
190 |
||
191 |
static TInt FileCacheReadAsync(TInt aDrive); |
|
192 |
static TInt FairSchedulingLen(TInt aDrive); |
|
193 |
static TInt MaxReadAheadLen(TInt aDrive); |
|
194 |
static TInt CacheSize(TInt aDrive); |
|
195 |
static TInt ClosedFileKeepAliveTime(TInt aDrive); |
|
196 |
static TInt DirtyDataFlushTime(TInt aDrive); |
|
197 |
static TInt GetFileCacheConfig(TInt aDrive, TFileCacheConfig*& aConfig); |
|
198 |
private: |
|
199 |
static void Init(); |
|
200 |
static void ReadEnum(const TDesC8& aSection, const TDesC8& aProperty, TInt32& aEnumVal, const TPtrC8* aEnumStrings); |
|
201 |
||
202 |
private: |
|
203 |
static RArray<TFileCacheConfig>* iFileCacheSettings; |
|
204 |
}; |
|
205 |
||
206 |
||
207 |
class TClosedFileUtils |
|
208 |
{ |
|
209 |
public: |
|
210 |
static void InitL(); |
|
211 |
||
212 |
static TInt Count(); |
|
213 |
static CFileCache* At(TInt aIndex); |
|
214 |
static TBool IsClosed(CFileCache* aFileCache); |
|
215 |
||
216 |
static void AddL(CFileCache* aFileCache, TBool aLock); |
|
217 |
||
218 |
static void Remove(); |
|
219 |
static void Remove(TInt aDrvNumber); |
|
220 |
static void Remove(CFileCache* aFileCache); |
|
221 |
||
222 |
static void Lock(); |
|
223 |
static void Unlock(); |
|
224 |
||
225 |
static void ReOpen(CFileCache* aFileCache, TBool aLock); |
|
226 |
private: |
|
227 |
typedef TBool (*TTestFunc)(CFileCache& aFileCache, TAny* aVal); |
|
228 |
static void RemoveFiles(TTestFunc aTestFunc, TAny* aTestVal); |
|
229 |
||
230 |
static TBool TestDrive(CFileCache& aFileCache, TAny* aVal); |
|
231 |
static TBool TestFile(CFileCache& aFileCache, TAny* aVal); |
|
232 |
||
233 |
private: |
|
234 |
static CFsObjectCon* iClosedFiles; |
|
235 |
}; |
|
236 |
||
237 |
||
238 |
||
239 |
#endif |