First public contribution.
1 #ifndef __ENDPOINT_READER_H
2 #define __ENDPOINT_READER_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 endpointreader.h
29 namespace NUnitTesting_USBDI
33 * The buffer to read control packet data into
35 * High-speed 8,16,32 or 64bytes
39 const TInt KFullSpeedPacketSize = 64;
42 This class describes a handler for bytes received from the endpoint
44 class MEndpointDataHandler
48 Called when data is read from an endpoint
49 @param aEndpointNumber the number of the endpoint that was read from
50 @param aData the data read from the endpoint (valid data if the completion code is KErrNone)
51 @param aCompletionCode the completion code for the read
53 virtual void DataReceivedFromEndpointL(TEndpointNumber aEndpointNumber,const TDesC8& aData) = 0;
56 Called when the read operation from the endpoint completes with an error
57 @param aEndpointNumber the number of the endpoint read from
58 @param aErrorCode the operation error completion code
60 virtual void EndpointReadError(TEndpointNumber aEndpointNumber,TInt aErrorCode) = 0;
65 This class describes a general asyncronous endpoint reader
67 class CEndpointReader : public CActive
70 enum TCompletionAction
77 Constructor, build a reader that reads byte data from the specified endpoint number
78 @param aClientDriver the driver channel to the usb client driver
79 @param aEndpoint the endpoint number to read from
81 CEndpointReader(RDevUsbcClient& aClientDriver,TEndpointNumber aEndpoint);
86 virtual ~CEndpointReader();
89 Return data buffer used for Reads - could be NULL!
95 Return the result of the last recorded validation result!
101 Return the number of bytes read so far on a repeated (asynchronous)'Read'
102 @return that number of bytes
104 TUint NumBytesReadSoFar();
107 Read a data packet from the endpoint specified
108 @param aHandler a pointer to the handler of the data that will be read from the host
110 void ReadPacketL(MEndpointDataHandler* aHandler);
113 Read the specified number of bytes from the endpoint
114 @param aByteCount the number of bytes to read
116 void ReadL(TInt aByteCount);
119 Read the specified number of bytes (or fewer id a short packet arrives) from the endpoint
120 @param aByteCount the number of bytes to read
122 void ReadUntilShortL(TInt aByteCount);
125 Read the specified number of bytes from the endpoint
126 Flag the need to halt the endpoint when the read has completed
127 @param aByteCount the number of bytes to read
129 void ReadAndHaltL(TInt aByteCount);
132 Read a specified number of bytes from the endpoint in sections,
133 performing a new 'Read' for each section.
134 After each 'Read' use the data pattern to validate the results.
135 Expect the data pattern to be repeated in its entirety until
136 the total number of bytes have been sent.
137 @param aDataPattern the data pattern to be used for validation
138 @param aNumBytesPerRead the number of bytes to ask for at each 'Read'
139 @param aTotalNumBytes the total number of bytes to read
141 void RepeatedReadAndValidateL(const TDesC8& aDataPattern, TUint aNumBytesPerRead, TUint aTotalNumBytes);
144 Send an acknowledgment back to the host
145 This will be a zero length DATA1 packet
146 @return KErrNone if successful otherwise a system wide error code
152 Cancels the reading from the host
161 The framework error function from RunL
162 @param aError the error from a RunL leave
165 TInt RunError(TInt aError);
169 The channel to use to communicate to the client driver
171 RDevUsbcClient& iClientDriver;
174 The endpoint number that this reader will read from
176 TEndpointNumber iEndpoint;
179 The handler for Endpoint zero requests received
181 MEndpointDataHandler* iHandler;
184 The buffer for the data read from the endpoint
190 The buffer for the data read from the endpoint
192 HBufC8* iValidationPatternBuffer;
193 TPtr8 iValidationPatternPtr;
198 TCompletionAction iCompletionAction;
201 Needed if completion action is ERepeatedRead
203 TUint iRepeatedReadTotalNumBytes;
204 TUint iRepeatedReadNumBytesPerRead;
205 TUint iNumBytesReadSoFar;
206 TUint iDataPatternLength;