|
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 LOG_FUNC |
|
114 iUsbInterface.CancelPermitSuspend(); |
|
115 } |
|
116 |
|
117 |
|
118 /** |
|
119 */ |
|
120 void RunL() |
|
121 { |
|
122 LOG_FUNC |
|
123 iCompletionCode = iStatus.Int(); |
|
124 User::LeaveIfError(iResumeCallBack.CallBack()); |
|
125 } |
|
126 |
|
127 /** |
|
128 */ |
|
129 TInt RunError() |
|
130 { |
|
131 LOG_FUNC |
|
132 |
|
133 return KErrNone; |
|
134 } |
|
135 |
|
136 private: |
|
137 |
|
138 /** |
|
139 The USB interface resource |
|
140 */ |
|
141 RUsbInterface& iUsbInterface; |
|
142 |
|
143 /** |
|
144 */ |
|
145 TCallBack iResumeCallBack; |
|
146 |
|
147 /** |
|
148 */ |
|
149 TInt iCompletionCode; |
|
150 }; |
|
151 |
|
152 |
|
153 } |
|
154 |
|
155 #endif |