os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/inc/endpointreader.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 #ifndef __ENDPOINT_READER_H
     2 #define __ENDPOINT_READER_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 endpointreader.h
    19 * @internalComponent
    20 * 
    21 *
    22 */
    23 
    24 
    25 
    26 #include <e32base.h>
    27 #include <d32usbc.h>
    28 
    29 namespace NUnitTesting_USBDI
    30 	{
    31 	
    32 /*
    33  * The buffer to read control packet data into
    34  * Low-speed 8bytes
    35  * High-speed 8,16,32 or 64bytes
    36  * Full-speed 64bytes
    37  */
    38 
    39 const TInt KFullSpeedPacketSize = 64;
    40 
    41 /**
    42 This class describes a handler for bytes received from the endpoint
    43 */
    44 class MEndpointDataHandler
    45 	{
    46 public:
    47 	/**
    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 
    52 	*/
    53 	virtual void DataReceivedFromEndpointL(TEndpointNumber aEndpointNumber,const TDesC8& aData) = 0;
    54 	
    55 	/**
    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
    59 	*/
    60 	virtual void EndpointReadError(TEndpointNumber aEndpointNumber,TInt aErrorCode) = 0;
    61 	};
    62 
    63 
    64 /**
    65 This class describes a general asyncronous endpoint reader
    66 */
    67 class CEndpointReader : public CActive
    68 	{
    69 public:
    70 	enum TCompletionAction
    71 		{
    72 		ENone,
    73 		EHaltEndpoint,
    74 		ERepeatedRead,
    75 		};
    76 	/**
    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
    80 	*/
    81 	CEndpointReader(RDevUsbcClient& aClientDriver,TEndpointNumber aEndpoint);
    82 
    83 	/**
    84 	Destructor
    85 	*/	
    86 	virtual ~CEndpointReader();
    87 
    88 	/**
    89 	Return data buffer used for Reads - could be NULL!
    90 	@return data buffer
    91 	*/
    92 	TPtr8 Buffer();
    93 
    94 	/**
    95 	Return the result of the last recorded validation result!
    96 	@return that result
    97 	*/
    98 	TBool IsValid();
    99 
   100 	/**
   101 	Return the number of bytes read so far on a repeated (asynchronous)'Read'
   102 	@return that number of bytes
   103 	*/
   104 	TUint NumBytesReadSoFar();
   105 
   106 	/**
   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
   109 	*/
   110 	void ReadPacketL(MEndpointDataHandler* aHandler);
   111 	
   112 	/**
   113 	Read the specified number of bytes from the endpoint
   114 	@param aByteCount the number of bytes to read
   115 	*/
   116 	void ReadL(TInt aByteCount);
   117 
   118 	/**
   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
   121 	*/
   122 	void ReadUntilShortL(TInt aByteCount);
   123 
   124 	/**
   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
   128 	*/
   129 	void ReadAndHaltL(TInt aByteCount);
   130 
   131 	/**
   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
   140 	*/
   141 	void RepeatedReadAndValidateL(const TDesC8& aDataPattern, TUint aNumBytesPerRead, TUint aTotalNumBytes);
   142 
   143 	/**
   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
   147 	*/
   148 	TInt Acknowledge();
   149 
   150 protected:
   151 	/**
   152 	Cancels the reading from the host
   153 	*/
   154 	void DoCancel();
   155 	
   156 	/**
   157 	*/
   158 	virtual void RunL();
   159 	
   160 	/**
   161 	The framework error function from RunL
   162 	@param aError the error from a RunL leave
   163 	@return KErrNone
   164 	*/
   165 	TInt RunError(TInt aError);
   166 
   167 protected:
   168 	/**
   169 	The channel to use to communicate to the client driver
   170 	*/
   171 	RDevUsbcClient& iClientDriver;
   172 	
   173 	/**
   174 	The endpoint number that this reader will read from
   175 	*/
   176 	TEndpointNumber iEndpoint;	
   177 	
   178 	/**
   179 	The handler for Endpoint zero requests received
   180 	*/
   181 	MEndpointDataHandler* iHandler;
   182 	
   183 	/**
   184 	The buffer for the data read from the endpoint
   185 	*/
   186 	HBufC8* iDataBuffer;
   187 	TPtr8 iDataPtr;
   188 	
   189 	/**
   190 	The buffer for the data read from the endpoint
   191 	*/
   192 	HBufC8* iValidationPatternBuffer;
   193 	TPtr8 iValidationPatternPtr;
   194 	
   195 	/**
   196 	Competion Action
   197 	*/
   198 	TCompletionAction iCompletionAction;
   199 
   200 	/**
   201 	Needed if completion action is ERepeatedRead
   202 	*/
   203 	TUint iRepeatedReadTotalNumBytes;
   204 	TUint iRepeatedReadNumBytesPerRead;
   205 	TUint iNumBytesReadSoFar;
   206 	TUint iDataPatternLength;
   207 	TBool iIsValid;
   208 	};
   209 
   210 
   211 	}
   212 
   213 #endif
   214 
   215 
   216