sl@0: /* sl@0: * Copyright (c) 2006-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: * Copied from messaging IMAP tests sl@0: * sl@0: */ sl@0: sl@0: sl@0: #ifndef ACTIVEWAITER_H sl@0: #define ACTIVEWAITER_H sl@0: sl@0: #include sl@0: sl@0: /** sl@0: @internalTechnology sl@0: @test sl@0: */ sl@0: class MActiveWaiterObserver sl@0: { sl@0: public: sl@0: virtual void DoCancel() =0; sl@0: }; sl@0: sl@0: /** sl@0: An generic active object that can be used to wait for an iStatus to be signalled. sl@0: This has a similar effect to User::WaitForRequest(), but works without sl@0: blocking the thread (which allows other active objects within the thread sl@0: to continue). Instead, a nested active scheduler loop is used. sl@0: sl@0: To use a CActiveWaiter, pass its iStatus to an asynchronous method, as usual. sl@0: Then call WaitActiveL() instead of SetActive(). sl@0: sl@0: The call will block until the asynchronous completes. sl@0: sl@0: E.g. sl@0: sl@0: void CMyClass::Foo() sl@0: { sl@0: CActiveWaiter* waiter = new(ELeave)CActiveWaiter; sl@0: sl@0: iAsyncObj->Bar(waiter->iStatus); sl@0: waiter->WaitActiveL(); sl@0: sl@0: delete waiter; sl@0: } sl@0: @internalTechnology sl@0: @test sl@0: */ sl@0: class CActiveWaiter : public CActive sl@0: { sl@0: public: sl@0: CActiveWaiter(CTestExecuteLogger& aLogger); sl@0: ~CActiveWaiter(); sl@0: sl@0: void WaitActiveL(TInt aExpectedStatus = KErrNone); sl@0: void SetActiveAndCancel(MActiveWaiterObserver& aCancelObserver); sl@0: void CancelWaitActive(MActiveWaiterObserver& aCancelObserver); sl@0: sl@0: protected: sl@0: // from CActive; sl@0: void RunL(); sl@0: void DoCancel(); sl@0: sl@0: private: sl@0: CTestExecuteLogger& Logger(); sl@0: CActiveSchedulerWait iScheduler; sl@0: MActiveWaiterObserver* iCancelObserver; sl@0: CTestExecuteLogger& iLogger; sl@0: }; sl@0: sl@0: #endif // ACTIVEWAITER_H