sl@0: /* sl@0: * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "activewaiter.h" sl@0: sl@0: CActiveWaiter::CActiveWaiter(CTestExecuteLogger& aLogger) sl@0: : CActive(CActive::EPriorityStandard) sl@0: , iLogger(aLogger) sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: CActiveWaiter::~CActiveWaiter() sl@0: { Cancel(); } sl@0: sl@0: void CActiveWaiter::WaitActiveL(TInt aExpectedStatus /*=KErrNone*/) sl@0: { sl@0: ASSERT(!iScheduler.IsStarted()); sl@0: SetActive(); sl@0: sl@0: iScheduler.Start(); sl@0: sl@0: if (iStatus.Int() != aExpectedStatus) sl@0: { sl@0: INFO_PRINTF3(_L("CActiveWaiter::WaitActiveL() Expected %d, Got %d"), aExpectedStatus, iStatus.Int()); sl@0: } sl@0: if(iStatus.Int() != aExpectedStatus) sl@0: { sl@0: User::Leave(iStatus.Int()); sl@0: } sl@0: //ASSERT_EQUALS(iStatus.Int(), aExpectedStatus); sl@0: } sl@0: sl@0: /** sl@0: Sets the active scheduler active and immidiately Cancels, calling the sl@0: supplied cancel observer during DoCancel(); sl@0: @param aCancelObserver performs and DoCancel() operations on behalf of this object sl@0: */ sl@0: void CActiveWaiter::SetActiveAndCancel(MActiveWaiterObserver& aCancelObserver) sl@0: { sl@0: ASSERT(!iScheduler.IsStarted()); sl@0: ASSERT(iCancelObserver == NULL); sl@0: SetActive(); sl@0: sl@0: iCancelObserver = &aCancelObserver; sl@0: sl@0: Cancel(); sl@0: } sl@0: sl@0: /** sl@0: Cancels the current operation, and stops the active scheduler loop, sl@0: allowing a previous call to WaitActiveL() to return. sl@0: @param aCancelObserver performs and DoCancel() operations on behalf of this object sl@0: */ sl@0: void CActiveWaiter::CancelWaitActive(MActiveWaiterObserver& aCancelObserver) sl@0: { sl@0: ASSERT(iScheduler.IsStarted()); sl@0: ASSERT(iCancelObserver == NULL); sl@0: sl@0: iCancelObserver = &aCancelObserver; sl@0: sl@0: Cancel(); sl@0: sl@0: ASSERT(iScheduler.CanStopNow()); sl@0: iScheduler.AsyncStop(); sl@0: } sl@0: sl@0: void CActiveWaiter::RunL() sl@0: { sl@0: if (iScheduler.IsStarted()) sl@0: { sl@0: ASSERT(iScheduler.CanStopNow()); sl@0: iScheduler.AsyncStop(); sl@0: } sl@0: } sl@0: sl@0: void CActiveWaiter::DoCancel() sl@0: { sl@0: ASSERT(iCancelObserver != NULL); sl@0: sl@0: iCancelObserver->DoCancel(); sl@0: iCancelObserver = NULL; sl@0: } sl@0: sl@0: CTestExecuteLogger& CActiveWaiter::Logger() sl@0: { sl@0: return iLogger; sl@0: }