os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/inc/BasicWatcher.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/inc/BasicWatcher.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,155 @@
     1.4 +#ifndef __BASIC_WATCHER_H
     1.5 +#define __BASIC_WATCHER_H
     1.6 +
     1.7 +/*
     1.8 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.9 +* All rights reserved.
    1.10 +* This component and the accompanying materials are made available
    1.11 +* under the terms of the License "Eclipse Public License v1.0"
    1.12 +* which accompanies this distribution, and is available
    1.13 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.14 +*
    1.15 +* Initial Contributors:
    1.16 +* Nokia Corporation - initial contribution.
    1.17 +*
    1.18 +* Contributors:
    1.19 +*
    1.20 +* Description:
    1.21 +* @file BasicWatcher.h
    1.22 +* @internalComponent
    1.23 +* 
    1.24 +*
    1.25 +*/
    1.26 +
    1.27 +
    1.28 +
    1.29 +#include <e32base.h>
    1.30 +#include <d32usbdi.h>
    1.31 +#include "testdebug.h"
    1.32 +
    1.33 +namespace NUnitTesting_USBDI
    1.34 +	{
    1.35 +
    1.36 +
    1.37 +/**
    1.38 +This class watches for asynchronous completions and calls back
    1.39 +*/
    1.40 +class CBasicWatcher : public CActive
    1.41 +	{
    1.42 +public:
    1.43 +	CBasicWatcher(const TCallBack& aCallBack,TInt aPriority=EPriorityStandard);
    1.44 +	virtual ~CBasicWatcher();
    1.45 +	
    1.46 +	void CompleteNow(TInt aCompletionCode = KErrNone);
    1.47 +	void StartWatching();
    1.48 +	
    1.49 +protected: // From CActive
    1.50 +	void DoCancel();
    1.51 +	void RunL();
    1.52 +	TInt RunError(TInt aError);	
    1.53 +
    1.54 +private:
    1.55 +	TCallBack iCallBack;
    1.56 +	TInt iCompletionCode;
    1.57 +	};
    1.58 +
    1.59 +
    1.60 +
    1.61 +
    1.62 +
    1.63 +/**
    1.64 +This class describes a watcher for resumptions of interfaces
    1.65 +*/
    1.66 +class CInterfaceWatcher : public CActive
    1.67 +	{
    1.68 +public:
    1.69 +	/**
    1.70 +	Constructor, build 
    1.71 +	@param aInterface the usb interface to suspend  
    1.72 +	@param aCallBack the call back object to call once a resumption signal has happened
    1.73 +	*/
    1.74 +	CInterfaceWatcher(RUsbInterface& aInterface,const TCallBack& aCallBack)
    1.75 +	:	CActive(EPriorityUserInput),
    1.76 +		iUsbInterface(aInterface),
    1.77 +		iResumeCallBack(aCallBack),
    1.78 +		iCompletionCode(KErrNone)
    1.79 +		{
    1.80 +		CActiveScheduler::Add(this);
    1.81 +		}
    1.82 +
    1.83 +	/**
    1.84 +	Destructor
    1.85 +	*/
    1.86 +	~CInterfaceWatcher()
    1.87 +		{
    1.88 +		Cancel();
    1.89 +		}
    1.90 +
    1.91 +	/**
    1.92 +	Suspend the interface and watch for resumtions
    1.93 +	*/
    1.94 +	void SuspendAndWatch()
    1.95 +		{
    1.96 +		iUsbInterface.PermitSuspendAndWaitForResume(iStatus);
    1.97 +		SetActive();
    1.98 +		}
    1.99 +
   1.100 +	/**
   1.101 +	Obtains the most recent completion code for the interface resumption
   1.102 +	asynchronous action
   1.103 +	@return the completion error code
   1.104 +	*/
   1.105 +	TInt CompletionCode() const
   1.106 +		{
   1.107 +		return iCompletionCode;
   1.108 +		}
   1.109 +
   1.110 +protected: // From CActive
   1.111 +
   1.112 +	/**
   1.113 +	*/
   1.114 +	void DoCancel()
   1.115 +		{
   1.116 +		LOG_FUNC
   1.117 +		iUsbInterface.CancelPermitSuspend();
   1.118 +		}
   1.119 +
   1.120 +	
   1.121 +	/**
   1.122 +	*/
   1.123 +	void RunL()
   1.124 +		{
   1.125 +		LOG_FUNC
   1.126 +		iCompletionCode = iStatus.Int();
   1.127 +		User::LeaveIfError(iResumeCallBack.CallBack());
   1.128 +		}
   1.129 +	
   1.130 +	/**
   1.131 +	*/
   1.132 +	TInt RunError()
   1.133 +		{
   1.134 +		LOG_FUNC
   1.135 +
   1.136 +		return KErrNone;
   1.137 +		}
   1.138 +
   1.139 +private:
   1.140 +
   1.141 +	/**
   1.142 +	The USB interface resource
   1.143 +	*/
   1.144 +	RUsbInterface& iUsbInterface;
   1.145 +
   1.146 +	/**
   1.147 +	*/
   1.148 +	TCallBack iResumeCallBack;
   1.149 +
   1.150 +	/**
   1.151 +	*/
   1.152 +	TInt iCompletionCode;
   1.153 +	};
   1.154 +
   1.155 +
   1.156 +	}
   1.157 +	
   1.158 +#endif