sl@0: #ifndef __BASIC_WATCHER_H sl@0: #define __BASIC_WATCHER_H sl@0: sl@0: /* sl@0: * Copyright (c) 2007-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: * @file BasicWatcher.h sl@0: * @internalComponent sl@0: * sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include "testdebug.h" sl@0: sl@0: namespace NUnitTesting_USBDI sl@0: { sl@0: sl@0: sl@0: /** sl@0: This class watches for asynchronous completions and calls back sl@0: */ sl@0: class CBasicWatcher : public CActive sl@0: { sl@0: public: sl@0: CBasicWatcher(const TCallBack& aCallBack,TInt aPriority=EPriorityStandard); sl@0: virtual ~CBasicWatcher(); sl@0: sl@0: void CompleteNow(TInt aCompletionCode = KErrNone); sl@0: void StartWatching(); sl@0: sl@0: protected: // From CActive sl@0: void DoCancel(); sl@0: void RunL(); sl@0: TInt RunError(TInt aError); sl@0: sl@0: private: sl@0: TCallBack iCallBack; sl@0: TInt iCompletionCode; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: This class describes a watcher for resumptions of interfaces sl@0: */ sl@0: class CInterfaceWatcher : public CActive sl@0: { sl@0: public: sl@0: /** sl@0: Constructor, build sl@0: @param aInterface the usb interface to suspend sl@0: @param aCallBack the call back object to call once a resumption signal has happened sl@0: */ sl@0: CInterfaceWatcher(RUsbInterface& aInterface,const TCallBack& aCallBack) sl@0: : CActive(EPriorityUserInput), sl@0: iUsbInterface(aInterface), sl@0: iResumeCallBack(aCallBack), sl@0: iCompletionCode(KErrNone) sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: /** sl@0: Destructor sl@0: */ sl@0: ~CInterfaceWatcher() sl@0: { sl@0: Cancel(); sl@0: } sl@0: sl@0: /** sl@0: Suspend the interface and watch for resumtions sl@0: */ sl@0: void SuspendAndWatch() sl@0: { sl@0: iUsbInterface.PermitSuspendAndWaitForResume(iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: /** sl@0: Obtains the most recent completion code for the interface resumption sl@0: asynchronous action sl@0: @return the completion error code sl@0: */ sl@0: TInt CompletionCode() const sl@0: { sl@0: return iCompletionCode; sl@0: } sl@0: sl@0: protected: // From CActive sl@0: sl@0: /** sl@0: */ sl@0: void DoCancel() sl@0: { sl@0: LOG_FUNC sl@0: iUsbInterface.CancelPermitSuspend(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: */ sl@0: void RunL() sl@0: { sl@0: LOG_FUNC sl@0: iCompletionCode = iStatus.Int(); sl@0: User::LeaveIfError(iResumeCallBack.CallBack()); sl@0: } sl@0: sl@0: /** sl@0: */ sl@0: TInt RunError() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: private: sl@0: sl@0: /** sl@0: The USB interface resource sl@0: */ sl@0: RUsbInterface& iUsbInterface; sl@0: sl@0: /** sl@0: */ sl@0: TCallBack iResumeCallBack; sl@0: sl@0: /** sl@0: */ sl@0: TInt iCompletionCode; sl@0: }; sl@0: sl@0: sl@0: } sl@0: sl@0: #endif