sl@0: #ifndef __ENDPOINT_READER_H sl@0: #define __ENDPOINT_READER_H sl@0: sl@0: /* sl@0: * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * @file endpointreader.h sl@0: * @internalComponent sl@0: * sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: #include sl@0: #include sl@0: sl@0: namespace NUnitTesting_USBDI sl@0: { sl@0: sl@0: /* sl@0: * The buffer to read control packet data into sl@0: * Low-speed 8bytes sl@0: * High-speed 8,16,32 or 64bytes sl@0: * Full-speed 64bytes sl@0: */ sl@0: sl@0: const TInt KFullSpeedPacketSize = 64; sl@0: sl@0: /** sl@0: This class describes a handler for bytes received from the endpoint sl@0: */ sl@0: class MEndpointDataHandler sl@0: { sl@0: public: sl@0: /** sl@0: Called when data is read from an endpoint sl@0: @param aEndpointNumber the number of the endpoint that was read from sl@0: @param aData the data read from the endpoint (valid data if the completion code is KErrNone) sl@0: @param aCompletionCode the completion code for the read sl@0: */ sl@0: virtual void DataReceivedFromEndpointL(TEndpointNumber aEndpointNumber,const TDesC8& aData) = 0; sl@0: sl@0: /** sl@0: Called when the read operation from the endpoint completes with an error sl@0: @param aEndpointNumber the number of the endpoint read from sl@0: @param aErrorCode the operation error completion code sl@0: */ sl@0: virtual void EndpointReadError(TEndpointNumber aEndpointNumber,TInt aErrorCode) = 0; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: This class describes a general asyncronous endpoint reader sl@0: */ sl@0: class CEndpointReader : public CActive sl@0: { sl@0: public: sl@0: enum TCompletionAction sl@0: { sl@0: ENone, sl@0: EHaltEndpoint, sl@0: ERepeatedRead, sl@0: }; sl@0: /** sl@0: Constructor, build a reader that reads byte data from the specified endpoint number sl@0: @param aClientDriver the driver channel to the usb client driver sl@0: @param aEndpoint the endpoint number to read from sl@0: */ sl@0: CEndpointReader(RDevUsbcClient& aClientDriver,TEndpointNumber aEndpoint); sl@0: sl@0: /** sl@0: Destructor sl@0: */ sl@0: virtual ~CEndpointReader(); sl@0: sl@0: /** sl@0: Return data buffer used for Reads - could be NULL! sl@0: @return data buffer sl@0: */ sl@0: TPtr8 Buffer(); sl@0: sl@0: /** sl@0: Return the result of the last recorded validation result! sl@0: @return that result sl@0: */ sl@0: TBool IsValid(); sl@0: sl@0: /** sl@0: Return the number of bytes read so far on a repeated (asynchronous)'Read' sl@0: @return that number of bytes sl@0: */ sl@0: TUint NumBytesReadSoFar(); sl@0: sl@0: /** sl@0: Read a data packet from the endpoint specified sl@0: @param aHandler a pointer to the handler of the data that will be read from the host sl@0: */ sl@0: void ReadPacketL(MEndpointDataHandler* aHandler); sl@0: sl@0: /** sl@0: Read the specified number of bytes from the endpoint sl@0: @param aByteCount the number of bytes to read sl@0: */ sl@0: void ReadL(TInt aByteCount); sl@0: sl@0: /** sl@0: Read the specified number of bytes (or fewer id a short packet arrives) from the endpoint sl@0: @param aByteCount the number of bytes to read sl@0: */ sl@0: void ReadUntilShortL(TInt aByteCount); sl@0: sl@0: /** sl@0: Read the specified number of bytes from the endpoint sl@0: Flag the need to halt the endpoint when the read has completed sl@0: @param aByteCount the number of bytes to read sl@0: */ sl@0: void ReadAndHaltL(TInt aByteCount); sl@0: sl@0: /** sl@0: Read a specified number of bytes from the endpoint in sections, sl@0: performing a new 'Read' for each section. sl@0: After each 'Read' use the data pattern to validate the results. sl@0: Expect the data pattern to be repeated in its entirety until sl@0: the total number of bytes have been sent. sl@0: @param aDataPattern the data pattern to be used for validation sl@0: @param aNumBytesPerRead the number of bytes to ask for at each 'Read' sl@0: @param aTotalNumBytes the total number of bytes to read sl@0: */ sl@0: void RepeatedReadAndValidateL(const TDesC8& aDataPattern, TUint aNumBytesPerRead, TUint aTotalNumBytes); sl@0: sl@0: /** sl@0: Send an acknowledgment back to the host sl@0: This will be a zero length DATA1 packet sl@0: @return KErrNone if successful otherwise a system wide error code sl@0: */ sl@0: TInt Acknowledge(); sl@0: sl@0: protected: sl@0: /** sl@0: Cancels the reading from the host sl@0: */ sl@0: void DoCancel(); sl@0: sl@0: /** sl@0: */ sl@0: virtual void RunL(); sl@0: sl@0: /** sl@0: The framework error function from RunL sl@0: @param aError the error from a RunL leave sl@0: @return KErrNone sl@0: */ sl@0: TInt RunError(TInt aError); sl@0: sl@0: protected: sl@0: /** sl@0: The channel to use to communicate to the client driver sl@0: */ sl@0: RDevUsbcClient& iClientDriver; sl@0: sl@0: /** sl@0: The endpoint number that this reader will read from sl@0: */ sl@0: TEndpointNumber iEndpoint; sl@0: sl@0: /** sl@0: The handler for Endpoint zero requests received sl@0: */ sl@0: MEndpointDataHandler* iHandler; sl@0: sl@0: /** sl@0: The buffer for the data read from the endpoint sl@0: */ sl@0: HBufC8* iDataBuffer; sl@0: TPtr8 iDataPtr; sl@0: sl@0: /** sl@0: The buffer for the data read from the endpoint sl@0: */ sl@0: HBufC8* iValidationPatternBuffer; sl@0: TPtr8 iValidationPatternPtr; sl@0: sl@0: /** sl@0: Competion Action sl@0: */ sl@0: TCompletionAction iCompletionAction; sl@0: sl@0: /** sl@0: Needed if completion action is ERepeatedRead sl@0: */ sl@0: TUint iRepeatedReadTotalNumBytes; sl@0: TUint iRepeatedReadNumBytesPerRead; sl@0: TUint iNumBytesReadSoFar; sl@0: TUint iDataPatternLength; sl@0: TBool iIsValid; sl@0: }; sl@0: sl@0: sl@0: } sl@0: sl@0: #endif sl@0: sl@0: sl@0: