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