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