29 iClientDriver(aClientDriver), |
33 iClientDriver(aClientDriver), |
30 iEndpoint(aEndpoint), |
34 iEndpoint(aEndpoint), |
31 iDataPtr(NULL,0), |
35 iDataPtr(NULL,0), |
32 iValidationPatternPtr(NULL,0) |
36 iValidationPatternPtr(NULL,0) |
33 { |
37 { |
|
38 OstTraceFunctionEntryExt( CENDPOINTREADER_CENDPOINTREADER_ENTRY, this ); |
34 CActiveScheduler::Add(this); |
39 CActiveScheduler::Add(this); |
|
40 OstTraceFunctionExit1( CENDPOINTREADER_CENDPOINTREADER_EXIT, this ); |
35 } |
41 } |
36 |
42 |
37 CEndpointReader::~CEndpointReader() |
43 CEndpointReader::~CEndpointReader() |
38 { |
44 { |
39 LOG_FUNC |
45 OstTraceFunctionEntry1( CENDPOINTREADER_CENDPOINTREADER_ENTRY_DUP01, this ); |
40 Cancel(); |
46 Cancel(); |
41 delete iDataBuffer; |
47 delete iDataBuffer; |
42 iDataBuffer = NULL; |
48 iDataBuffer = NULL; |
43 delete iValidationPatternBuffer; |
49 delete iValidationPatternBuffer; |
44 iValidationPatternBuffer = NULL; |
50 iValidationPatternBuffer = NULL; |
|
51 OstTraceFunctionExit1( CENDPOINTREADER_CENDPOINTREADER_EXIT_DUP01, this ); |
45 } |
52 } |
46 |
53 |
47 TPtr8 CEndpointReader::Buffer() |
54 TPtr8 CEndpointReader::Buffer() |
48 { |
55 { |
|
56 OstTraceFunctionEntry1( CENDPOINTREADER_BUFFER_ENTRY, this ); |
|
57 OstTraceFunctionExitExt( CENDPOINTREADER_BUFFER_EXIT, this, ( TUint )&( iDataPtr ) ); |
49 return iDataPtr; |
58 return iDataPtr; |
50 } |
59 } |
51 |
60 |
52 TBool CEndpointReader::IsValid() |
61 TBool CEndpointReader::IsValid() |
53 { |
62 { |
|
63 OstTraceFunctionEntry1( CENDPOINTREADER_ISVALID_ENTRY, this ); |
|
64 OstTraceFunctionExitExt( CENDPOINTREADER_ISVALID_EXIT, this, iIsValid ); |
54 return iIsValid; |
65 return iIsValid; |
55 } |
66 } |
56 |
67 |
57 TUint CEndpointReader::NumBytesReadSoFar() |
68 TUint CEndpointReader::NumBytesReadSoFar() |
58 { |
69 { |
|
70 OstTraceFunctionEntry1( CENDPOINTREADER_NUMBYTESREADSOFAR_ENTRY, this ); |
|
71 OstTraceFunctionExitExt( CENDPOINTREADER_NUMBYTESREADSOFAR_EXIT, this, iNumBytesReadSoFar ); |
59 return iNumBytesReadSoFar; |
72 return iNumBytesReadSoFar; |
60 } |
73 } |
61 |
74 |
62 void CEndpointReader::ReadPacketL(MEndpointDataHandler* aHandler) |
75 void CEndpointReader::ReadPacketL(MEndpointDataHandler* aHandler) |
63 { |
76 { |
64 LOG_FUNC |
77 OstTraceFunctionEntryExt( CENDPOINTREADER_READPACKETL_ENTRY, this ); |
65 RDebug::Printf("Endpoint %d", iEndpoint); |
78 OstTrace1(TRACE_NORMAL, CENDPOINTREADER_READPACKETL, "Endpoint %d", iEndpoint); |
66 |
79 |
67 iHandler = aHandler; |
80 iHandler = aHandler; |
68 |
81 |
69 // Allocate buffer for reading a data packet |
82 // Allocate buffer for reading a data packet |
70 if(iDataBuffer) |
83 if(iDataBuffer) |
116 iDataPtr.Set(iDataBuffer->Des()); |
131 iDataPtr.Set(iDataBuffer->Des()); |
117 |
132 |
118 // Read from the endpoint |
133 // Read from the endpoint |
119 iClientDriver.ReadUntilShort(iStatus,iEndpoint,iDataPtr,aByteCount); |
134 iClientDriver.ReadUntilShort(iStatus,iEndpoint,iDataPtr,aByteCount); |
120 SetActive(); |
135 SetActive(); |
|
136 OstTraceFunctionExit1( CENDPOINTREADER_READUNTILSHORTL_EXIT, this ); |
121 } |
137 } |
122 |
138 |
123 void CEndpointReader::ReadAndHaltL(TInt aByteCount) |
139 void CEndpointReader::ReadAndHaltL(TInt aByteCount) |
124 { |
140 { |
125 LOG_FUNC |
141 OstTraceFunctionEntryExt( CENDPOINTREADER_READANDHALTL_ENTRY, this ); |
126 iCompletionAction = EHaltEndpoint; |
142 iCompletionAction = EHaltEndpoint; |
127 ReadL(aByteCount); |
143 ReadL(aByteCount); |
|
144 OstTraceFunctionExit1( CENDPOINTREADER_READANDHALTL_EXIT, this ); |
128 } |
145 } |
129 |
146 |
130 void CEndpointReader::RepeatedReadAndValidateL(const TDesC8& aDataPattern, TUint aNumBytesPerRead, TUint aTotalNumBytes) |
147 void CEndpointReader::RepeatedReadAndValidateL(const TDesC8& aDataPattern, TUint aNumBytesPerRead, TUint aTotalNumBytes) |
131 { |
148 { |
132 LOG_FUNC |
149 OstTraceFunctionEntryExt( CENDPOINTREADER_REPEATEDREADANDVALIDATEL_ENTRY, this ); |
133 |
150 |
134 iCompletionAction = ERepeatedRead; |
151 iCompletionAction = ERepeatedRead; |
135 iRepeatedReadTotalNumBytes = aTotalNumBytes; |
152 iRepeatedReadTotalNumBytes = aTotalNumBytes; |
136 iRepeatedReadNumBytesPerRead = aNumBytesPerRead; |
153 iRepeatedReadNumBytesPerRead = aNumBytesPerRead; |
137 iNumBytesReadSoFar = 0; |
154 iNumBytesReadSoFar = 0; |
138 iDataPatternLength = aDataPattern.Length(); |
155 iDataPatternLength = aDataPattern.Length(); |
139 iIsValid = ETrue; //until proven guilty! |
156 iIsValid = ETrue; //until proven guilty! |
140 RDebug::Printf("Total Bytes To Read: %d, Bytes Per Individual Read: %d", iRepeatedReadTotalNumBytes, iRepeatedReadNumBytesPerRead); |
157 OstTraceExt2(TRACE_NORMAL, CENDPOINTREADER_REPEATEDREADANDVALIDATEL, "Total Bytes To Read: %u, Bytes Per Individual Read: %u", iRepeatedReadTotalNumBytes, iRepeatedReadNumBytesPerRead); |
141 //Create buffer to contain two lots of the payload pattern |
158 //Create buffer to contain two lots of the payload pattern |
142 //..so that we may grab cyclic chunks of said payload pattern |
159 //..so that we may grab cyclic chunks of said payload pattern |
143 delete iValidationPatternBuffer; |
160 delete iValidationPatternBuffer; |
144 iValidationPatternBuffer = NULL; |
161 iValidationPatternBuffer = NULL; |
145 iValidationPatternBuffer = HBufC8::New(KNumPatternRepeatsNeededForValidation*aDataPattern.Length()); |
162 iValidationPatternBuffer = HBufC8::New(KNumPatternRepeatsNeededForValidation*aDataPattern.Length()); |
149 { |
166 { |
150 iValidationPatternPtr.Append(aDataPattern); |
167 iValidationPatternPtr.Append(aDataPattern); |
151 } |
168 } |
152 |
169 |
153 ReadUntilShortL(iRepeatedReadNumBytesPerRead); |
170 ReadUntilShortL(iRepeatedReadNumBytesPerRead); |
|
171 OstTraceFunctionExit1( CENDPOINTREADER_REPEATEDREADANDVALIDATEL_EXIT, this ); |
154 } |
172 } |
155 |
173 |
156 |
174 |
157 TInt CEndpointReader::Acknowledge() |
175 TInt CEndpointReader::Acknowledge() |
158 { |
176 { |
159 LOG_FUNC |
177 OstTraceFunctionEntry1( CENDPOINTREADER_ACKNOWLEDGE_ENTRY, this ); |
160 TInt err(iClientDriver.SendEp0StatusPacket()); |
178 TInt err(iClientDriver.SendEp0StatusPacket()); |
161 if(err != KErrNone) |
179 if(err != KErrNone) |
162 { |
180 { |
163 RDebug::Printf("<Error %d> Sending acknowledge packet",err); |
181 OstTrace1(TRACE_NORMAL, CENDPOINTREADER_ACKNOWLEDGE, "<Error %d> Sending acknowledge packet",err); |
164 } |
182 } |
|
183 OstTraceFunctionExitExt( CENDPOINTREADER_ACKNOWLEDGE_EXIT, this, err ); |
165 return err; |
184 return err; |
166 } |
185 } |
167 |
186 |
168 |
187 |
169 void CEndpointReader::DoCancel() |
188 void CEndpointReader::DoCancel() |
170 { |
189 { |
171 LOG_FUNC |
190 OstTraceFunctionEntry1( CENDPOINTREADER_DOCANCEL_ENTRY, this ); |
172 |
191 |
173 // Cancel reading from the endpoint |
192 // Cancel reading from the endpoint |
174 |
193 |
175 iClientDriver.ReadCancel(iEndpoint); |
194 iClientDriver.ReadCancel(iEndpoint); |
|
195 OstTraceFunctionExit1( CENDPOINTREADER_DOCANCEL_EXIT, this ); |
176 } |
196 } |
177 |
197 |
178 |
198 |
179 void CEndpointReader::RunL() |
199 void CEndpointReader::RunL() |
180 { |
200 { |
181 LOG_FUNC |
201 OstTraceFunctionEntry1( CENDPOINTREADER_RUNL_ENTRY, this ); |
182 RDebug::Printf("Endpoint %d", iEndpoint); |
202 OstTrace1(TRACE_NORMAL, CENDPOINTREADER_RUNL, "Endpoint %d", iEndpoint); |
183 RDebug::Printf("Completion Action %d", iCompletionAction); |
203 OstTrace1(TRACE_NORMAL, CENDPOINTREADER_RUNL_DUP01, "Completion Action %d", iCompletionAction); |
184 TCompletionAction completionAction = iCompletionAction; |
204 TCompletionAction completionAction = iCompletionAction; |
185 iCompletionAction = ENone; //reset here in case of 'early' returns |
205 iCompletionAction = ENone; //reset here in case of 'early' returns |
186 |
206 |
187 // The operation completion code |
207 // The operation completion code |
188 TInt completionCode(iStatus.Int()); |
208 TInt completionCode(iStatus.Int()); |
189 |
209 |
190 if(completionCode != KErrNone) |
210 if(completionCode != KErrNone) |
191 { |
211 { |
192 RDebug::Printf("<Error> void CEndpointReader::RunL()completed with ERROR %d", completionCode); |
212 OstTrace1(TRACE_NORMAL, CENDPOINTREADER_RUNL_DUP02, "<Error> void CEndpointReader::RunL()completed with ERROR %d", completionCode); |
193 |
213 |
194 // Nak the packet received |
214 // Nak the packet received |
195 iClientDriver.HaltEndpoint(iEndpoint); |
215 iClientDriver.HaltEndpoint(iEndpoint); |
196 |
216 |
197 if(iHandler) |
217 if(iHandler) |
198 { |
218 { |
199 iHandler->EndpointReadError(iEndpoint,completionCode); |
219 iHandler->EndpointReadError(iEndpoint,completionCode); |
200 } |
220 } |
201 else |
221 else |
202 { |
222 { |
203 RDebug::Printf("No handler set"); |
223 OstTrace0(TRACE_NORMAL, CENDPOINTREADER_RUNL_DUP03, "No handler set"); |
204 } |
224 } |
205 } |
225 } |
206 else |
226 else |
207 { |
227 { |
208 // Some data has arrived but |
228 // Some data has arrived but |
209 TInt ent = iDataBuffer->Length()/16; |
229 TInt ent = iDataBuffer->Length()/16; |
210 ent = ent==0?1:ent; |
230 ent = ent==0?1:ent; |
211 for(TInt i=0; i<iDataBuffer->Length(); i+=ent) |
231 for(TInt i=0; i<iDataBuffer->Length(); i+=ent) |
212 { |
232 { |
213 RDebug::Printf("byte %d %02x %c",i,(*iDataBuffer)[i],(*iDataBuffer)[i]); |
233 OstTraceExt3(TRACE_NORMAL, CENDPOINTREADER_RUNL_DUP04, "byte %d %02x %c",i,(*iDataBuffer)[i],(*iDataBuffer)[i]); |
214 } |
234 } |
215 |
235 |
216 if(iHandler) |
236 if(iHandler) |
217 { |
237 { |
218 iHandler->DataReceivedFromEndpointL(iEndpoint,*iDataBuffer); |
238 iHandler->DataReceivedFromEndpointL(iEndpoint,*iDataBuffer); |
219 } |
239 } |
220 else |
240 else |
221 { |
241 { |
222 RDebug::Printf("No handler set"); |
242 OstTrace0(TRACE_NORMAL, CENDPOINTREADER_RUNL_DUP05, "No handler set"); |
223 } |
243 } |
224 |
244 |
225 if(completionAction==EHaltEndpoint) |
245 if(completionAction==EHaltEndpoint) |
226 { |
246 { |
227 RDebug::Printf("Halting Endpoint"); |
247 OstTrace0(TRACE_NORMAL, CENDPOINTREADER_RUNL_DUP06, "Halting Endpoint"); |
228 iClientDriver.HaltEndpoint(iEndpoint); |
248 iClientDriver.HaltEndpoint(iEndpoint); |
229 } |
249 } |
230 |
250 |
231 if(completionAction==ERepeatedRead) |
251 if(completionAction==ERepeatedRead) |
232 { |
252 { |
233 RDebug::Printf("Repeated Read"); |
253 OstTrace0(TRACE_NORMAL, CENDPOINTREADER_RUNL_DUP07, "Repeated Read"); |
234 iCompletionAction = ERepeatedRead; |
254 iCompletionAction = ERepeatedRead; |
235 |
255 |
236 //Prepare to validate |
256 //Prepare to validate |
237 TInt previousBytesToRead = iRepeatedReadTotalNumBytes - iNumBytesReadSoFar; //PRIOR TO THIS READ |
257 TInt previousBytesToRead = iRepeatedReadTotalNumBytes - iNumBytesReadSoFar; //PRIOR TO THIS READ |
238 TUint expectedNumJustReadBytes = previousBytesToRead < iRepeatedReadNumBytesPerRead ? previousBytesToRead : iRepeatedReadNumBytesPerRead; |
258 TUint expectedNumJustReadBytes = previousBytesToRead < iRepeatedReadNumBytesPerRead ? previousBytesToRead : iRepeatedReadNumBytesPerRead; |
239 TPtrC8 valDesc = iValidationPatternPtr.Mid(iNumBytesReadSoFar%iDataPatternLength, expectedNumJustReadBytes); |
259 TPtrC8 valDesc = iValidationPatternPtr.Mid(iNumBytesReadSoFar%iDataPatternLength, expectedNumJustReadBytes); |
240 TInt err = iDataPtr.Compare(valDesc); |
260 TInt err = iDataPtr.Compare(valDesc); |
241 |
261 |
242 iNumBytesReadSoFar += iDataPtr.Length(); |
262 iNumBytesReadSoFar += iDataPtr.Length(); |
243 RDebug::Printf("Bytes read so far %d, Total bytes to read %d", iNumBytesReadSoFar, iRepeatedReadTotalNumBytes); |
263 OstTraceExt2(TRACE_NORMAL, CENDPOINTREADER_RUNL_DUP08, "Bytes read so far %u, Total bytes to read %u", iNumBytesReadSoFar, iRepeatedReadTotalNumBytes); |
244 |
264 |
245 if(err!=0) |
265 if(err!=0) |
246 { |
266 { |
247 RDebug::Printf("Validation Result %d, Validation String Length %d, Bytes Actually Read %d", err, valDesc.Length(), iDataPtr.Length()); |
267 OstTraceExt3(TRACE_NORMAL, CENDPOINTREADER_RUNL_DUP09, "Validation Result %d, Validation String Length %d, Bytes Actually Read %d", err, valDesc.Length(), iDataPtr.Length()); |
248 RDebug::Printf("Expected string, followed by read string"); |
268 OstTrace0(TRACE_NORMAL, CENDPOINTREADER_RUNL_DUP10, "Expected string, followed by read string"); |
249 RDebug::RawPrint(valDesc); |
269 OstTraceData(TRACE_NORMAL, CENDPOINTREADER_RUNL_DUP50, "", valDesc.Ptr(), valDesc.Length()); |
250 RDebug::Printf("\n"); |
270 OstTrace0(TRACE_NORMAL, CENDPOINTREADER_RUNL_DUP11, "\n"); |
251 RDebug::RawPrint(iDataPtr); |
271 OstTraceData(TRACE_NORMAL, CENDPOINTREADER_RUNL_DUP51, "", iDataPtr.Ptr(), iDataPtr.Length()); |
252 RDebug::Printf("\n"); |
272 OstTrace0(TRACE_NORMAL, CENDPOINTREADER_RUNL_DUP12, "\n"); |
253 iIsValid = EFalse; //record validation error |
273 iIsValid = EFalse; //record validation error |
254 } |
274 } |
255 |
275 |
256 if(iNumBytesReadSoFar < iRepeatedReadTotalNumBytes) |
276 if(iNumBytesReadSoFar < iRepeatedReadTotalNumBytes) |
257 { |
277 { |