author | sl |
Tue, 10 Jun 2014 14:32:02 +0200 | |
changeset 1 | 260cb5ec6c19 |
permissions | -rw-r--r-- |
sl@0 | 1 |
#ifndef __BASIC_WATCHER_H |
sl@0 | 2 |
#define __BASIC_WATCHER_H |
sl@0 | 3 |
|
sl@0 | 4 |
/* |
sl@0 | 5 |
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
sl@0 | 6 |
* All rights reserved. |
sl@0 | 7 |
* This component and the accompanying materials are made available |
sl@0 | 8 |
* under the terms of the License "Eclipse Public License v1.0" |
sl@0 | 9 |
* which accompanies this distribution, and is available |
sl@0 | 10 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
sl@0 | 11 |
* |
sl@0 | 12 |
* Initial Contributors: |
sl@0 | 13 |
* Nokia Corporation - initial contribution. |
sl@0 | 14 |
* |
sl@0 | 15 |
* Contributors: |
sl@0 | 16 |
* |
sl@0 | 17 |
* Description: |
sl@0 | 18 |
* @file BasicWatcher.h |
sl@0 | 19 |
* @internalComponent |
sl@0 | 20 |
* |
sl@0 | 21 |
* |
sl@0 | 22 |
*/ |
sl@0 | 23 |
|
sl@0 | 24 |
|
sl@0 | 25 |
|
sl@0 | 26 |
#include <e32base.h> |
sl@0 | 27 |
#include <d32usbdi.h> |
sl@0 | 28 |
#include "testdebug.h" |
sl@0 | 29 |
|
sl@0 | 30 |
namespace NUnitTesting_USBDI |
sl@0 | 31 |
{ |
sl@0 | 32 |
|
sl@0 | 33 |
|
sl@0 | 34 |
/** |
sl@0 | 35 |
This class watches for asynchronous completions and calls back |
sl@0 | 36 |
*/ |
sl@0 | 37 |
class CBasicWatcher : public CActive |
sl@0 | 38 |
{ |
sl@0 | 39 |
public: |
sl@0 | 40 |
CBasicWatcher(const TCallBack& aCallBack,TInt aPriority=EPriorityStandard); |
sl@0 | 41 |
virtual ~CBasicWatcher(); |
sl@0 | 42 |
|
sl@0 | 43 |
void CompleteNow(TInt aCompletionCode = KErrNone); |
sl@0 | 44 |
void StartWatching(); |
sl@0 | 45 |
|
sl@0 | 46 |
protected: // From CActive |
sl@0 | 47 |
void DoCancel(); |
sl@0 | 48 |
void RunL(); |
sl@0 | 49 |
TInt RunError(TInt aError); |
sl@0 | 50 |
|
sl@0 | 51 |
private: |
sl@0 | 52 |
TCallBack iCallBack; |
sl@0 | 53 |
TInt iCompletionCode; |
sl@0 | 54 |
}; |
sl@0 | 55 |
|
sl@0 | 56 |
|
sl@0 | 57 |
|
sl@0 | 58 |
|
sl@0 | 59 |
|
sl@0 | 60 |
/** |
sl@0 | 61 |
This class describes a watcher for resumptions of interfaces |
sl@0 | 62 |
*/ |
sl@0 | 63 |
class CInterfaceWatcher : public CActive |
sl@0 | 64 |
{ |
sl@0 | 65 |
public: |
sl@0 | 66 |
/** |
sl@0 | 67 |
Constructor, build |
sl@0 | 68 |
@param aInterface the usb interface to suspend |
sl@0 | 69 |
@param aCallBack the call back object to call once a resumption signal has happened |
sl@0 | 70 |
*/ |
sl@0 | 71 |
CInterfaceWatcher(RUsbInterface& aInterface,const TCallBack& aCallBack) |
sl@0 | 72 |
: CActive(EPriorityUserInput), |
sl@0 | 73 |
iUsbInterface(aInterface), |
sl@0 | 74 |
iResumeCallBack(aCallBack), |
sl@0 | 75 |
iCompletionCode(KErrNone) |
sl@0 | 76 |
{ |
sl@0 | 77 |
CActiveScheduler::Add(this); |
sl@0 | 78 |
} |
sl@0 | 79 |
|
sl@0 | 80 |
/** |
sl@0 | 81 |
Destructor |
sl@0 | 82 |
*/ |
sl@0 | 83 |
~CInterfaceWatcher() |
sl@0 | 84 |
{ |
sl@0 | 85 |
Cancel(); |
sl@0 | 86 |
} |
sl@0 | 87 |
|
sl@0 | 88 |
/** |
sl@0 | 89 |
Suspend the interface and watch for resumtions |
sl@0 | 90 |
*/ |
sl@0 | 91 |
void SuspendAndWatch() |
sl@0 | 92 |
{ |
sl@0 | 93 |
iUsbInterface.PermitSuspendAndWaitForResume(iStatus); |
sl@0 | 94 |
SetActive(); |
sl@0 | 95 |
} |
sl@0 | 96 |
|
sl@0 | 97 |
/** |
sl@0 | 98 |
Obtains the most recent completion code for the interface resumption |
sl@0 | 99 |
asynchronous action |
sl@0 | 100 |
@return the completion error code |
sl@0 | 101 |
*/ |
sl@0 | 102 |
TInt CompletionCode() const |
sl@0 | 103 |
{ |
sl@0 | 104 |
return iCompletionCode; |
sl@0 | 105 |
} |
sl@0 | 106 |
|
sl@0 | 107 |
protected: // From CActive |
sl@0 | 108 |
|
sl@0 | 109 |
/** |
sl@0 | 110 |
*/ |
sl@0 | 111 |
void DoCancel() |
sl@0 | 112 |
{ |
sl@0 | 113 |
LOG_FUNC |
sl@0 | 114 |
iUsbInterface.CancelPermitSuspend(); |
sl@0 | 115 |
} |
sl@0 | 116 |
|
sl@0 | 117 |
|
sl@0 | 118 |
/** |
sl@0 | 119 |
*/ |
sl@0 | 120 |
void RunL() |
sl@0 | 121 |
{ |
sl@0 | 122 |
LOG_FUNC |
sl@0 | 123 |
iCompletionCode = iStatus.Int(); |
sl@0 | 124 |
User::LeaveIfError(iResumeCallBack.CallBack()); |
sl@0 | 125 |
} |
sl@0 | 126 |
|
sl@0 | 127 |
/** |
sl@0 | 128 |
*/ |
sl@0 | 129 |
TInt RunError() |
sl@0 | 130 |
{ |
sl@0 | 131 |
LOG_FUNC |
sl@0 | 132 |
|
sl@0 | 133 |
return KErrNone; |
sl@0 | 134 |
} |
sl@0 | 135 |
|
sl@0 | 136 |
private: |
sl@0 | 137 |
|
sl@0 | 138 |
/** |
sl@0 | 139 |
The USB interface resource |
sl@0 | 140 |
*/ |
sl@0 | 141 |
RUsbInterface& iUsbInterface; |
sl@0 | 142 |
|
sl@0 | 143 |
/** |
sl@0 | 144 |
*/ |
sl@0 | 145 |
TCallBack iResumeCallBack; |
sl@0 | 146 |
|
sl@0 | 147 |
/** |
sl@0 | 148 |
*/ |
sl@0 | 149 |
TInt iCompletionCode; |
sl@0 | 150 |
}; |
sl@0 | 151 |
|
sl@0 | 152 |
|
sl@0 | 153 |
} |
sl@0 | 154 |
|
sl@0 | 155 |
#endif |