os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/inc/HostTransfers.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 #ifndef __HOST_TRANSFERS_H
     2 #define __HOST_TRANSFERS_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 HostTransfers.h
    19 * @internalComponent
    20 * 
    21 *
    22 */
    23 
    24 
    25 
    26 #include <e32base.h>
    27 #include <e32ver.h>
    28 #include <d32usbdescriptors.h>
    29 #include <d32usbtransfers.h>
    30 #include <d32usbdi.h>
    31 #include "testdebug.h"
    32 #include "ControlTransferRequests.h"
    33 
    34 namespace NUnitTesting_USBDI
    35 	{
    36 
    37 /**
    38 This class describes an interface to a class which wants to observe transfers
    39 */
    40 class MTransferObserver
    41 	{
    42 public: 
    43 	/**
    44 	Called when a transfer with the supplied transfer identity has completed
    45 	@param aTransferId the identity of the transfer
    46 	@param aCompletionCode the error completion code for the asynchronous transfer
    47 	*/
    48 	virtual void TransferCompleteL(TInt aTransferId,TInt aCompletionCode) = 0;
    49 	};
    50 
    51 
    52 /**
    53 This class describes a base class for a transfer
    54 */
    55 class CBaseTransfer : public CActive
    56 	{
    57 public:
    58 	/**
    59 	Destructor
    60 	*/
    61 	virtual ~CBaseTransfer()
    62 		{
    63 		}
    64 	
    65 	/**
    66 	Retrieve the identity of the transfer
    67 	@return the transfer identity
    68 	*/
    69 	TInt Identity() const
    70 		{
    71 		return iTransferIdentity;
    72 		}
    73 	
    74 protected:
    75 	/**
    76 	Constructor 
    77 	*/
    78 	CBaseTransfer(RUsbPipe& aPipe,RUsbInterface& aInterface,MTransferObserver& aObserver,TInt aTransferIdentity)
    79 	:	CActive(EPriorityStandard),
    80 		iPipe(aPipe),
    81 		iInterface(aInterface),
    82 		iObserver(aObserver),
    83 		iTransferIdentity(aTransferIdentity)
    84 		{
    85 		CActiveScheduler::Add(this);
    86 		}
    87 		
    88 	/**
    89 	*/
    90 	void SelfComplete()
    91 		{
    92 		iStatus = KRequestPending;
    93 		TRequestStatus* s = &iStatus;
    94 		User::RequestComplete(s,KErrNone);
    95 		SetActive();
    96 		}
    97 	
    98 protected:
    99 	/**
   100 	*/
   101 	virtual TInt RunError(TInt aError)
   102 		{
   103 		RDebug::Printf("<Error %d> a transfer RunL left",aError);
   104 		return KErrNone;
   105 		}
   106 	
   107 	/**
   108 	*/
   109 	void RunL()
   110 		{
   111 		LOG_FUNC
   112 		
   113 		TInt completionCode(iStatus.Int());
   114 		RDebug::Printf("Transfer err=%d",completionCode);
   115 		
   116 		// Notify of transfer completion (successful or otherwise)
   117 		iObserver.TransferCompleteL(iTransferIdentity,completionCode);
   118 		}
   119 	
   120 	/**
   121 	*/
   122 	void DoCancel()
   123 		{
   124 		LOG_FUNC
   125 		
   126 		// Will cancel all transfers on this pipe
   127 		
   128 		Pipe().CancelAllTransfers();
   129 		}
   130 	
   131 protected:
   132 	
   133 	/**
   134 	Get the pipe object for the transfer
   135 	@return a opened pipe for transfers
   136 	*/
   137 	RUsbPipe& Pipe()
   138 		{
   139 		return iPipe;
   140 		}
   141 	
   142 	/**
   143 	Get the interface for the transfer
   144 	@return the opened interface 
   145 	*/
   146 	RUsbInterface& Interface()
   147 		{
   148 		return iInterface;
   149 		}
   150 
   151 	/**
   152 	Access the observer of the transfers
   153 	@return the transfer observer
   154 	*/
   155 	MTransferObserver& Observer()
   156 		{
   157 		return iObserver;
   158 		}
   159 	
   160 private:
   161 	/**
   162 	The usb pipe that will be used for the transfer and where
   163 	the buffer pool is located.
   164 	*/
   165 	RUsbPipe& iPipe;
   166 
   167 	/**
   168 	The interface that will be used for the transfer
   169 	*/
   170 	RUsbInterface& iInterface;
   171 	
   172 	/**
   173 	The observer for the transfers
   174 	*/
   175 	MTransferObserver& iObserver;
   176 
   177 	/**
   178 	The identity of a transfer (not the type)
   179 	*/
   180 	TInt iTransferIdentity;
   181 	};
   182 	
   183 /**
   184 This class represents a interrupt transfer to the device
   185 */
   186 class CInterruptTransfer : public CBaseTransfer
   187 	{
   188 public:
   189 	/**
   190 	C++ constructor, builds a interrupt transfer object with a transfer buffer of maximum fixed size.
   191 	The caller must ensure that this instance can handle the transfer specified
   192 	@param aPipe the pipe to be used for the transfer and buffer pool
   193 	@param aTransferSize the required maximum size of the buffer to handle all transfers
   194 	@param aObserver the observer of the transfer
   195 	@param aTransferId a unique identity of the transfer
   196 	*/
   197 	CInterruptTransfer(RUsbPipe& aPipe,RUsbInterface& aInterface,TInt aMaxTransferSize,MTransferObserver& aObserver,TInt aTransferId);
   198 
   199 	/**
   200 	Destructor
   201 	*/
   202 	virtual ~CInterruptTransfer();
   203 	
   204 	/**
   205 	Poll for interrupt data queued by the device and transfer to host 
   206 	@param aSize the size of the data from requested from the client
   207 	@return KErrNone if successful or system-wide error code
   208 	*/
   209 	TInt TransferInL(TInt aSize);
   210 	
   211 	/**
   212 	Register the transfer descriptor
   213 	@return KErrNone if successful or system-wide error code
   214 	*/
   215 	TInt RegisterTransferDescriptor();
   216 	
   217 	/**
   218 	On successful completion of an interrupt 'in' transfer, obtain the polled data
   219 	@return the interrupt data from the device
   220 	*/
   221 	TPtrC8 DataPolled();
   222 
   223 private:
   224 	/**
   225 	The transfer descriptor for interrupt transfers
   226 	*/
   227 	RUsbIntrTransferDescriptor iTransferDescriptor;
   228 	};
   229 
   230 /**
   231 This class represents a isochronous transfer to a device
   232 */
   233 class CIsochTransfer : public CBaseTransfer
   234 	{
   235 public:
   236 	/**
   237 	C++ constructor, builds a isochronous transfer object with a transfer buffer of maximum fixed size.
   238 	The caller must ensure that this instance can handle the transfer specified
   239 	@param aPipe the pipe to be used for the transfer and buffer pool
   240 	@param aMaxPacketSize the maximum packet size to send
   241 	@param aMaxNumPackets the maximum number of packets to be transfered on this pipe
   242 	@param aObserver the observer of the transfer
   243 	@param aTransferId a unique identity of the transfer
   244 	*/
   245 	CIsochTransfer(RUsbPipe& aPipe,RUsbInterface& aInterface,TUint16 aMaxPacketSize,
   246 					TInt aMaxNumPackets,MTransferObserver& aObserver,TInt aTransferId);
   247 
   248 	/**
   249 	Destructor
   250 	*/
   251 	virtual ~CIsochTransfer();
   252 	
   253 	TInt RegisterTransferDescriptor();
   254 
   255 	/**
   256 	Transfer the data to the device
   257 	@param aIsochData the 8bit Isochronous data to transfer
   258 	@return KErrNone if successful, or system wide error code
   259 	*/	
   260 	TInt TransferOut();
   261 	
   262 	/**
   263 	Prepare the transfer before its sending
   264 	@param aIsochData the 8bit Isochronous data to transfer
   265 	@return KErrNone if successful, or system wide error code
   266 	*/	
   267 	TInt PrepareTransfer(const TDesC8& aIsochData);
   268 	
   269 	/**
   270 	Start the IN transfer
   271 	@param aPacketsExpected nb of expected packets
   272 	@return KErrNone if successful, or system wide error code
   273 	*/
   274 	TInt TransferInL(TInt aPacketsExpected);
   275 		
   276 	/**
   277 	Store the polled data into internal buffer
   278 	@param[int] aPacketsToBeRead nb of packets to be read
   279 	@param[out] aDataPolled data being transfered
   280 	@return ETrue if successful, EFalse otherwise
   281 	*/
   282 	TBool DataPolled(TUint aPacketsToBeRead, RBuf8& aDataPolled);
   283 				
   284 private:
   285 	/**
   286 	The transfer descriptor for isochronous transfers
   287 	*/
   288 	RUsbIsocTransferDescriptor iTransferDescriptor;
   289 	
   290 	/**
   291 	The maximum packet size for the respective isochronous endpoint
   292 	*/
   293 	TUint16 iMaxPacketSize;	
   294 	
   295 	};
   296 
   297 
   298 /**
   299 This class represents a bulk transfer to a device
   300 */
   301 class CBulkTransfer : public CBaseTransfer
   302 	{
   303 public:
   304 	/**
   305 	C++ constructor
   306 	*/
   307 	CBulkTransfer(RUsbPipe& aPipe,RUsbInterface& aUsbInterface,TInt aMaxTransferSize,
   308 		MTransferObserver& aObserver,TInt aTransferId);
   309 
   310 	/**
   311 	*/
   312 	virtual ~CBulkTransfer();
   313 	
   314 	/**
   315 	*/
   316 	void TransferOut(const TDesC8& aBulkData, TBool aUseZLPIfRequired = ETrue);
   317 		
   318 	/**
   319 	*/
   320 	void TransferOut(const TDesC8& aBulkDataPattern, TUint aNumBytes, TBool aUseZLPIfRequired = ETrue);
   321 				
   322 	/**
   323 	*/
   324 	void TransferOut(const TDesC8& aBulkDataPattern, TUint aStartPoint, TUint aNumBytes, TBool aUseZLPIfRequired);
   325 	
   326 	/**
   327 	*/
   328 	void TransferIn(TInt aExpectedDataSize);
   329 	
   330 	/**
   331 	*/
   332 	RUsbPipe&  Pipe(){return CBaseTransfer::Pipe();};
   333 	
   334 	RUsbBulkTransferDescriptor& TransferDescriptor(){return iTransferDescriptor;};
   335 
   336 	/**
   337 	*/
   338 	TPtrC8 DataPolled();
   339 	
   340 private:
   341 	/**
   342 	The transfer descriptor for bulk transfers
   343 	*/
   344 	RUsbBulkTransferDescriptor iTransferDescriptor;
   345 	};
   346 
   347 	
   348 	}
   349 
   350 #endif
   351 
   352