os/security/authorisation/userpromptservice/policies/test/tupspolicies/source/activewaiter.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 * Copied from messaging IMAP tests
    16 *
    17 */
    18 
    19 
    20 #ifndef ACTIVEWAITER_H
    21 #define ACTIVEWAITER_H
    22 
    23 #include <test/tefunit.h>
    24 
    25 /**
    26 @internalTechnology
    27 @test
    28 */
    29 class MActiveWaiterObserver
    30 	{
    31 	public:
    32 		virtual void DoCancel() =0;
    33 	};
    34 
    35 /**
    36 An generic active object that can be used to wait for an iStatus to be signalled.
    37 This has a similar effect to User::WaitForRequest(), but works without
    38 blocking the thread (which allows other active objects within the thread
    39 to continue).  Instead, a nested active scheduler loop is used.
    40 
    41 To use a CActiveWaiter, pass its iStatus to an asynchronous method, as usual.
    42 Then call WaitActive() instead of SetActive().
    43 
    44 The call will block until the asynchronous completes.
    45 
    46 E.g.
    47 
    48 void CMyClass::Foo()
    49 {
    50 	CActiveWaiter* waiter = new(ELeave)CActiveWaiter;
    51 
    52 	iAsyncObj->Bar(waiter->iStatus);
    53 	waiter->WaitActive();
    54 	
    55 	delete waiter;
    56 }
    57 @internalTechnology
    58 @test
    59 */
    60 class CActiveWaiter : public CActive
    61 	{
    62 public:
    63 	CActiveWaiter(CTestExecuteLogger& aLogger);
    64 	~CActiveWaiter();
    65 	
    66 	void WaitActive(TInt aExpectedStatus = KErrNone);
    67 	void SetActiveAndCancel(MActiveWaiterObserver& aCancelObserver);
    68 	void CancelWaitActive(MActiveWaiterObserver& aCancelObserver);
    69 
    70 protected:
    71 	// from CActive;
    72 	void RunL();
    73 	void DoCancel();
    74 private:
    75 	CTestExecuteLogger& Logger();
    76 	CActiveSchedulerWait iScheduler;
    77 	MActiveWaiterObserver* iCancelObserver;
    78 	CTestExecuteLogger& iLogger;
    79 	};
    80 	
    81 #endif // ACTIVEWAITER_H