os/ossrv/lowlevellibsandfws/apputils/tsrc/T_backupSrv.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
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
// class CBackupFileObserver
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
class CBackupFileObserver : public CActive, public MBackupObserver
sl@0
    19
	{
sl@0
    20
public:
sl@0
    21
	enum TFileLock
sl@0
    22
		{ELocked,EReadOnly,ENoAccess};
sl@0
    23
public:
sl@0
    24
	static CBackupFileObserver* NewL(TInt aFileObserverNumber);
sl@0
    25
	~CBackupFileObserver();
sl@0
    26
	void AddFileL(TInt aFileNumber);
sl@0
    27
public:
sl@0
    28
	TInt GetFileLocksChanged();
sl@0
    29
	void ZeroFileLocksChanged();
sl@0
    30
	void SetDelay(TBool aDelay);
sl@0
    31
private:
sl@0
    32
	CBackupFileObserver();
sl@0
    33
	void ConstructL(TInt aFileObserverNumber);
sl@0
    34
private: // from MBackupObserver
sl@0
    35
	void ChangeFileLockL(const TDesC& aFileName,TFileLockFlags aFlags);
sl@0
    36
public: // From CActive
sl@0
    37
	void RunL();
sl@0
    38
	void DoCancel();
sl@0
    39
public:
sl@0
    40
	void Kill(RThread* aThread);
sl@0
    41
private:
sl@0
    42
	// File observer session into the server
sl@0
    43
	CBaBackupSessionWrapper* iBackupSession;
sl@0
    44
	// Instance number for this obsever
sl@0
    45
	TInt iFileObserverNumber;
sl@0
    46
	// Number of file lock notifications received this backup
sl@0
    47
	TInt iFileLocksChanged;
sl@0
    48
	// Whether we're testing with an introduced delay or not
sl@0
    49
	TBool iDelay;
sl@0
    50
	// Local RTest for this class - needed because global RTest fails in multi-threaded environment
sl@0
    51
	RTest* iLocalRTest;
sl@0
    52
	// Name of the file we're observing
sl@0
    53
	TFileName iFileName;
sl@0
    54
	// State of the file we're observing
sl@0
    55
	TFileLock iFileLockState;
sl@0
    56
	};
sl@0
    57
sl@0
    58
//
sl@0
    59
//	class CBackupOperationObserver
sl@0
    60
//
sl@0
    61
class CBackupOperationObserver : public CActive, public MBackupOperationObserver
sl@0
    62
	{
sl@0
    63
public:
sl@0
    64
	static CBackupOperationObserver* NewL(TInt aObserverNumber);
sl@0
    65
	~CBackupOperationObserver();
sl@0
    66
public: // From CActive
sl@0
    67
	void RunL();
sl@0
    68
	void DoCancel();
sl@0
    69
public:
sl@0
    70
	void Kill(RThread* aThread);
sl@0
    71
private:
sl@0
    72
	CBackupOperationObserver();
sl@0
    73
	void ConstructL(TInt aObserverNumber);
sl@0
    74
sl@0
    75
	// from MBackupOperationObserver
sl@0
    76
	virtual void HandleBackupOperationEventL(const TBackupOperationAttributes& aBackupOperationAttributes);
sl@0
    77
private: 
sl@0
    78
	// Every backup observer has their own session
sl@0
    79
	CBaBackupSessionWrapper* iBackupSession;
sl@0
    80
	// Every backup observer has their own identifying number
sl@0
    81
	TInt iObserverNumber;
sl@0
    82
	// Local RTest for this class - needed because global RTest fails in multi-threaded environment
sl@0
    83
	RTest* iLocalRTest;
sl@0
    84
	};
sl@0
    85
sl@0
    86
//
sl@0
    87
//	class CBackupTestsStateMachine
sl@0
    88
//
sl@0
    89
sl@0
    90
class CBackupTestsStateMachine : public CActive
sl@0
    91
	{
sl@0
    92
public:
sl@0
    93
	static CBackupTestsStateMachine* NewL();
sl@0
    94
	CBackupTestsStateMachine();
sl@0
    95
	~CBackupTestsStateMachine();
sl@0
    96
public: // From CActive
sl@0
    97
	void RunL();
sl@0
    98
	void RunError();
sl@0
    99
	void DoCancel();
sl@0
   100
public:
sl@0
   101
	void Start();
sl@0
   102
	void End();
sl@0
   103
	void Complete();
sl@0
   104
	void StartBackupL();
sl@0
   105
	void EndBackup(TInt aFileLockChangesExpected, TBool oneTimeOnly);
sl@0
   106
	void SignalEndBackupL();
sl@0
   107
	void SingleFileLockTestsL();
sl@0
   108
public:
sl@0
   109
	void CreateObserversThreadsL();
sl@0
   110
	static TInt BackupObserversThreadStartL(TAny* aPtr);
sl@0
   111
	static TInt FileObserversThreadStartL(TAny* aPtr);
sl@0
   112
	void CreateBackupObserverInstanceL();
sl@0
   113
	void CreateFileObserverInstanceL();
sl@0
   114
public:
sl@0
   115
	enum StateMachineState
sl@0
   116
		{EStateMachineStart,
sl@0
   117
		 ESingleFileTests,		   ENoBackupSessionSingleFileTests,
sl@0
   118
		 ECloseAllNormalReadOnly,  ECloseAllNormalReadOnlyReturned, 
sl@0
   119
		 ECloseAllNormalNoAccess,  ECloseAllNormalNoAccessReturned, 
sl@0
   120
		 ECloseAllDelayReadOnly,   ECloseAllDelayReadOnlyReturned,  
sl@0
   121
		 ECloseAllDelayNoAccess,   ECloseAllDelayNoAccessReturned,
sl@0
   122
		 ECloseAllDropFileSession, ECloseAllDropFileSessionReturned,
sl@0
   123
		 ECloseAllDropBackupObserverSession, ECloseAllDropBackupObserverSessionReturned,
sl@0
   124
		 EStateMachineEnd};
sl@0
   125
public:
sl@0
   126
	void CloseAllStartL(StateMachineState aNextState, MBackupObserver::TFileLockFlags aFlag);
sl@0
   127
	void CloseAllEndL(StateMachineState aNextState, TInt aExpectedNotifications);
sl@0
   128
private:
sl@0
   129
	void ConstructL();
sl@0
   130
private:
sl@0
   131
	// The RTest class for this thread
sl@0
   132
	RTest* iLocalRTest;
sl@0
   133
	// The "command" session
sl@0
   134
	CBaBackupSessionWrapper* iBackupSession;	
sl@0
   135
	// Safety for RArrays
sl@0
   136
	RMutex iMutex;
sl@0
   137
	// Array of backup observers
sl@0
   138
	RPointerArray<CBackupOperationObserver> iBackupObservers;
sl@0
   139
	// Array of file lock observers
sl@0
   140
	RPointerArray<CBackupFileObserver> iBackupFileObservers;
sl@0
   141
	// Used for single file tests
sl@0
   142
	TInt iEndBackupRecursionCount;
sl@0
   143
	// Current state of the State Machine
sl@0
   144
	StateMachineState iState;
sl@0
   145
	// Used for backup observer threads
sl@0
   146
	RPointerArray<RThread> iBackupObserverThreads;
sl@0
   147
	// Used for file observer threads
sl@0
   148
	RPointerArray<RThread> iFileObserverThreads;
sl@0
   149
	};
sl@0
   150