185 // --------------------------------------------------------------------------- |
185 // --------------------------------------------------------------------------- |
186 // |
186 // |
187 TInt CDunDownstream::Stop( TBool aStopMplex ) |
187 TInt CDunDownstream::Stop( TBool aStopMplex ) |
188 { |
188 { |
189 FTRACE(FPrint( _L("CDunDownstream::Stop() (Dir=%d)" ), iDirection)); |
189 FTRACE(FPrint( _L("CDunDownstream::Stop() (Dir=%d)" ), iDirection)); |
190 if ( !iPushData.iDataPusher ) |
|
191 { |
|
192 FTRACE(FPrint( _L("CDunDownstream::Stop() (iPushData.iDatapusher not initialized!) complete" ))); |
|
193 return KErrGeneral; |
|
194 } |
|
195 // Stop the downstream related AT command handling functionality |
190 // Stop the downstream related AT command handling functionality |
196 if ( aStopMplex ) // optional |
191 if ( aStopMplex ) // optional |
197 { |
192 { |
198 if ( iPushData.iAtCmdHandler ) |
193 if ( iPushData.iAtCmdHandler ) |
199 { |
194 { |
200 iPushData.iAtCmdHandler->StopAtCmdHandling(); |
195 iPushData.iAtCmdHandler->StopAtCmdHandling(); |
201 } |
196 } |
202 // Stop the multiplexer separately |
197 // Stop the multiplexer separately |
203 iPushData.iDataPusher->Stop(); |
198 if ( iPushData.iDataPusher ) |
204 } |
|
205 if ( iTransferState != EDunStateTransferring ) |
|
206 { |
|
207 FTRACE(FPrint( _L("CDunDownstream::Stop() (not ready) complete" ))); |
|
208 return KErrNotReady; |
|
209 } |
|
210 // Stop only current operation |
|
211 if ( iOperationType == EDunOperationTypeRead ) |
|
212 { |
|
213 if ( iNetwork ) |
|
214 { |
199 { |
215 iNetwork->ReadCancel(); |
200 iPushData.iDataPusher->Stop(); |
216 Cancel(); |
|
217 FTRACE(FPrint( _L("CDunDownstream::Stop() (Network) cancelled" ))); |
|
218 } |
201 } |
219 } |
202 } |
220 else if ( iOperationType == EDunOperationTypeWrite ) |
203 Cancel(); |
221 { |
|
222 iPushData.iDataPusher->StopOneEvent( iBufferPtr ); |
|
223 } |
|
224 iTransferState = EDunStateIdle; |
|
225 iOperationType = EDunOperationTypeUndefined; |
204 iOperationType = EDunOperationTypeUndefined; |
226 FTRACE(FPrint( _L("CDunDownstream::Stop() complete" ))); |
205 FTRACE(FPrint( _L("CDunDownstream::Stop() complete" ))); |
227 return KErrNone; |
206 return KErrNone; |
228 } |
207 } |
229 |
208 |
271 { |
250 { |
272 // Set direction |
251 // Set direction |
273 iDirection = static_cast<TDunDirection>( EDunStreamTypeDownstream | iOperationType ); |
252 iDirection = static_cast<TDunDirection>( EDunStreamTypeDownstream | iOperationType ); |
274 |
253 |
275 FTRACE(FPrint( _L("CDunDownstream::IssueRequest() (Dir=%d)" ), iDirection)); |
254 FTRACE(FPrint( _L("CDunDownstream::IssueRequest() (Dir=%d)" ), iDirection)); |
276 if ( !iPushData.iDataPusher ) |
255 |
277 { |
256 if ( IsActive() ) |
278 FTRACE(FPrint( _L("CDunDownstream::IssueRequest() (iPushData.iDataPusher not initialized!) complete" ) )); |
|
279 return KErrGeneral; |
|
280 } |
|
281 |
|
282 if ( iTransferState != EDunStateIdle ) |
|
283 { |
257 { |
284 FTRACE(FPrint( _L("CDunDownstream::IssueRequest() (not ready) complete" ) )); |
258 FTRACE(FPrint( _L("CDunDownstream::IssueRequest() (not ready) complete" ) )); |
285 return KErrNotReady; |
259 return KErrNotReady; |
286 } |
260 } |
287 |
261 |
296 } |
270 } |
297 |
271 |
298 switch ( iDirection ) |
272 switch ( iDirection ) |
299 { |
273 { |
300 case EDunReaderDownstream: |
274 case EDunReaderDownstream: |
301 iStatus = KRequestPending; |
|
302 iTransferState = EDunStateTransferring; |
|
303 iNetwork->ReadOneOrMore( iStatus, *iBufferPtr ); |
275 iNetwork->ReadOneOrMore( iStatus, *iBufferPtr ); |
304 SetActive(); |
276 SetActive(); |
305 FTRACE(FPrint( _L("CDunDownstream::IssueRequest() RComm ReadOneOrMore() requested" ) )); |
277 FTRACE(FPrint( _L("CDunDownstream::IssueRequest() RComm ReadOneOrMore() requested" ) )); |
306 break; |
278 break; |
307 case EDunWriterDownstream: |
279 case EDunWriterDownstream: |
308 iTransferState = EDunStateTransferring; |
|
309 AddToQueueAndSend( iBufferPtr, this ); |
280 AddToQueueAndSend( iBufferPtr, this ); |
310 break; |
281 break; |
311 default: |
282 default: |
312 FTRACE(FPrint( _L("CDunDownstream::IssueRequest() (ERROR) complete" ) )); |
283 FTRACE(FPrint( _L("CDunDownstream::IssueRequest() (ERROR) complete" ) )); |
313 return KErrGeneral; |
284 return KErrGeneral; |
323 // --------------------------------------------------------------------------- |
294 // --------------------------------------------------------------------------- |
324 // |
295 // |
325 void CDunDownstream::RunL() |
296 void CDunDownstream::RunL() |
326 { |
297 { |
327 FTRACE(FPrint( _L("CDunDownstream::RunL() (Dir=%d)" ), iDirection)); |
298 FTRACE(FPrint( _L("CDunDownstream::RunL() (Dir=%d)" ), iDirection)); |
328 iTransferState = EDunStateIdle; |
299 |
329 if ( iOperationType != EDunOperationTypeRead ) |
300 if ( iOperationType != EDunOperationTypeRead ) |
330 { |
301 { |
331 FTRACE(FPrint( _L("CDunDownstream::RunL() (wrong operation type!) complete" ))); |
302 FTRACE(FPrint( _L("CDunDownstream::RunL() (wrong operation type!) complete" ))); |
332 return; |
303 return; |
333 } |
304 } |
374 // --------------------------------------------------------------------------- |
345 // --------------------------------------------------------------------------- |
375 // |
346 // |
376 void CDunDownstream::DoCancel() |
347 void CDunDownstream::DoCancel() |
377 { |
348 { |
378 FTRACE(FPrint( _L("CDunDownstream::DoCancel()" ))); |
349 FTRACE(FPrint( _L("CDunDownstream::DoCancel()" ))); |
|
350 iNetwork->ReadCancel(); |
379 FTRACE(FPrint( _L("CDunDownstream::DoCancel() complete" ))); |
351 FTRACE(FPrint( _L("CDunDownstream::DoCancel() complete" ))); |
380 } |
352 } |
381 |
353 |
382 // --------------------------------------------------------------------------- |
354 // --------------------------------------------------------------------------- |
383 // From class MDunStreamManipulator. |
355 // From class MDunStreamManipulator. |
422 TInt foundIndex = iPushData.iDataPusher->FindEventFromQueue( iBufferPtr ); |
394 TInt foundIndex = iPushData.iDataPusher->FindEventFromQueue( iBufferPtr ); |
423 iPushData.iDataPusher->SignalCompletionAndClearQueue(); |
395 iPushData.iDataPusher->SignalCompletionAndClearQueue(); |
424 FTRACE(FPrint( _L("CDunDownstream::NotifyDataPushComplete() (find event)" ))); |
396 FTRACE(FPrint( _L("CDunDownstream::NotifyDataPushComplete() (find event)" ))); |
425 if ( foundIndex >= 0 ) |
397 if ( foundIndex >= 0 ) |
426 { |
398 { |
427 iTransferState = EDunStateIdle; |
|
428 iOperationType = EDunOperationTypeUndefined; |
399 iOperationType = EDunOperationTypeUndefined; |
429 FTRACE(FPrint( _L("CDunDownstream::NotifyDataPushComplete() (issue request)" ))); |
400 FTRACE(FPrint( _L("CDunDownstream::NotifyDataPushComplete() (issue request)" ))); |
430 if ( iPushData.iDataMode ) |
401 if ( iPushData.iDataMode ) |
431 { |
402 { |
432 iOperationType = EDunOperationTypeRead; |
403 iOperationType = EDunOperationTypeRead; |
443 // |
414 // |
444 void CDunDownstream::NotifyCommandModeStart() |
415 void CDunDownstream::NotifyCommandModeStart() |
445 { |
416 { |
446 FTRACE(FPrint( _L("CDunDownstream::NotifyCommandModeStart()" ))); |
417 FTRACE(FPrint( _L("CDunDownstream::NotifyCommandModeStart()" ))); |
447 iPushData.iDataMode = EFalse; |
418 iPushData.iDataMode = EFalse; |
448 // Now the data mode has ended. If read operation then cancel it. |
419 // Now the data mode has ended. Stop read operation but not the multiplexer. |
449 // Check for iTransferState here to minimize logging |
420 Stop( EFalse ); |
450 if ( iTransferState==EDunStateTransferring && |
|
451 iOperationType==EDunOperationTypeRead ) |
|
452 { |
|
453 Stop( EFalse ); |
|
454 } |
|
455 FTRACE(FPrint( _L("CDunDownstream::NotifyCommandModeStart() complete" ))); |
421 FTRACE(FPrint( _L("CDunDownstream::NotifyCommandModeStart() complete" ))); |
456 } |
422 } |
457 |
423 |
458 // --------------------------------------------------------------------------- |
424 // --------------------------------------------------------------------------- |
459 // From class MDunCmdModeMonitor. |
425 // From class MDunCmdModeMonitor. |
462 // |
428 // |
463 void CDunDownstream::NotifyCommandModeEnd() |
429 void CDunDownstream::NotifyCommandModeEnd() |
464 { |
430 { |
465 FTRACE(FPrint( _L("CDunDownstream::NotifyCommandModeEnd()" ))); |
431 FTRACE(FPrint( _L("CDunDownstream::NotifyCommandModeEnd()" ))); |
466 iPushData.iDataMode = ETrue; |
432 iPushData.iDataMode = ETrue; |
467 // Command mode ends here so start reading from Dataport only if generic |
433 iOperationType = EDunOperationTypeRead; // just in case |
468 // transferring state is not EDunStateIdle. This is a reduced form of having |
434 IssueRequest(); |
469 // read pending -> reissue not needed OR write pending -> reissue not needed |
|
470 // (NotifyDataPushComplete() will reissue). |
|
471 if ( iTransferState == EDunStateIdle ) |
|
472 { |
|
473 iOperationType = EDunOperationTypeRead; // just in case |
|
474 IssueRequest(); |
|
475 } |
|
476 FTRACE(FPrint( _L("CDunDownstream::NotifyCommandModeEnd() complete" ))); |
435 FTRACE(FPrint( _L("CDunDownstream::NotifyCommandModeEnd() complete" ))); |
477 } |
436 } |