os/security/authorisation/userpromptservice/database/test/tupsdb/source/activewaiter.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/authorisation/userpromptservice/database/test/tupsdb/source/activewaiter.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,82 @@
     1.4 +/*
     1.5 +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +* Copied from messaging IMAP tests
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +#ifndef ACTIVEWAITER_H
    1.24 +#define ACTIVEWAITER_H
    1.25 +
    1.26 +#include <test/tefunit.h>
    1.27 +
    1.28 +/**
    1.29 +@internalTechnology
    1.30 +@test
    1.31 +*/
    1.32 +class MActiveWaiterObserver
    1.33 +	{
    1.34 +	public:
    1.35 +		virtual void DoCancel() =0;
    1.36 +	};
    1.37 +
    1.38 +/**
    1.39 +An generic active object that can be used to wait for an iStatus to be signalled.
    1.40 +This has a similar effect to User::WaitForRequest(), but works without
    1.41 +blocking the thread (which allows other active objects within the thread
    1.42 +to continue).  Instead, a nested active scheduler loop is used.
    1.43 +
    1.44 +To use a CActiveWaiter, pass its iStatus to an asynchronous method, as usual.
    1.45 +Then call WaitActiveL() instead of SetActive().
    1.46 +
    1.47 +The call will block until the asynchronous completes.
    1.48 +
    1.49 +E.g.
    1.50 +
    1.51 +void CMyClass::Foo()
    1.52 +{
    1.53 +	CActiveWaiter* waiter = new(ELeave)CActiveWaiter;
    1.54 +
    1.55 +	iAsyncObj->Bar(waiter->iStatus);
    1.56 +	waiter->WaitActiveL();
    1.57 +	
    1.58 +	delete waiter;
    1.59 +}
    1.60 +@internalTechnology
    1.61 +@test
    1.62 +*/
    1.63 +class CActiveWaiter : public CActive
    1.64 +	{
    1.65 +public:
    1.66 +	CActiveWaiter(CTestExecuteLogger& aLogger);
    1.67 +	~CActiveWaiter();
    1.68 +	
    1.69 +	void WaitActiveL(TInt aExpectedStatus = KErrNone);
    1.70 +	void SetActiveAndCancel(MActiveWaiterObserver& aCancelObserver);
    1.71 +	void CancelWaitActive(MActiveWaiterObserver& aCancelObserver);
    1.72 +
    1.73 +protected:
    1.74 +	// from CActive;
    1.75 +	void RunL();
    1.76 +	void DoCancel();
    1.77 +	
    1.78 +private:
    1.79 +	CTestExecuteLogger& Logger();
    1.80 +	CActiveSchedulerWait iScheduler;
    1.81 +	MActiveWaiterObserver* iCancelObserver;
    1.82 +	CTestExecuteLogger& iLogger;
    1.83 +	};
    1.84 +	
    1.85 +#endif // ACTIVEWAITER_H