email/imap4mtm/imapsession/test/src/cactivewaiter.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "cactivewaiter.h"
       
    17 
       
    18 CActiveWaiter::CActiveWaiter(CTestExecuteLogger& aLogger)
       
    19 	: CActive(CActive::EPriorityStandard)
       
    20 	, iLogger(aLogger)
       
    21 	{
       
    22 	CActiveScheduler::Add(this);
       
    23 	}
       
    24 	
       
    25 CActiveWaiter::~CActiveWaiter()
       
    26 	{ Cancel(); }
       
    27 
       
    28 void CActiveWaiter::WaitActive(TInt aExpectedStatus /*=KErrNone*/)
       
    29 	{ 
       
    30 	ASSERT(!iScheduler.IsStarted());
       
    31 	SetActive();
       
    32 	
       
    33 	iScheduler.Start();
       
    34 	
       
    35 	if (iStatus.Int() != aExpectedStatus)
       
    36 		{
       
    37 		INFO_PRINTF3(_L("CActiveWaiter::WaitActive() Expected %d, Got %d"), aExpectedStatus, iStatus.Int());
       
    38 		}
       
    39 	ASSERT_EQUALS(iStatus.Int(), aExpectedStatus);
       
    40 	}
       
    41 
       
    42 /**
       
    43 Sets the active scheduler active and immidiately Cancels, calling the 
       
    44 supplied cancel observer during DoCancel();
       
    45 @param aCancelObserver performs and DoCancel() operations on behalf of this object
       
    46 */
       
    47 void CActiveWaiter::SetActiveAndCancel(MActiveWaiterObserver& aCancelObserver)
       
    48 	{
       
    49 	ASSERT(!iScheduler.IsStarted());
       
    50 	ASSERT(iCancelObserver == NULL);
       
    51 	SetActive();
       
    52 	
       
    53 	iCancelObserver = &aCancelObserver;
       
    54 	
       
    55 	Cancel();
       
    56 	}
       
    57 
       
    58 /**
       
    59 Cancels the current operation, and stops the active scheduler loop,
       
    60 allowing a previous call to WaitActive() to return.
       
    61 @param aCancelObserver performs and DoCancel() operations on behalf of this object
       
    62 */
       
    63 void CActiveWaiter::CancelWaitActive(MActiveWaiterObserver& aCancelObserver)
       
    64 	{ 
       
    65 	ASSERT(iScheduler.IsStarted());
       
    66 	ASSERT(iCancelObserver == NULL);
       
    67 		
       
    68 	iCancelObserver = &aCancelObserver;
       
    69 	
       
    70 	Cancel();
       
    71 	
       
    72 	ASSERT(iScheduler.CanStopNow());
       
    73 	iScheduler.AsyncStop();
       
    74 	}
       
    75 
       
    76 void CActiveWaiter::RunL()
       
    77 	{
       
    78 	if (iScheduler.IsStarted())
       
    79 		{
       
    80 		ASSERT(iScheduler.CanStopNow());
       
    81 		iScheduler.AsyncStop();
       
    82 		}
       
    83 	}
       
    84 
       
    85 void CActiveWaiter::DoCancel()
       
    86 	{
       
    87 	ASSERT(iCancelObserver != NULL);
       
    88 	
       
    89 	iCancelObserver->DoCancel();
       
    90 	iCancelObserver = NULL;
       
    91 	}