author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 31 Aug 2010 16:34:26 +0300 | |
branch | RCL_3 |
changeset 256 | c1f20ce4abcf |
parent 0 | a41df078684a |
child 257 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1 |
// Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 endpointwriter.cpp |
|
15 |
// @internalComponent |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
16 |
// |
0 | 17 |
// |
18 |
||
19 |
#include <e32base.h> |
|
20 |
#include <e32base_private.h> |
|
21 |
#include <d32usbc.h> |
|
22 |
#include "endpointwriter.h" |
|
23 |
#include "testdebug.h" |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
24 |
#include "OstTraceDefinitions.h" |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
25 |
#ifdef OST_TRACE_COMPILER_IN_USE |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
26 |
#include "endpointwriterTraces.h" |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
27 |
#endif |
0 | 28 |
|
29 |
namespace NUnitTesting_USBDI |
|
30 |
{ |
|
31 |
const TUint KMaxTransferBuffer = 0x1000; |
|
32 |
||
33 |
||
34 |
CEndpointWriter::CEndpointWriter(RDevUsbcClient& aClientDriver,TEndpointNumber aEndpoint) |
|
35 |
: CActive(EPriorityStandard), |
|
36 |
iClientDriver(aClientDriver), |
|
37 |
iEndpoint(aEndpoint), |
|
38 |
iBufPtr(NULL,0) |
|
39 |
{ |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
40 |
OstTraceFunctionEntryExt( CENDPOINTWRITER_CENDPOINTWRITER_ENTRY, this ); |
0 | 41 |
CActiveScheduler::Add(this); |
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
42 |
OstTraceFunctionExit1( CENDPOINTWRITER_CENDPOINTWRITER_EXIT, this ); |
0 | 43 |
} |
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
44 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
45 |
|
0 | 46 |
CEndpointWriter::~CEndpointWriter() |
47 |
{ |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
48 |
OstTraceFunctionEntry1( CENDPOINTWRITER_CENDPOINTWRITER_ENTRY_DUP01, this ); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
49 |
|
0 | 50 |
Cancel(); |
51 |
if(iBuffer) |
|
52 |
{ |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
53 |
OstTrace1(TRACE_NORMAL, CENDPOINTWRITER_DCENDPOINTWRITER, "Freeing %d bytes", iBuffer->Size()); |
0 | 54 |
} |
55 |
delete iBuffer; |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
56 |
OstTraceFunctionExit1( CENDPOINTWRITER_CENDPOINTWRITER_EXIT_DUP01, this ); |
0 | 57 |
} |
58 |
||
59 |
||
60 |
void CEndpointWriter::DoCancel() |
|
61 |
{ |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
62 |
OstTraceFunctionEntry1( CENDPOINTWRITER_DOCANCEL_ENTRY, this ); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
63 |
|
0 | 64 |
// Cancel the write to the endpoint |
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
65 |
|
0 | 66 |
iClientDriver.WriteCancel(iEndpoint); |
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
67 |
OstTraceFunctionExit1( CENDPOINTWRITER_DOCANCEL_EXIT, this ); |
0 | 68 |
} |
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
69 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
70 |
|
0 | 71 |
TUint CEndpointWriter::NumBytesWrittenSoFar() |
72 |
{ |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
OstTraceFunctionEntry1( CENDPOINTWRITER_NUMBYTESWRITTENSOFAR_ENTRY, this ); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
74 |
OstTraceFunctionExitExt( CENDPOINTWRITER_NUMBYTESWRITTENSOFAR_EXIT, this, iNumBytesWritten ); |
0 | 75 |
return iNumBytesWritten; |
76 |
} |
|
77 |
||
78 |
void CEndpointWriter::RunL() |
|
79 |
{ |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
80 |
OstTraceFunctionEntry1( CENDPOINTWRITER_RUNL_ENTRY, this ); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
81 |
|
0 | 82 |
TInt completionCode(iStatus.Int()); |
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
83 |
OstTrace1(TRACE_NORMAL, CENDPOINTWRITER_RUNL, "Write completed, err=%d",completionCode); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
84 |
|
0 | 85 |
iNumBytesWritten += iNumBytesOnCurrentWrite; // all zero if not a repeated write |
86 |
if(iNumBytesWritten < iTotalNumBytes) |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
87 |
//This conditional will not be entered for non-repeat cases because then |
0 | 88 |
//'iNumBytesWritten' and 'iTotalNumBytes' will both be zero. |
89 |
{ |
|
90 |
TUint totalNumBytesStillToWrite = iTotalNumBytes - iNumBytesWritten; |
|
91 |
||
92 |
//NB iNumBytesOnCurrentWrite should remain at the requested 'bytes per Write' value until the last iteration |
|
93 |
iNumBytesOnCurrentWrite = totalNumBytesStillToWrite <= iNumBytesOnCurrentWrite ? totalNumBytesStillToWrite : iNumBytesOnCurrentWrite; |
|
94 |
||
95 |
//Only add a ZLP, if requested and if the last 'Write' |
|
96 |
TBool useUsb = totalNumBytesStillToWrite <= iNumBytesOnCurrentWrite ? iUseZLP : EFalse; |
|
97 |
TPtrC8 writeDesc = iBufPtr.Mid(iNumBytesWritten%iDataPatternLength, iNumBytesOnCurrentWrite); |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
98 |
OstTraceExt4(TRACE_NORMAL, CENDPOINTWRITER_RUNL_DUP01, "Total Bytes To Write = %u, Bytes Still To Write = %u, Bytes Written = %d, Bytes on Current Write = %d", iTotalNumBytes, totalNumBytesStillToWrite, iNumBytesWritten, iNumBytesOnCurrentWrite); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
99 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
100 |
OstTrace0(TRACE_NORMAL, CENDPOINTWRITER_RUNL_DUP02, "\n"); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
101 |
OstTrace0(TRACE_NORMAL, CENDPOINTWRITER_RUNL_DUP03, "First 256 bytes (or all) of data to write"); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
102 |
OstTraceData(TRACE_NORMAL, CENDPOINTWRITER_RUNL_DUP53, "", writeDesc.Ptr(), writeDesc.Length()); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
103 |
OstTrace0(TRACE_NORMAL, CENDPOINTWRITER_RUNL_DUP04, "\n"); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
104 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
105 |
|
0 | 106 |
Write(writeDesc, useUsb, EFalse); |
107 |
} |
|
108 |
else |
|
109 |
{ |
|
110 |
if(iBuffer!=NULL) |
|
111 |
{ |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
112 |
OstTrace1(TRACE_NORMAL, CENDPOINTWRITER_RUNL_DUP05, "Freeing %d bytes", iBuffer->Size()); |
0 | 113 |
} |
114 |
else |
|
115 |
{ |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
116 |
OstTrace0(TRACE_NORMAL, CENDPOINTWRITER_RUNL_DUP06, "iBuffer is NULL"); |
0 | 117 |
} |
118 |
if(iTotalNumBytes != 0) |
|
119 |
//if a repeated write |
|
120 |
{ |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
121 |
OstTraceExt2(TRACE_NORMAL, CENDPOINTWRITER_RUNL_DUP07, "Total Bytes = %u, Bytes Written = %u", iTotalNumBytes, iNumBytesWritten); |
0 | 122 |
} |
123 |
delete iBuffer; |
|
124 |
iBuffer = 0; |
|
125 |
iNumBytesOnCurrentWrite = 0; |
|
126 |
iNumBytesWritten = 0; |
|
127 |
iTotalNumBytes = 0; |
|
128 |
iDataPatternLength = 0; |
|
129 |
iUseZLP = EFalse; |
|
130 |
} |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
131 |
OstTraceFunctionExit1( CENDPOINTWRITER_RUNL_EXIT, this ); |
0 | 132 |
} |
133 |
||
134 |
||
135 |
TInt CEndpointWriter::RunError(TInt aError) |
|
136 |
{ |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
137 |
OstTraceFunctionEntryExt( CENDPOINTWRITER_RUNERROR_ENTRY, this ); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
138 |
|
0 | 139 |
aError = KErrNone; |
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
140 |
OstTraceFunctionExitExt( CENDPOINTWRITER_RUNERROR_EXIT, this, aError ); |
0 | 141 |
return aError; |
142 |
} |
|
143 |
||
144 |
||
145 |
void CEndpointWriter::Write(const TDesC8& aData, TBool aUseZLP, TBool aCreateBuffer) |
|
146 |
{ |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
147 |
OstTraceFunctionEntryExt( CENDPOINTWRITER_WRITE_ENTRY, this ); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
148 |
|
0 | 149 |
if(aCreateBuffer == EFalse) |
150 |
{ |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
151 |
OstTrace1(TRACE_NORMAL, CENDPOINTWRITER_WRITE, "Use ZLP %d", aUseZLP?1:0); |
0 | 152 |
iClientDriver.Write(iStatus,iEndpoint,aData,aData.Length(),aUseZLP); |
153 |
SetActive(); |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
154 |
OstTraceFunctionExit1( CENDPOINTWRITER_WRITE_EXIT, this ); |
0 | 155 |
return; |
156 |
} |
|
157 |
||
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
158 |
|
0 | 159 |
//Copy aData to this object's buffer |
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
160 |
//'aData' will go out of scope before the USB driver 'Write' completes |
0 | 161 |
delete iBuffer; |
162 |
iBuffer = NULL; |
|
163 |
iBuffer = HBufC8::NewL(aData.Length()); |
|
164 |
iBufPtr.Set(iBuffer->Des()); |
|
165 |
iBufPtr.Copy(aData); |
|
166 |
||
167 |
// Write the data to the host through the endpoint (host opened pipe) |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
168 |
OstTrace1(TRACE_NORMAL, CENDPOINTWRITER_WRITE_DUP01, "Write Length = %d", iBufPtr.Length()); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
169 |
OstTraceData(TRACE_NORMAL, CENDPOINTWRITER_WRITE_DUP51, "", iBufPtr.Ptr(), iBufPtr.Length()); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
170 |
OstTrace0(TRACE_NORMAL, CENDPOINTWRITER_WRITE_DUP02, "\n"); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
171 |
OstTrace1(TRACE_NORMAL, CENDPOINTWRITER_WRITE_DUP03, "Use ZLP %d", aUseZLP?1:0); |
0 | 172 |
iClientDriver.Write(iStatus,iEndpoint,iBufPtr,iBufPtr.Length(),aUseZLP); |
173 |
SetActive(); |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
174 |
OstTraceFunctionExit1( CENDPOINTWRITER_WRITE_EXIT_DUP01, this ); |
0 | 175 |
} |
176 |
||
177 |
TInt CEndpointWriter::WriteSynchronous(const TDesC8& aData, TBool aUseZLP) |
|
178 |
{ |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
179 |
OstTraceFunctionEntryExt( CENDPOINTWRITER_WRITESYNCHRONOUS_ENTRY, this ); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
180 |
|
0 | 181 |
TRequestStatus status = KRequestPending; |
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
182 |
OstTrace1(TRACE_NORMAL, CENDPOINTWRITER_WRITESYNCHRONOUS, "Write Length = %d", aData.Length()); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
183 |
OstTraceData(TRACE_NORMAL, CENDPOINTWRITER_WRITESYNCHRONOUS_DUP50, "", aData.Ptr(), aData.Length()); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
184 |
OstTrace0(TRACE_NORMAL, CENDPOINTWRITER_WRITESYNCHRONOUS_DUP01, "\n"); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
185 |
OstTrace1(TRACE_NORMAL, CENDPOINTWRITER_WRITESYNCHRONOUS_DUP02, "Use ZLP %d", aUseZLP?1:0); |
0 | 186 |
iClientDriver.Write(status,iEndpoint,aData,aData.Length(),aUseZLP); |
187 |
User::WaitForRequest(status); |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
188 |
OstTrace1(TRACE_NORMAL, CENDPOINTWRITER_WRITESYNCHRONOUS_DUP03, "Write has completed with error %d", status.Int()); |
0 | 189 |
return status.Int(); |
190 |
} |
|
191 |
||
192 |
void CEndpointWriter::WriteSynchronousUsingPatternL(const TDesC8& aData, const TUint aNumBytes, const TBool aUseZLP) |
|
193 |
{ |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
194 |
OstTraceFunctionEntryExt( CENDPOINTWRITER_WRITESYNCHRONOUSUSINGPATTERNL_ENTRY, this ); |
0 | 195 |
|
196 |
TBool useZLP = EFalse; //only want this if you are making the last call to client Write (=WriteSynchronous) |
|
197 |
if(aNumBytes <= aData.Length()) |
|
198 |
//Don't need to allocate a buffer and copy to it - write will be done synchronously |
|
199 |
{ |
|
200 |
if(aUseZLP) |
|
201 |
{ |
|
202 |
useZLP = ETrue; |
|
203 |
} |
|
204 |
WriteSynchronous(aData.Left(aNumBytes),useZLP); |
|
205 |
} |
|
206 |
||
207 |
else if(aNumBytes <= KMaxTransferBuffer) |
|
208 |
//Create a buffer based on the data pattern sent and use just one 'Synchronous Write' |
|
209 |
{ |
|
210 |
if(aUseZLP) |
|
211 |
{ |
|
212 |
useZLP = ETrue; |
|
213 |
} |
|
214 |
TInt repeats = aNumBytes/aData.Length(); |
|
215 |
TInt extraBytes = aNumBytes%aData.Length(); |
|
216 |
delete iBuffer; |
|
217 |
iBuffer = NULL; |
|
218 |
iBuffer = HBufC8::NewL(aNumBytes); |
|
219 |
TPtr8 ptr = iBuffer->Des(); |
|
220 |
ptr.Zero(); |
|
221 |
for(TUint i =0; i<repeats; i++) |
|
222 |
{ |
|
223 |
ptr.Append(aData); |
|
224 |
} |
|
225 |
if(extraBytes) |
|
226 |
{ |
|
227 |
ptr.Append(aData.Left(extraBytes)); |
|
228 |
} |
|
229 |
WriteSynchronous(ptr, useZLP); |
|
230 |
delete iBuffer; |
|
231 |
} |
|
232 |
||
233 |
else |
|
234 |
//Create a buffer based on the data pattern sent and use SEVERAL 'Synchronous Write's |
|
235 |
{ |
|
236 |
//Write data in reasonably sized chunks |
|
237 |
//Create buffer using max whole number of data patterns |
|
238 |
TInt repeats = KMaxTransferBuffer/aData.Length(); |
|
239 |
CreateBigBuffer(aData, repeats); |
|
240 |
||
241 |
//Now write data |
|
242 |
repeats = aNumBytes/iBufPtr.Length(); //re-use 'repeats' |
|
243 |
TInt endBytes = aNumBytes%iBufPtr.Length(); |
|
244 |
for(TInt i=0;i<repeats;i++) |
|
245 |
{ |
|
246 |
if(i==(repeats-1)&&endBytes==0) |
|
247 |
//last loop - request ZLP if appropriate |
|
248 |
{ |
|
249 |
WriteSynchronous(*iBuffer, aUseZLP); //if last 'Write' |
|
250 |
} |
|
251 |
else |
|
252 |
{ |
|
253 |
WriteSynchronous(*iBuffer, EFalse); |
|
254 |
} |
|
255 |
} |
|
256 |
if(endBytes) |
|
257 |
{ |
|
258 |
WriteSynchronous(iBufPtr.Left(endBytes), aUseZLP); //if last 'Write' |
|
259 |
} |
|
260 |
} |
|
261 |
delete iBuffer; |
|
262 |
iBuffer = 0; |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
263 |
OstTraceFunctionExit1( CENDPOINTWRITER_WRITESYNCHRONOUSUSINGPATTERNL_EXIT, this ); |
0 | 264 |
} |
265 |
||
266 |
void CEndpointWriter::WriteSynchronousUsingPatternL(const TDesC8& aData, const TUint aNumBytes) |
|
267 |
{ |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
268 |
OstTraceFunctionEntryExt( CENDPOINTWRITER_WRITESYNCHRONOUSUSINGPATTERNL_ENTRY_DUP01, this ); |
0 | 269 |
WriteSynchronousUsingPatternL(aData, aNumBytes, ETrue); |
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
270 |
OstTraceFunctionExit1( CENDPOINTWRITER_WRITESYNCHRONOUSUSINGPATTERNL_EXIT_DUP01, this ); |
0 | 271 |
} |
272 |
||
273 |
void CEndpointWriter::WriteSynchronousUsingPatternAndHaltL(const TDesC8& aData, const TUint aNumBytes) |
|
274 |
{ |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
275 |
OstTraceFunctionEntryExt( CENDPOINTWRITER_WRITESYNCHRONOUSUSINGPATTERNANDHALTL_ENTRY, this ); |
0 | 276 |
WriteSynchronousUsingPatternL(aData, aNumBytes, EFalse); |
277 |
iClientDriver.HaltEndpoint(iEndpoint); |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
278 |
OstTraceFunctionExit1( CENDPOINTWRITER_WRITESYNCHRONOUSUSINGPATTERNANDHALTL_EXIT, this ); |
0 | 279 |
} |
280 |
||
281 |
void CEndpointWriter::WriteUsingPatternL(const TDesC8& aData, const TUint aNumBytes, const TBool aUseZLP) |
|
282 |
{ |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
283 |
OstTraceFunctionEntryExt( CENDPOINTWRITER_WRITEUSINGPATTERNL_ENTRY, this ); |
0 | 284 |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
285 |
OstTrace1(TRACE_NORMAL, CENDPOINTWRITER_WRITEUSINGPATTERNL, "Allocating %d bytes", aNumBytes); |
0 | 286 |
delete iBuffer; |
287 |
iBuffer = NULL; |
|
288 |
iBuffer = HBufC8::NewL(aNumBytes); |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
289 |
OstTrace1(TRACE_NORMAL, CENDPOINTWRITER_WRITEUSINGPATTERNL_DUP01, "Allocated %d bytes", aNumBytes); |
0 | 290 |
iBufPtr.Set(iBuffer->Des()); |
291 |
iBufPtr.Zero(); |
|
292 |
TInt repeats = aNumBytes/aData.Length(); |
|
293 |
for(TUint i =0; i<repeats; i++) |
|
294 |
{ |
|
295 |
iBufPtr.Append(aData); |
|
296 |
} |
|
297 |
if(TInt extraBytes = aNumBytes%aData.Length()) |
|
298 |
{ |
|
299 |
iBufPtr.Append(aData.Left(extraBytes)); |
|
300 |
} |
|
301 |
Write(*iBuffer, aUseZLP, EFalse); |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
302 |
OstTraceFunctionExit1( CENDPOINTWRITER_WRITEUSINGPATTERNL_EXIT, this ); |
0 | 303 |
} |
304 |
||
305 |
void CEndpointWriter::WriteInPartsUsingPatternL(const TDesC8& aData, const TUint aNumBytesPerWrite, TUint aTotalNumBytes, const TBool aUseZLP) |
|
306 |
{ |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
307 |
OstTraceFunctionEntryExt( CENDPOINTWRITER_WRITEINPARTSUSINGPATTERNL_ENTRY, this ); |
0 | 308 |
|
309 |
iUseZLP = aUseZLP; |
|
310 |
TInt repeats = aNumBytesPerWrite/aData.Length() + 1; |
|
311 |
repeats *= 2; |
|
312 |
CreateBigBuffer(aData, repeats); |
|
313 |
iDataPatternLength = aData.Length(); |
|
314 |
iTotalNumBytes = aTotalNumBytes; |
|
315 |
iNumBytesOnCurrentWrite = aNumBytesPerWrite; |
|
316 |
iNumBytesWritten = 0; |
|
317 |
Write(iBufPtr.Mid(iNumBytesWritten%iDataPatternLength, iNumBytesOnCurrentWrite), EFalse, EFalse); //this is not the first 'Write' so do not use a ZLP |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
318 |
OstTrace1(TRACE_NORMAL, CENDPOINTWRITER_WRITEINPARTSUSINGPATTERNL, "Write %d bytes",iNumBytesOnCurrentWrite); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
319 |
OstTraceExt2(TRACE_NORMAL, CENDPOINTWRITER_WRITEINPARTSUSINGPATTERNL_DUP01, "Total Bytes = %u, Data Pattern Length = %u", iTotalNumBytes, iDataPatternLength); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
320 |
OstTraceFunctionExit1( CENDPOINTWRITER_WRITEINPARTSUSINGPATTERNL_EXIT, this ); |
0 | 321 |
} |
322 |
||
323 |
void CEndpointWriter::CreateBigBuffer(const TDesC8& aData, const TUint aRepeats) |
|
324 |
/* |
|
325 |
Create a payload buffer a section of which can always be used for each cyclic 'Write'. |
|
326 |
*/ |
|
327 |
{ |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
328 |
OstTraceFunctionEntryExt( CENDPOINTWRITER_CREATEBIGBUFFER_ENTRY, this ); |
0 | 329 |
//We require a buffer containing a sufficient number of repeats of the data pattern |
330 |
//to allow us simply to use a section of it for any individual 'Write' payload. |
|
331 |
delete iBuffer; |
|
332 |
iBuffer = NULL; |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
333 |
OstTraceExt2(TRACE_NORMAL, CENDPOINTWRITER_CREATEBIGBUFFER, "Data buffer is using %u repeats of string starting...\n\"%s\"", aRepeats, aData); |
0 | 334 |
iBuffer = HBufC8::NewL(aRepeats*aData.Length()); |
335 |
iBufPtr.Set(iBuffer->Des()); |
|
336 |
iBufPtr.Zero(); |
|
337 |
for(TUint i =0; i<aRepeats; i++) |
|
338 |
{ |
|
339 |
iBufPtr.Append(aData); |
|
340 |
} |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
341 |
OstTraceFunctionExit1( CENDPOINTWRITER_CREATEBIGBUFFER_EXIT, this ); |
0 | 342 |
} |
343 |
||
344 |
} |