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