datacommsserver/esockserver/core_states/ss_corepractivities.cpp
branchRCL_3
changeset 12 8b5d60ce1e94
parent 4 928ed51ddc43
child 13 0b0e9fce0b58
equal deleted inserted replaced
11:98a7181d2ce7 12:8b5d60ce1e94
   106 	FIRST_NODEACTIVITY_ENTRY(CoreNetStates::TAwaitingDataClientJoinRequest, MeshMachine::TNoTag)
   106 	FIRST_NODEACTIVITY_ENTRY(CoreNetStates::TAwaitingDataClientJoinRequest, MeshMachine::TNoTag)
   107 	LAST_NODEACTIVITY_ENTRY(KNoTag, CoreNetStates::TAddDataClientAndRespond)
   107 	LAST_NODEACTIVITY_ENTRY(KNoTag, CoreNetStates::TAddDataClientAndRespond)
   108 NODEACTIVITY_END()
   108 NODEACTIVITY_END()
   109 }
   109 }
   110 
   110 
       
   111 
       
   112 namespace PRDestroyOrphansActivity
       
   113 {
       
   114 DECLARE_DEFINE_CUSTOM_NODEACTIVITY(ECFActivityDestroyOrphans, PRDestroyOrphans, TCFMessage::TDestroyOrphans, CoreActivities::CDestroyOrphansActivity::New)
       
   115     // Destroy non-Default Data clients first (as there can be references from non-Default Data clients to the Default Data client)
       
   116     FIRST_NODEACTIVITY_ENTRY(MeshMachine::TAwaitingMessageState<TCFMessage::TDestroyOrphans>, PRStates::TOrphansOrNoTag)
       
   117     NODEACTIVITY_ENTRY(KOrphans, PRStates::TDestroyFirstOrphan, MeshMachine::TAwaitingMessageState<Messages::TEChild::TLeft>, MeshMachine::TTag<KContinue>)
       
   118     THROUGH_NODEACTIVITY_ENTRY(KContinue, PRStates::TProcessClientLeft, PRStates::TOrphansBackwardsOrNoTag)
       
   119     ROUTING_NODEACTIVITY_ENTRY(KNoTag, CDestroyOrphansActivity::TNoTagOrNoClients)
       
   120     LAST_NODEACTIVITY_ENTRY(KNoTag, MeshMachine::TDoNothing)
       
   121 
       
   122     // At this point, there are no Data or Control clients, so leave the Service Providers (if any) and destroy the node.
       
   123     // (Can we just modify the above tuples so that they do not accept the very last TLeft, and thus leave it
       
   124     // to MCPrDestroyActivity or PRClientLeftActivity to accept and do the destruction for us?).
       
   125     
       
   126     // If Control Provider is present, send a TIdle message.
       
   127     THROUGH_NODEACTIVITY_ENTRY(KNoClients, CoreNetStates::TSendDataClientIdle, TNoTag)
       
   128     // If Control Provider is present, terminate the activity (KNoTag), as
       
   129     // Control Provider will send us a TDestroy in response to the TIdle message. 
       
   130     ROUTING_NODEACTIVITY_ENTRY(KNoTag, CDestroyOrphansActivity::TControlProviderNoTagOrNoClients)
       
   131     LAST_NODEACTIVITY_ENTRY(KNoTag, MeshMachine::TDoNothing)
       
   132 
       
   133     // No Control Provider - leave Service Providers (if any) and destroy the node.
       
   134     ROUTING_NODEACTIVITY_ENTRY(KNoClients, CoreNetStates::TNoTagOrNoBearer)
       
   135     THROUGH_NODEACTIVITY_ENTRY(KNoTag, CoreNetStates::TSendClientLeavingRequestToServiceProviders, TNoTag)
       
   136     NODEACTIVITY_ENTRY(KNoTag, MeshMachine::TDoNothing, MeshMachine::TAwaitingLeaveComplete, CDestroyOrphansActivity::TNoTagOrNoTagBackwards)
       
   137 
       
   138     ROUTING_NODEACTIVITY_ENTRY(KNoBearer, TNoTag)
       
   139     LAST_NODEACTIVITY_ENTRY(KNoTag, CDestroyOrphansActivity::TMarkNodeForDestruction)
       
   140     // Node will be destroyed in CDestroyOrphansActivity::Destroy() 
       
   141 NODEACTIVITY_END()
       
   142 }
       
   143 
   111 namespace PRClientLeaveActivity
   144 namespace PRClientLeaveActivity
   112 {//This activity will wait for ECFActivityBinderRequest to complete
   145 {//This activity will wait for ECFActivityBinderRequest to complete
   113 DEFINE_EXPORT_NODEACTIVITY(ECFActivityClientLeave, PRClientLeave, TNodeSignal::TNullMessageId) //May be waiting for both messages
   146 DEFINE_EXPORT_NODEACTIVITY(ECFActivityClientLeave, PRClientLeave, Messages::TEPeer::TLeaveRequest) 
   114 NODEACTIVITY_ENTRY(KNoTag, PRStates::TProcessClientLeave, CoreStates::TAwaitingClientLeave, MeshMachine::TNoTag)
   147     NODEACTIVITY_ENTRY(KNoTag, PRStates::TProcessClientLeave, MeshMachine::TAwaitingMessageState<TEPeer::TLeaveRequest>, MeshMachine::TNoTag)
       
   148 NODEACTIVITY_END()
       
   149 }
       
   150 
       
   151 namespace PRClientLeftActivity
       
   152 {
       
   153 //This activity waits for TLeft which is a response to destroy, shouldn't really be needed
       
   154 DEFINE_EXPORT_NODEACTIVITY(ECFActivityClientLeft, PRClientLeft, Messages::TEChild::TLeft)
       
   155     NODEACTIVITY_ENTRY(KNoTag, PRStates::TProcessClientLeft, MeshMachine::TAwaitingMessageState<Messages::TEChild::TLeft>, MeshMachine::TNoTag)
   115 NODEACTIVITY_END()
   156 NODEACTIVITY_END()
   116 }
   157 }
   117 
   158 
   118 namespace PRDataClientIdleActivity
   159 namespace PRDataClientIdleActivity
   119 {
   160 {
   133 {
   174 {
   134 //The generic Destroy activity. Carries out the node's goodbye handshake.
   175 //The generic Destroy activity. Carries out the node's goodbye handshake.
   135 DECLARE_DEFINE_CUSTOM_NODEACTIVITY(ECFActivityDestroy, PRDestroy, TEChild::TDestroy, CoreActivities::CDestroyActivity::New)
   176 DECLARE_DEFINE_CUSTOM_NODEACTIVITY(ECFActivityDestroy, PRDestroy, TEChild::TDestroy, CoreActivities::CDestroyActivity::New)
   136 	FIRST_NODEACTIVITY_ENTRY(MeshMachine::TAwaitingDestroy, CoreActivities::CDestroyActivity::TNoTagBlockedByActivitiesOrLeavingDataClient)
   177 	FIRST_NODEACTIVITY_ENTRY(MeshMachine::TAwaitingDestroy, CoreActivities::CDestroyActivity::TNoTagBlockedByActivitiesOrLeavingDataClient)
   137 
   178 
   138     //Stop self first
   179     ROUTING_NODEACTIVITY_ENTRY(KNoTag, PRStates::TNonLeavingNoTagOrNoClients)
   139     NODEACTIVITY_ENTRY(KNoTag, CoreNetStates::TStopSelf, CoreNetStates::TAwaitingDataClientStopped, CoreStates::TNoTagOrNoClients)
   180     NODEACTIVITY_ENTRY(KNoTag, PRStates::TDestroyFirstClient, MeshMachine::TAwaitingMessageState<Messages::TEChild::TLeft>, MeshMachine::TTag<KContinue>)
   140 
   181     THROUGH_NODEACTIVITY_ENTRY(KContinue, PRStates::TProcessClientLeft, PRStates::TNoTagBackwardsOrNoClients)
   141     //The node mustn't go out of scope with clients present. The node must get rid of them first.
       
   142 	NODEACTIVITY_ENTRY(KNoTag, CoreActivities::CDestroyActivity::TMakeClientsLeaveOrProcessClientLeave, CoreStates::TAwaitingClientLeave,  CDestroyActivity::TNoTagOrNoTagBackwards)
       
   143 	THROUGH_NODEACTIVITY_ENTRY(KNoTag, CoreActivities::CDestroyActivity::TProcessClientLeave, TTag<KNoClients>)
       
   144 
   182 
   145  	THROUGH_NODEACTIVITY_ENTRY(KNoClients, PRStates::TProcessDestroy, MeshMachine::TNoTag)
   183  	THROUGH_NODEACTIVITY_ENTRY(KNoClients, PRStates::TProcessDestroy, MeshMachine::TNoTag)
   146  	NODEACTIVITY_ENTRY(KNoTag, MeshMachine::TDoNothing, MeshMachine::TAwaitingLeaveComplete, CoreActivities::CDestroyActivity::TNoTagOrNoTagBackwards)
   184  	NODEACTIVITY_ENTRY(KNoTag, MeshMachine::TDoNothing, MeshMachine::TAwaitingLeaveComplete, CoreActivities::CDestroyActivity::TNoTagOrNoTagBackwards)
   147  	LAST_NODEACTIVITY_ENTRY(KNoTag, CoreNetStates::TSendClientLeavingAndRemoveControlProvider)
   185  	LAST_NODEACTIVITY_ENTRY(KNoTag, CoreNetStates::TSendClientLeavingAndRemoveControlProvider)
   148 NODEACTIVITY_END()
   186 NODEACTIVITY_END()
   294 
   332 
   295 	NODEACTIVITY_ENTRY(CoreNetStates::KDataClientsToStop, CoreNetStates::TStopDataClients, CoreNetStates::TAwaitingDataClientsStopped, MeshMachine::TNoTag)
   333 	NODEACTIVITY_ENTRY(CoreNetStates::KDataClientsToStop, CoreNetStates::TStopDataClients, CoreNetStates::TAwaitingDataClientsStopped, MeshMachine::TNoTag)
   296 	THROUGH_NODEACTIVITY_ENTRY(KNoTag, MeshMachine::TDoNothing, CoreNetStates::TNoTagOrUnbindOnStop)
   334 	THROUGH_NODEACTIVITY_ENTRY(KNoTag, MeshMachine::TDoNothing, CoreNetStates::TNoTagOrUnbindOnStop)
   297 
   335 
   298 	NODEACTIVITY_ENTRY(CoreNetStates::KUnbind, CoreNetStates::TSendClientLeavingRequestToServiceProvider, MeshMachine::TAwaitingLeaveComplete, MeshMachine::TNoTag)
   336 	NODEACTIVITY_ENTRY(CoreNetStates::KUnbind, CoreNetStates::TSendClientLeavingRequestToServiceProvider, MeshMachine::TAwaitingLeaveComplete, MeshMachine::TNoTag)
       
   337 	// Note that if CMMCommsProviderBase::DestroyOrphanedDataClients() finds this activity running, it
       
   338 	// will do nothing and assume that destruction of orphans will be initiated below.
   299 	THROUGH_NODEACTIVITY_ENTRY(KNoTag, PRStates::TDestroyOrphanedDataClients, MeshMachine::TNoTag)
   339 	THROUGH_NODEACTIVITY_ENTRY(KNoTag, PRStates::TDestroyOrphanedDataClients, MeshMachine::TNoTag)
   300 	LAST_NODEACTIVITY_ENTRY(KNoTag, PRStates::TSendDataClientStopped)
   340 	LAST_NODEACTIVITY_ENTRY(KNoTag, PRStates::TSendDataClientStopped)
   301 NODEACTIVITY_END()
   341 NODEACTIVITY_END()
   302 }
   342 }
   303 
   343 
   630 
   670 
   631 CDestroyActivity::CDestroyActivity(const MeshMachine::TNodeActivity& aActivitySig, MeshMachine::AMMNodeBase& aNode)
   671 CDestroyActivity::CDestroyActivity(const MeshMachine::TNodeActivity& aActivitySig, MeshMachine::AMMNodeBase& aNode)
   632 :	CNodeRetryActivity(aActivitySig, aNode),
   672 :	CNodeRetryActivity(aActivitySig, aNode),
   633 	APreallocatedOriginators<1>(iOriginators)
   673 	APreallocatedOriginators<1>(iOriginators)
   634 	{
   674 	{
   635 	//Mark the provider for deletion, so that it's not served by the factory from now on.
   675     //Mark the provider for deletion, so that it's not served by the factory from now on.
   636     static_cast<ESock::CMMCommsProviderBase&>(iNode).MarkMeForDeletion();
   676     static_cast<ESock::CMMCommsProviderBase&>(iNode).MarkMeForDeletion();
   637 	}
   677 	}
   638 
   678 
   639 void CDestroyActivity::Destroy()
   679 void CDestroyActivity::Destroy()
   640 	{
   680 	{
   642 	this->~CDestroyActivity(); //Run the destructor
   682 	this->~CDestroyActivity(); //Run the destructor
   643 
   683 
   644 	//Delete the provider.
   684 	//Delete the provider.
   645 	static_cast<ESock::CMMCommsProviderBase&>(iNode).DeleteMeNow();
   685 	static_cast<ESock::CMMCommsProviderBase&>(iNode).DeleteMeNow();
   646 	}
   686 	}
   647 
       
   648 TBool CDestroyActivity::Next(TNodeContextBase& aContext)
       
   649     {
       
   650     if (aContext.iMessage.IsMessage<TEBase::TCancel>())
       
   651         {  
       
   652         return ETrue;
       
   653         }
       
   654     else
       
   655         return CNodeActivityBase::Next(aContext);
       
   656     }
       
   657 
   687 
   658 EXPORT_DEFINE_SMELEMENT(CDestroyActivity::TNoTagOrNoTagBackwards, NetStateMachine::MStateFork, PRStates::TContext)
   688 EXPORT_DEFINE_SMELEMENT(CDestroyActivity::TNoTagOrNoTagBackwards, NetStateMachine::MStateFork, PRStates::TContext)
   659 EXPORT_C TInt CDestroyActivity::TNoTagOrNoTagBackwards::TransitionTag()
   689 EXPORT_C TInt CDestroyActivity::TNoTagOrNoTagBackwards::TransitionTag()
   660     {
   690     {
   661 	if (iContext.iMessage.IsMessage<TEChild::TLeft>())
   691 	if (iContext.iMessage.IsMessage<TEChild::TLeft>())
   701 	//MZTODO: this asserion may need to be changed since TDestroy can
   731 	//MZTODO: this asserion may need to be changed since TDestroy can
   702 	//come while data client is active etc.
   732 	//come while data client is active etc.
   703     __ASSERT_DEBUG(iContext.Node().GetFirstClient<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EData, TCFClientType::EActive|TCFClientType::EActivating|TCFClientType::EStarting|TCFClientType::EStarted))==NULL,
   733     __ASSERT_DEBUG(iContext.Node().GetFirstClient<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EData, TCFClientType::EActive|TCFClientType::EActivating|TCFClientType::EStarting|TCFClientType::EStarted))==NULL,
   704     	User::Panic(KCorePrPanic, KPanicClientsStillPresent));
   734     	User::Panic(KCorePrPanic, KPanicClientsStillPresent));
   705 
   735 
   706    	TClientIter<TDefaultClientMatchPolicy> dciter = iContext.Node().GetClientIter<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EData),	TClientType(0, TCFClientType::ELeaving));
   736 	iContext.Node().PostToClients<TDefaultClientMatchPolicy>(iContext.NodeId(),
   707    	RNodeInterface* dc = NULL;
   737 		TEChild::TDestroy().CRef(),
   708     while ((dc = dciter[0]) != NULL) //always inspect the first elem as we're invalidating the iterator with each hit.
   738 		TClientType(TCFClientType::EData),
   709         {
   739 		TClientType(0, TCFClientType::ELeaving|TCFClientType::EDefault),
   710 		dc->PostMessage(iContext.NodeId(), TEChild::TDestroy().CRef());
   740 		TClientType::ELeaving
   711 		dc->SetFlags(TCFClientType::ELeaving);
   741 		);
   712         }
   742 	iContext.Node().PostToClients<TDefaultClientMatchPolicy>(iContext.NodeId(),
       
   743 		TEChild::TDestroy().CRef(),
       
   744 		TClientType(TCFClientType::EData),
       
   745 		TClientType(0, TCFClientType::ELeaving),
       
   746 		TClientType::ELeaving
       
   747 		);
   713 	}
   748 	}
   714 
   749 
   715 void CDestroyActivity::TMakeClientsLeaveOrProcessClientLeave::ProcessClientLeaveL()
   750 void CDestroyActivity::TMakeClientsLeaveOrProcessClientLeave::ProcessClientLeaveL()
   716     {
   751     {
   717     CDestroyActivity::TProcessClientLeave processClientLeave(iContext);
   752     CDestroyActivity::TProcessClientLeave processClientLeave(iContext);
   718     processClientLeave.DoL();
   753     processClientLeave.DoL();
   719     }
   754     }
   720 
   755 
       
   756 //-=========================================================
       
   757 //
       
   758 // Destroy Orphan Activity - will delete the node when destructed
       
   759 // if TMarkNodeForDestruction tuple has been called.
       
   760 //
       
   761 //-=========================================================
       
   762 
       
   763 CNodeActivityBase* CDestroyOrphansActivity::New(const MeshMachine::TNodeActivity& aActivitySig, MeshMachine::AMMNodeBase& aNode)
       
   764     {
       
   765     TAny* space = BorrowPreallocatedSpace(aNode, sizeof(CDestroyOrphansActivity));
       
   766     CDestroyOrphansActivity* self = new (space) CDestroyOrphansActivity(aActivitySig, aNode);
       
   767     self->InsertPreallocatedDestroyActivity(); //Destructing preallocated activity
       
   768     return self;
       
   769     }
       
   770 
       
   771 CDestroyOrphansActivity::CDestroyOrphansActivity(const MeshMachine::TNodeActivity& aActivitySig, MeshMachine::AMMNodeBase& aNode)
       
   772   : MeshMachine::CNodeActivityBase(aActivitySig, aNode),
       
   773           MeshMachine::APreallocatedOriginators<1>(iOriginators)
       
   774     {
       
   775     }
       
   776 
       
   777 CDestroyOrphansActivity::~CDestroyOrphansActivity() 
       
   778     {
       
   779     }
       
   780 
       
   781 void CDestroyOrphansActivity::Destroy() 
       
   782     {
       
   783     ReturnPreallocatedSpace(this);
       
   784     if (DestroyFlag() && iNode.CountActivities(ECFActivityDestroy) == 0)
       
   785         {
       
   786         static_cast<ESock::CMMCommsProviderBase&>(iNode).MarkMeForDeletion();
       
   787         this->~CDestroyOrphansActivity(); //Run the destructor
       
   788         static_cast<ESock::CMMCommsProviderBase&>(iNode).DeleteMeNow();
       
   789         }
       
   790     else
       
   791         {
       
   792         this->~CDestroyOrphansActivity(); //Run the destructor
       
   793         }
       
   794     }
       
   795 
       
   796 void CDestroyOrphansActivity::SetDestroyFlag()
       
   797     {
       
   798     iDestroyFlag = ETrue;
       
   799     }
       
   800 
       
   801 TBool CDestroyOrphansActivity::DestroyFlag() const
       
   802     {
       
   803     return iDestroyFlag;
       
   804     }
       
   805 
       
   806 DEFINE_SMELEMENT(CDestroyOrphansActivity::TMarkNodeForDestruction, NetStateMachine::MStateTransition, CDestroyOrphansActivity::TContext)
       
   807 void CDestroyOrphansActivity::TMarkNodeForDestruction::DoL()
       
   808 /**
       
   809 Flag that the node should be destroyed when the activity completes.
       
   810 */
       
   811     {
       
   812     CDestroyOrphansActivity* act = static_cast<CDestroyOrphansActivity*>(iContext.Activity());
       
   813     ASSERT(act);
       
   814     act->SetDestroyFlag();
       
   815     }
       
   816 
       
   817 // This is a copy from CDestroyActivity.
       
   818 DEFINE_SMELEMENT(CDestroyOrphansActivity::TNoTagOrNoTagBackwards, NetStateMachine::MStateFork, CDestroyOrphansActivity::TContext)
       
   819 TInt CDestroyOrphansActivity::TNoTagOrNoTagBackwards::TransitionTag()
       
   820     {
       
   821     if (iContext.iMessage.IsMessage<TEChild::TLeft>())
       
   822         {
       
   823         TClientIter<TDefaultClientMatchPolicy> iter = iContext.Node().GetClientIter<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EData|TCFClientType::ECtrl));
       
   824         __ASSERT_DEBUG(iter[0], User::Panic(KSpecAssert_ESockCrStaCPRAC, 7)); //One leaving client must still be there.
       
   825         return iter[1] == NULL ?  MeshMachine::KNoTag : MeshMachine::KNoTag | NetStateMachine::EBackward;
       
   826         }
       
   827     else if (iContext.iMessage.IsMessage<TEPeer::TLeaveComplete>())
       
   828         {
       
   829         __ASSERT_DEBUG(iContext.Node().GetFirstClient<TDefaultClientMatchPolicy>(TClientType(TCFClientType::ECtrl|TCFClientType::EData))==NULL,
       
   830         User::Panic(KCorePrPanic, KPanicClientsStillPresent));
       
   831         if (iContext.Node().GetFirstClient<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EServProvider))==NULL)
       
   832             {
       
   833             return NetStateMachine::EForward | MeshMachine::KNoTag;
       
   834             }
       
   835         return NetStateMachine::EBackward | MeshMachine::KNoTag; //Loop back to the same triple (& remove the peer)
       
   836         }
       
   837     __ASSERT_DEBUG(EFalse, User::Panic(KSpecAssert_ESockCrStaCPRAC, 8));
       
   838     return KNoTag;
       
   839     }
       
   840 
       
   841 DEFINE_SMELEMENT(CDestroyOrphansActivity::TNoTagOrNoClients, NetStateMachine::MStateFork, CDestroyOrphansActivity::TContext)
       
   842 TInt CDestroyOrphansActivity::TNoTagOrNoClients::TransitionTag()
       
   843 /**
       
   844 If the Destroy activity is not running and there are no data/control clients, return KNoClients, else return KNoTag.
       
   845 */
       
   846     {
       
   847     if (iContext.Node().CountActivities(ECFActivityDestroy))
       
   848         {
       
   849         return KNoTag;
       
   850         }
       
   851     CoreStates::TNoTagOrNoClients fork(iContext);
       
   852     return fork.TransitionTag();
       
   853     }
       
   854 
       
   855 
       
   856 DEFINE_SMELEMENT(CDestroyOrphansActivity::TControlProviderNoTagOrNoClients, NetStateMachine::MStateFork, CDestroyOrphansActivity::TContext)
       
   857 TInt CDestroyOrphansActivity::TControlProviderNoTagOrNoClients::TransitionTag()
       
   858 /**
       
   859 If there is a Control Provider, return KNoTag, else return KNoClients
       
   860 */
       
   861     {
       
   862     return iContext.Node().ControlProvider() ? KNoTag : KNoClients;
       
   863     }
   721 
   864 
   722 //-=========================================================
   865 //-=========================================================
   723 //
   866 //
   724 //Loppin Activity
   867 //Loppin Activity
   725 //
   868 //
   792     //Please allow it to server everyone equally.
   935     //Please allow it to server everyone equally.
   793     //Please handle the error conditions properly so that you obey this API's semantics.
   936     //Please handle the error conditions properly so that you obey this API's semantics.
   794     //If you are not providing a clean error handling solution for your activity,
   937     //If you are not providing a clean error handling solution for your activity,
   795     //please use IsBinding() before calling this API!
   938     //please use IsBinding() before calling this API!
   796     __ASSERT_DEBUG(!iOriginator.IsNull(), User::Panic(KSpecAssert_ESockCrStaCPRAC, 10)); //The iOriginator must be set.
   939     __ASSERT_DEBUG(!iOriginator.IsNull(), User::Panic(KSpecAssert_ESockCrStaCPRAC, 10)); //The iOriginator must be set.
   797     RClientInterface::OpenPostMessageClose(iOurNode, iOriginator, TCFDataClient::TBindToComplete(aError).CRef());
   940     
   798     iOriginator.SetNull();
   941     RClientInterface::OpenPostMessageClose(iOurNode, iOriginator, TCFServiceProvider::TBindToComplete(aError).CRef());
       
   942 
       
   943      iOriginator.SetNull();
   799     }
   944     }
   800 
   945 
   801 EXPORT_DEFINE_SMELEMENT(ABindingActivity::TSendBindToComplete, NetStateMachine::MStateTransition, CoreStates::TContext)
   946 EXPORT_DEFINE_SMELEMENT(ABindingActivity::TSendBindToComplete, NetStateMachine::MStateTransition, CoreStates::TContext)
   802 EXPORT_C void ABindingActivity::TSendBindToComplete::DoL()
   947 EXPORT_C void ABindingActivity::TSendBindToComplete::DoL()
   803 	{
   948 	{
   804     __ASSERT_DEBUG(iContext.iNodeActivity, User::Panic(KCorePrPanic, KPanicNoActivity));
   949     __ASSERT_DEBUG(iContext.iNodeActivity, User::Panic(KCorePrPanic, KPanicNoActivity));
   805     __ASSERT_DEBUG(iContext.iNodeActivity->SupportsExtInterface(ABindingActivity::KInterfaceId), User::Panic(KSpecAssert_ESockCrStaCPRAC, 11));
   950     __ASSERT_DEBUG(iContext.iNodeActivity->SupportsExtInterface(ABindingActivity::KInterfaceId), User::Panic(KSpecAssert_ESockCrStaCPRAC, 11));
   806     ABindingActivity* bindingActivity = reinterpret_cast<ABindingActivity*>(iContext.iNodeActivity->FetchExtInterfaceL(ABindingActivity::KInterfaceId));
   951     ABindingActivity* bindingActivity = reinterpret_cast<ABindingActivity*>(iContext.iNodeActivity->FetchExtInterfaceL(ABindingActivity::KInterfaceId));
   807     bindingActivity->ReplyToOriginator(iContext.iNodeActivity->Error());
   952     bindingActivity->ReplyToOriginator(iContext.iNodeActivity->Error());
   808 	}
       
   809 
       
   810 EXPORT_DEFINE_SMELEMENT(ABindingActivity::TSendBindToCompleteIfExpected, NetStateMachine::MStateTransition, CoreStates::TContext)
       
   811 EXPORT_C void ABindingActivity::TSendBindToCompleteIfExpected::DoL()
       
   812 	{
       
   813     __ASSERT_DEBUG(iContext.iNodeActivity, User::Panic(KCorePrPanic, KPanicNoActivity));
       
   814     __ASSERT_DEBUG(iContext.iNodeActivity->SupportsExtInterface(ABindingActivity::KInterfaceId), User::Panic(KSpecAssert_ESockCrStaCPRAC, 12));
       
   815     ABindingActivity* bindingActivity = reinterpret_cast<ABindingActivity*>(iContext.iNodeActivity->FetchExtInterfaceL(ABindingActivity::KInterfaceId));
       
   816     if (bindingActivity->IsBinding())
       
   817 	    {
       
   818 		bindingActivity->ReplyToOriginator(iContext.iNodeActivity->Error());
       
   819 	    }
       
   820 	}
   953 	}
   821 
   954 
   822 void ABindingActivity::FinalReplyToOriginator(TInt aError)
   955 void ABindingActivity::FinalReplyToOriginator(TInt aError)
   823 /**
   956 /**
   824 Intended to be called from derived class destructors to arrange for a TBindToComplete reply to be sent
   957 Intended to be called from derived class destructors to arrange for a TBindToComplete reply to be sent
   839 namespace PRActivities
   972 namespace PRActivities
   840 {
   973 {
   841 DECLARE_DEFINE_ACTIVITY_MAP(coreActivitiesPR)
   974 DECLARE_DEFINE_ACTIVITY_MAP(coreActivitiesPR)
   842 	ACTIVITY_MAP_ENTRY(PRDataClientJoinActivity, PRDataClientJoin)
   975 	ACTIVITY_MAP_ENTRY(PRDataClientJoinActivity, PRDataClientJoin)
   843 	ACTIVITY_MAP_ENTRY(PRControlClientJoinActivity, PRControlClientJoin)
   976 	ACTIVITY_MAP_ENTRY(PRControlClientJoinActivity, PRControlClientJoin)
   844 	ACTIVITY_MAP_ENTRY(PRClientLeaveActivity, PRClientLeave)
   977 	ACTIVITY_MAP_ENTRY(PRClientLeftActivity, PRClientLeft)
       
   978     ACTIVITY_MAP_ENTRY(PRClientLeaveActivity, PRClientLeave)
   845 	ACTIVITY_MAP_ENTRY(PRForwardStateChangeActivity, PRForwardStateChange)
   979 	ACTIVITY_MAP_ENTRY(PRForwardStateChangeActivity, PRForwardStateChange)
   846 	ACTIVITY_MAP_ENTRY(PRBindToActivity, PRBindTo)
   980 	ACTIVITY_MAP_ENTRY(PRBindToActivity, PRBindTo)
       
   981 	ACTIVITY_MAP_ENTRY(PRDestroyOrphansActivity, PRDestroyOrphans)
   847 ACTIVITY_MAP_END_BASE(CoreActivities,coreActivitiesAll)
   982 ACTIVITY_MAP_END_BASE(CoreActivities,coreActivitiesAll)
   848 
   983 
   849 //Activity Map provided by CorePr to be used by SCprs.
   984 //Activity Map provided by CorePr to be used by SCprs.
   850 //(it is further extended in CoreSCpr).
   985 //(it is further extended in CoreSCpr).
   851 DEFINE_EXPORT_ACTIVITY_MAP(coreActivitiesSCpr)
   986 DEFINE_EXPORT_ACTIVITY_MAP(coreActivitiesSCpr)
   892 DEFINE_EXPORT_ACTIVITY_MAP(coreActivitiesMCpr)
  1027 DEFINE_EXPORT_ACTIVITY_MAP(coreActivitiesMCpr)
   893 	ACTIVITY_MAP_ENTRY(PRDataClientIdleActivity, PRDataClientIdle)
  1028 	ACTIVITY_MAP_ENTRY(PRDataClientIdleActivity, PRDataClientIdle)
   894 	ACTIVITY_MAP_ENTRY(PRDataClientActiveActivity, PRDataClientActive)
  1029 	ACTIVITY_MAP_ENTRY(PRDataClientActiveActivity, PRDataClientActive)
   895     ACTIVITY_MAP_ENTRY(PRDataClientStatusChangeActivity, PRDataClientStatusChange)
  1030     ACTIVITY_MAP_ENTRY(PRDataClientStatusChangeActivity, PRDataClientStatusChange)
   896     ACTIVITY_MAP_ENTRY(PRLegacyRMessage2HandlerActivity, PRLegacyRMessage2Handler)
  1031     ACTIVITY_MAP_ENTRY(PRLegacyRMessage2HandlerActivity, PRLegacyRMessage2Handler)
       
  1032     ACTIVITY_MAP_ENTRY(PRDestroyActivity, PRDestroy)
   897 ACTIVITY_MAP_END_BASE(PRActivities,coreActivitiesPR)
  1033 ACTIVITY_MAP_END_BASE(PRActivities,coreActivitiesPR)
   898 
  1034 
   899 //Activity Map provided by CorePr to be used by TMs.
  1035 //Activity Map provided by CorePr to be used by TMs.
   900 //(it is further extended in CoreTM).
  1036 //(it is further extended in CoreTM).
   901 DEFINE_EXPORT_ACTIVITY_MAP(coreActivitiesTM)
  1037 DEFINE_EXPORT_ACTIVITY_MAP(coreActivitiesTM)
  1317             //up. This error must have happened before any of the clients have been added to the new
  1453             //up. This error must have happened before any of the clients have been added to the new
  1318             //owner as such addition must either collectively succeed or collectively fail. Reinstall
  1454             //owner as such addition must either collectively succeed or collectively fail. Reinstall
  1319             //clients in at the current owner.
  1455             //clients in at the current owner.
  1320             for (TInt i = 0; i < iDataClients.Count(); i++)
  1456             for (TInt i = 0; i < iDataClients.Count(); i++)
  1321                 {
  1457                 {
  1322                 if (!(iDataClients[i].iDataClient.Flags() & TCFClientType::EActive))
  1458                 Messages::RNodeInterface& dataClient = iDataClients[i].iDataClient; 
       
  1459                 if (!(dataClient.Flags() & TCFClientType::EActive))
  1323                     {
  1460                     {
  1324 #ifndef __GCCXML__
  1461 #ifndef __GCCXML__
  1325 					//If the dataclient managed to report idle in the mean time, have him destroyed
  1462                     //If the dataclient managed to report idle in the mean time, have him destroyed
  1326                     RClientInterface::OpenPostMessageClose(iNode.Id(), iDataClients[i].iDataClient.RecipientId(), TEChild::TDestroy().CRef());
  1463                     RClientInterface::OpenPostMessageClose(iNode.Id(), dataClient.RecipientId(), TEChild::TDestroy().CRef());
       
  1464                     dataClient.SetFlags(TCFClientType::ELeaving);
  1327 #endif
  1465 #endif
  1328                     }
  1466                     }
  1329                 iDataClients[i].iDataClient.ClearFlags(TCFClientType::EActivating);
  1467                 dataClient.ClearFlags(TCFClientType::EActivating);
  1330 #ifndef __GCCXML__
  1468 #ifndef __GCCXML__
  1331                 //Simulate client leaving on the new owner.
  1469                 //Simulate client leaving on the new owner.
  1332                 RClientInterface::OpenPostMessageClose(iDataClients[i].iDataClient.RecipientId(), iDataClients[i].iNewOwner,
  1470                 RClientInterface::OpenPostMessageClose(dataClient.RecipientId(), iDataClients[i].iNewOwner,
  1333                 	TEChild::TLeft().CRef());
  1471                         TEChild::TLeft().CRef());
  1334 #endif
  1472 #endif
  1335                 }
  1473                 }
  1336             }
  1474             }
  1337         else
  1475         else
  1338             {
  1476             {
  1709 	__ASSERT_DEBUG(iContext.iNodeActivity->SupportsExtInterface(CCommsBinderActivity::KInterfaceId), User::Panic(KCorePrPanic, KPanicExtInterfaceNotSupported));
  1847 	__ASSERT_DEBUG(iContext.iNodeActivity->SupportsExtInterface(CCommsBinderActivity::KInterfaceId), User::Panic(KCorePrPanic, KPanicExtInterfaceNotSupported));
  1710 	CCommsBinderActivity* intf = reinterpret_cast<CCommsBinderActivity*>(iContext.iNodeActivity->FetchExtInterface(CCommsBinderActivity::KInterfaceId));
  1848 	CCommsBinderActivity* intf = reinterpret_cast<CCommsBinderActivity*>(iContext.iNodeActivity->FetchExtInterface(CCommsBinderActivity::KInterfaceId));
  1711 
  1849 
  1712     intf->SendCustomFlowProvision();
  1850     intf->SendCustomFlowProvision();
  1713 	}
  1851 	}
  1714 
  1852     
  1715 EXPORT_DEFINE_SMELEMENT(CCommsBinderActivity::TAwaitingBindToComplete, NetStateMachine::MState, PRStates::TContext)
  1853 EXPORT_DEFINE_SMELEMENT(CCommsBinderActivity::TAwaitingBindToComplete, NetStateMachine::MState, PRStates::TContext)
  1716 EXPORT_C TBool CCommsBinderActivity::TAwaitingBindToComplete::Accept()
  1854 EXPORT_C TBool CCommsBinderActivity::TAwaitingBindToComplete::Accept()
  1717 	{
  1855 	{   
  1718 	CoreNetStates::TAwaitingBindToComplete awaitingBindToComplete(iContext);
  1856 	TCFServiceProvider::TBindToComplete* bindToComplete = message_cast<TCFServiceProvider::TBindToComplete>(&iContext.iMessage); 
  1719 	if (awaitingBindToComplete.Accept())
  1857 	if (bindToComplete) 
  1720 		{
  1858 	    { 
       
  1859 	    __ASSERT_DEBUG(iContext.iNodeActivity, User::Panic(KCorePrPanic, KPanicNoActivity)); 
       
  1860 	    iContext.iNodeActivity->SetError(bindToComplete->iValue); 
       
  1861 	    
  1721 	    CCommsBinderActivity* binderActivity = reinterpret_cast<CCommsBinderActivity*>(iContext.iNodeActivity->FetchExtInterface(CCommsBinderActivity::KInterfaceId));
  1862 	    CCommsBinderActivity* binderActivity = reinterpret_cast<CCommsBinderActivity*>(iContext.iNodeActivity->FetchExtInterface(CCommsBinderActivity::KInterfaceId));
  1722 	    __ASSERT_DEBUG(binderActivity, User::Panic(KSpecAssert_ESockCrStaCPRAC, 30));
  1863 	    __ASSERT_DEBUG(binderActivity, User::Panic(KSpecAssert_ESockCrStaCPRAC, 30));
  1723 	    binderActivity->BindToComplete();
  1864 	    binderActivity->BindToComplete();
  1724 		iContext.Node().DestroyOrphanedDataClients();
  1865 	    iContext.Node().DestroyOrphanedDataClients();
  1725 		return ETrue;
  1866 	    return ETrue; 
  1726 		}
  1867 	    }
       
  1868 
  1727 	return EFalse;
  1869 	return EFalse;
  1728 	}
  1870 	}
  1729 
  1871 
  1730 //-=========================================================
  1872 //-=========================================================
  1731 //
  1873 //
  1909         
  2051         
  1910             TClientIter<TDefaultClientMatchPolicy> iter = iNode.GetClientIter<TDefaultClientMatchPolicy>(
  2052             TClientIter<TDefaultClientMatchPolicy> iter = iNode.GetClientIter<TDefaultClientMatchPolicy>(
  1911                     TClientType(TCFClientType::ECtrl), TClientType(0, TCFClientType::ELeaving));
  2053                     TClientType(TCFClientType::ECtrl), TClientType(0, TCFClientType::ELeaving));
  1912             RNodeInterface* ctrlClient = NULL;
  2054             RNodeInterface* ctrlClient = NULL;
  1913 
  2055 
  1914             while ( (ctrlClient = iter++) )
  2056             while ( (ctrlClient = iter++) != NULL )
  1915                 {
  2057                 {
  1916                 // Let control clients know the node has gone down, other than those that originated Start (they will be errored by ~CNodeActivityBase)...
  2058                 // Let control clients know the node has gone down, other than those that originated Start (they will be errored by ~CNodeActivityBase)...
  1917                 if (FindOriginator(*ctrlClient) >= 0)
  2059                 if (FindOriginator(*ctrlClient) >= 0)
  1918                     {
  2060                     {
  1919                     continue; // ControlClient is a Start originator
  2061                     continue; // ControlClient is a Start originator