|
1 // Copyright (c) 1997-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 "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 // |
|
15 |
|
16 #ifndef __AGSFILEMANAGER_H__ |
|
17 #define __AGSFILEMANAGER_H__ |
|
18 |
|
19 #include "agmfilter.h" |
|
20 #include "calasynctask.h" |
|
21 #include "calchangecallback.h" |
|
22 |
|
23 #include <s32stor.h> |
|
24 #include <badesca.h> |
|
25 |
|
26 class CAgnCategoryList; |
|
27 class CAgnEntryManager; |
|
28 class CAgnEntryModel; |
|
29 class CAgnPermanentData; |
|
30 class CAgnServer; |
|
31 class CAgnServerSession; |
|
32 class CAgnTlsProxy; |
|
33 class CCalAsyncDelete; |
|
34 class CFileStore; |
|
35 class RFile; |
|
36 class RFs; |
|
37 class TAgnChangeFilter; |
|
38 class TAgnVersion; |
|
39 class CAgnServFileShutdownDelayTimer; |
|
40 class CAgnTzRuleIndex; |
|
41 class CAgnCalendarInfo; |
|
42 |
|
43 const TUid KUidAgnCategoryList = {0x101FA9E1}; |
|
44 const TUid KUidAgnCalendarInfo = {0x101FA9E2}; |
|
45 |
|
46 const TInt KAgnPercentageComplete = 100; |
|
47 //Working calendar filename length 220 chars (excluding private path) |
|
48 //Restricted filename length to 200 chars = 220 - 12(attachment doc name)-2(_a added at last of every filename) -2 ( folder number) - 4 (for sperators "\\" "\\") |
|
49 const TInt KCalMaxFilePath = 200; |
|
50 |
|
51 // for model index filenames |
|
52 _LIT (KIdxFilePostFix, "Idx"); //add to filename to ensure 1 idx per calendar file |
|
53 const TInt KIdxFilePostFixLength = 3; |
|
54 |
|
55 /** |
|
56 Class to store details about the current asynchronous operation. |
|
57 These are held in an array in @see CAgnServFile. |
|
58 */ |
|
59 class TAgnMessageToComplete |
|
60 { |
|
61 public: |
|
62 TAgnMessageToComplete(RMessage2& aMessage, TBool aReportProgress, CAgnServerSession& aSession); |
|
63 RMessage2 Message() const; |
|
64 TBool ReportProgress() const; |
|
65 CAgnServerSession& Session() const; |
|
66 |
|
67 private: |
|
68 TAgnMessageToComplete(const TAgnMessageToComplete& ); // not implemented |
|
69 void operator=(const TAgnMessageToComplete& ); // not implemented |
|
70 |
|
71 private: |
|
72 RMessage2 iMessage; |
|
73 TBool iReportProgress; |
|
74 CAgnServerSession& iSession; |
|
75 }; |
|
76 |
|
77 /* |
|
78 Class to control access to a Calendar file. |
|
79 All operations requiring file access should come through here (open/close file, commit changes, etc.) |
|
80 |
|
81 This class is also the active object which controls asynchronous operations. |
|
82 */ |
|
83 class CAgnServFile : public CActive |
|
84 { |
|
85 public: |
|
86 static CAgnServFile* NewL(RFs& aFs, CAgnServer& aAgnServer); |
|
87 ~CAgnServFile(); |
|
88 |
|
89 // File functions |
|
90 CFileStore* CreateAgendaFileLC(const TDesC& aFileName); |
|
91 void OpenAgendaL(const TDesC& aFilename, CalCommon::TCalFileVersionSupport& status); |
|
92 static void CloseAgenda(TAny* aFile); |
|
93 void CloseAgenda(TBool aCloseImmediately); |
|
94 |
|
95 void DoCloseAgenda(); |
|
96 |
|
97 |
|
98 TBool IsReadOnly() const; |
|
99 const TDesC& FileName() const; |
|
100 TBool IsLocked() const; |
|
101 |
|
102 void OpenFileL(RFile& aFileHandle, const TDesC& aFileName); |
|
103 void CreateNewFileL(RFile& aFileHandle, const TDesC& aFileName); |
|
104 |
|
105 TBool FileExistsL(const TDesC& aFileName) const; |
|
106 TBool FileIsReadOnlyL(const TDesC& aFileName) const; |
|
107 void CreateDirL(const TDesC& aDirectory) const; |
|
108 void DeleteFileL(const TDesC& aFileName) const; |
|
109 void MoveFileL(const TDesC& aSource, const TDesC& aDestination) const; |
|
110 void CopyFileL(const TDesC& aSource, const TDesC& aDestination) const; |
|
111 |
|
112 static TBool FileExistsL(RFs& aFs, const TDesC& aFileName); |
|
113 static void CreateDirL(RFs& aFs, const TDesC& aDirectory); |
|
114 static void DeleteFileL(RFs& aFs, const TDesC& aFileName); |
|
115 |
|
116 void GetAttachmentFolderNameL(TDes& aFolderName); |
|
117 static void GetAttachmentFolderNameL(const TDesC& aFileName, TDes& aFolderName); |
|
118 |
|
119 // Compaction functions |
|
120 void CompactFileL(); |
|
121 |
|
122 // Index building functions |
|
123 void StartBuildIndex(TAgnMessageToComplete& aMessageToComplete); |
|
124 void DoStartBuildIndex(); |
|
125 TBool AreIndexesBuilt() const; |
|
126 |
|
127 // Tidy functions |
|
128 void TidyByDateSetup(CAgnServerSession& aSession, |
|
129 const TAgnFilter& aFilter, |
|
130 const TTime& aTodaysDate, |
|
131 const TTime& aStartDate, |
|
132 const TTime& aEndDate); |
|
133 |
|
134 void TidyByDateStartL(TAgnMessageToComplete& aMessageToComplete, TAgnChangeFilter& aChangeFilter); |
|
135 TBool HasServerSession() const; |
|
136 TBool IsInterestedSession(CAgnServerSession* aSession); |
|
137 |
|
138 // Accessor functions. |
|
139 CAgnEntryModel* Model() const; |
|
140 CFileStore* StoreL() const; |
|
141 CStreamDictionary* Dictionary() const; |
|
142 CAgnCategoryList& CategoryList() const; |
|
143 CAgnServer& Server() const; |
|
144 CAgnServerSession* ServerSession(); |
|
145 CAgnTlsProxy* TimeZoneConverter() const; |
|
146 TUint32 FileNameHash() const; |
|
147 const TDesC& PrivatePath() const; |
|
148 |
|
149 // Asynchronous operation functions |
|
150 void RequestProgressL(TAgnMessageToComplete& aMessageToComplete); |
|
151 void CategoryTaskStartL(TAgnMessageToComplete& aMessageToComplete, CCalAsyncTaskManager::TAsyncAction aTask); |
|
152 TBool DoTaskCompleteL(TInt aErr, CAgnServerSession* aSession); |
|
153 |
|
154 // File version functions |
|
155 void ReplaceConvertedAgendaFileL(CAgnEntryManager& aEntryManager, CAgnTzRuleIndex& aTzRuleIndex); |
|
156 void GetFileVersionSupportStatusL(TAgnVersion& aFileVersion, CalCommon::TCalFileVersionSupport& aStatus); |
|
157 |
|
158 // Misc. functions. |
|
159 void AddReference(); |
|
160 |
|
161 TInt ReferenceCount() const; |
|
162 void ExternalizeCategoryListL(); |
|
163 TStreamId WriteCategoryListL(CStreamStore& aStore) const; |
|
164 void AddStreamToDictionaryL(const TUid& aStreamUid, const TStreamId& aStreamId, CStreamDictionary& aDictionary, CPersistentStore& aStore) const; |
|
165 void CloseAgendaImmediately(); |
|
166 CAgnServFileShutdownDelayTimer& FileShutdownDelayTimer() const; |
|
167 void TzRulesHaveChangedL(); |
|
168 void SetCollectionId(TCalCollectionId aFileId); |
|
169 TCalCollectionId CollectionId()const; |
|
170 TInt BackupReStoreChanged(MCalChangeCallBack2::TChangeType aChangeType); |
|
171 void BackupRestoreLock(TBool aLock); |
|
172 TBool IsBackupRestoreLock() const; |
|
173 void CancelTaskL(CAgnServerSession* aSession); |
|
174 void SetRefreshTzRules(TBool aSetRefresjTzRule); |
|
175 TBool RefreshTzRules() const; |
|
176 |
|
177 HBufC8* GetPropertyValueLC(TStreamId aStreamId); |
|
178 TBool SetCalendarInfoL(const CAgnCalendarInfo& aCalendarInfo); |
|
179 CAgnCalendarInfo* GetCalendarInfoLC() const; |
|
180 TBool IsCalendarInfoExistL()const; |
|
181 TBool IsFileDisabled(); |
|
182 |
|
183 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT |
|
184 void QueueAlarmsImmediately(); |
|
185 void SetShutdownFlag(TBool aNotificationFlag); |
|
186 void DeleteAlarmsAndRequeueSessionAlarm(); |
|
187 #endif |
|
188 |
|
189 private: |
|
190 CAgnServFile(RFs& aFs, CAgnServer& aAgnServer); |
|
191 void ConstructL(); |
|
192 |
|
193 void RunL(); // from CActive |
|
194 void DoCancel(); // from CActive |
|
195 |
|
196 // category functions |
|
197 void CreateCategoryListL() const; |
|
198 void SaveCategoryListL(); |
|
199 void InternalizeCategoryListL(const TStreamId& aStreamId); |
|
200 |
|
201 // asynchronous operations |
|
202 void Start(); |
|
203 void SetActiveAndMakeRequest(); |
|
204 void AddAsyncRequesterL(TAgnMessageToComplete& aMessageToComplete); |
|
205 void CompleteRequests(TBool aIsCompleted, TInt aCompleteCode, CAgnServerSession* aSession); |
|
206 |
|
207 // AO state machine functions. |
|
208 TBool DoStepL(); |
|
209 TInt DoBuildIndexStepL(); |
|
210 TInt AddAsyncRequester(TAgnMessageToComplete& aMessageToComplete); |
|
211 |
|
212 // miscellaneous functions |
|
213 void DoCompactFileL(); |
|
214 TBool DoCompactL(); |
|
215 TBool DoCompactorStepL(); |
|
216 void SetFileNameHashL(); |
|
217 void CreateModelForFileL(); |
|
218 |
|
219 TStreamId DictionaryLookup(TUid aUid) const; |
|
220 void AddStreamToDictionaryL(const TUid& aStreamUid, const TStreamId& aStreamId) const; |
|
221 |
|
222 void DoSaveIndexFile(); |
|
223 void SetLock(TBool aToLock); |
|
224 void CreateFileStoreL(const TDesC& aFilename); |
|
225 void ReopenAgendaAfterRestoreL(); |
|
226 |
|
227 |
|
228 private: |
|
229 |
|
230 TStreamId iModelStreamId; |
|
231 CAgnServer& iAgnServer; |
|
232 HBufC* iFileName; |
|
233 TUint32 iFileNameHash; |
|
234 CFileStore* iStore; |
|
235 TInt iRefCount; |
|
236 CAgnEntryModel* iModel; |
|
237 CStreamDictionary* iDictionary; |
|
238 RFs& iFs; |
|
239 TBool iReadOnly; |
|
240 TInt iActiveStep; // active object step |
|
241 |
|
242 CArrayFixFlat<TAgnMessageToComplete>* iMessageVector; |
|
243 CAgnServerSession* iSession; |
|
244 |
|
245 // Progress of current operation. |
|
246 TInt iProgressTotal; |
|
247 |
|
248 // Build index data. |
|
249 TBool iIndexesBuilt; |
|
250 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT |
|
251 TBool iShutdownNotification; |
|
252 #endif |
|
253 // Tidy by Todo list and Date data. |
|
254 TAgnFilter iTidyByDateFilter; |
|
255 TTime iTidyByDateUndatedTodoDate; |
|
256 TTime iTidyByDateStartDate; |
|
257 TTime iTidyByDateEndDate; |
|
258 |
|
259 // Compaction data. |
|
260 TInt iNextCompactEffort; |
|
261 enum |
|
262 { |
|
263 ENothing, |
|
264 ECompacting, |
|
265 EReclaiming |
|
266 } iCompactionStage; |
|
267 RStoreReclaim iCompactor; |
|
268 CAgnCategoryList* iCategoryList; |
|
269 CCalAsyncDelete* iAsyncDelete; |
|
270 |
|
271 CAgnServFileShutdownDelayTimer* iFileShutdownDelayTimer; |
|
272 TCalCollectionId iCollectionId; |
|
273 TBool iLocked; |
|
274 TBool iRefreshTzRules; |
|
275 TBool iIsFileDisabled; |
|
276 TBool iBackupRestoreLock; |
|
277 }; |
|
278 |
|
279 |
|
280 /** |
|
281 Class to control general file access to Calendar files. |
|
282 For access to a specific Calendar file, use @see CAgnServFile. |
|
283 */ |
|
284 class CAgnServFileMgr : public CBase |
|
285 { |
|
286 public: |
|
287 static CAgnServFileMgr* NewL(RFs& aFs, CAgnServer& aAgnServer); |
|
288 ~CAgnServFileMgr(); |
|
289 |
|
290 CAgnServFile& OpenAgendaL(const TDesC& aFilename, CAgnServer& aAgnServer, CalCommon::TCalFileVersionSupport& status); |
|
291 TInt CloseAgenda(CAgnServFile& aStore, TBool aCloseAgendaWithDelay); |
|
292 CFileStore* CreateAgendaFileLC(const TDesC& aFileName); |
|
293 void DeleteAgendaFileL(const TDesC& aFilename); |
|
294 |
|
295 const TDesC& PrivatePath() const; |
|
296 CDesCArray* ListAgendaFilesL() const; |
|
297 HBufC* ParseFilenameLC(const TDesC& aFileName) const; |
|
298 TBool AgendaFileExistsL(const TDesC& aFileName) const; |
|
299 |
|
300 void CreatePermanentDataL(); |
|
301 |
|
302 TBool FileCloseTimersRunning() const; |
|
303 void CloseScheduledFilesImmediately(); |
|
304 void CloseAgendaFile(CAgnServFile* aServFile); |
|
305 |
|
306 CAgnServFile* GetFile(const TDesC& aFilename) const; |
|
307 CAgnServFile* GetFileL(TInt64 aFileId) const; |
|
308 CAgnServFile* GetFileL(TCalCollectionId aCollectionId) const; |
|
309 |
|
310 TInt64 GetLongFileIdL(TCalCollectionId aCollectionId) const; |
|
311 void BackupReStoreChanged(MCalChangeCallBack2::TChangeType aChangeType); |
|
312 |
|
313 // iterate through files |
|
314 TInt Count(); |
|
315 CAgnServFile* File(TInt aIndex); |
|
316 |
|
317 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT |
|
318 void QueueAlarmsImmediatelyForShutdown(); |
|
319 void RequeueAlarmsForShutdownCancellation(); |
|
320 #endif |
|
321 private: |
|
322 CAgnServFileMgr(RFs& aFs, CAgnServer& aAgnServer); |
|
323 void ConstructL(); |
|
324 |
|
325 private: |
|
326 CAgnServer& iAgnServer; |
|
327 CArrayFixFlat<CAgnServFile*>* iFileList; |
|
328 RFs& iFs; |
|
329 TFileName iPrivatePath; |
|
330 CAgnPermanentData* iPermanentData; |
|
331 }; |
|
332 |
|
333 |
|
334 // Delay period before the calendar file is closed on the server side |
|
335 const TInt KServerShutdownDelay = 5000000; |
|
336 |
|
337 /** |
|
338 * Class representing the calendar file close delay timer. An agenda server calendar file can be closed either immediately or after a delay on the server side |
|
339 * The delay is triggered using a timer owned by the calendar file and represented by this class. |
|
340 * If a session tries to access the calendar file during the course of the delay, the delay is cancelled and the file is not closed |
|
341 */ |
|
342 class CAgnServFileShutdownDelayTimer : public CTimer |
|
343 { |
|
344 public: |
|
345 // aServFile is not owned |
|
346 static CAgnServFileShutdownDelayTimer* NewL(CAgnServFile& aServFile); |
|
347 void Start(); |
|
348 void DoCloseAgenda(); |
|
349 void CloseAgenda(); |
|
350 private: |
|
351 CAgnServFileShutdownDelayTimer (CAgnServFile& aServFile); |
|
352 void ConstructL(); |
|
353 void RunL(); |
|
354 |
|
355 private: |
|
356 CAgnServFile& iServFile; |
|
357 }; |
|
358 |
|
359 #endif |