1 /* |
|
2 * Copyright (c) 2003-2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: data struct for remote files metadata |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_RSFWFILETABLE_H |
|
20 #define C_RSFWFILETABLE_H |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <f32file.h> |
|
24 #include "rsfwmetadatastore.h" |
|
25 |
|
26 class CRsfwVolume; |
|
27 class CRsfwFileEntry; |
|
28 class TFid; |
|
29 class TMetaDataEvent; |
|
30 |
|
31 /** file where permanent metadata is stored */ |
|
32 _LIT(KMetaDataFileName, "M.dat"); |
|
33 |
|
34 /** an entry has been added */ |
|
35 const TInt KNotifyNodeAdded = 1; |
|
36 |
|
37 /** an entry has been modified */ |
|
38 const TInt KNotifyNodeModified = 2; |
|
39 |
|
40 /** an entry has been deleted */ |
|
41 const TInt KNotifyNodeRemoved = 3; |
|
42 |
|
43 /** size of the buffer used when writing file entry to permanent metadata */ |
|
44 const TInt KMaxExternalizedFileEntrySize = 1024; |
|
45 |
|
46 /** internal state bits */ |
|
47 |
|
48 /** local changes (eg caching bits) */ |
|
49 const TUint KNodeLocallyDirty = 0x0001; |
|
50 /** remote changes */ |
|
51 const TUint KNodeRemotelyDirty = 0x0002; |
|
52 /** temp mark for various purposes */ |
|
53 const TUint KNodeMarked = 0x0004; |
|
54 |
|
55 const TUint KNodeHasValidLock = 0x0008; |
|
56 const TUint KNodeOpenedForWriting = 0x0010; |
|
57 |
|
58 const TUint KNodeWritingCancelled = 0x0020; |
|
59 |
|
60 const TUint KNodePartlyCached = 0x0100; |
|
61 |
|
62 /** indicates that a file that has been |
|
63 opened has been created (instead of opening |
|
64 an already existing file). This affects |
|
65 logic when closing the file (PUT + RENAME |
|
66 trick to protect the existing file in case of |
|
67 cancelled PUT is not used) |
|
68 **/ |
|
69 const TUint KNodeNewlyCreated = 0x0200; |
|
70 |
|
71 |
|
72 class TMetaDataEvent |
|
73 { |
|
74 public: |
|
75 TInt iEvent; // notified event |
|
76 TInt iNodeId; // node id |
|
77 CRsfwFileEntry* iEntry; // file entry |
|
78 }; |
|
79 |
|
80 |
|
81 class CRsfwFileTable: public CBase |
|
82 { |
|
83 private: |
|
84 enum TMetaDataState |
|
85 { |
|
86 EMetaDataSaveNone = 0, // meta data saving has not started yet |
|
87 EMetaDataSaveStarted, // meta data saving has been started |
|
88 EMetaDataSaveFailed // meta data saving has failed |
|
89 }; |
|
90 |
|
91 class TMetaDataSlot |
|
92 { |
|
93 public: |
|
94 TInt iNodeId; // node id |
|
95 TInt iSlotId; // slot index |
|
96 }; |
|
97 |
|
98 public: |
|
99 static CRsfwFileTable* NewL(CRsfwVolume* aVolume, TFileName& aCachePath); |
|
100 |
|
101 inline CRsfwVolume* Volume(); |
|
102 inline CRsfwFileEntry* Root(); |
|
103 |
|
104 ~CRsfwFileTable(); |
|
105 |
|
106 // add node to three |
|
107 void AddL(CRsfwFileEntry* aFep); |
|
108 |
|
109 // remove node from thee |
|
110 void RemoveL(CRsfwFileEntry* aFep); |
|
111 |
|
112 // lookup three |
|
113 CRsfwFileEntry *Lookup(const TFid& aFid); |
|
114 void DumpL(TBool aAll); |
|
115 inline const TBool Permanence() const; |
|
116 void SetPermanenceL(TBool aPermanence); |
|
117 void HandleMetaDataEvent(TInt aEvent, CRsfwFileEntry* aFep); |
|
118 CRsfwFileEntry* LoadMetaDataL(); |
|
119 TInt SaveMetaDataDelta(); |
|
120 void SetupCacheL(); |
|
121 TInt TotalCachedSize(); |
|
122 TInt TotalEntryCount(); |
|
123 inline TInt OpenFileCount(); |
|
124 inline void UpdateOpenFileCount(TInt aDelta); |
|
125 void ResolveDirtyFilesL(); |
|
126 void ResolveDirtyFileL(CRsfwFileEntry* aFep); |
|
127 |
|
128 |
|
129 private: |
|
130 void ConstructL(CRsfwVolume* aVolume, TFileName& aCachePath); |
|
131 void ClearCacheL(); |
|
132 void ConstructL(RReadStream& aStream); |
|
133 TMetaDataEvent* NodeEvent(TInt aNodeId); |
|
134 void AddEvent(TInt aEvent, CRsfwFileEntry* aFep); |
|
135 void RemoveEvent(TInt aNodeId); |
|
136 void LoadNodeL(CRsfwFileEntry*& aFep, TInt &aSlot); |
|
137 void SaveNodeL(CRsfwFileEntry* aFep, TInt &aSlot); |
|
138 void SaveMetaDataDeltaL(); |
|
139 |
|
140 private: |
|
141 RFs iFs; // inherited from RFE environment |
|
142 TInt iNodeId; // next node id to assign |
|
143 CRsfwVolume* iVolume; // volume info |
|
144 CRsfwFileEntry* iRootFep; // root file entry |
|
145 TFileName iCachePath; // cache directory path |
|
146 TBool iPermanence; // permanent meta data |
|
147 RArray<TMetaDataEvent> iMetaDataEvents; // dirty entries since last flush |
|
148 CRsfwMetaDataStore* iMetaDataStore; // permanent store for metadata |
|
149 RArray<TMetaDataSlot> iMetaDataSlots; // maps file slot to node ids |
|
150 TFileName iMetaDataFilePath; // meta data file path |
|
151 TInt iMetaDataSaveState; // the state of meta data saving |
|
152 CRsfwFileEntry* iCurrentParent; // parent of last looked up entry |
|
153 TInt iOpenFileCount; // count of open files |
|
154 }; |
|
155 |
|
156 #include "rsfwfiletable.inl" |
|
157 |
|
158 #endif |
|