os/security/authorisation/userpromptservice/database/test/tupsdb/source/activewaiter.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 WaitActiveL() 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->WaitActiveL();
    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 WaitActiveL(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 	
    75 private:
    76 	CTestExecuteLogger& Logger();
    77 	CActiveSchedulerWait iScheduler;
    78 	MActiveWaiterObserver* iCancelObserver;
    79 	CTestExecuteLogger& iLogger;
    80 	};
    81 	
    82 #endif // ACTIVEWAITER_H