Update contrib.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // @file hostcontroltransfers.cpp
19 #include "hosttransfers.h"
22 namespace NUnitTesting_USBDI
26 CBulkTransfer::CBulkTransfer(RUsbPipe& aPipe,RUsbInterface& aInterface,TInt aMaxTransferSize,MTransferObserver& aObserver,TInt aTransferId)
27 : CBaseTransfer(aPipe,aInterface,aObserver,aTransferId),
28 iTransferDescriptor(aMaxTransferSize) // Allocate the buffer for bulk transfers
31 // Register the transfer descriptor with the interface
33 TInt err(Interface().RegisterTransferDescriptor(iTransferDescriptor));
36 RDebug::Printf("<Error %d> Unable to register transfer descriptor",err);
41 CBulkTransfer::~CBulkTransfer()
45 // Cancel the transfer
51 TPtrC8 CBulkTransfer::DataPolled()
53 return iTransferDescriptor.Buffer();
57 void CBulkTransfer::TransferIn(TInt aExpectedDataSize)
61 // Activate the asynchronous transfer
63 RDebug::Printf("Activating bulk in transfer");
64 iTransferDescriptor.SaveData(aExpectedDataSize);
65 Pipe().Transfer(iTransferDescriptor,iStatus);
69 void CBulkTransfer::TransferOut(const TDesC8& aBulkData, TBool aUseZLPIfRequired)
73 // Copy the data across
74 if(aBulkData.Length() > iTransferDescriptor.iMaxSize)
76 RDebug::Printf("Too much data in bulk transfer. This test suite will now PANIC!");
77 RDebug::Printf("Bytes requested %d, Max allowed %d", aBulkData.Length(), iTransferDescriptor.iMaxSize);
81 TPtr8 buffer = iTransferDescriptor.WritableBuffer();
82 buffer.Copy(aBulkData);
83 RDebug::Printf("Transfer buffer now has %d bytes to write",buffer.Length());
84 iTransferDescriptor.SaveData(buffer.Length());
87 iTransferDescriptor.SetZlpStatus(RUsbTransferDescriptor::ESendZlpIfRequired);
91 iTransferDescriptor.SetZlpStatus(RUsbTransferDescriptor::ESuppressZlp);
94 // Activate the asynchronous transfer
96 RDebug::Printf("Activating bulk out transfer");
97 Pipe().Transfer(iTransferDescriptor,iStatus);
101 void CBulkTransfer::TransferOut(const TDesC8& aBulkDataPattern, TUint aNumBytes, TBool aUseZLPIfRequired)
105 TransferOut(aBulkDataPattern, 0, aNumBytes, aUseZLPIfRequired);
109 void CBulkTransfer::TransferOut(const TDesC8& aBulkDataPattern, TUint aStartPoint, TUint aNumBytes, TBool aUseZLPIfRequired)
113 // Copy the data across
114 if(aNumBytes > iTransferDescriptor.iMaxSize)
116 RDebug::Printf("Too much data in bulk transfer. This test suite will now PANIC!");
117 RDebug::Printf("Bytes requested %d, Max allowed %d", aNumBytes, iTransferDescriptor.iMaxSize);
120 if(aBulkDataPattern.Length()<=0)
122 RDebug::Printf("ZERO LENGTH data pattern used in TransferOut. This test suite will now PANIC!");
125 TUint startPoint = aStartPoint%aBulkDataPattern.Length();
126 TUint numStartBytes = (aBulkDataPattern.Length() - startPoint)%aBulkDataPattern.Length();
127 TUint fullRepeats = (aNumBytes-numStartBytes)/aBulkDataPattern.Length();
128 TUint numEndBytes = aNumBytes - fullRepeats*aBulkDataPattern.Length() - numStartBytes;
129 TPtr8 buffer = iTransferDescriptor.WritableBuffer();
130 buffer.Zero(); //set length to zero
133 buffer.Append(aBulkDataPattern.Right(numStartBytes));
135 for(TUint i = 0; i<fullRepeats; i++)
137 buffer.Append(aBulkDataPattern);
141 buffer.Append(aBulkDataPattern.Left(numEndBytes));
143 RDebug::Printf("Transfer buffer now has %d bytes to write",buffer.Length());
144 iTransferDescriptor.SaveData(buffer.Length());
145 if(aUseZLPIfRequired)
147 iTransferDescriptor.SetZlpStatus(RUsbTransferDescriptor::ESendZlpIfRequired);
151 iTransferDescriptor.SetZlpStatus(RUsbTransferDescriptor::ESuppressZlp);
154 // Activate the asynchronous transfer
156 RDebug::Printf("Activating bulk out transfer");
157 Pipe().Transfer(iTransferDescriptor,iStatus);