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