os/security/authorisation/userpromptservice/policies/test/tupspolicies/source/activewaiter.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2007-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 *
    16 */
    17 
    18 
    19 #include "activewaiter.h"
    20 
    21 CActiveWaiter::CActiveWaiter(CTestExecuteLogger& aLogger)
    22 	: CActive(CActive::EPriorityStandard)
    23 	, iLogger(aLogger)
    24 	{
    25 	CActiveScheduler::Add(this);
    26 	}
    27 	
    28 CActiveWaiter::~CActiveWaiter()
    29 	{ Cancel(); }
    30 
    31 void CActiveWaiter::WaitActive(TInt aExpectedStatus /*=KErrNone*/)
    32 	{ 
    33 	ASSERT(!iScheduler.IsStarted());
    34 	SetActive();
    35 	
    36 	iScheduler.Start();
    37 	
    38 	if (iStatus.Int() != aExpectedStatus)
    39 		{
    40 		INFO_PRINTF3(_L("CActiveWaiter::WaitActive() Expected %d, Got %d"), aExpectedStatus, iStatus.Int());
    41 		}
    42 	ASSERT_EQUALS(iStatus.Int(), aExpectedStatus);
    43 	}
    44 
    45 /**
    46 Sets the active scheduler active and immidiately Cancels, calling the 
    47 supplied cancel observer during DoCancel();
    48 @param aCancelObserver performs and DoCancel() operations on behalf of this object
    49 */
    50 void CActiveWaiter::SetActiveAndCancel(MActiveWaiterObserver& aCancelObserver)
    51 	{
    52 	ASSERT(!iScheduler.IsStarted());
    53 	ASSERT(iCancelObserver == NULL);
    54 	SetActive();
    55 	
    56 	iCancelObserver = &aCancelObserver;
    57 	
    58 	Cancel();
    59 	}
    60 
    61 /**
    62 Cancels the current operation, and stops the active scheduler loop,
    63 allowing a previous call to WaitActive() to return.
    64 @param aCancelObserver performs and DoCancel() operations on behalf of this object
    65 */
    66 void CActiveWaiter::CancelWaitActive(MActiveWaiterObserver& aCancelObserver)
    67 	{ 
    68 	ASSERT(iScheduler.IsStarted());
    69 	ASSERT(iCancelObserver == NULL);
    70 		
    71 	iCancelObserver = &aCancelObserver;
    72 	
    73 	Cancel();
    74 	
    75 	ASSERT(iScheduler.CanStopNow());
    76 	iScheduler.AsyncStop();
    77 	}
    78 
    79 void CActiveWaiter::RunL()
    80 	{
    81 	if (iScheduler.IsStarted())
    82 		{
    83 		ASSERT(iScheduler.CanStopNow());
    84 		iScheduler.AsyncStop();
    85 		}
    86 	}
    87 
    88 void CActiveWaiter::DoCancel()
    89 	{
    90 	ASSERT(iCancelObserver != NULL);
    91 	
    92 	iCancelObserver->DoCancel();
    93 	iCancelObserver = NULL;
    94 	}
    95 CTestExecuteLogger& CActiveWaiter::Logger()
    96 	{
    97 	return iLogger;	
    98 	}