First public contribution.
1 #ifndef __HOST_TRANSFERS_H
2 #define __HOST_TRANSFERS_H
5 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
12 * Initial Contributors:
13 * Nokia Corporation - initial contribution.
18 * @file HostTransfers.h
28 #include <d32usbdescriptors.h>
29 #include <d32usbtransfers.h>
31 #include "testdebug.h"
32 #include "ControlTransferRequests.h"
34 namespace NUnitTesting_USBDI
38 This class describes an interface to a class which wants to observe transfers
40 class MTransferObserver
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
48 virtual void TransferCompleteL(TInt aTransferId,TInt aCompletionCode) = 0;
53 This class describes a base class for a transfer
55 class CBaseTransfer : public CActive
61 virtual ~CBaseTransfer()
66 Retrieve the identity of the transfer
67 @return the transfer identity
71 return iTransferIdentity;
78 CBaseTransfer(RUsbPipe& aPipe,RUsbInterface& aInterface,MTransferObserver& aObserver,TInt aTransferIdentity)
79 : CActive(EPriorityStandard),
81 iInterface(aInterface),
83 iTransferIdentity(aTransferIdentity)
85 CActiveScheduler::Add(this);
92 iStatus = KRequestPending;
93 TRequestStatus* s = &iStatus;
94 User::RequestComplete(s,KErrNone);
101 virtual TInt RunError(TInt aError)
103 RDebug::Printf("<Error %d> a transfer RunL left",aError);
113 TInt completionCode(iStatus.Int());
114 RDebug::Printf("Transfer err=%d",completionCode);
116 // Notify of transfer completion (successful or otherwise)
117 iObserver.TransferCompleteL(iTransferIdentity,completionCode);
126 // Will cancel all transfers on this pipe
128 Pipe().CancelAllTransfers();
134 Get the pipe object for the transfer
135 @return a opened pipe for transfers
143 Get the interface for the transfer
144 @return the opened interface
146 RUsbInterface& Interface()
152 Access the observer of the transfers
153 @return the transfer observer
155 MTransferObserver& Observer()
162 The usb pipe that will be used for the transfer and where
163 the buffer pool is located.
168 The interface that will be used for the transfer
170 RUsbInterface& iInterface;
173 The observer for the transfers
175 MTransferObserver& iObserver;
178 The identity of a transfer (not the type)
180 TInt iTransferIdentity;
184 This class represents a interrupt transfer to the device
186 class CInterruptTransfer : public CBaseTransfer
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
197 CInterruptTransfer(RUsbPipe& aPipe,RUsbInterface& aInterface,TInt aMaxTransferSize,MTransferObserver& aObserver,TInt aTransferId);
202 virtual ~CInterruptTransfer();
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
209 TInt TransferInL(TInt aSize);
212 Register the transfer descriptor
213 @return KErrNone if successful or system-wide error code
215 TInt RegisterTransferDescriptor();
218 On successful completion of an interrupt 'in' transfer, obtain the polled data
219 @return the interrupt data from the device
225 The transfer descriptor for interrupt transfers
227 RUsbIntrTransferDescriptor iTransferDescriptor;
231 This class represents a isochronous transfer to a device
233 class CIsochTransfer : public CBaseTransfer
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
245 CIsochTransfer(RUsbPipe& aPipe,RUsbInterface& aInterface,TUint16 aMaxPacketSize,
246 TInt aMaxNumPackets,MTransferObserver& aObserver,TInt aTransferId);
251 virtual ~CIsochTransfer();
253 TInt RegisterTransferDescriptor();
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
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
267 TInt PrepareTransfer(const TDesC8& aIsochData);
270 Start the IN transfer
271 @param aPacketsExpected nb of expected packets
272 @return KErrNone if successful, or system wide error code
274 TInt TransferInL(TInt aPacketsExpected);
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
282 TBool DataPolled(TUint aPacketsToBeRead, RBuf8& aDataPolled);
286 The transfer descriptor for isochronous transfers
288 RUsbIsocTransferDescriptor iTransferDescriptor;
291 The maximum packet size for the respective isochronous endpoint
293 TUint16 iMaxPacketSize;
299 This class represents a bulk transfer to a device
301 class CBulkTransfer : public CBaseTransfer
307 CBulkTransfer(RUsbPipe& aPipe,RUsbInterface& aUsbInterface,TInt aMaxTransferSize,
308 MTransferObserver& aObserver,TInt aTransferId);
312 virtual ~CBulkTransfer();
316 void TransferOut(const TDesC8& aBulkData, TBool aUseZLPIfRequired = ETrue);
320 void TransferOut(const TDesC8& aBulkDataPattern, TUint aNumBytes, TBool aUseZLPIfRequired = ETrue);
324 void TransferOut(const TDesC8& aBulkDataPattern, TUint aStartPoint, TUint aNumBytes, TBool aUseZLPIfRequired);
328 void TransferIn(TInt aExpectedDataSize);
332 RUsbPipe& Pipe(){return CBaseTransfer::Pipe();};
334 RUsbBulkTransferDescriptor& TransferDescriptor(){return iTransferDescriptor;};
342 The transfer descriptor for bulk transfers
344 RUsbBulkTransferDescriptor iTransferDescriptor;