sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // generic backup server sl@0: // sl@0: // sl@0: sl@0: #if !defined(__BAKSRV_H__) sl@0: #define __BAKSRV_H__ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: //Forward declarations sl@0: class BSUL::CClientMessage; sl@0: sl@0: /** sl@0: @internalTechnology sl@0: */ sl@0: const TInt KBakServMajorVN =0; sl@0: const TInt KBakServMinorVN =1; sl@0: const TInt KBakServBuildVN =1; sl@0: const TInt KBakServMessageSlots =4; // no async messages to backup server sl@0: sl@0: /** sl@0: @internalTechnology sl@0: */ sl@0: enum TBaBackupServPanic sl@0: { sl@0: EReqAlreadyOutstanding =0, sl@0: EReqDoesNotExist =1, sl@0: EBadFileName =2, sl@0: ELocksAlreadyReleased =3, sl@0: EBufferOverflow =4, sl@0: ENoEventToFetch =5, sl@0: EHandleNotClosed =6, sl@0: }; sl@0: sl@0: class CBaServBackupSession; sl@0: sl@0: /** sl@0: @internalTechnology sl@0: */ sl@0: enum TCompletionType sl@0: { sl@0: ECompleteSync =0x00, sl@0: ECompleteAsync =0x01, sl@0: }; sl@0: sl@0: sl@0: /** sl@0: @internalTechnology sl@0: */ sl@0: class CBaServBackupScheduler : public CActiveScheduler sl@0: { sl@0: public: sl@0: IMPORT_C CBaServBackupScheduler(); sl@0: inline static CBaServBackupScheduler* Current(); sl@0: IMPORT_C void SetErrorHandler(CBaServBackupSession* aErrorHandler); sl@0: IMPORT_C ~CBaServBackupScheduler(); sl@0: public: // from CActiveScheduler sl@0: IMPORT_C virtual void Error(TInt aError) const; sl@0: private: sl@0: CBaServBackupSession* iErrorHandler; sl@0: }; sl@0: sl@0: /** sl@0: @internalTechnology sl@0: */ sl@0: NONSHARABLE_CLASS(CBaServBackupMessageQueue) : public CBase sl@0: { sl@0: public: sl@0: static CBaServBackupMessageQueue* NewL(); sl@0: ~CBaServBackupMessageQueue(); sl@0: void AddItemL(const TDesC& aFileName,MBackupObserver::TFileLockFlags aFlag); sl@0: void AddItem(const TDesC& aFileName); sl@0: TBool IsEmpty() const; sl@0: void GetHead(TDes& aFileName,MBackupObserver::TFileLockFlags& aFlag) const; sl@0: void RemoveHead(); sl@0: void RemoveItem(const TDesC& aFileName); sl@0: private: sl@0: TInt HeadIndex() const; sl@0: private: sl@0: enum TOperation sl@0: { sl@0: ENoOp =-1, sl@0: ETakeLock =0, sl@0: }; sl@0: class TQueueItem sl@0: { sl@0: public: sl@0: inline TQueueItem(HBufC* aFileName,TInt aOperation); sl@0: public: sl@0: HBufC* iFileName; sl@0: TInt iOperation; sl@0: }; sl@0: private: sl@0: RArray iQueue; sl@0: }; sl@0: sl@0: class CBaBackupServer; sl@0: sl@0: /** sl@0: @internalTechnology sl@0: */ sl@0: class CBaServBackupSession : public CSession2 sl@0: sl@0: { sl@0: public: sl@0: class TClosedFile sl@0: { sl@0: public: sl@0: inline TBool operator==(const TClosedFile& aClosedFile) const; sl@0: public: sl@0: TFileName iDocName; sl@0: TUid iUid; sl@0: }; sl@0: enum TLockType sl@0: {ENull,ERelease,ETake,EPendingReleaseReadOnly,EPendingReleaseNoAccess,EPendingTake}; sl@0: class TFileLock sl@0: { sl@0: public: sl@0: RMessagePtr2 iMessagePtr; sl@0: TLockType iRequest; sl@0: HBufC* iFileName; sl@0: }; sl@0: public: sl@0: class CReRegistrationTimer; sl@0: public: sl@0: IMPORT_C ~CBaServBackupSession(); sl@0: inline CBaBackupServer* BackupServer() const; sl@0: public: sl@0: IMPORT_C virtual void HandleError(TInt aError); sl@0: protected: // from CSession sl@0: IMPORT_C virtual void ServiceL(const RMessage2& aMessage); sl@0: IMPORT_C virtual void CreateL(); sl@0: protected: sl@0: IMPORT_C virtual void ConstructL(); sl@0: IMPORT_C virtual TCompletionType CloseAllFilesL(const RMessage2& aMessage); sl@0: IMPORT_C TCompletionType DoCloseAllFilesL(const RMessage2& aMessage); sl@0: IMPORT_C virtual void RestartAll(); sl@0: protected: sl@0: IMPORT_C CBaServBackupSession(); sl@0: inline CArrayFix* ClosedFiles() const; sl@0: inline void SetClosedFiles(CArrayFix* aClosedFiles); sl@0: inline TInt UniqueClientId() const; sl@0: public: sl@0: static CBaServBackupSession* NewL(); sl@0: void SignalReleaseAllFileLocksL(MBackupObserver::TFileLockFlags aFlag); sl@0: void SignalRetakeAllFileLocks(); sl@0: void SignalReleaseFileLockL(MBackupObserver::TFileLockFlags aFlag,const TDesC& aFileName); sl@0: void SignalRetakeFileLocks(const TDesC& aFileName); sl@0: void SignalBackupOperation(const TBackupOperationAttributes& aBackupOperationAttributes); sl@0: private: sl@0: static void CleanupCloseAllFiles(TAny* aPtr); sl@0: void HandleEventReadyL(); sl@0: void GetEventL(); sl@0: void RestartFileL(); sl@0: void NotifyLockChangeL(); sl@0: void NotifyLockChangeCancelL(); sl@0: void GetFileNameL(TDes& aFileName); sl@0: void BackupOperationEventReadyL(); sl@0: void GetBackupOperationEventL(const RMessagePtr2& aPtr); sl@0: void GetBackupOperationStateL(); sl@0: void DoRestartAll(); sl@0: void NotifyBackupOperationL(); sl@0: void DoServiceL(TCompletionType& aCompleteType); sl@0: void CloseFileL(); sl@0: void StopNotifications(); sl@0: private: sl@0: TUint32 iUniqueClientId; sl@0: CBaServBackupMessageQueue* iMessageQueue; sl@0: RMessagePtr2 iNotificationPullMsg; sl@0: CArrayFix* iClosedFiles; sl@0: CDesCArray* iFileLockObservers; sl@0: CDesCArray* iReleasedFiles; sl@0: RMessagePtr2 iBackupOperationMessagePtr; sl@0: TBackupOperationAttributes iBackupOperationAttributes; sl@0: TBool iBackupOperationObserverPresent; sl@0: CReRegistrationTimer* iReRegistrationTimer; /* File lock re-registration timer */ sl@0: BSUL::CClientMessage* iClientMessage; sl@0: sl@0: }; sl@0: sl@0: class CShutdownServer; sl@0: sl@0: /** sl@0: @internalTechnology sl@0: */ sl@0: class CBaBackupServerExt : public CBase sl@0: { sl@0: public: sl@0: TUint32 iCachedBusyClientId; sl@0: TUint32 iUniqueBusyClientId; sl@0: }; sl@0: sl@0: // sl@0: // CBaBackupServer sl@0: // sl@0: sl@0: sl@0: /** sl@0: @internalTechnology sl@0: */ sl@0: class CBaBackupServer : public CServer2 sl@0: sl@0: { sl@0: public: sl@0: class CBaServCloseAllOperationTimer; sl@0: public: sl@0: IMPORT_C static CBaBackupServer* NewL(); sl@0: IMPORT_C ~CBaBackupServer(); sl@0: IMPORT_C void SetBusy(TUint32 aUniqueClientId); sl@0: IMPORT_C TBool IsClientBusy(TUint32 aUniqueClientId) const; sl@0: IMPORT_C void SignalBackupOperation(const TBackupOperationAttributes& aBackupOperationAttributes); sl@0: IMPORT_C TBool HaveAllCloseAllFilesClientsReRegistered(); sl@0: IMPORT_C void SetCloseAllOperationRunningState(TBool aRunning); sl@0: public: sl@0: inline TBool IsBackupOperationRunning() const; sl@0: inline void SetBackupOperationRunning(TBool aBackupOperationRunning); sl@0: public: sl@0: IMPORT_C virtual void CloseAllFilesL(MBackupObserver::TFileLockFlags aFlag); sl@0: IMPORT_C virtual void RestartAll(); sl@0: IMPORT_C virtual void ConstructL(); sl@0: IMPORT_C virtual void CompleteClosingFiles(CArrayFix* aClosedFiles); sl@0: IMPORT_C virtual TBool IsOtherClientBusy(TUint32 aUniqueClientId) const; sl@0: public: sl@0: void CloseFileL(MBackupObserver::TFileLockFlags aFlag,const TDesC& aFileName); sl@0: void RestartFile(const TDesC& aFileName); sl@0: void AddSession(); sl@0: void DropSession(); sl@0: void IncrementRegisteredFilesCount(); sl@0: void DecrementRegisteredFilesCount(TInt aNumberFiles = 1); sl@0: void IncrementFilesReRegistrationCount(); sl@0: void StartCloseAllFilesOperationTimer(const RMessagePtr2& aPtr); sl@0: TBool IsCloseAllOperationRunning(); sl@0: public: // from CServer sl@0: IMPORT_C TInt RunError(TInt aError); sl@0: protected: sl@0: IMPORT_C CBaBackupServer(TInt aPriority); sl@0: protected: // from CServer sl@0: IMPORT_C CSession2* NewSessionL(const TVersion &aVersion, const RMessage2& aMessage) const; sl@0: private: sl@0: CBaBackupServerExt* iExtension; sl@0: TBool iBackupOperationRunning; sl@0: TInt iSessionCount; sl@0: CShutdownServer* iShutdown; sl@0: TInt16 iRegisteredFilesCount; sl@0: TInt16 iSessionLockReRegistrationCount; /* Number of file lock sessions currently registered */ sl@0: CBaServCloseAllOperationTimer* iCloseAllFilesOperationTimer; /* Base file lock re-registration timer */ sl@0: TBool iCloseAllOperationRunning; /* Indicates that a CloseAll operation is in progress */ sl@0: }; sl@0: sl@0: inline CBaServBackupScheduler* CBaServBackupScheduler::Current() sl@0: { // static sl@0: return static_cast(CActiveScheduler::Current()); sl@0: } sl@0: sl@0: inline CBaBackupServer* CBaServBackupSession::BackupServer() const sl@0: { sl@0: return static_cast(const_cast(CSession2::Server())); sl@0: } sl@0: sl@0: inline CArrayFix* CBaServBackupSession::ClosedFiles() const sl@0: { sl@0: return iClosedFiles; sl@0: } sl@0: sl@0: inline void CBaServBackupSession::SetClosedFiles(CArrayFix* aClosedFiles) sl@0: { sl@0: if(!iClosedFiles) sl@0: { sl@0: iClosedFiles=aClosedFiles; sl@0: } sl@0: } sl@0: sl@0: inline TInt CBaServBackupSession::UniqueClientId() const sl@0: { sl@0: return iUniqueClientId; sl@0: } sl@0: sl@0: inline TBool CBaServBackupSession::TClosedFile::operator==(const TClosedFile& aClosedFile) const sl@0: { sl@0: return iDocName==aClosedFile.iDocName && iUid==aClosedFile.iUid; sl@0: } sl@0: sl@0: inline TBool CBaBackupServer::IsBackupOperationRunning() const sl@0: { sl@0: return iBackupOperationRunning; sl@0: } sl@0: sl@0: inline void CBaBackupServer::SetBackupOperationRunning(TBool aBackupOperationRunning) sl@0: { sl@0: iBackupOperationRunning = aBackupOperationRunning; sl@0: } sl@0: sl@0: #endif