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