sl@0: #ifndef __HOST_TRANSFERS_H sl@0: #define __HOST_TRANSFERS_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 HostTransfers.h sl@0: * @internalComponent sl@0: * sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "testdebug.h" sl@0: #include "ControlTransferRequests.h" sl@0: sl@0: namespace NUnitTesting_USBDI sl@0: { sl@0: sl@0: /** sl@0: This class describes an interface to a class which wants to observe transfers sl@0: */ sl@0: class MTransferObserver sl@0: { sl@0: public: sl@0: /** sl@0: Called when a transfer with the supplied transfer identity has completed sl@0: @param aTransferId the identity of the transfer sl@0: @param aCompletionCode the error completion code for the asynchronous transfer sl@0: */ sl@0: virtual void TransferCompleteL(TInt aTransferId,TInt aCompletionCode) = 0; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: This class describes a base class for a transfer sl@0: */ sl@0: class CBaseTransfer : public CActive sl@0: { sl@0: public: sl@0: /** sl@0: Destructor sl@0: */ sl@0: virtual ~CBaseTransfer() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Retrieve the identity of the transfer sl@0: @return the transfer identity sl@0: */ sl@0: TInt Identity() const sl@0: { sl@0: return iTransferIdentity; sl@0: } sl@0: sl@0: protected: sl@0: /** sl@0: Constructor sl@0: */ sl@0: CBaseTransfer(RUsbPipe& aPipe,RUsbInterface& aInterface,MTransferObserver& aObserver,TInt aTransferIdentity) sl@0: : CActive(EPriorityStandard), sl@0: iPipe(aPipe), sl@0: iInterface(aInterface), sl@0: iObserver(aObserver), sl@0: iTransferIdentity(aTransferIdentity) sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: /** sl@0: */ sl@0: void SelfComplete() sl@0: { sl@0: iStatus = KRequestPending; sl@0: TRequestStatus* s = &iStatus; sl@0: User::RequestComplete(s,KErrNone); sl@0: SetActive(); sl@0: } sl@0: sl@0: protected: sl@0: /** sl@0: */ sl@0: virtual TInt RunError(TInt aError) sl@0: { sl@0: RDebug::Printf(" a transfer RunL left",aError); sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: */ sl@0: void RunL() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: TInt completionCode(iStatus.Int()); sl@0: RDebug::Printf("Transfer err=%d",completionCode); sl@0: sl@0: // Notify of transfer completion (successful or otherwise) sl@0: iObserver.TransferCompleteL(iTransferIdentity,completionCode); sl@0: } sl@0: sl@0: /** sl@0: */ sl@0: void DoCancel() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: // Will cancel all transfers on this pipe sl@0: sl@0: Pipe().CancelAllTransfers(); sl@0: } sl@0: sl@0: protected: sl@0: sl@0: /** sl@0: Get the pipe object for the transfer sl@0: @return a opened pipe for transfers sl@0: */ sl@0: RUsbPipe& Pipe() sl@0: { sl@0: return iPipe; sl@0: } sl@0: sl@0: /** sl@0: Get the interface for the transfer sl@0: @return the opened interface sl@0: */ sl@0: RUsbInterface& Interface() sl@0: { sl@0: return iInterface; sl@0: } sl@0: sl@0: /** sl@0: Access the observer of the transfers sl@0: @return the transfer observer sl@0: */ sl@0: MTransferObserver& Observer() sl@0: { sl@0: return iObserver; sl@0: } sl@0: sl@0: private: sl@0: /** sl@0: The usb pipe that will be used for the transfer and where sl@0: the buffer pool is located. sl@0: */ sl@0: RUsbPipe& iPipe; sl@0: sl@0: /** sl@0: The interface that will be used for the transfer sl@0: */ sl@0: RUsbInterface& iInterface; sl@0: sl@0: /** sl@0: The observer for the transfers sl@0: */ sl@0: MTransferObserver& iObserver; sl@0: sl@0: /** sl@0: The identity of a transfer (not the type) sl@0: */ sl@0: TInt iTransferIdentity; sl@0: }; sl@0: sl@0: /** sl@0: This class represents a interrupt transfer to the device sl@0: */ sl@0: class CInterruptTransfer : public CBaseTransfer sl@0: { sl@0: public: sl@0: /** sl@0: C++ constructor, builds a interrupt transfer object with a transfer buffer of maximum fixed size. sl@0: The caller must ensure that this instance can handle the transfer specified sl@0: @param aPipe the pipe to be used for the transfer and buffer pool sl@0: @param aTransferSize the required maximum size of the buffer to handle all transfers sl@0: @param aObserver the observer of the transfer sl@0: @param aTransferId a unique identity of the transfer sl@0: */ sl@0: CInterruptTransfer(RUsbPipe& aPipe,RUsbInterface& aInterface,TInt aMaxTransferSize,MTransferObserver& aObserver,TInt aTransferId); sl@0: sl@0: /** sl@0: Destructor sl@0: */ sl@0: virtual ~CInterruptTransfer(); sl@0: sl@0: /** sl@0: Poll for interrupt data queued by the device and transfer to host sl@0: @param aSize the size of the data from requested from the client sl@0: @return KErrNone if successful or system-wide error code sl@0: */ sl@0: TInt TransferInL(TInt aSize); sl@0: sl@0: /** sl@0: Register the transfer descriptor sl@0: @return KErrNone if successful or system-wide error code sl@0: */ sl@0: TInt RegisterTransferDescriptor(); sl@0: sl@0: /** sl@0: On successful completion of an interrupt 'in' transfer, obtain the polled data sl@0: @return the interrupt data from the device sl@0: */ sl@0: TPtrC8 DataPolled(); sl@0: sl@0: private: sl@0: /** sl@0: The transfer descriptor for interrupt transfers sl@0: */ sl@0: RUsbIntrTransferDescriptor iTransferDescriptor; sl@0: }; sl@0: sl@0: /** sl@0: This class represents a isochronous transfer to a device sl@0: */ sl@0: class CIsochTransfer : public CBaseTransfer sl@0: { sl@0: public: sl@0: /** sl@0: C++ constructor, builds a isochronous transfer object with a transfer buffer of maximum fixed size. sl@0: The caller must ensure that this instance can handle the transfer specified sl@0: @param aPipe the pipe to be used for the transfer and buffer pool sl@0: @param aMaxPacketSize the maximum packet size to send sl@0: @param aMaxNumPackets the maximum number of packets to be transfered on this pipe sl@0: @param aObserver the observer of the transfer sl@0: @param aTransferId a unique identity of the transfer sl@0: */ sl@0: CIsochTransfer(RUsbPipe& aPipe,RUsbInterface& aInterface,TUint16 aMaxPacketSize, sl@0: TInt aMaxNumPackets,MTransferObserver& aObserver,TInt aTransferId); sl@0: sl@0: /** sl@0: Destructor sl@0: */ sl@0: virtual ~CIsochTransfer(); sl@0: sl@0: TInt RegisterTransferDescriptor(); sl@0: sl@0: /** sl@0: Transfer the data to the device sl@0: @param aIsochData the 8bit Isochronous data to transfer sl@0: @return KErrNone if successful, or system wide error code sl@0: */ sl@0: TInt TransferOut(); sl@0: sl@0: /** sl@0: Prepare the transfer before its sending sl@0: @param aIsochData the 8bit Isochronous data to transfer sl@0: @return KErrNone if successful, or system wide error code sl@0: */ sl@0: TInt PrepareTransfer(const TDesC8& aIsochData); sl@0: sl@0: /** sl@0: Start the IN transfer sl@0: @param aPacketsExpected nb of expected packets sl@0: @return KErrNone if successful, or system wide error code sl@0: */ sl@0: TInt TransferInL(TInt aPacketsExpected); sl@0: sl@0: /** sl@0: Store the polled data into internal buffer sl@0: @param[int] aPacketsToBeRead nb of packets to be read sl@0: @param[out] aDataPolled data being transfered sl@0: @return ETrue if successful, EFalse otherwise sl@0: */ sl@0: TBool DataPolled(TUint aPacketsToBeRead, RBuf8& aDataPolled); sl@0: sl@0: private: sl@0: /** sl@0: The transfer descriptor for isochronous transfers sl@0: */ sl@0: RUsbIsocTransferDescriptor iTransferDescriptor; sl@0: sl@0: /** sl@0: The maximum packet size for the respective isochronous endpoint sl@0: */ sl@0: TUint16 iMaxPacketSize; sl@0: sl@0: }; sl@0: sl@0: sl@0: /** sl@0: This class represents a bulk transfer to a device sl@0: */ sl@0: class CBulkTransfer : public CBaseTransfer sl@0: { sl@0: public: sl@0: /** sl@0: C++ constructor sl@0: */ sl@0: CBulkTransfer(RUsbPipe& aPipe,RUsbInterface& aUsbInterface,TInt aMaxTransferSize, sl@0: MTransferObserver& aObserver,TInt aTransferId); sl@0: sl@0: /** sl@0: */ sl@0: virtual ~CBulkTransfer(); sl@0: sl@0: /** sl@0: */ sl@0: void TransferOut(const TDesC8& aBulkData, TBool aUseZLPIfRequired = ETrue); sl@0: sl@0: /** sl@0: */ sl@0: void TransferOut(const TDesC8& aBulkDataPattern, TUint aNumBytes, TBool aUseZLPIfRequired = ETrue); sl@0: sl@0: /** sl@0: */ sl@0: void TransferOut(const TDesC8& aBulkDataPattern, TUint aStartPoint, TUint aNumBytes, TBool aUseZLPIfRequired); sl@0: sl@0: /** sl@0: */ sl@0: void TransferIn(TInt aExpectedDataSize); sl@0: sl@0: /** sl@0: */ sl@0: RUsbPipe& Pipe(){return CBaseTransfer::Pipe();}; sl@0: sl@0: RUsbBulkTransferDescriptor& TransferDescriptor(){return iTransferDescriptor;}; sl@0: sl@0: /** sl@0: */ sl@0: TPtrC8 DataPolled(); sl@0: sl@0: private: sl@0: /** sl@0: The transfer descriptor for bulk transfers sl@0: */ sl@0: RUsbBulkTransferDescriptor iTransferDescriptor; sl@0: }; sl@0: sl@0: sl@0: } sl@0: sl@0: #endif sl@0: sl@0: