First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // generic backup server
18 #if !defined(__BAKSRV_H__)
25 #include <bsul/clientmessage.h>
27 //Forward declarations
28 class BSUL::CClientMessage;
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
41 enum TBaBackupServPanic
43 EReqAlreadyOutstanding =0,
46 ELocksAlreadyReleased =3,
52 class CBaServBackupSession;
67 class CBaServBackupScheduler : public CActiveScheduler
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;
77 CBaServBackupSession* iErrorHandler;
83 NONSHARABLE_CLASS(CBaServBackupMessageQueue) : public CBase
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;
93 void RemoveItem(const TDesC& aFileName);
95 TInt HeadIndex() const;
105 inline TQueueItem(HBufC* aFileName,TInt aOperation);
111 RArray<TQueueItem> iQueue;
114 class CBaBackupServer;
119 class CBaServBackupSession : public CSession2
126 inline TBool operator==(const TClosedFile& aClosedFile) const;
132 {ENull,ERelease,ETake,EPendingReleaseReadOnly,EPendingReleaseNoAccess,EPendingTake};
136 RMessagePtr2 iMessagePtr;
141 class CReRegistrationTimer;
143 IMPORT_C ~CBaServBackupSession();
144 inline CBaBackupServer* BackupServer() const;
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();
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();
156 IMPORT_C CBaServBackupSession();
157 inline CArrayFix<TClosedFile>* ClosedFiles() const;
158 inline void SetClosedFiles(CArrayFix<TClosedFile>* aClosedFiles);
159 inline TInt UniqueClientId() const;
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);
168 static void CleanupCloseAllFiles(TAny* aPtr);
169 void HandleEventReadyL();
172 void NotifyLockChangeL();
173 void NotifyLockChangeCancelL();
174 void GetFileNameL(TDes& aFileName);
175 void BackupOperationEventReadyL();
176 void GetBackupOperationEventL(const RMessagePtr2& aPtr);
177 void GetBackupOperationStateL();
179 void NotifyBackupOperationL();
180 void DoServiceL(TCompletionType& aCompleteType);
182 void StopNotifications();
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;
198 class CShutdownServer;
203 class CBaBackupServerExt : public CBase
206 TUint32 iCachedBusyClientId;
207 TUint32 iUniqueBusyClientId;
218 class CBaBackupServer : public CServer2
222 class CBaServCloseAllOperationTimer;
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);
232 inline TBool IsBackupOperationRunning() const;
233 inline void SetBackupOperationRunning(TBool aBackupOperationRunning);
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;
241 void CloseFileL(MBackupObserver::TFileLockFlags aFlag,const TDesC& aFileName);
242 void RestartFile(const TDesC& aFileName);
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);
253 IMPORT_C CBaBackupServer(TInt aPriority);
254 protected: // from CServer
255 IMPORT_C CSession2* NewSessionL(const TVersion &aVersion, const RMessage2& aMessage) const;
257 CBaBackupServerExt* iExtension;
258 TBool iBackupOperationRunning;
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 */
267 inline CBaServBackupScheduler* CBaServBackupScheduler::Current()
269 return static_cast<CBaServBackupScheduler*>(CActiveScheduler::Current());
272 inline CBaBackupServer* CBaServBackupSession::BackupServer() const
274 return static_cast<CBaBackupServer*>(const_cast<CServer2*>(CSession2::Server()));
277 inline CArrayFix<CBaServBackupSession::TClosedFile>* CBaServBackupSession::ClosedFiles() const
282 inline void CBaServBackupSession::SetClosedFiles(CArrayFix<TClosedFile>* aClosedFiles)
286 iClosedFiles=aClosedFiles;
290 inline TInt CBaServBackupSession::UniqueClientId() const
292 return iUniqueClientId;
295 inline TBool CBaServBackupSession::TClosedFile::operator==(const TClosedFile& aClosedFile) const
297 return iDocName==aClosedFile.iDocName && iUid==aClosedFile.iUid;
300 inline TBool CBaBackupServer::IsBackupOperationRunning() const
302 return iBackupOperationRunning;
305 inline void CBaBackupServer::SetBackupOperationRunning(TBool aBackupOperationRunning)
307 iBackupOperationRunning = aBackupOperationRunning;