|
1 #ifndef __TEST_INTERFACE_BASE_H |
|
2 #define __TEST_INTERFACE_BASE_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 testinterfacebase.h |
|
19 * @internalComponent |
|
20 * |
|
21 * |
|
22 */ |
|
23 |
|
24 |
|
25 |
|
26 #include <e32base.h> |
|
27 #include "usbclientstatewatcher.h" |
|
28 #include "controlendpointreader.h" |
|
29 #include "endpointwriter.h" |
|
30 #include "endpointstallwatcher.h" |
|
31 |
|
32 |
|
33 namespace NUnitTesting_USBDI |
|
34 { |
|
35 |
|
36 // Forward declarations |
|
37 |
|
38 class RUsbTestDevice; |
|
39 class CInterfaceSettingBase; |
|
40 |
|
41 /** |
|
42 This class represents a test USB interface for the test USB device |
|
43 |
|
44 */ |
|
45 class CInterfaceBase : public CBase, public MAlternateSettingObserver, public MRequestHandler |
|
46 { |
|
47 public: |
|
48 /** |
|
49 Constructor, build an interface for a USB modelled device |
|
50 @param aTestDevice the device that this is an interface for |
|
51 @param aName the name given to the interface |
|
52 */ |
|
53 |
|
54 CInterfaceBase(RUsbTestDevice& aTestDevice,const TDesC16& aName); |
|
55 |
|
56 /** |
|
57 Base class 2nd phase construction |
|
58 */ |
|
59 |
|
60 void BaseConstructL(); |
|
61 |
|
62 /** |
|
63 Destructor |
|
64 */ |
|
65 |
|
66 virtual ~CInterfaceBase(); |
|
67 |
|
68 /** |
|
69 Adds an alternate interface setting for this interface |
|
70 @param aInterface an alternate interface setting associated with this interface |
|
71 */ |
|
72 |
|
73 void AddInterfaceSettingL(CInterfaceSettingBase* aInterfaceSetting); |
|
74 |
|
75 /** |
|
76 Accesses an alternate interface setting with the specified setting number |
|
77 @param aSettingNumber the alternate interface setting number |
|
78 @return a referrence to the alternate setting |
|
79 */ |
|
80 |
|
81 CInterfaceSettingBase& AlternateSetting(TInt aSettingNumber) const; |
|
82 |
|
83 /** |
|
84 Query the number of alternate interface settings for this interface |
|
85 @return the number of alternate interface settings |
|
86 */ |
|
87 |
|
88 TInt InterfaceSettingCount() const; |
|
89 |
|
90 /** |
|
91 Start the interface reading interface directed control transfers on endpoint 0 |
|
92 */ |
|
93 |
|
94 void StartEp0Reading(); |
|
95 |
|
96 /** |
|
97 Stop the interface from reading interface directed control transfers on endpoint 0 |
|
98 */ |
|
99 |
|
100 void StopEp0Reading(); |
|
101 |
|
102 /** |
|
103 Stall the specified endpoint |
|
104 @param aEndpointNumber the endpoint to stall |
|
105 @return KErrNone if successful |
|
106 */ |
|
107 |
|
108 TInt StallEndpoint(TUint16 aEndpointNumber); |
|
109 |
|
110 public: // From MAlternateSettingObserver |
|
111 |
|
112 /** |
|
113 Get notification when the host selects an alternate interface setting on this interface |
|
114 @param aAlternateInterfaceSetting the alternate interface setting number |
|
115 */ |
|
116 virtual void AlternateInterfaceSelectedL(TInt aAlternateInterfaceSetting); |
|
117 |
|
118 public: // From MEndpointDataHandler |
|
119 |
|
120 /** |
|
121 Process any Ep0 control transfer requests that are interface directed |
|
122 @param aRequest the request number (id) |
|
123 @param aValue the parameter to the request |
|
124 @param aIndex the interface number that the request is directed at |
|
125 @param aDataReqLength the data size in the transfer DATA1 packet(s) |
|
126 @param aPayload the request content data (i.e. all the data from DATA1 packets) |
|
127 */ |
|
128 virtual TInt ProcessRequestL(TUint8 aRequest,TUint16 aValue,TUint16 aIndex,TUint16 aDataReqLength,const TDesC8& aPayload); |
|
129 |
|
130 private: |
|
131 TUint32 ExtractNumberL(const TDesC8& aPayload); |
|
132 void ExtractTwoNumbersL(const TDesC8& aPayload, TUint32& aFirstNum, TUint32& aSecondNum); |
|
133 |
|
134 private: |
|
135 /** |
|
136 The test device object that owns this interface |
|
137 */ |
|
138 RUsbTestDevice& iDevice; |
|
139 |
|
140 /** |
|
141 The USB client driver |
|
142 Only use interface related API |
|
143 */ |
|
144 RDevUsbcClient iClientDriver; |
|
145 |
|
146 /** |
|
147 The alternate settings for this interface |
|
148 */ |
|
149 RPointerArray<CInterfaceSettingBase> iAlternateSettings; |
|
150 |
|
151 /** |
|
152 The watcher of alternate interface selection by host |
|
153 */ |
|
154 CAlternateInterfaceSelectionWatcher* iSelectionWatcher; |
|
155 |
|
156 /** |
|
157 The watcher of endpoint stalling |
|
158 */ |
|
159 CEndpointStallWatcher* iStallWatcher; |
|
160 |
|
161 /** |
|
162 The reader of interface control endpoint 0 |
|
163 */ |
|
164 CControlEndpointReader* iEp0Reader; |
|
165 |
|
166 /** |
|
167 The writer of interface control endpoint 0 |
|
168 */ |
|
169 CEndpointWriter* iEp0Writer; |
|
170 |
|
171 /** |
|
172 */ |
|
173 TBuf16<64> iInterfaceName; |
|
174 |
|
175 /** |
|
176 An Auxiliary buffer, to be used for anything temporary |
|
177 */ |
|
178 HBufC8* iAuxBuffer; |
|
179 |
|
180 /** |
|
181 The current alternate interface setting that is selected (defaults to zero) |
|
182 */ |
|
183 TInt iCurrentAlternateInterfaceSetting; |
|
184 }; |
|
185 |
|
186 |
|
187 } |
|
188 |
|
189 #endif |
|
190 |