os/security/authorisation/userpromptservice/database/test/tupsdb/source/activewaiter.cpp
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) 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::WaitActiveL(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::WaitActiveL() Expected %d, Got %d"), aExpectedStatus, iStatus.Int());
    41 		}
    42 	if(iStatus.Int() != aExpectedStatus)
    43 		{
    44 		User::Leave(iStatus.Int());
    45 		}
    46 	//ASSERT_EQUALS(iStatus.Int(), aExpectedStatus);
    47 	}
    48 
    49 /**
    50 Sets the active scheduler active and immidiately Cancels, calling the 
    51 supplied cancel observer during DoCancel();
    52 @param aCancelObserver performs and DoCancel() operations on behalf of this object
    53 */
    54 void CActiveWaiter::SetActiveAndCancel(MActiveWaiterObserver& aCancelObserver)
    55 	{
    56 	ASSERT(!iScheduler.IsStarted());
    57 	ASSERT(iCancelObserver == NULL);
    58 	SetActive();
    59 	
    60 	iCancelObserver = &aCancelObserver;
    61 	
    62 	Cancel();
    63 	}
    64 
    65 /**
    66 Cancels the current operation, and stops the active scheduler loop,
    67 allowing a previous call to WaitActiveL() to return.
    68 @param aCancelObserver performs and DoCancel() operations on behalf of this object
    69 */
    70 void CActiveWaiter::CancelWaitActive(MActiveWaiterObserver& aCancelObserver)
    71 	{ 
    72 	ASSERT(iScheduler.IsStarted());
    73 	ASSERT(iCancelObserver == NULL);
    74 		
    75 	iCancelObserver = &aCancelObserver;
    76 	
    77 	Cancel();
    78 	
    79 	ASSERT(iScheduler.CanStopNow());
    80 	iScheduler.AsyncStop();
    81 	}
    82 
    83 void CActiveWaiter::RunL()
    84 	{
    85 	if (iScheduler.IsStarted())
    86 		{
    87 		ASSERT(iScheduler.CanStopNow());
    88 		iScheduler.AsyncStop();
    89 		}
    90 	}
    91 
    92 void CActiveWaiter::DoCancel()
    93 	{
    94 	ASSERT(iCancelObserver != NULL);
    95 	
    96 	iCancelObserver->DoCancel();
    97 	iCancelObserver = NULL;
    98 	}
    99 
   100 CTestExecuteLogger& CActiveWaiter::Logger()
   101 	{
   102 	return iLogger;	
   103 	}