phonebookengines_old/contactsmodel/tsrc/ThreadBase.h
changeset 40 b46a585f6909
equal deleted inserted replaced
37:fd64c38c277d 40:b46a585f6909
       
     1 // Copyright (c) 2003-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 //
       
    15 
       
    16 #ifndef __ThreadBase_H__
       
    17 #define __ThreadBase_H__
       
    18 
       
    19 // System includes
       
    20 #if !defined(__E32MATH_H__)
       
    21 #include <e32math.h> 
       
    22 #endif
       
    23 #if !defined(__E32TEST_H__)
       
    24 #include <e32test.h>
       
    25 #endif
       
    26 
       
    27 // Constant
       
    28 
       
    29 const TInt KMinDelay = 10000;
       
    30 const TInt KMaxDelay = 50000;
       
    31 const TInt KStandardTimeOut = 50000;
       
    32 
       
    33 //
       
    34 /* CThreadBase - Specification                                               */
       
    35 class CThreadBase : public CBase
       
    36 	{
       
    37 public: // user API
       
    38 	CThreadBase();
       
    39 	virtual ~CThreadBase();
       
    40 	void Go();
       
    41 	void WaitForCompetion();
       
    42 
       
    43 public: // can be used by derived class.
       
    44 	void SyncronizeSignal();
       
    45 	void SyncronizeWait();
       
    46 	void RandomDelay(TInt aMax, TInt aMin) const;
       
    47 
       
    48 protected: // to be overridden by the user
       
    49 	virtual void ThreadL() = 0;
       
    50 	virtual const TDesC& ThreadName() const = 0;
       
    51 
       
    52 private: // don't touch
       
    53 	void DoRunThreadL();
       
    54 	void SetUpTestL( const TDesC& aThreadName );
       
    55 	void TakeDownTest();
       
    56 	void OpenSemaphore();
       
    57 	void CloseSemaphore();
       
    58 	TInt RunThread();
       
    59 	static TInt ThreadFunction(TAny* aMe);
       
    60 
       
    61 public: // data
       
    62 	RThread					iThread;
       
    63 protected:
       
    64 	RTest*					iTest;
       
    65 private: // data
       
    66 	RSemaphore				iSemaphoreSignal;
       
    67 	RSemaphore				iSemaphoreWait;
       
    68 	TBool					iSemaphoreOpen;
       
    69 	CTrapCleanup* 			iCleanup;
       
    70 	TRequestStatus			iThreadStatus;
       
    71 	};
       
    72 
       
    73 #endif // __ThreadBase_H__