datacommsserver/esockserver/core_states/ss_corepractivities.cpp
changeset 1 21d2ab05f085
parent 0 dfb7c4ff071f
child 2 dee179edb159
equal deleted inserted replaced
0:dfb7c4ff071f 1:21d2ab05f085
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Symbian Foundation License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     7 //
     8 // Initial Contributors:
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
     9 // Nokia Corporation - initial contribution.
    10 //
    10 //
    11 // Contributors:
    11 // Contributors:
    22  @internalComponent
    22  @internalComponent
    23 */
    23 */
    24 
    24 
    25 #define SYMBIAN_NETWORKING_UPS
    25 #define SYMBIAN_NETWORKING_UPS
    26 
    26 
       
    27 #include "ss_corepractivities.h"
       
    28 
       
    29 
    27 #include <comms-infras/ss_log.h>
    30 #include <comms-infras/ss_log.h>
    28 #include "ss_internal_activities.h"
    31 #include "ss_internal_activities.h"
    29 #include "ss_coreprstates.h"
    32 #include <comms-infras/ss_coreprstates.h>
    30 #include "ss_corepractivities.h"
       
    31 #include <comms-infras/ss_subconnprov.h>
    33 #include <comms-infras/ss_subconnprov.h>
    32 #include "ss_mcprnodemessages.h"
    34 #include <comms-infras/ss_mcprnodemessages.h>
    33 
    35 
    34 #include <comms-infras/ss_protocolparameterset.h>
    36 #include <comms-infras/ss_protocolparameterset.h>
    35 #include <ss_glob.h>
    37 #include <ss_glob.h>
    36 
    38 
    37 
    39 
    38 #include <elements/nm_messages_child.h>
    40 #include <elements/nm_messages_child.h>
    39 #include <elements/nm_messages_peer.h>
    41 #include <elements/nm_messages_peer.h>
    40 #include <elements/nm_messages_errorrecovery.h>
    42 #include <elements/nm_messages_errorrecovery.h>
    41 #include "ss_nodemessages_dataclient.h"
    43 #include "ss_nodemessages_dataclient.h"
    42 #include "ss_nodemessages_serviceprovider.h"
    44 #include "ss_nodemessages_serviceprovider.h"
    43 #include "ss_nodemessages_rejoiningprovider.h"
    45 #include <comms-infras/ss_nodemessages_rejoiningprovider.h>
    44 #include "ss_nodemessages_flow.h"
    46 #include <comms-infras/ss_nodemessages_flow.h>
    45 #include "ss_nodemessages_factory.h"
    47 #include "ss_nodemessages_factory.h"
    46 #include "ss_nodemessages_internal_esock.h"
    48 #include <comms-infras/ss_nodemessages_internal_esock.h>
    47 
    49 
    48 
    50 
    49 #ifdef _DEBUG
    51 #ifdef _DEBUG
    50 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
    52 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
    51 // (if it could happen through user error then you should give it an explicit, documented, category + code)
    53 // (if it could happen through user error then you should give it an explicit, documented, category + code)
    67 using namespace CorePanics;
    69 using namespace CorePanics;
    68 using namespace Elements;
    70 using namespace Elements;
    69 using namespace Messages;
    71 using namespace Messages;
    70 using namespace MeshMachine;
    72 using namespace MeshMachine;
    71 using namespace Factories;
    73 using namespace Factories;
       
    74 
    72 
    75 
    73 #ifdef _DEBUG
    76 #ifdef _DEBUG
    74 _LIT (KCorePrPanic,"CorePrPanic");
    77 _LIT (KCorePrPanic,"CorePrPanic");
    75 #endif
    78 #endif
    76 
    79 
   649 
   652 
   650 	//Delete the provider.
   653 	//Delete the provider.
   651 	static_cast<ESock::CMMCommsProviderBase&>(iNode).DeleteMeNow();
   654 	static_cast<ESock::CMMCommsProviderBase&>(iNode).DeleteMeNow();
   652 	}
   655 	}
   653 
   656 
       
   657 TBool CDestroyActivity::Next(TNodeContextBase& aContext)
       
   658     {
       
   659     if (aContext.iMessage.IsMessage<TEBase::TCancel>())
       
   660         {  
       
   661         return ETrue;
       
   662         }
       
   663     else
       
   664         return CNodeActivityBase::Next(aContext);
       
   665     }
       
   666 
   654 EXPORT_DEFINE_SMELEMENT(CDestroyActivity::TNoTagOrNoTagBackwards, NetStateMachine::MStateFork, PRStates::TContext)
   667 EXPORT_DEFINE_SMELEMENT(CDestroyActivity::TNoTagOrNoTagBackwards, NetStateMachine::MStateFork, PRStates::TContext)
   655 EXPORT_C TInt CDestroyActivity::TNoTagOrNoTagBackwards::TransitionTag()
   668 EXPORT_C TInt CDestroyActivity::TNoTagOrNoTagBackwards::TransitionTag()
   656     {
   669     {
   657 	if (iContext.iMessage.IsMessage<TEChild::TLeft>())
   670 	if (iContext.iMessage.IsMessage<TEChild::TLeft>())
   658 		{
   671 		{
   838 	ACTIVITY_MAP_ENTRY(PRDataClientJoinActivity, PRDataClientJoin)
   851 	ACTIVITY_MAP_ENTRY(PRDataClientJoinActivity, PRDataClientJoin)
   839 	ACTIVITY_MAP_ENTRY(PRControlClientJoinActivity, PRControlClientJoin)
   852 	ACTIVITY_MAP_ENTRY(PRControlClientJoinActivity, PRControlClientJoin)
   840 	ACTIVITY_MAP_ENTRY(PRClientLeaveActivity, PRClientLeave)
   853 	ACTIVITY_MAP_ENTRY(PRClientLeaveActivity, PRClientLeave)
   841 	ACTIVITY_MAP_ENTRY(PRForwardStateChangeActivity, PRForwardStateChange)
   854 	ACTIVITY_MAP_ENTRY(PRForwardStateChangeActivity, PRForwardStateChange)
   842 	ACTIVITY_MAP_ENTRY(PRBindToActivity, PRBindTo)
   855 	ACTIVITY_MAP_ENTRY(PRBindToActivity, PRBindTo)
   843 	ACTIVITY_MAP_ENTRY(PRDataClientStartActivity, PRDataClientStart)
       
   844 	ACTIVITY_MAP_ENTRY(PRDataClientStopActivity, PRDataClientStop)
       
   845 ACTIVITY_MAP_END_BASE(CoreActivities,coreActivitiesAll)
   856 ACTIVITY_MAP_END_BASE(CoreActivities,coreActivitiesAll)
   846 
   857 
   847 //Activity Map provided by CorePr to be used by SCprs.
   858 //Activity Map provided by CorePr to be used by SCprs.
   848 //(it is further extended in CoreSCpr).
   859 //(it is further extended in CoreSCpr).
   849 DEFINE_EXPORT_ACTIVITY_MAP(coreActivitiesSCpr)
   860 DEFINE_EXPORT_ACTIVITY_MAP(coreActivitiesSCpr)
   850 	ACTIVITY_MAP_ENTRY(PRProvisionActivity, PrProvision)
   861 	ACTIVITY_MAP_ENTRY(PRProvisionActivity, PrProvision)
   851     ACTIVITY_MAP_ENTRY(PRStartActivity, PRStart)
   862     ACTIVITY_MAP_ENTRY(PRStartActivity, PRStart)
   852     ACTIVITY_MAP_ENTRY(PRStopActivity, PRStop)
   863     ACTIVITY_MAP_ENTRY(PRStopActivity, PRStop)
       
   864 	ACTIVITY_MAP_ENTRY(PRDataClientStartActivity, PRDataClientStart)
       
   865 	ACTIVITY_MAP_ENTRY(PRDataClientStopActivity, PRDataClientStop)
   853 	ACTIVITY_MAP_ENTRY(PRDataClientIdleActivity, PRDataClientIdle)
   866 	ACTIVITY_MAP_ENTRY(PRDataClientIdleActivity, PRDataClientIdle)
   854 	ACTIVITY_MAP_ENTRY(PRDataClientActiveActivity, PRDataClientActive)
   867 	ACTIVITY_MAP_ENTRY(PRDataClientActiveActivity, PRDataClientActive)
   855 	ACTIVITY_MAP_ENTRY(PRDestroyActivity, PRDestroy)
   868 	ACTIVITY_MAP_ENTRY(PRDestroyActivity, PRDestroy)
   856 	ACTIVITY_MAP_ENTRY(PRGoneDownActivity, PRGoneDown)
   869 	ACTIVITY_MAP_ENTRY(PRGoneDownActivity, PRGoneDown)
   857 	ACTIVITY_MAP_ENTRY(PRGoneUpActivity, PRGoneUp) //robertomaro
   870 	ACTIVITY_MAP_ENTRY(PRGoneUpActivity, PRGoneUp) //robertomaro
   866 //(it is further extended in CoreCpr).
   879 //(it is further extended in CoreCpr).
   867 DEFINE_EXPORT_ACTIVITY_MAP(coreActivitiesCpr)
   880 DEFINE_EXPORT_ACTIVITY_MAP(coreActivitiesCpr)
   868 	ACTIVITY_MAP_ENTRY(PRProvisionActivity, PrProvision)
   881 	ACTIVITY_MAP_ENTRY(PRProvisionActivity, PrProvision)
   869     ACTIVITY_MAP_ENTRY(PRStartActivity, PRStart)
   882     ACTIVITY_MAP_ENTRY(PRStartActivity, PRStart)
   870     ACTIVITY_MAP_ENTRY(PRStopActivity, PRStop)
   883     ACTIVITY_MAP_ENTRY(PRStopActivity, PRStop)
       
   884 	ACTIVITY_MAP_ENTRY(PRDataClientStartActivity, PRDataClientStart)
       
   885 	ACTIVITY_MAP_ENTRY(PRDataClientStopActivity, PRDataClientStop)
   871 	ACTIVITY_MAP_ENTRY(PRDataClientIdleActivity, PRDataClientIdle)
   886 	ACTIVITY_MAP_ENTRY(PRDataClientIdleActivity, PRDataClientIdle)
   872 	ACTIVITY_MAP_ENTRY(PRDataClientActiveActivity, PRDataClientActive)
   887 	ACTIVITY_MAP_ENTRY(PRDataClientActiveActivity, PRDataClientActive)
   873 	ACTIVITY_MAP_ENTRY(PRDestroyActivity, PRDestroy)
   888 	ACTIVITY_MAP_ENTRY(PRDestroyActivity, PRDestroy)
   874 	ACTIVITY_MAP_ENTRY(PRGoneDownActivity, PRGoneDown)
   889 	ACTIVITY_MAP_ENTRY(PRGoneDownActivity, PRGoneDown)
   875 	ACTIVITY_MAP_ENTRY(PRGoneUpActivity, PRGoneUp) //robertomaro
   890 	ACTIVITY_MAP_ENTRY(PRGoneUpActivity, PRGoneUp) //robertomaro
   980 	__ASSERT_DEBUG(iContext.iNodeActivity, User::Panic(KCorePrPanic, KPanicNoActivity));
   995 	__ASSERT_DEBUG(iContext.iNodeActivity, User::Panic(KCorePrPanic, KPanicNoActivity));
   981     CBindToActivity& activity = static_cast<CBindToActivity&>(*iContext.iNodeActivity);
   996     CBindToActivity& activity = static_cast<CBindToActivity&>(*iContext.iNodeActivity);
   982 	const TCFDataClient::TBindTo& bindToMsg(message_cast<const TCFDataClient::TBindTo>(iContext.iMessage));
   997 	const TCFDataClient::TBindTo& bindToMsg(message_cast<const TCFDataClient::TBindTo>(iContext.iMessage));
   983 
   998 
   984 	__ASSERT_DEBUG(!bindToMsg.iNodeId.IsNull(), User::Panic(KCorePrPanic, KPanicNoServiceProvider));
   999 	__ASSERT_DEBUG(!bindToMsg.iNodeId.IsNull(), User::Panic(KCorePrPanic, KPanicNoServiceProvider));
   985 	activity.iNewServiceProvider = iContext.Node().AddClientL(bindToMsg.iNodeId,
  1000     RNodeInterface* newServiceProvider = iContext.Node().AddClientL(bindToMsg.iNodeId,
   986 							TClientType(TCFClientType::EServProvider, TCFClientType::EActivating));
  1001                             TClientType(TCFClientType::EServProvider, TCFClientType::EActivating));
   987 	//Join the new service provider
  1002     __ASSERT_DEBUG(newServiceProvider, User::Panic(KCorePrPanic, KPanicNoServiceProvider));
   988 	iContext.iNodeActivity->PostRequestTo(*activity.iNewServiceProvider,
  1003     activity.iNewServiceProvider = bindToMsg.iNodeId;
   989 							TCFControlClient::TJoinRequest(iContext.NodeId(), TClientType(TCFClientType::ECtrl)).CRef());
  1004     //Join the new service provider
       
  1005     iContext.Activity()->PostRequestTo(*newServiceProvider,
       
  1006                             TCFControlClient::TJoinRequest(iContext.NodeId(), TClientType(TCFClientType::ECtrl)).CRef());
   990     }
  1007     }
   991 
  1008 
   992 EXPORT_DEFINE_SMELEMENT(CBindToActivity::TAwaitingBindToCompleteOrError, NetStateMachine::MState, CRejoinDataClientActivity::TContext)
  1009 EXPORT_DEFINE_SMELEMENT(CBindToActivity::TAwaitingBindToCompleteOrError, NetStateMachine::MState, CRejoinDataClientActivity::TContext)
   993 TBool CBindToActivity::TAwaitingBindToCompleteOrError::Accept()
  1010 TBool CBindToActivity::TAwaitingBindToCompleteOrError::Accept()
   994     {
  1011     {
  1035 	__ASSERT_DEBUG(iContext.Node().CountClients<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EData)),User::Panic(KCorePrPanic, KPanicDataClient));
  1052 	__ASSERT_DEBUG(iContext.Node().CountClients<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EData)),User::Panic(KCorePrPanic, KPanicDataClient));
  1036 	__ASSERT_DEBUG(iContext.iNodeActivity, User::Panic(KCorePrPanic, KPanicNoActivity));
  1053 	__ASSERT_DEBUG(iContext.iNodeActivity, User::Panic(KCorePrPanic, KPanicNoActivity));
  1037   	CBindToActivity& activity = static_cast<CBindToActivity&>(*iContext.iNodeActivity);
  1054   	CBindToActivity& activity = static_cast<CBindToActivity&>(*iContext.iNodeActivity);
  1038 
  1055 
  1039   	//The service provider has been joined already and must be found here
  1056   	//The service provider has been joined already and must be found here
  1040   	__ASSERT_DEBUG(activity.iNewServiceProvider , User::Panic(KCorePrPanic, KPanicNoServiceProvider));
  1057     __ASSERT_DEBUG(!activity.iNewServiceProvider.IsNull(), User::Panic(KCorePrPanic, KPanicNoServiceProvider));
  1041 
  1058     RNodeInterface* newServiceProvider = iContext.Node().FindClient(activity.iNewServiceProvider);
       
  1059     __ASSERT_DEBUG(newServiceProvider, User::Panic(KCorePrPanic, KPanicNoServiceProvider));
  1042     //We must not be in this transition if dc was not found
  1060     //We must not be in this transition if dc was not found
  1043     __ASSERT_DEBUG(activity.CurrentDataClient(), User::Panic(KCorePrPanic, KPanicDataClient));
  1061     __ASSERT_DEBUG(activity.CurrentDataClient(), User::Panic(KCorePrPanic, KPanicDataClient));
  1044 
  1062 
  1045     // Also if it is not so common to have multiple DataClient (except
  1063     // Also if it is not so common to have multiple DataClient (except
  1046     // 	for the relation "SCPR<-CPR"), there are situation where it happens
  1064     // 	for the relation "SCPR<-CPR"), there are situation where it happens
  1069     	}
  1087     	}
  1070     // --- WORKAROUND END ---
  1088     // --- WORKAROUND END ---
  1071 
  1089 
  1072     // Send "TCommsBinderRequest" to the Current ServiceProvider
  1090     // Send "TCommsBinderRequest" to the Current ServiceProvider
  1073    	activity.PostRequestTo(
  1091    	activity.PostRequestTo(
  1074    			*activity.iNewServiceProvider,
  1092    			*newServiceProvider,
  1075    			TCFServiceProvider::TCommsBinderRequest(subConnOpenType).CRef()
  1093    			TCFServiceProvider::TCommsBinderRequest(subConnOpenType).CRef()
  1076    			);
  1094    			);
  1077     }
  1095     }
  1078 
  1096 
  1079 
  1097 
  1150     	//received a null service provider, the node is at the stack's bottom.
  1168     	//received a null service provider, the node is at the stack's bottom.
  1151         {
  1169         {
  1152         return KBearerReady;
  1170         return KBearerReady;
  1153         }
  1171         }
  1154 
  1172 
  1155 	if (iContext.Node().ServiceProvider()
  1173     RNodeInterface* sp = iContext.Node().ServiceProvider();
  1156 		&& bindToReq.iNodeId == iContext.Node().ServiceProvider()->RecipientId())
  1174     if (sp && bindToReq.iNodeId == sp->RecipientId())
  1157 		{
  1175         {
  1158 		//received the same service provider, it's already bound to.
  1176         //received the same service provider, it's already bound to.
  1159 		bindToActivity.iNewServiceProvider = iContext.Node().ServiceProvider();
  1177         bindToActivity.iNewServiceProvider = sp->RecipientId();
  1160 		return KBearerReady;
  1178 		return KBearerReady;
  1161 		}
  1179 		}
  1162 	bindToActivity.iNewServiceProvider = iContext.Node().FindClient(bindToReq.iNodeId);
  1180     RNodeInterface* newServiceProvider = iContext.Node().FindClient(bindToReq.iNodeId);
  1163 	if (bindToActivity.iNewServiceProvider)
  1181 	if (newServiceProvider)
  1164 		{
  1182 		{
  1165 		__ASSERT_DEBUG(bindToActivity.iNewServiceProvider->Type() == TCFClientType::EServProvider, User::Panic(KCorePrPanic, KPanicIncorrectState));
  1183 		__ASSERT_DEBUG(newServiceProvider->Type() == TCFClientType::EServProvider, User::Panic(KCorePrPanic, KPanicIncorrectState));
  1166 		//Ok, we've received a TBindTo holding a service provider that we already know of and that is not
  1184 		//Ok, we've received a TBindTo holding a service provider that we already know of and that is not
  1167 		//our current service provider. We're going to assume this node tolerates multiple service providers (like MCPRs do).
  1185 		//our current service provider. We're going to assume this node tolerates multiple service providers (like MCPRs do).
  1168 		//the current service provider will be swapped, but won't be dropped.
  1186 		//the current service provider will be swapped, but won't be dropped.
  1169 		bindToActivity.iNewServiceProvider->SetFlags(TCFClientType::EActivating);
  1187 		bindToActivity.iNewServiceProvider = bindToReq.iNodeId;
       
  1188 		newServiceProvider->SetFlags(TCFClientType::EActivating);
  1170 		bindToActivity.SetDontLeaveServiceProvider();
  1189 		bindToActivity.SetDontLeaveServiceProvider();
  1171 		return KBearerReady;
  1190 		return KBearerReady;
  1172 		}
  1191 		}
       
  1192 	else
       
  1193 	    {
       
  1194         bindToActivity.iNewServiceProvider = TNodeId::NullId();
       
  1195 	    }
  1173 	//The node received a new service provider...
  1196 	//The node received a new service provider...
  1174 	return KNoTag;
  1197 	return KNoTag;
  1175     }
  1198     }
  1176 
  1199 
  1177 
  1200 
  1185     	{
  1208     	{
  1186     	//No more dataclients to bind
  1209     	//No more dataclients to bind
  1187     	return KBindToComplete;
  1210     	return KBindToComplete;
  1188     	}
  1211     	}
  1189 
  1212 
  1190     if (!bindToActivity.iNewServiceProvider)
  1213     if (bindToActivity.iNewServiceProvider.IsNull())
  1191     	{
  1214     	{
  1192     	//There is no service provider (new or old) below us.
  1215     	//There is no service provider (new or old) below us.
  1193     	return KBearerReady;
  1216     	return KBearerReady;
  1194     	}
  1217     	}
  1195 
  1218 
  1207     	{
  1230     	{
  1208     	bindToActivity.PostRequestTo(*bindToActivity.iSuccessfulDataClients[--count], TCFDataClient::TCommitBindTo().CRef());
  1231     	bindToActivity.PostRequestTo(*bindToActivity.iSuccessfulDataClients[--count], TCFDataClient::TCommitBindTo().CRef());
  1209         };
  1232         };
  1210     bindToActivity.iSuccessfulDataClients.Reset();
  1233     bindToActivity.iSuccessfulDataClients.Reset();
  1211     RNodeInterface* sp = iContext.Node().ServiceProvider();
  1234     RNodeInterface* sp = iContext.Node().ServiceProvider();
  1212     if (sp && sp != bindToActivity.iNewServiceProvider)
  1235 
       
  1236     if (sp && sp->RecipientId() != bindToActivity.iNewServiceProvider)
  1213     	{
  1237     	{
  1214     	if (bindToActivity.ShouldLeaveServiceProvider())
  1238     	if (bindToActivity.ShouldLeaveServiceProvider())
  1215     		{
  1239     		{
  1216 	    	bindToActivity.PostRequestTo(*sp, TEPeer::TLeaveRequest().CRef());
  1240 	    	bindToActivity.PostRequestTo(*sp, TEPeer::TLeaveRequest().CRef());
  1217 	    	sp->SetFlags(TCFClientType::ELeaving);
  1241 	    	sp->SetFlags(TCFClientType::ELeaving);
  1227     	{
  1251     	{
  1228     	//Didn't leave, no need for waiting for TLeaveComplete;
  1252     	//Didn't leave, no need for waiting for TLeaveComplete;
  1229     	bindToActivity.SetIdle();
  1253     	bindToActivity.SetIdle();
  1230     	}
  1254     	}
  1231 
  1255 
  1232     if (bindToActivity.iNewServiceProvider && sp != bindToActivity.iNewServiceProvider)
  1256     if (!bindToActivity.iNewServiceProvider.IsNull() && (sp == NULL || sp->RecipientId() != bindToActivity.iNewServiceProvider))
  1233     	{
  1257         {
  1234     	__ASSERT_DEBUG(bindToActivity.iNewServiceProvider->Flags() & TCFClientType::EActivating, User::Panic(KCorePrPanic, KPanicIncorrectState));
  1258         RNodeInterface* newServiceProvider = iContext.Node().FindClient(bindToActivity.iNewServiceProvider);
  1235     	bindToActivity.iNewServiceProvider->ClearFlags(TCFClientType::EActivating);
  1259         if (newServiceProvider)
  1236     	bindToActivity.iNewServiceProvider->SetFlags(TCFClientType::EActive);
  1260             {
  1237     	__ASSERT_DEBUG(iContext.Node().ServiceProvider() == bindToActivity.iNewServiceProvider, User::Panic(KCorePrPanic, KPanicIncorrectState));
  1261             __ASSERT_DEBUG(newServiceProvider->Flags() & TCFClientType::EActivating, User::Panic(KCorePrPanic, KPanicIncorrectState));
  1238     	}
  1262             newServiceProvider->ClearFlags(TCFClientType::EActivating);
  1239 	bindToActivity.iNewServiceProvider = NULL;
  1263             newServiceProvider->SetFlags(TCFClientType::EActive);
       
  1264             // Note: iContext.Node().ServiceProvider() must be re-evaluated in the ASSERT below (i.e. don't use any previously cached value).
       
  1265             __ASSERT_DEBUG(iContext.Node().ServiceProvider() == newServiceProvider, User::Panic(KCorePrPanic, KPanicIncorrectState));
       
  1266             }
       
  1267         }
       
  1268     bindToActivity.iNewServiceProvider = TNodeId::NullId();
  1240     }
  1269     }
  1241 
  1270 
  1242 EXPORT_DEFINE_SMELEMENT(CBindToActivity::TCancel, NetStateMachine::MStateTransition, CBindToActivity::TContext)
  1271 EXPORT_DEFINE_SMELEMENT(CBindToActivity::TCancel, NetStateMachine::MStateTransition, CBindToActivity::TContext)
  1243 void CBindToActivity::TCancel::DoL()
  1272 void CBindToActivity::TCancel::DoL()
  1244     {
  1273     {
  1249     	{
  1278     	{
  1250     	bindToActivity.PostRequestTo(*bindToActivity.iSuccessfulDataClients[--count], TEBase::TCancel().CRef());
  1279     	bindToActivity.PostRequestTo(*bindToActivity.iSuccessfulDataClients[--count], TEBase::TCancel().CRef());
  1251         };
  1280         };
  1252     bindToActivity.iSuccessfulDataClients.Reset();
  1281     bindToActivity.iSuccessfulDataClients.Reset();
  1253 
  1282 
  1254     if (bindToActivity.iNewServiceProvider && bindToActivity.iNewServiceProvider != iContext.Node().ServiceProvider())
  1283 	TBool setIdle = ETrue;
  1255     	{
  1284     if (!bindToActivity.iNewServiceProvider.IsNull())
  1256     	__ASSERT_DEBUG(bindToActivity.iNewServiceProvider->Flags() & TCFClientType::EActivating, User::Panic(KCorePrPanic, KPanicIncorrectState));
  1285         {
  1257     	bindToActivity.iNewServiceProvider->ClearFlags(TCFClientType::EActivating);
  1286         RNodeInterface* newServiceProvider = iContext.Node().FindClient(bindToActivity.iNewServiceProvider);
  1258     	if (bindToActivity.ShouldLeaveServiceProvider())
  1287         if (newServiceProvider && newServiceProvider != iContext.Node().ServiceProvider())
  1259     		{
  1288             {
  1260 	    	bindToActivity.PostRequestTo(*bindToActivity.iNewServiceProvider, TEPeer::TLeaveRequest().CRef());
  1289             __ASSERT_DEBUG(newServiceProvider->Flags() & TCFClientType::EActivating, User::Panic(KCorePrPanic, KPanicIncorrectState));
  1261 	    	bindToActivity.iNewServiceProvider->SetFlags(TCFClientType::ELeaving);
  1290             newServiceProvider->ClearFlags(TCFClientType::EActivating);
  1262     		}
  1291             if (bindToActivity.ShouldLeaveServiceProvider())
  1263         else
  1292                 {
  1264         	{
  1293                 bindToActivity.PostRequestTo(*newServiceProvider, TEPeer::TLeaveRequest().CRef());
  1265         	bindToActivity.SetIdle();
  1294                 newServiceProvider->SetFlags(TCFClientType::ELeaving);
  1266         	}
  1295                 setIdle = EFalse;
  1267     	}
  1296                 }
  1268     else
  1297             }
  1269     	{
  1298         }
  1270     	bindToActivity.SetIdle();
  1299 
  1271     	}
  1300     if (setIdle)
  1272 	bindToActivity.iNewServiceProvider = NULL;
  1301         {
       
  1302         bindToActivity.SetIdle();
       
  1303         }
       
  1304     bindToActivity.iNewServiceProvider = TNodeId::NullId();
  1273     }
  1305     }
  1274 
  1306 
  1275 
  1307 
  1276 //-=========================================================
  1308 //-=========================================================
  1277 //
  1309 //