diff -r 9ddb1d67ebaf -r 9644881fedd0 commsfwsupport/commselements/meshmachine/src/mm_node.cpp --- a/commsfwsupport/commselements/meshmachine/src/mm_node.cpp Tue May 11 17:20:19 2010 +0300 +++ b/commsfwsupport/commselements/meshmachine/src/mm_node.cpp Tue May 25 14:00:39 2010 +0300 @@ -26,7 +26,6 @@ #include #include - #ifdef _DEBUG // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module // (if it could happen through user error then you should give it an explicit, documented, category + code) @@ -232,7 +231,7 @@ for (TInt i = iActivities.Count() - 1; i>=0 && a==NULL; i--) { CNodeActivityBase* act = iActivities[i]; - const TNodeId& postedTo = act->iPostedToId; + const TNodeId& postedTo = act->PostedToNodeId(); if (!act->IsIdle() && (postedTo.IsNull() || aContext.iSender == postedTo) && (recipient->NodeCtx() == act->ActivityId())) @@ -430,6 +429,7 @@ } } + EXPORT_C void AMMNodeBase::AbortActivitiesOriginatedBy(TNodeContextBase& aContext, const TNodeId& aCommsId, TBool aIsNodeBeingDestroyed) { CNodeActivityBase* caller = aContext.iNodeActivity; @@ -438,6 +438,20 @@ for (TInt i = iActivities.Count() - 1; i>=0; i--) { aContext.iNodeActivity = iActivities[i]; + + if (!abortAll && aContext.iNodeActivity->PostedToNodeId() == aCommsId) + {//clear postedto if a leaver has been set as a postedto at any of the running activities. + //No other messages will ever come from the leaver and it is not gonna be safe to forward TCancels + //to the leaver, so at least postedto must be cleared to avoid the crash. It could be speculated that + //if the postedto is still set, then either the postedto node failed to respond or the local activity failed to + //clear postedto when it had responded. Worth putting a speculative ASSERT here to catch misdeeds. + + //clearing postedto shouldn't be done in here (AbortActivitiesOriginatedBy), but I (RZ) have expressed my disrespect to the + //this method before and the suggestion that it should go (replaced by a CancelActivitiesOriginatedBy). + //So instead of introducing another method that loops through activities i decided to piggyback the function in an + //existing method. Note that the final logic should be based on RNodeInterfaces and not TNodeIds. + aContext.iNodeActivity->ClearPostedTo(); + } // We dont want to abort already idle activities or they may error. if(aContext.iNodeActivity->IsIdle()) @@ -622,21 +636,36 @@ void AMMNodeBase::StartActivityL(TNodeContextBase& aContext, const TNodeActivity& aActivitySig, const NetStateMachine::TStateTriple& aFirst) { - CNodeActivityBase* a = aActivitySig.iCtor(aActivitySig,*this); - if (iActivities.Find(a)==KErrNotFound) + CNodeActivityBase* nodeActivity; + // Activity is based on one of 2 declarations. One of which has an extra member. In the case of the instance + // with a second member the activities Ctor will point to this second member. Since the first member is a TNodeActivity + // We can compare the activities Ctor pointer to the address of the second member to assess which type of declarations + // this is. + + if (aActivitySig.iFlags & TNodeActivity::EContextCtor) + { // TNodeActivity's iCtor is a pointer to Activity Ctor + nodeActivity = ((TNodeActivity::TStaticActivityContextCtor)aActivitySig.iCtor)(aActivitySig,aContext); + } + else + { // TNodeActivity's iCtor is a pointer to activity constructor + nodeActivity = ((TNodeActivity::TStaticActivityCtor)aActivitySig.iCtor)(aActivitySig,*this); + } + + if (iActivities.Find(nodeActivity)==KErrNotFound) { //The activity did not add itself to the list in any special way, append it here - CleanupStack::PushL(a); - a->AppendActivityL(); - CleanupStack::Pop(a); + CleanupStack::PushL(nodeActivity); + nodeActivity->AppendActivityL(); + CleanupStack::Pop(nodeActivity); } + //assign only after the activity is successfully appended - aContext.iNodeActivity = a; + aContext.iNodeActivity = nodeActivity; //if StartL leaves the "a" will be removed from the array and deleted in ::PostReceived //since it will be idle XNodePeerId originator(aContext.iSender, aContext.iPeer); - a->StartL(aContext, originator, aFirst); + nodeActivity->StartL(aContext, originator, aFirst); } void AMMNodeBase::PreallocateSpaceL(TUint aSize)