1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/inc/endpointreader.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,216 @@
1.4 +#ifndef __ENDPOINT_READER_H
1.5 +#define __ENDPOINT_READER_H
1.6 +
1.7 +/*
1.8 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.9 +* All rights reserved.
1.10 +* This component and the accompanying materials are made available
1.11 +* under the terms of the License "Eclipse Public License v1.0"
1.12 +* which accompanies this distribution, and is available
1.13 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.14 +*
1.15 +* Initial Contributors:
1.16 +* Nokia Corporation - initial contribution.
1.17 +*
1.18 +* Contributors:
1.19 +*
1.20 +* Description:
1.21 +* @file endpointreader.h
1.22 +* @internalComponent
1.23 +*
1.24 +*
1.25 +*/
1.26 +
1.27 +
1.28 +
1.29 +#include <e32base.h>
1.30 +#include <d32usbc.h>
1.31 +
1.32 +namespace NUnitTesting_USBDI
1.33 + {
1.34 +
1.35 +/*
1.36 + * The buffer to read control packet data into
1.37 + * Low-speed 8bytes
1.38 + * High-speed 8,16,32 or 64bytes
1.39 + * Full-speed 64bytes
1.40 + */
1.41 +
1.42 +const TInt KFullSpeedPacketSize = 64;
1.43 +
1.44 +/**
1.45 +This class describes a handler for bytes received from the endpoint
1.46 +*/
1.47 +class MEndpointDataHandler
1.48 + {
1.49 +public:
1.50 + /**
1.51 + Called when data is read from an endpoint
1.52 + @param aEndpointNumber the number of the endpoint that was read from
1.53 + @param aData the data read from the endpoint (valid data if the completion code is KErrNone)
1.54 + @param aCompletionCode the completion code for the read
1.55 + */
1.56 + virtual void DataReceivedFromEndpointL(TEndpointNumber aEndpointNumber,const TDesC8& aData) = 0;
1.57 +
1.58 + /**
1.59 + Called when the read operation from the endpoint completes with an error
1.60 + @param aEndpointNumber the number of the endpoint read from
1.61 + @param aErrorCode the operation error completion code
1.62 + */
1.63 + virtual void EndpointReadError(TEndpointNumber aEndpointNumber,TInt aErrorCode) = 0;
1.64 + };
1.65 +
1.66 +
1.67 +/**
1.68 +This class describes a general asyncronous endpoint reader
1.69 +*/
1.70 +class CEndpointReader : public CActive
1.71 + {
1.72 +public:
1.73 + enum TCompletionAction
1.74 + {
1.75 + ENone,
1.76 + EHaltEndpoint,
1.77 + ERepeatedRead,
1.78 + };
1.79 + /**
1.80 + Constructor, build a reader that reads byte data from the specified endpoint number
1.81 + @param aClientDriver the driver channel to the usb client driver
1.82 + @param aEndpoint the endpoint number to read from
1.83 + */
1.84 + CEndpointReader(RDevUsbcClient& aClientDriver,TEndpointNumber aEndpoint);
1.85 +
1.86 + /**
1.87 + Destructor
1.88 + */
1.89 + virtual ~CEndpointReader();
1.90 +
1.91 + /**
1.92 + Return data buffer used for Reads - could be NULL!
1.93 + @return data buffer
1.94 + */
1.95 + TPtr8 Buffer();
1.96 +
1.97 + /**
1.98 + Return the result of the last recorded validation result!
1.99 + @return that result
1.100 + */
1.101 + TBool IsValid();
1.102 +
1.103 + /**
1.104 + Return the number of bytes read so far on a repeated (asynchronous)'Read'
1.105 + @return that number of bytes
1.106 + */
1.107 + TUint NumBytesReadSoFar();
1.108 +
1.109 + /**
1.110 + Read a data packet from the endpoint specified
1.111 + @param aHandler a pointer to the handler of the data that will be read from the host
1.112 + */
1.113 + void ReadPacketL(MEndpointDataHandler* aHandler);
1.114 +
1.115 + /**
1.116 + Read the specified number of bytes from the endpoint
1.117 + @param aByteCount the number of bytes to read
1.118 + */
1.119 + void ReadL(TInt aByteCount);
1.120 +
1.121 + /**
1.122 + Read the specified number of bytes (or fewer id a short packet arrives) from the endpoint
1.123 + @param aByteCount the number of bytes to read
1.124 + */
1.125 + void ReadUntilShortL(TInt aByteCount);
1.126 +
1.127 + /**
1.128 + Read the specified number of bytes from the endpoint
1.129 + Flag the need to halt the endpoint when the read has completed
1.130 + @param aByteCount the number of bytes to read
1.131 + */
1.132 + void ReadAndHaltL(TInt aByteCount);
1.133 +
1.134 + /**
1.135 + Read a specified number of bytes from the endpoint in sections,
1.136 + performing a new 'Read' for each section.
1.137 + After each 'Read' use the data pattern to validate the results.
1.138 + Expect the data pattern to be repeated in its entirety until
1.139 + the total number of bytes have been sent.
1.140 + @param aDataPattern the data pattern to be used for validation
1.141 + @param aNumBytesPerRead the number of bytes to ask for at each 'Read'
1.142 + @param aTotalNumBytes the total number of bytes to read
1.143 + */
1.144 + void RepeatedReadAndValidateL(const TDesC8& aDataPattern, TUint aNumBytesPerRead, TUint aTotalNumBytes);
1.145 +
1.146 + /**
1.147 + Send an acknowledgment back to the host
1.148 + This will be a zero length DATA1 packet
1.149 + @return KErrNone if successful otherwise a system wide error code
1.150 + */
1.151 + TInt Acknowledge();
1.152 +
1.153 +protected:
1.154 + /**
1.155 + Cancels the reading from the host
1.156 + */
1.157 + void DoCancel();
1.158 +
1.159 + /**
1.160 + */
1.161 + virtual void RunL();
1.162 +
1.163 + /**
1.164 + The framework error function from RunL
1.165 + @param aError the error from a RunL leave
1.166 + @return KErrNone
1.167 + */
1.168 + TInt RunError(TInt aError);
1.169 +
1.170 +protected:
1.171 + /**
1.172 + The channel to use to communicate to the client driver
1.173 + */
1.174 + RDevUsbcClient& iClientDriver;
1.175 +
1.176 + /**
1.177 + The endpoint number that this reader will read from
1.178 + */
1.179 + TEndpointNumber iEndpoint;
1.180 +
1.181 + /**
1.182 + The handler for Endpoint zero requests received
1.183 + */
1.184 + MEndpointDataHandler* iHandler;
1.185 +
1.186 + /**
1.187 + The buffer for the data read from the endpoint
1.188 + */
1.189 + HBufC8* iDataBuffer;
1.190 + TPtr8 iDataPtr;
1.191 +
1.192 + /**
1.193 + The buffer for the data read from the endpoint
1.194 + */
1.195 + HBufC8* iValidationPatternBuffer;
1.196 + TPtr8 iValidationPatternPtr;
1.197 +
1.198 + /**
1.199 + Competion Action
1.200 + */
1.201 + TCompletionAction iCompletionAction;
1.202 +
1.203 + /**
1.204 + Needed if completion action is ERepeatedRead
1.205 + */
1.206 + TUint iRepeatedReadTotalNumBytes;
1.207 + TUint iRepeatedReadNumBytesPerRead;
1.208 + TUint iNumBytesReadSoFar;
1.209 + TUint iDataPatternLength;
1.210 + TBool iIsValid;
1.211 + };
1.212 +
1.213 +
1.214 + }
1.215 +
1.216 +#endif
1.217 +
1.218 +
1.219 +
1.220 \ No newline at end of file