kerneltest/e32test/usbho/t_usbdi/inc/testinterfacesettingbase.h
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 #ifndef __TEST_INTERFACE_SETTING_BASE_H
       
     2 #define __TEST_INTERFACE_SETTING_BASE_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 testinterfacesettingbase.h
       
    19 * @internalComponent
       
    20 * 
       
    21 *
       
    22 */
       
    23 
       
    24 
       
    25 
       
    26 #include <e32base.h>
       
    27 #include <d32usbc.h>
       
    28 #include <e32hashtab.h>
       
    29 #include "testendpointbase.h"
       
    30 #include "endpointreader.h"
       
    31 #include "endpointwriter.h"
       
    32 
       
    33 namespace NUnitTesting_USBDI
       
    34 	{	
       
    35 
       
    36 // For the RHashMap
       
    37 inline TUint32 EndpointNumberHash(const TEndpointNumber& aEndpointNumber)
       
    38 	{
       
    39 	return DefaultHash::Integer(static_cast<TInt>(aEndpointNumber));
       
    40 	}
       
    41 	
       
    42 inline TBool EndpointIdentityRelationship(const TEndpointNumber& aArg1,const TEndpointNumber& aArg2)
       
    43 	{
       
    44 	return aArg1 == aArg2;
       
    45 	}
       
    46 		
       
    47 	
       
    48 // Forward declarations
       
    49 class TEndpoint;
       
    50 	
       
    51 /**
       
    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
       
    54 is selected.
       
    55 */
       
    56 class CInterfaceSettingBase : public CBase
       
    57 	{
       
    58 	
       
    59 	friend class CInterfaceBase;
       
    60 
       
    61 	typedef RHashMap<TEndpointNumber,TEndpoint> REndpointMap;
       
    62 
       
    63 public:
       
    64 	
       
    65 	/**
       
    66 	Constructor, build an interface setting
       
    67 	@param aString the name of this interface setting
       
    68 	*/
       
    69 	
       
    70 	explicit CInterfaceSettingBase(const TDesC& aString);	
       
    71 	
       
    72 	/**
       
    73 	Destructor
       
    74 	*/
       
    75 	virtual ~CInterfaceSettingBase();
       
    76 	
       
    77 	/**
       
    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
       
    81 		   01h  Audio   
       
    82 		   02h  Communications and CDC Control (together with device)
       
    83 		   03h  HID (Human Interface Device) 
       
    84 		   05h  Physical 
       
    85 		   06h  Image 
       
    86 		   07h  Printer 
       
    87 		   08h  Mass Storage 
       
    88 		   0Ah  CDC-Data 
       
    89 		   0Bh  Smart Card 
       
    90 		   0Dh  Content Security 
       
    91 		   0Eh  Video 
       
    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
       
    99 	*/
       
   100 	void SetClassCodeL(TUint8 aClassCode,TUint8 aSubClassCode,TUint8 aDeviceProtocol);
       
   101 	
       
   102 	/**
       
   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
       
   106 			resource limitation
       
   107 	*/
       
   108 	TInt AddEndpoint(TEndpoint& anEndpoint);
       
   109 	
       
   110 	/**
       
   111 	Create 
       
   112 	*/
       
   113 	void CreateEndpointReaderL(RDevUsbcClient& aClientDriver,TUint aEndpoint);
       
   114 	
       
   115 	/**
       
   116 	Create 
       
   117 	*/
       
   118 	void CreateEndpointWriterL(RDevUsbcClient& aClientDriver,TUint aEndpoint);
       
   119 		
       
   120 	/**
       
   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.
       
   126 	*/
       
   127 	void WriteSpecifiedDataToEndpointL(const TDesC8& aData,TUint16 aEndpointNumber);
       
   128 
       
   129 	/**
       
   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.
       
   134 	*/
       
   135 	void CancelWriteDataToEndpointL(TUint16 aEndpointNumber);
       
   136 	
       
   137 	/**
       
   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.
       
   144 	*/
       
   145 	void WriteSpecifiedDataToEndpointL(const TDesC8& aDataPattern, TUint aNumBytes, TUint16 aEndpointNumber);
       
   146 	
       
   147 	/**
       
   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.
       
   155 	*/
       
   156 	void RepeatedWriteSpecifiedDataToEndpointL(const TDesC8& aDataPattern, TUint aNumBytesPerWrite, TUint aTotalNumBytes, TUint16 aEndpointNumber);
       
   157 	
       
   158 	/**
       
   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.
       
   164 	*/
       
   165 	void WriteCachedEndpointDataToEndpointL(const TUint16 aSourceEndpointNumber,TUint16 aWriteEndpointNumber);
       
   166 
       
   167 
       
   168 	/**
       
   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.
       
   175 	*/
       
   176 	void WriteSynchronousSpecifiedDataToEndpointL(const TDesC8& aDataPattern, TUint aNumBytes, TUint16 aEndpointNumber);
       
   177 	
       
   178 	/**
       
   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.
       
   185 	*/
       
   186 	void WriteSynchronousSpecifiedDataToAndHaltEndpointL(const TDesC8& aDataPattern, TUint aNumBytes, TUint16 aEndpointNumber);
       
   187 
       
   188 	/**
       
   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.
       
   194 	*/
       
   195 	void WriteSynchronousCachedEndpointDataToEndpointL(const TUint16 aSourceEndpointNumber,TUint16 aWriteEndpointNumber);
       
   196 
       
   197 	/**
       
   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
       
   205 	*/
       
   206 	void WriteSynchronousCachedEndpointDataToEndpointL(const TUint16 aSourceEndpointNumber,TUint16 aWriteEndpointNumber, TUint aStartPoint, TUint aLength);
       
   207 	
       
   208 	/**
       
   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
       
   213 	*/
       
   214 	TBool CachedEndpointResultL(const TUint16 aEndpointNumber);
       
   215 
       
   216 	/**
       
   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
       
   221 	*/
       
   222 	TInt NumBytesReadSoFarL(const TUint16 aEndpointNumber);
       
   223 	
       
   224 	/**
       
   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
       
   229 	*/
       
   230 	TInt NumBytesWrittenSoFarL(const TUint16 aEndpointNumber);
       
   231 	
       
   232 	/**
       
   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
       
   239 	*/
       
   240 	TBool ValidateCachedEndpointDataL(const TDesC8& aDataPattern, const TUint aNumBytes, const TUint16 aEndpointNumber);
       
   241 	
       
   242 	/**
       
   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
       
   250 	*/
       
   251 	TBool ValidateCachedEndpointDataL(const TDesC8& aDataPattern, const TUint aStartPoint, const TUint aNumBytes, const TUint16 aEndpointNumber);
       
   252 	
       
   253 	/**
       
   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.
       
   259 	*/
       
   260 	void ReadDataFromEndpointL(TUint aNumBytes, TUint16 aEndpointNumber);
       
   261 
       
   262 	/**
       
   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.
       
   267 	*/
       
   268 	void CancelAnyReadDataFromEndpointL(TUint16 aEndpointNumber);
       
   269 
       
   270 	/**
       
   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.
       
   276 	*/
       
   277 	void ReadDataFromAndHaltEndpointL(TUint aNumBytes, TUint16 aEndpointNumber);
       
   278 
       
   279 	/**
       
   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.
       
   288 	*/
       
   289 	void RepeatedReadAndValidateFromEndpointL(const TDesC8& aDataPattern, TUint aNumBytesPerRead, TUint aTotalNumBytes, TUint16 aEndpointNumber);
       
   290 /**
       
   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.
       
   296 	*/
       
   297 	void ReadDataUntilShortFromEndpointL(TUint aNumBytes, TUint16 aEndpointNumber);
       
   298 
       
   299 	/**
       
   300 	Get the name of this interface setting
       
   301 	@return the interface setting name
       
   302 	*/
       
   303 	const TDesC& Name() const;
       
   304 	
       
   305 private:
       
   306 
       
   307 	/**
       
   308 	Disable default constructor
       
   309 	*/
       
   310 	CInterfaceSettingBase();
       
   311 
       
   312 protected:
       
   313 	
       
   314 	/**
       
   315 	The information for this interface setting about endpoints
       
   316 	*/
       
   317 	TUsbcInterfaceInfoBuf iInterfaceInfo;
       
   318 	
       
   319 	/**
       
   320 	The name for this interface setting
       
   321 	*/
       
   322 	TBuf<64> iSettingString;
       
   323 	
       
   324 	/**
       
   325 	The array of endpoints for this interface setting
       
   326 	*/
       
   327 	THashFunction32<TEndpointNumber> iHashEndpointFunction;
       
   328 	TIdentityRelation<TEndpointNumber> iIdRelEndpoint;
       
   329 	REndpointMap iEndpoints;
       
   330 	
       
   331 	/**
       
   332 	The readers for the endpoints on this interface setting
       
   333 	*/
       
   334 	RPointerArray<CEndpointReader> iEndpointReaders;
       
   335 	
       
   336 	/**
       
   337 	The writers for the endpoints on this interface setting
       
   338 	*/
       
   339 	RPointerArray<CEndpointWriter> iEndpointWriters;
       
   340 	};
       
   341 	
       
   342 	}
       
   343 	
       
   344 #endif