localconnectivityservice/dun/utils/src/DunUpstream.cpp
changeset 60 841f70763fbe
parent 52 866b4af7ffbe
equal deleted inserted replaced
52:866b4af7ffbe 60:841f70763fbe
   164 //
   164 //
   165 TInt CDunUpstream::Stop()
   165 TInt CDunUpstream::Stop()
   166     {
   166     {
   167     FTRACE(FPrint( _L("CDunUpstream::Stop() (Dir=%d)" ), iDirection));
   167     FTRACE(FPrint( _L("CDunUpstream::Stop() (Dir=%d)" ), iDirection));
   168     // Don't stop CDunAtCmdHandler here as it is downstream related!
   168     // Don't stop CDunAtCmdHandler here as it is downstream related!
   169     if ( iTransferState != EDunStateTransferring )
       
   170         {
       
   171         FTRACE(FPrint( _L("CDunUpstream::Stop() (not ready) complete" )));
       
   172         return KErrNotReady;
       
   173         }
       
   174     // Stop only current operation
       
   175     if ( iOperationType == EDunOperationTypeRead )
       
   176         {
       
   177         if ( iComm )
       
   178             {
       
   179             iComm->ReadCancel();
       
   180             FTRACE(FPrint( _L("CDunUpstream::Stop() (RComm) cancelled" )));
       
   181             }
       
   182         else if ( iSocket )
       
   183             {
       
   184             iSocket->CancelRecv();
       
   185             FTRACE(FPrint( _L("CDunUpstream::Stop() (RSocket) cancelled" )));
       
   186             }
       
   187         }
       
   188     else if ( iOperationType == EDunOperationTypeWrite )
       
   189         {
       
   190         if ( iNetwork )
       
   191             {
       
   192             iNetwork->WriteCancel();
       
   193             FTRACE(FPrint( _L("CDunUpstream::Stop() (Network) cancelled" )));
       
   194             }
       
   195         }
       
   196     Cancel();
   169     Cancel();
   197     iTransferState = EDunStateIdle;
       
   198     iOperationType = EDunOperationTypeUndefined;
   170     iOperationType = EDunOperationTypeUndefined;
   199     // Notify parent about inactivity
   171     // Notify parent about inactivity
   200     if ( iActivityData.iActivityCallback && iActivityData.iNotified )
   172     if ( iActivityData.iActivityCallback && iActivityData.iNotified )
   201         {
   173         {
   202         iActivityData.iActivityCallback->NotifyChannelInactivity();
   174         iActivityData.iActivityCallback->NotifyChannelInactivity();
   262     // Set direction
   234     // Set direction
   263     iDirection = static_cast<TDunDirection>( EDunStreamTypeUpstream | iOperationType );
   235     iDirection = static_cast<TDunDirection>( EDunStreamTypeUpstream | iOperationType );
   264 
   236 
   265     FTRACE(FPrint( _L("CDunUpstream::IssueRequest() (Dir=%d)" ), iDirection));
   237     FTRACE(FPrint( _L("CDunUpstream::IssueRequest() (Dir=%d)" ), iDirection));
   266 
   238 
   267     if ( iTransferState != EDunStateIdle )
   239     if ( IsActive() )
   268         {
   240         {
   269         FTRACE(FPrint( _L("CDunUpstream::IssueRequest() (not ready) complete" ) ));
   241         FTRACE(FPrint( _L("CDunUpstream::IssueRequest() (not ready) complete" ) ));
   270         return KErrNotReady;
   242         return KErrNotReady;
   271         }
   243         }
   272 
   244 
   283     switch ( iDirection )
   255     switch ( iDirection )
   284         {
   256         {
   285         case EDunReaderUpstream:
   257         case EDunReaderUpstream:
   286             if ( iComm )
   258             if ( iComm )
   287                 {
   259                 {
   288                 iStatus = KRequestPending;
       
   289                 iTransferState = EDunStateTransferring;
       
   290                 iComm->ReadOneOrMore( iStatus, *iBufferPtr );
   260                 iComm->ReadOneOrMore( iStatus, *iBufferPtr );
   291                 SetActive();
   261                 SetActive();
   292                 FTRACE(FPrint( _L("CDunUpstream::IssueRequest() RComm ReadOneOrMore() requested" ) ));
   262                 FTRACE(FPrint( _L("CDunUpstream::IssueRequest() RComm ReadOneOrMore() requested" ) ));
   293                 }
   263                 }
   294             else if ( iSocket )
   264             else if ( iSocket )
   295                 {
   265                 {
   296                 iStatus = KRequestPending;
       
   297                 iTransferState = EDunStateTransferring;
       
   298                 iSocket->RecvOneOrMore( *iBufferPtr, 0, iStatus, iReadLengthSocket );
   266                 iSocket->RecvOneOrMore( *iBufferPtr, 0, iStatus, iReadLengthSocket );
   299                 SetActive();
   267                 SetActive();
   300                 FTRACE(FPrint( _L("CDunUpstream::IssueRequest() RSocket RecvOneOrMore() requested" ) ));
   268                 FTRACE(FPrint( _L("CDunUpstream::IssueRequest() RSocket RecvOneOrMore() requested" ) ));
   301                 }
   269                 }
   302             else
   270             else
   304                 FTRACE(FPrint( _L("CDunUpstream::IssueRequest() (ERROR) complete" ) ));
   272                 FTRACE(FPrint( _L("CDunUpstream::IssueRequest() (ERROR) complete" ) ));
   305                 return KErrGeneral;
   273                 return KErrGeneral;
   306                 }
   274                 }
   307             break;
   275             break;
   308         case EDunWriterUpstream:
   276         case EDunWriterUpstream:
   309             iStatus = KRequestPending;
       
   310             iTransferState = EDunStateTransferring;
       
   311             iNetwork->Write( iStatus, *iBufferPtr );
   277             iNetwork->Write( iStatus, *iBufferPtr );
   312             SetActive();
   278             SetActive();
   313             FTRACE(FPrint( _L("CDunUpstream::IssueRequest() RComm Write() requested" ) ));
   279             FTRACE(FPrint( _L("CDunUpstream::IssueRequest() RComm Write() requested" ) ));
   314             break;
   280             break;
   315         default:
   281         default:
   384 // ---------------------------------------------------------------------------
   350 // ---------------------------------------------------------------------------
   385 //
   351 //
   386 void CDunUpstream::RunL()
   352 void CDunUpstream::RunL()
   387     {
   353     {
   388     FTRACE(FPrint( _L("CDunUpstream::RunL() (Dir=%d)" ), iDirection));
   354     FTRACE(FPrint( _L("CDunUpstream::RunL() (Dir=%d)" ), iDirection));
   389     iTransferState = EDunStateIdle;
       
   390 
   355 
   391     TBool isError;
   356     TBool isError;
   392     TInt retTemp = iStatus.Int();
   357     TInt retTemp = iStatus.Int();
   393     TInt stop = ProcessErrorCondition( retTemp, isError );
   358     TInt stop = ProcessErrorCondition( retTemp, isError );
   394 
   359 
   449 // ---------------------------------------------------------------------------
   414 // ---------------------------------------------------------------------------
   450 //
   415 //
   451 void CDunUpstream::DoCancel()
   416 void CDunUpstream::DoCancel()
   452     {
   417     {
   453     FTRACE(FPrint( _L("CDunUpstream::DoCancel()" )));
   418     FTRACE(FPrint( _L("CDunUpstream::DoCancel()" )));
       
   419     // Stop only current operation
       
   420     if ( iOperationType == EDunOperationTypeRead )
       
   421         {
       
   422         if ( iComm )
       
   423             {
       
   424             iComm->ReadCancel();
       
   425             FTRACE(FPrint( _L("CDunUpstream::DoCancel() (RComm) cancelled" )));
       
   426             }
       
   427         else if ( iSocket )
       
   428             {
       
   429             iSocket->CancelRecv();
       
   430             FTRACE(FPrint( _L("CDunUpstream::DoCancel() (RSocket) cancelled" )));
       
   431             }
       
   432         }
       
   433     else if ( iOperationType == EDunOperationTypeWrite )
       
   434         {
       
   435         if ( iNetwork )
       
   436             {
       
   437             iNetwork->WriteCancel();
       
   438             FTRACE(FPrint( _L("CDunUpstream::DoCancel() (Network) cancelled" )));
       
   439             }
       
   440         }
       
   441     else
       
   442         {
       
   443         FTRACE(FPrint( _L("CDunUpstream::DoCancel() (ERROR) complete" )));
       
   444         }
   454     FTRACE(FPrint( _L("CDunUpstream::DoCancel() complete" )));
   445     FTRACE(FPrint( _L("CDunUpstream::DoCancel() complete" )));
   455     }
   446     }
   456 
   447 
   457 // ---------------------------------------------------------------------------
   448 // ---------------------------------------------------------------------------
   458 // From class MDunAtCmdStatusReporter
   449 // From class MDunAtCmdStatusReporter
   516 // ---------------------------------------------------------------------------
   507 // ---------------------------------------------------------------------------
   517 // From class MDunAtCmdHandler
   508 // From class MDunAtCmdHandler
   518 // Stops AT command handling downstream related activity (also URC)
   509 // Stops AT command handling downstream related activity (also URC)
   519 // ---------------------------------------------------------------------------
   510 // ---------------------------------------------------------------------------
   520 //
   511 //
   521 TInt CDunUpstream::StopAtCmdHandling()
   512 void CDunUpstream::StopAtCmdHandling()
   522     {
   513     {
   523     FTRACE(FPrint( _L("CDunUpstream::StopAtCmdHandling()" )));
   514     FTRACE(FPrint( _L("CDunUpstream::StopAtCmdHandling()" )));
   524     TInt retVal = KErrNone;
       
   525     if ( iParseData.iAtCmdHandler )  // optional
   515     if ( iParseData.iAtCmdHandler )  // optional
   526         {
   516         {
   527         retVal = iParseData.iAtCmdHandler->StopUrc();
   517         iParseData.iAtCmdHandler->StopUrc();
   528         if ( retVal != KErrNone )
   518         iParseData.iAtCmdHandler->Stop();
   529             {
       
   530             iParseData.iAtCmdHandler->Stop();
       
   531             FTRACE(FPrint( _L("CDunUpstream::StopAtCmdHandling() (iAtCmdHandler) complete" )));
       
   532             return retVal;
       
   533             }
       
   534         retVal = iParseData.iAtCmdHandler->Stop();
       
   535         }
   519         }
   536     FTRACE(FPrint( _L("CDunUpstream::StopAtCmdHandling() complete" )));
   520     FTRACE(FPrint( _L("CDunUpstream::StopAtCmdHandling() complete" )));
   537     return retVal;
       
   538     }
   521     }
   539 
   522 
   540 // ---------------------------------------------------------------------------
   523 // ---------------------------------------------------------------------------
   541 // From class MDunCmdModeMonitor.
   524 // From class MDunCmdModeMonitor.
   542 // Notifies about command mode start
   525 // Notifies about command mode start