bearermanagement/S60MCPR/src/s60mcprstates.cpp
changeset 18 fcbbe021d614
parent 2 086aae6fc07e
child 23 7ec726f93df1
--- a/bearermanagement/S60MCPR/src/s60mcprstates.cpp	Tue Feb 02 00:24:11 2010 +0200
+++ b/bearermanagement/S60MCPR/src/s60mcprstates.cpp	Fri Apr 16 15:21:37 2010 +0300
@@ -54,7 +54,6 @@
               node.RequestPermissionToSendStarted() )
         {
         S60MCPRLOGSTRING2("S60MCPR<%x>::THandleMPMStatusChange::DoL() calling IAPConnectionStartedL IAP %d",(TInt*)&iContext.Node(),iapid)
-        // TODO use progress notification KLinkLayerOpen once Symbian provides them.
         node.Policy()->IAPConnectionStartedL( iapid );  // codescanner::leave
         }
     else if ( msg.iValue == TCFControlProvider::TDataClientStatusChange::EStopped &&
@@ -114,28 +113,46 @@
     RNodeInterface* stoppingSP = NULL;
     RNodeInterface* startingSP = NULL;
 
-    // The one that will be started is the one MPM selected.
-    // Both must be present in the MCPR -plane.
+    // Get the MCPR
+    CS60MetaConnectionProvider& node = (CS60MetaConnectionProvider&)iContext.Node();
+    
+    // At this point MCPR has selected two active IPProtoMCPRs.
+    // The one that will be started is the one MPM selected and
+    // the one which doesn't match the policy preferences is the
+    // old selection and needs to be disconnected.
+    //
+    TUint32 newAP = node.PolicyPrefs().IapId();
+    ASSERT( newAP > 0 );
 
     // Choose Service Providers to work on
     TClientIter<TDefaultClientMatchPolicy> iter = 
         iContext.Node().GetClientIter<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EServProvider));
-
-    RNodeInterface* itf = NULL;
-    for ( itf = iter++; ( itf != NULL && ( stoppingSP == NULL || startingSP == NULL ) ); itf = iter++ )
+    
+    RMetaServiceProviderInterface* itf = NULL;
+    //RNodeInterface* itf = NULL;
+    
+    for ( itf = (RMetaServiceProviderInterface*)iter++;
+             ( itf != NULL && ( stoppingSP == NULL || startingSP == NULL ) );
+             itf = (RMetaServiceProviderInterface*)iter++ )
         {
-        // Only one of the selected MCPRs can be EStarted.
-        //
-        if ( itf->Flags() & TCFClientType::EStarted )
+        if ( itf->Flags() & TCFClientType::EActive )
             {
-            stoppingSP = itf; //Our current started Service Provider.
-            itf->ClearFlags( TCFClientType::EActive );
-            }
-        // The other which is not EStarted must be EActive.
-        //
-        else if ( itf->Flags() & TCFClientType::EActive )
-            {
-            startingSP = itf; //And the new one to try next
+            // Select one that shall be stopped.
+            //
+            if ( itf->ProviderInfo().APId() != newAP )
+                {
+                stoppingSP = itf;
+                itf->ClearFlags( TCFClientType::EActive );
+                }
+            // Select one that shall be started
+            //
+            else if ( itf->ProviderInfo().APId() == newAP )
+                {
+                startingSP = itf;
+                itf->ClearFlags( TCFClientType::EActive );
+                }
+            // no else.
+            //
             }
         }
     // One must be started since this is already a reconnection
@@ -147,10 +164,6 @@
         User::Leave( KErrCorrupt );  // codescanner::leave
         }
 
-    //Sanity check.
-    //The new provider must not be started, there can be only one started at a time.
-    ASSERT( startingSP == NULL || ( startingSP->Flags() & TCFClientType::EStarted ) == 0 );
-
     //If there is no other Service Provider to try, return KErrNotFound
     if ( startingSP == NULL )
         {
@@ -167,7 +180,28 @@
                                                                 startingSP->RecipientId()).CRef() );
     }
 
+// -----------------------------------------------------------------------------
+// TRequestReConnectToCurrentSP::DoL
+// -----------------------------------------------------------------------------
+//
+DEFINE_SMELEMENT( TRequestReConnectToCurrentSP, NetStateMachine::MStateTransition, TContext )
+void TRequestReConnectToCurrentSP::DoL() // codescanner::leave
+    {
+    __ASSERT_DEBUG(iContext.iNodeActivity, User::Panic(KS60MCprPanic, KPanicNoActivity));
+    S60MCPRLOGSTRING1("S60MCPR<%x>::TRequestReConnectToCurrentSP::DoL()",(TInt*)&iContext.Node())
+    RNodeInterface* currentSP = iContext.Node().ServiceProvider();
 
+    // There MUST be a service provider
+    __ASSERT_DEBUG( currentSP != NULL, User::Panic(KS60MCprPanic, KPanicNoServiceProvider));
+    
+    // Diagnostic - there must be a data client or we cannot be here
+    __ASSERT_DEBUG(iContext.Node().GetFirstClient<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EData)),
+                   User::Panic(KS60MCprPanic, KPanicNoDataClient));    
+    
+    iContext.iNodeActivity->PostRequestTo( iContext.NodeId(),
+                                           TCFMcpr::TReConnect( currentSP->RecipientId(), 
+                                                                currentSP->RecipientId()).CRef() );
+    }
 // -----------------------------------------------------------------------------
 // TProcessError::DoL
 // -----------------------------------------------------------------------------