First public contribution.
1 #ifndef __TEST_INTERFACE_SETTING_BASE_H
2 #define __TEST_INTERFACE_SETTING_BASE_H
5 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
12 * Initial Contributors:
13 * Nokia Corporation - initial contribution.
18 * @file testinterfacesettingbase.h
28 #include <e32hashtab.h>
29 #include "testendpointbase.h"
30 #include "endpointreader.h"
31 #include "endpointwriter.h"
33 namespace NUnitTesting_USBDI
37 inline TUint32 EndpointNumberHash(const TEndpointNumber& aEndpointNumber)
39 return DefaultHash::Integer(static_cast<TInt>(aEndpointNumber));
42 inline TBool EndpointIdentityRelationship(const TEndpointNumber& aArg1,const TEndpointNumber& aArg2)
44 return aArg1 == aArg2;
48 // Forward declarations
52 This class represents a base class for alternate interface settings.
53 The class contains the endpoints that will be configured for use when this interface setting
56 class CInterfaceSettingBase : public CBase
59 friend class CInterfaceBase;
61 typedef RHashMap<TEndpointNumber,TEndpoint> REndpointMap;
66 Constructor, build an interface setting
67 @param aString the name of this interface setting
70 explicit CInterfaceSettingBase(const TDesC& aString);
75 virtual ~CInterfaceSettingBase();
78 Sets the specific class code, subclass code and protocol for this interface
79 codes are stated by the USB org.
80 @param aClassCode the class code for this interface
82 02h Communications and CDC Control (together with device)
83 03h HID (Human Interface Device)
92 DCh Diagnostic Device (together with device)
93 E0h Wireless Controller
94 EFh Miscellaneous (together with device)
95 FEh Application Specific
96 FFh Vendor Specific (together with device)
97 @param aSubClassCode the subclass code specified by the USB org
98 @param aDeviceProtocol
100 void SetClassCodeL(TUint8 aClassCode,TUint8 aSubClassCode,TUint8 aDeviceProtocol);
103 Add an endpoint to this alternate interface setting
104 @param anEndpoint the endpoint resource to add
105 @return KErrNone if successful or KErrOverflow if the endpoint cannot be added due to
108 TInt AddEndpoint(TEndpoint& anEndpoint);
113 void CreateEndpointReaderL(RDevUsbcClient& aClientDriver,TUint aEndpoint);
118 void CreateEndpointWriterL(RDevUsbcClient& aClientDriver,TUint aEndpoint);
121 Write the supplied data to the specified endpoint that can be found on
122 this interface setting
123 @param aData the data to write to the host
124 @param aEndpointNumber the number of the endpoint on this setting that a host
125 has an opened pipe to.
127 void WriteSpecifiedDataToEndpointL(const TDesC8& aData,TUint16 aEndpointNumber);
130 Cancel a current asynchronous 'Write' on the specified endpoint that can be found on
131 this interface setting
132 @param aEndpointNumber the number of the endpoint on this setting that a host
133 has an opened pipe to.
135 void CancelWriteDataToEndpointL(TUint16 aEndpointNumber);
138 Write the supplied data to the specified endpoint that can be found on
139 this interface setting
140 @param aDataPattern the data pattern to use when writing to the host
141 @param aNumBytes the number of bytes to write using this data pattern
142 @param aEndpointNumber the number of the endpoint on this setting that a host
143 has an opened pipe to.
145 void WriteSpecifiedDataToEndpointL(const TDesC8& aDataPattern, TUint aNumBytes, TUint16 aEndpointNumber);
148 Write the supplied data to the specified endpoint that can be found on
149 this interface setting
150 @param aDataPattern the data pattern to use when writing to the host
151 @param aNumBytesPerWrite the number of bytes to write at each call to 'Write' using this data pattern
152 @param aTotalNumBytes the total number of bytes to write
153 @param aEndpointNumber the number of the endpoint on this setting that a host
154 has an opened pipe to.
156 void RepeatedWriteSpecifiedDataToEndpointL(const TDesC8& aDataPattern, TUint aNumBytesPerWrite, TUint aTotalNumBytes, TUint16 aEndpointNumber);
159 Write the data cached on the 'source' endpoint to the 'write' endpoint. These endpoints can be found on
160 this interface setting
161 @param aSourceEndpointNumber the number of the endpoint on this setting that should contain cached data.
162 @param aWriteEndpointNumber the number of the endpoint on this setting that the cached data on 'aSourceEndpointNumber'
163 should be written to.
165 void WriteCachedEndpointDataToEndpointL(const TUint16 aSourceEndpointNumber,TUint16 aWriteEndpointNumber);
169 Write the supplied data to the specified endpoint that can be found on
170 this interface setting. Wait for Completion.
171 @param aDataPattern the data pattern to use when writing to the host
172 @param aNumBytes the number of bytes to write using this data pattern
173 @param aEndpointNumber the number of the endpoint on this setting that a host
174 has an opened pipe to.
176 void WriteSynchronousSpecifiedDataToEndpointL(const TDesC8& aDataPattern, TUint aNumBytes, TUint16 aEndpointNumber);
179 Write the supplied data to the specified endpoint that can be found on
180 this interface setting, and halt that endpoint. Wait for Completion.
181 @param aDataPattern the data pattern to use when writing to the host
182 @param aNumBytes the number of bytes to write using this data pattern
183 @param aEndpointNumber the number of the endpoint on this setting that a host
184 has an opened pipe to.
186 void WriteSynchronousSpecifiedDataToAndHaltEndpointL(const TDesC8& aDataPattern, TUint aNumBytes, TUint16 aEndpointNumber);
189 Synchronously write the data cached on the 'source' endpoint to the 'write' endpoint. These endpoints can be found on
190 this interface setting. Wait for Completion.
191 @param aSourceEndpointNumber the number of the endpoint on this setting that should contain cached data.
192 @param aWriteEndpointNumber the number of the endpoint on this setting that the cached data on 'aSourceEndpointNumber'
193 should be written to.
195 void WriteSynchronousCachedEndpointDataToEndpointL(const TUint16 aSourceEndpointNumber,TUint16 aWriteEndpointNumber);
198 Synchronously write a section of the data cached on the 'source' endpoint to the 'write' endpoint. These endpoints can be found on
199 this interface setting. Wait for Completion.
200 @param aSourceEndpointNumber the number of the endpoint on this setting that should contain cached data.
201 @param aWriteEndpointNumber the number of the endpoint on this setting that the cached data on 'aSourceEndpointNumber'
202 should be written to.
203 @param aStartPoint the beginning of the part of the cached data that is to be written
204 @param aLength the length of the part of the cached data that is to be written
206 void WriteSynchronousCachedEndpointDataToEndpointL(const TUint16 aSourceEndpointNumber,TUint16 aWriteEndpointNumber, TUint aStartPoint, TUint aLength);
209 Get the cached result of a validation from an endpoint
210 @param aEndpointNumber the number of the endpoint on this setting that a host
211 has an opened pipe to.
212 @return ETrue if the data is validated, EFalse if not
214 TBool CachedEndpointResultL(const TUint16 aEndpointNumber);
217 Get the cached of the number of bytes read so far on a repeated (asynchronous) 'Read' being perfomed on an endpoint
218 @param aEndpointNumber the number of the endpoint on this setting that a host
219 has an opened pipe to.
220 @return the number of bytes read so far
222 TInt NumBytesReadSoFarL(const TUint16 aEndpointNumber);
225 Get the cached of the number of bytes written so far on a repeated (asynchronous) 'Write' being perfomed on an endpoint
226 @param aEndpointNumber the number of the endpoint on this setting that a host
227 has an opened pipe to.
228 @return the number of bytes written so far
230 TInt NumBytesWrittenSoFarL(const TUint16 aEndpointNumber);
233 Validate the data read on the supplied endpoint using the global pattern.
234 @param aDataPattern basic data pattern sent by host for comparison
235 @param aNumBytes - the number of bytes to validate using that data pattern
236 @param aEndpointNumber the number of the endpoint on this setting that a host
237 has an opened pipe to.
238 @return ETrue if the data is validated, EFalse if not
240 TBool ValidateCachedEndpointDataL(const TDesC8& aDataPattern, const TUint aNumBytes, const TUint16 aEndpointNumber);
243 Validate the data read on the supplied endpoint using the global pattern.
244 @param aDataPattern basic data pattern sent by host for comparison
245 @param aStartPoint - the point (in bytes) in the data pattern to start (this value is used cyclically - so may be greater than the data pattern length)
246 @param aNumBytes - the number of bytes to validate using that data pattern
247 @param aEndpointNumber the number of the endpoint on this setting that a host
248 has an opened pipe to.
249 @return ETrue if the data is validated, EFalse if not
251 TBool ValidateCachedEndpointDataL(const TDesC8& aDataPattern, const TUint aStartPoint, const TUint aNumBytes, const TUint16 aEndpointNumber);
254 Read the supplied number of bytes on the specified endpoint that can be found on
255 this interface setting
256 @param aNumBytes the amount of data to be read from the host
257 @param aEndpointNumber the number of the endpoint on this setting that a host
258 has an opened pipe to.
260 void ReadDataFromEndpointL(TUint aNumBytes, TUint16 aEndpointNumber);
263 Cancel Read on the specified endpoint that can be found on
264 this interface setting
265 @param aEndpointNumber the number of the endpoint on this setting that a host
266 has an opened pipe to.
268 void CancelAnyReadDataFromEndpointL(TUint16 aEndpointNumber);
271 Read the supplied number of bytes on the specified endpoint that can be found on
272 this interface setting ... then halt the endpoint
273 @param aNumBytes the amount of data to be read from the host
274 @param aEndpointNumber the number of the endpoint on this setting that a host
275 has an opened pipe to.
277 void ReadDataFromAndHaltEndpointL(TUint aNumBytes, TUint16 aEndpointNumber);
280 Read the supplied number of bytes on the specified endpoint that can be found on
281 this interface setting.
282 Do these in sections, performing multiple 'Reads'
283 @param aDataPattern the data pattern to use in validation
284 @param aNumBytesPerRead the amount of data to be read from the host in each section
285 @param aTotalNumBytes the total amount of data to be read from the host
286 @param aEndpointNumber the number of the endpoint on this setting that a host
287 has an opened pipe to.
289 void RepeatedReadAndValidateFromEndpointL(const TDesC8& aDataPattern, TUint aNumBytesPerRead, TUint aTotalNumBytes, TUint16 aEndpointNumber);
291 Read the supplied number of bytes (or fewer if a short packet arrives)
292 on the specified endpoint that can be found on this interface setting
293 @param aNumBytes the amount of data to be read from the host
294 @param aEndpointNumber the number of the endpoint on this setting that a host
295 has an opened pipe to.
297 void ReadDataUntilShortFromEndpointL(TUint aNumBytes, TUint16 aEndpointNumber);
300 Get the name of this interface setting
301 @return the interface setting name
303 const TDesC& Name() const;
308 Disable default constructor
310 CInterfaceSettingBase();
315 The information for this interface setting about endpoints
317 TUsbcInterfaceInfoBuf iInterfaceInfo;
320 The name for this interface setting
322 TBuf<64> iSettingString;
325 The array of endpoints for this interface setting
327 THashFunction32<TEndpointNumber> iHashEndpointFunction;
328 TIdentityRelation<TEndpointNumber> iIdRelEndpoint;
329 REndpointMap iEndpoints;
332 The readers for the endpoints on this interface setting
334 RPointerArray<CEndpointReader> iEndpointReaders;
337 The writers for the endpoints on this interface setting
339 RPointerArray<CEndpointWriter> iEndpointWriters;