|
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 // generic backup server |
|
15 // |
|
16 // |
|
17 |
|
18 #if !defined(__BAKSRV_H__) |
|
19 #define __BAKSRV_H__ |
|
20 |
|
21 #include <e32std.h> |
|
22 #include <e32base.h> |
|
23 #include <babackup.h> |
|
24 #include <badesca.h> |
|
25 #include <bsul/clientmessage.h> |
|
26 |
|
27 //Forward declarations |
|
28 class BSUL::CClientMessage; |
|
29 |
|
30 /** |
|
31 @internalTechnology |
|
32 */ |
|
33 const TInt KBakServMajorVN =0; |
|
34 const TInt KBakServMinorVN =1; |
|
35 const TInt KBakServBuildVN =1; |
|
36 const TInt KBakServMessageSlots =4; // no async messages to backup server |
|
37 |
|
38 /** |
|
39 @internalTechnology |
|
40 */ |
|
41 enum TBaBackupServPanic |
|
42 { |
|
43 EReqAlreadyOutstanding =0, |
|
44 EReqDoesNotExist =1, |
|
45 EBadFileName =2, |
|
46 ELocksAlreadyReleased =3, |
|
47 EBufferOverflow =4, |
|
48 ENoEventToFetch =5, |
|
49 EHandleNotClosed =6, |
|
50 }; |
|
51 |
|
52 class CBaServBackupSession; |
|
53 |
|
54 /** |
|
55 @internalTechnology |
|
56 */ |
|
57 enum TCompletionType |
|
58 { |
|
59 ECompleteSync =0x00, |
|
60 ECompleteAsync =0x01, |
|
61 }; |
|
62 |
|
63 |
|
64 /** |
|
65 @internalTechnology |
|
66 */ |
|
67 class CBaServBackupScheduler : public CActiveScheduler |
|
68 { |
|
69 public: |
|
70 IMPORT_C CBaServBackupScheduler(); |
|
71 inline static CBaServBackupScheduler* Current(); |
|
72 IMPORT_C void SetErrorHandler(CBaServBackupSession* aErrorHandler); |
|
73 IMPORT_C ~CBaServBackupScheduler(); |
|
74 public: // from CActiveScheduler |
|
75 IMPORT_C virtual void Error(TInt aError) const; |
|
76 private: |
|
77 CBaServBackupSession* iErrorHandler; |
|
78 }; |
|
79 |
|
80 /** |
|
81 @internalTechnology |
|
82 */ |
|
83 NONSHARABLE_CLASS(CBaServBackupMessageQueue) : public CBase |
|
84 { |
|
85 public: |
|
86 static CBaServBackupMessageQueue* NewL(); |
|
87 ~CBaServBackupMessageQueue(); |
|
88 void AddItemL(const TDesC& aFileName,MBackupObserver::TFileLockFlags aFlag); |
|
89 void AddItem(const TDesC& aFileName); |
|
90 TBool IsEmpty() const; |
|
91 void GetHead(TDes& aFileName,MBackupObserver::TFileLockFlags& aFlag) const; |
|
92 void RemoveHead(); |
|
93 void RemoveItem(const TDesC& aFileName); |
|
94 private: |
|
95 TInt HeadIndex() const; |
|
96 private: |
|
97 enum TOperation |
|
98 { |
|
99 ENoOp =-1, |
|
100 ETakeLock =0, |
|
101 }; |
|
102 class TQueueItem |
|
103 { |
|
104 public: |
|
105 inline TQueueItem(HBufC* aFileName,TInt aOperation); |
|
106 public: |
|
107 HBufC* iFileName; |
|
108 TInt iOperation; |
|
109 }; |
|
110 private: |
|
111 RArray<TQueueItem> iQueue; |
|
112 }; |
|
113 |
|
114 class CBaBackupServer; |
|
115 |
|
116 /** |
|
117 @internalTechnology |
|
118 */ |
|
119 class CBaServBackupSession : public CSession2 |
|
120 |
|
121 { |
|
122 public: |
|
123 class TClosedFile |
|
124 { |
|
125 public: |
|
126 inline TBool operator==(const TClosedFile& aClosedFile) const; |
|
127 public: |
|
128 TFileName iDocName; |
|
129 TUid iUid; |
|
130 }; |
|
131 enum TLockType |
|
132 {ENull,ERelease,ETake,EPendingReleaseReadOnly,EPendingReleaseNoAccess,EPendingTake}; |
|
133 class TFileLock |
|
134 { |
|
135 public: |
|
136 RMessagePtr2 iMessagePtr; |
|
137 TLockType iRequest; |
|
138 HBufC* iFileName; |
|
139 }; |
|
140 public: |
|
141 class CReRegistrationTimer; |
|
142 public: |
|
143 IMPORT_C ~CBaServBackupSession(); |
|
144 inline CBaBackupServer* BackupServer() const; |
|
145 public: |
|
146 IMPORT_C virtual void HandleError(TInt aError); |
|
147 protected: // from CSession |
|
148 IMPORT_C virtual void ServiceL(const RMessage2& aMessage); |
|
149 IMPORT_C virtual void CreateL(); |
|
150 protected: |
|
151 IMPORT_C virtual void ConstructL(); |
|
152 IMPORT_C virtual TCompletionType CloseAllFilesL(const RMessage2& aMessage); |
|
153 IMPORT_C TCompletionType DoCloseAllFilesL(const RMessage2& aMessage); |
|
154 IMPORT_C virtual void RestartAll(); |
|
155 protected: |
|
156 IMPORT_C CBaServBackupSession(); |
|
157 inline CArrayFix<TClosedFile>* ClosedFiles() const; |
|
158 inline void SetClosedFiles(CArrayFix<TClosedFile>* aClosedFiles); |
|
159 inline TInt UniqueClientId() const; |
|
160 public: |
|
161 static CBaServBackupSession* NewL(); |
|
162 void SignalReleaseAllFileLocksL(MBackupObserver::TFileLockFlags aFlag); |
|
163 void SignalRetakeAllFileLocks(); |
|
164 void SignalReleaseFileLockL(MBackupObserver::TFileLockFlags aFlag,const TDesC& aFileName); |
|
165 void SignalRetakeFileLocks(const TDesC& aFileName); |
|
166 void SignalBackupOperation(const TBackupOperationAttributes& aBackupOperationAttributes); |
|
167 private: |
|
168 static void CleanupCloseAllFiles(TAny* aPtr); |
|
169 void HandleEventReadyL(); |
|
170 void GetEventL(); |
|
171 void RestartFileL(); |
|
172 void NotifyLockChangeL(); |
|
173 void NotifyLockChangeCancelL(); |
|
174 void GetFileNameL(TDes& aFileName); |
|
175 void BackupOperationEventReadyL(); |
|
176 void GetBackupOperationEventL(const RMessagePtr2& aPtr); |
|
177 void GetBackupOperationStateL(); |
|
178 void DoRestartAll(); |
|
179 void NotifyBackupOperationL(); |
|
180 void DoServiceL(TCompletionType& aCompleteType); |
|
181 void CloseFileL(); |
|
182 void StopNotifications(); |
|
183 private: |
|
184 TUint32 iUniqueClientId; |
|
185 CBaServBackupMessageQueue* iMessageQueue; |
|
186 RMessagePtr2 iNotificationPullMsg; |
|
187 CArrayFix<TClosedFile>* iClosedFiles; |
|
188 CDesCArray* iFileLockObservers; |
|
189 CDesCArray* iReleasedFiles; |
|
190 RMessagePtr2 iBackupOperationMessagePtr; |
|
191 TBackupOperationAttributes iBackupOperationAttributes; |
|
192 TBool iBackupOperationObserverPresent; |
|
193 CReRegistrationTimer* iReRegistrationTimer; /* File lock re-registration timer */ |
|
194 BSUL::CClientMessage* iClientMessage; |
|
195 |
|
196 }; |
|
197 |
|
198 class CShutdownServer; |
|
199 |
|
200 /** |
|
201 @internalTechnology |
|
202 */ |
|
203 class CBaBackupServerExt : public CBase |
|
204 { |
|
205 public: |
|
206 TUint32 iCachedBusyClientId; |
|
207 TUint32 iUniqueBusyClientId; |
|
208 }; |
|
209 |
|
210 // |
|
211 // CBaBackupServer |
|
212 // |
|
213 |
|
214 |
|
215 /** |
|
216 @internalTechnology |
|
217 */ |
|
218 class CBaBackupServer : public CServer2 |
|
219 |
|
220 { |
|
221 public: |
|
222 class CBaServCloseAllOperationTimer; |
|
223 public: |
|
224 IMPORT_C static CBaBackupServer* NewL(); |
|
225 IMPORT_C ~CBaBackupServer(); |
|
226 IMPORT_C void SetBusy(TUint32 aUniqueClientId); |
|
227 IMPORT_C TBool IsClientBusy(TUint32 aUniqueClientId) const; |
|
228 IMPORT_C void SignalBackupOperation(const TBackupOperationAttributes& aBackupOperationAttributes); |
|
229 IMPORT_C TBool HaveAllCloseAllFilesClientsReRegistered(); |
|
230 IMPORT_C void SetCloseAllOperationRunningState(TBool aRunning); |
|
231 public: |
|
232 inline TBool IsBackupOperationRunning() const; |
|
233 inline void SetBackupOperationRunning(TBool aBackupOperationRunning); |
|
234 public: |
|
235 IMPORT_C virtual void CloseAllFilesL(MBackupObserver::TFileLockFlags aFlag); |
|
236 IMPORT_C virtual void RestartAll(); |
|
237 IMPORT_C virtual void ConstructL(); |
|
238 IMPORT_C virtual void CompleteClosingFiles(CArrayFix<CBaServBackupSession::TClosedFile>* aClosedFiles); |
|
239 IMPORT_C virtual TBool IsOtherClientBusy(TUint32 aUniqueClientId) const; |
|
240 public: |
|
241 void CloseFileL(MBackupObserver::TFileLockFlags aFlag,const TDesC& aFileName); |
|
242 void RestartFile(const TDesC& aFileName); |
|
243 void AddSession(); |
|
244 void DropSession(); |
|
245 void IncrementRegisteredFilesCount(); |
|
246 void DecrementRegisteredFilesCount(TInt aNumberFiles = 1); |
|
247 void IncrementFilesReRegistrationCount(); |
|
248 void StartCloseAllFilesOperationTimer(const RMessagePtr2& aPtr); |
|
249 TBool IsCloseAllOperationRunning(); |
|
250 public: // from CServer |
|
251 IMPORT_C TInt RunError(TInt aError); |
|
252 protected: |
|
253 IMPORT_C CBaBackupServer(TInt aPriority); |
|
254 protected: // from CServer |
|
255 IMPORT_C CSession2* NewSessionL(const TVersion &aVersion, const RMessage2& aMessage) const; |
|
256 private: |
|
257 CBaBackupServerExt* iExtension; |
|
258 TBool iBackupOperationRunning; |
|
259 TInt iSessionCount; |
|
260 CShutdownServer* iShutdown; |
|
261 TInt16 iRegisteredFilesCount; |
|
262 TInt16 iSessionLockReRegistrationCount; /* Number of file lock sessions currently registered */ |
|
263 CBaServCloseAllOperationTimer* iCloseAllFilesOperationTimer; /* Base file lock re-registration timer */ |
|
264 TBool iCloseAllOperationRunning; /* Indicates that a CloseAll operation is in progress */ |
|
265 }; |
|
266 |
|
267 inline CBaServBackupScheduler* CBaServBackupScheduler::Current() |
|
268 { // static |
|
269 return static_cast<CBaServBackupScheduler*>(CActiveScheduler::Current()); |
|
270 } |
|
271 |
|
272 inline CBaBackupServer* CBaServBackupSession::BackupServer() const |
|
273 { |
|
274 return static_cast<CBaBackupServer*>(const_cast<CServer2*>(CSession2::Server())); |
|
275 } |
|
276 |
|
277 inline CArrayFix<CBaServBackupSession::TClosedFile>* CBaServBackupSession::ClosedFiles() const |
|
278 { |
|
279 return iClosedFiles; |
|
280 } |
|
281 |
|
282 inline void CBaServBackupSession::SetClosedFiles(CArrayFix<TClosedFile>* aClosedFiles) |
|
283 { |
|
284 if(!iClosedFiles) |
|
285 { |
|
286 iClosedFiles=aClosedFiles; |
|
287 } |
|
288 } |
|
289 |
|
290 inline TInt CBaServBackupSession::UniqueClientId() const |
|
291 { |
|
292 return iUniqueClientId; |
|
293 } |
|
294 |
|
295 inline TBool CBaServBackupSession::TClosedFile::operator==(const TClosedFile& aClosedFile) const |
|
296 { |
|
297 return iDocName==aClosedFile.iDocName && iUid==aClosedFile.iUid; |
|
298 } |
|
299 |
|
300 inline TBool CBaBackupServer::IsBackupOperationRunning() const |
|
301 { |
|
302 return iBackupOperationRunning; |
|
303 } |
|
304 |
|
305 inline void CBaBackupServer::SetBackupOperationRunning(TBool aBackupOperationRunning) |
|
306 { |
|
307 iBackupOperationRunning = aBackupOperationRunning; |
|
308 } |
|
309 |
|
310 #endif |