bearermanagement/S60MCPR/src/s60mcprstates.cpp
branchRCL_3
changeset 62 bb1f80fb7db2
parent 58 83ca720e2b9a
child 69 cf1b3ddbe9a1
equal deleted inserted replaced
58:83ca720e2b9a 62:bb1f80fb7db2
    19 @file s60mcprstates.cpp
    19 @file s60mcprstates.cpp
    20 S60 MCPR states implementation
    20 S60 MCPR states implementation
    21 */
    21 */
    22 
    22 
    23 #include <cdblen.h>
    23 #include <cdblen.h>
       
    24 #include <comms-infras/mobilitymcpractivities.h>
    24 
    25 
    25 #include "s60mcprstates.h"
    26 #include "s60mcprstates.h"
    26 
    27 
    27 using namespace S60MCprStates;
    28 using namespace S60MCprStates;
    28 using namespace ESock;
    29 using namespace ESock;
   388         {
   389         {
   389         return EFalse;
   390         return EFalse;
   390         }
   391         }
   391     }
   392     }
   392 
   393 
       
   394 
       
   395 // -----------------------------------------------------------------------------
       
   396 // TAwaitingStopIAPNotification::Accept
       
   397 // -----------------------------------------------------------------------------
       
   398 //
       
   399 DEFINE_SMELEMENT( TAwaitingStopIAPNotification, NetStateMachine::MState, TContext )
       
   400 TBool TAwaitingStopIAPNotification::Accept()
       
   401     {  
       
   402     TUint32 iapId( 0 );
       
   403     TCFS60MCPRMessage::TMPMStopIAPNotificationMsg* msg =
       
   404             message_cast<TCFS60MCPRMessage::TMPMStopIAPNotificationMsg>(&iContext.iMessage);
       
   405     if ( msg )
       
   406         {
       
   407         iapId = msg->iValue;
       
   408         // Only accept the notification if it matches current service provider, or if the IAP is undefined
       
   409         if ( iContext.Node().ServiceProvider() &&
       
   410              (((RMetaServiceProviderInterface*)iContext.Node().ServiceProvider())->ProviderInfo().APId() == iapId ||
       
   411              iapId == 0 ) )
       
   412             {
       
   413             return ETrue;
       
   414             }
       
   415 #ifdef _DEBUG
       
   416         else
       
   417             {
       
   418             S60MCPRLOGSTRING2("S60MCPR<%x>::TAwaitingStopIAPNotification() NO MATCH! IAP %d",(TInt*)this,iapId);
       
   419             }
       
   420 #endif        
       
   421         }    
       
   422     return EFalse;
       
   423     }
       
   424 
       
   425 // -----------------------------------------------------------------------------
       
   426 // TProcessError::DoL
       
   427 // -----------------------------------------------------------------------------
       
   428 //
       
   429 DEFINE_SMELEMENT( TSendStop, NetStateMachine::MStateTransition, TContext )
       
   430 void TSendStop::DoL() // codescanner::leave
       
   431     {
       
   432     __ASSERT_DEBUG(iContext.iNodeActivity, User::Panic(KS60MCprPanic, KPanicNoActivity));
       
   433     __ASSERT_DEBUG(iContext.Node().ServiceProvider(), User::Panic(KS60MCprPanic, KPanicNoServiceProvider));    
       
   434     
       
   435     // Send TStop to current Service Provider.
       
   436     iContext.iNodeActivity->PostRequestTo( 
       
   437             iContext.Node().ServiceProvider()->RecipientId(), 
       
   438             TCFServiceProvider::TStop( KErrDisconnected ).CRef() );
       
   439     }
       
   440 
       
   441 // -----------------------------------------------------------------------------
       
   442 // TAwaitingStoppedOrError::Accept
       
   443 // -----------------------------------------------------------------------------
       
   444 //
       
   445 DEFINE_SMELEMENT( TAwaitingStoppedOrError, NetStateMachine::MState, TContext )
       
   446 TBool TAwaitingStoppedOrError::Accept()
       
   447     {
       
   448     __ASSERT_DEBUG(iContext.iNodeActivity, User::Panic(KS60MCprPanic, KPanicNoActivity));
       
   449     
       
   450     if ( iContext.iMessage.IsMessage<TCFServiceProvider::TStopped>() )
       
   451         {
       
   452         return ETrue;
       
   453         }
       
   454     
       
   455     // Error is returned if S60MCPR leaves IPProtoMCPr before Stopped is received
       
   456     if( iContext.iMessage.IsMessage<TEBase::TError>() )
       
   457         {
       
   458         // Ignore the error code. It's better than crashing.
       
   459         // Propagating might lead to situation where self-posted message ends up to a dead node.
       
   460         return ETrue;
       
   461         }    
       
   462     
       
   463     // Rare scenario: if the stopping service provider is sending a TStateChange message, 
       
   464     // and a mobility activity is ongoing, the message must be ignored in order to keep
       
   465     // harmful connection stages such as KLinkLayerClosed from reaching the client    
       
   466     TUint32 mobilityActivities = iContext.Node().CountActivities( ECFActivityMCprMobility );
       
   467     TBool isStateChange = iContext.iMessage.IsMessage<TCFMessage::TStateChange>();
       
   468     TBool isServProvider = 
       
   469             iContext.iPeer &&
       
   470             iContext.iPeer->Type() == TCFClientType::EServProvider &&
       
   471             iContext.iPeer->Flags() & TCFClientType::EActive;
       
   472     
       
   473     S60MCPRLOGSTRING4("S60MCPR<%x>::TAwaitingStoppedOrError() M %d, SC %d, SP %d",(TInt*)this,
       
   474             mobilityActivities, isStateChange, isServProvider );
       
   475         
       
   476     if ( isStateChange && isServProvider && mobilityActivities > 0 )
       
   477         {
       
   478         // Discard the message 
       
   479         iContext.iMessage.ClearMessageId();
       
   480         }
       
   481 
       
   482     return EFalse;
       
   483     }
       
   484 
       
   485 
       
   486 
   393 // -----------------------------------------------------------------------------
   487 // -----------------------------------------------------------------------------
   394 // TRetrieveServiceId::DoL
   488 // TRetrieveServiceId::DoL
   395 // -----------------------------------------------------------------------------
   489 // -----------------------------------------------------------------------------
   396 //
   490 //
   397 DEFINE_SMELEMENT( TRetrieveServiceId, NetStateMachine::MStateTransition, TContext )
   491 DEFINE_SMELEMENT( TRetrieveServiceId, NetStateMachine::MStateTransition, TContext )