|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // @file hostcontroltransfers.cpp |
|
15 // @internalComponent |
|
16 // |
|
17 // |
|
18 |
|
19 #include "hosttransfers.h" |
|
20 #include <e32debug.h> |
|
21 |
|
22 namespace NUnitTesting_USBDI |
|
23 { |
|
24 |
|
25 |
|
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 |
|
29 { |
|
30 |
|
31 // Register the transfer descriptor with the interface |
|
32 |
|
33 TInt err(Interface().RegisterTransferDescriptor(iTransferDescriptor)); |
|
34 if(err != KErrNone) |
|
35 { |
|
36 RDebug::Printf("<Error %d> Unable to register transfer descriptor",err); |
|
37 } |
|
38 } |
|
39 |
|
40 |
|
41 CBulkTransfer::~CBulkTransfer() |
|
42 { |
|
43 LOG_FUNC |
|
44 |
|
45 // Cancel the transfer |
|
46 |
|
47 Cancel(); |
|
48 } |
|
49 |
|
50 |
|
51 TPtrC8 CBulkTransfer::DataPolled() |
|
52 { |
|
53 return iTransferDescriptor.Buffer(); |
|
54 } |
|
55 |
|
56 |
|
57 void CBulkTransfer::TransferIn(TInt aExpectedDataSize) |
|
58 { |
|
59 LOG_FUNC |
|
60 |
|
61 // Activate the asynchronous transfer |
|
62 |
|
63 RDebug::Printf("Activating bulk in transfer"); |
|
64 iTransferDescriptor.SaveData(aExpectedDataSize); |
|
65 Pipe().Transfer(iTransferDescriptor,iStatus); |
|
66 SetActive(); |
|
67 } |
|
68 |
|
69 void CBulkTransfer::TransferOut(const TDesC8& aBulkData, TBool aUseZLPIfRequired) |
|
70 { |
|
71 LOG_FUNC |
|
72 |
|
73 // Copy the data across |
|
74 if(aBulkData.Length() > iTransferDescriptor.iMaxSize) |
|
75 { |
|
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); |
|
78 ASSERT(EFalse); |
|
79 } |
|
80 |
|
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()); |
|
85 if(aUseZLPIfRequired) |
|
86 { |
|
87 iTransferDescriptor.SetZlpStatus(RUsbTransferDescriptor::ESendZlpIfRequired); |
|
88 } |
|
89 else |
|
90 { |
|
91 iTransferDescriptor.SetZlpStatus(RUsbTransferDescriptor::ESuppressZlp); |
|
92 } |
|
93 |
|
94 // Activate the asynchronous transfer |
|
95 |
|
96 RDebug::Printf("Activating bulk out transfer"); |
|
97 Pipe().Transfer(iTransferDescriptor,iStatus); |
|
98 SetActive(); |
|
99 } |
|
100 |
|
101 void CBulkTransfer::TransferOut(const TDesC8& aBulkDataPattern, TUint aNumBytes, TBool aUseZLPIfRequired) |
|
102 { |
|
103 LOG_FUNC |
|
104 |
|
105 TransferOut(aBulkDataPattern, 0, aNumBytes, aUseZLPIfRequired); |
|
106 } |
|
107 |
|
108 |
|
109 void CBulkTransfer::TransferOut(const TDesC8& aBulkDataPattern, TUint aStartPoint, TUint aNumBytes, TBool aUseZLPIfRequired) |
|
110 { |
|
111 LOG_FUNC |
|
112 |
|
113 // Copy the data across |
|
114 if(aNumBytes > iTransferDescriptor.iMaxSize) |
|
115 { |
|
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); |
|
118 ASSERT(EFalse); |
|
119 } |
|
120 if(aBulkDataPattern.Length()<=0) |
|
121 { |
|
122 RDebug::Printf("ZERO LENGTH data pattern used in TransferOut. This test suite will now PANIC!"); |
|
123 ASSERT(EFalse); |
|
124 } |
|
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 |
|
131 if(numStartBytes) |
|
132 { |
|
133 buffer.Append(aBulkDataPattern.Right(numStartBytes)); |
|
134 } |
|
135 for(TUint i = 0; i<fullRepeats; i++) |
|
136 { |
|
137 buffer.Append(aBulkDataPattern); |
|
138 } |
|
139 if(numEndBytes) |
|
140 { |
|
141 buffer.Append(aBulkDataPattern.Left(numEndBytes)); |
|
142 } |
|
143 RDebug::Printf("Transfer buffer now has %d bytes to write",buffer.Length()); |
|
144 iTransferDescriptor.SaveData(buffer.Length()); |
|
145 if(aUseZLPIfRequired) |
|
146 { |
|
147 iTransferDescriptor.SetZlpStatus(RUsbTransferDescriptor::ESendZlpIfRequired); |
|
148 } |
|
149 else |
|
150 { |
|
151 iTransferDescriptor.SetZlpStatus(RUsbTransferDescriptor::ESuppressZlp); |
|
152 } |
|
153 |
|
154 // Activate the asynchronous transfer |
|
155 |
|
156 RDebug::Printf("Activating bulk out transfer"); |
|
157 Pipe().Transfer(iTransferDescriptor,iStatus); |
|
158 SetActive(); |
|
159 } |
|
160 |
|
161 } |