167 //The role of this method is to filter out all messages that 'this' should |
167 //The role of this method is to filter out all messages that 'this' should |
168 //not be bothered with. 'this' should be interested in messages coming from |
168 //not be bothered with. 'this' should be interested in messages coming from |
169 //what's set as iPostedToId or from one of the orginators. |
169 //what's set as iPostedToId or from one of the orginators. |
170 //if the message's recipient specifies the activity id, then that |
170 //if the message's recipient specifies the activity id, then that |
171 //activity must much that of 'this'. |
171 //activity must much that of 'this'. |
172 TBool sender = iPostedToId.IsNull() || |
172 TBool sender = PostedToNodeId().IsNull() || |
173 aContext.iSender == iPostedToId || |
173 aContext.iSender == PostedToNodeId() || |
174 FindOriginator(aContext.iSender) != KErrNotFound; |
174 FindOriginator(aContext.iSender) != KErrNotFound; |
175 const TNodeCtxId* recipient = address_cast<const TNodeCtxId>(&aContext.iRecipient); |
175 const TNodeCtxId* recipient = address_cast<const TNodeCtxId>(&aContext.iRecipient); |
176 TBool activity = (recipient == NULL || ActivityId() == recipient->NodeCtx()); |
176 TBool activity = (recipient == NULL || ActivityId() == recipient->NodeCtx()); |
177 |
177 |
178 #ifdef SYMBIAN_TRACE_ENABLE |
178 #ifdef SYMBIAN_TRACE_ENABLE |
181 { |
181 { |
182 NM_LOG_START_BLOCK(KMeshMachineSubTag, _L8("CNodeActivityBase::MatchSender")); |
182 NM_LOG_START_BLOCK(KMeshMachineSubTag, _L8("CNodeActivityBase::MatchSender")); |
183 if(!sender) |
183 if(!sender) |
184 { |
184 { |
185 MESH_LOG((KMeshMachineSubTag(), _L8("CNodeActivityBase %08x:\tiPostedToId mismatch:"), this)); |
185 MESH_LOG((KMeshMachineSubTag(), _L8("CNodeActivityBase %08x:\tiPostedToId mismatch:"), this)); |
186 NM_LOG_ADDRESS(KMeshMachineSubTag(), iPostedToId); |
186 NM_LOG_ADDRESS(KMeshMachineSubTag(), PostedToNodeId()); |
187 NM_LOG_ADDRESS(KMeshMachineSubTag(), aContext.iSender); |
187 NM_LOG_ADDRESS(KMeshMachineSubTag(), aContext.iSender); |
188 MESH_LOG((KMeshMachineSubTag(), _L8("CNodeActivityBase %08x:\toriginators' mismatch:"), this)); |
188 MESH_LOG((KMeshMachineSubTag(), _L8("CNodeActivityBase %08x:\toriginators' mismatch:"), this)); |
189 for (TInt i = iOriginators.Count() - 1; i>=0; i--) |
189 for (TInt i = iOriginators.Count() - 1; i>=0; i--) |
190 { |
190 { |
191 NM_LOG_ADDRESS(KMeshMachineSubTag(), iOriginators[i].RecipientId()); |
191 NM_LOG_ADDRESS(KMeshMachineSubTag(), iOriginators[i].RecipientId()); |
317 return nextRet; |
317 return nextRet; |
318 } |
318 } |
319 |
319 |
320 EXPORT_C void CNodeActivityBase::Cancel(TNodeContextBase& aContext) |
320 EXPORT_C void CNodeActivityBase::Cancel(TNodeContextBase& aContext) |
321 {//we expect KErrCancel be set as a result of the state cancelation |
321 {//we expect KErrCancel be set as a result of the state cancelation |
322 MESH_LOG((KMeshMachineSubTag, _L8("CNodeActivityBase %08x:\tCancel(), iPostedToId %08x"), this, iPostedToId.Ptr() ? &iPostedToId.Node() : NULL)); |
322 MESH_LOG((KMeshMachineSubTag, _L8("CNodeActivityBase %08x:\tCancel(), PostedToNodeId %08x"), this, PostedToNodeId().Ptr())); |
323 |
323 |
324 if (!iPostedToId.IsNull()) |
324 if ((PostedToPeer() && !(PostedToPeer()->Flags() & TClientType::ELeaving)) || |
325 { |
325 PostedToNodeId() == aContext.Node().Id()) |
326 RClientInterface::OpenPostMessageClose(TNodeCtxId(ActivityId(), iNode.Id()), iPostedToId, TEBase::TCancel().CRef()); |
326 {//only safe to forward TCancels to non-leavers or self. There is an underlying assumption that a node won't dissapear in presence of activities (see AMMNodeBase::~AMMNodeBase) |
|
327 RClientInterface::OpenPostMessageClose(TNodeCtxId(ActivityId(), iNode.Id()), PostedToNodeId(), TEBase::TCancel().CRef()); |
327 } |
328 } |
328 else |
329 else |
329 { |
330 { |
330 NetStateMachine::ACore::Cancel(&aContext); |
331 NetStateMachine::ACore::Cancel(&aContext); |
331 } |
332 } |
361 return msgSendCount; |
362 return msgSendCount; |
362 } |
363 } |
363 |
364 |
364 EXPORT_C void CNodeActivityBase::SetPostedTo(const TNodeId& aNodeId) |
365 EXPORT_C void CNodeActivityBase::SetPostedTo(const TNodeId& aNodeId) |
365 { |
366 { |
366 iPostedToId = aNodeId; |
367 //You are being punished for storing a postedto TNodeId that you also know as your peer. |
|
368 //the Messages::RNodeInterface& overload of CNodeActivityBase::SetPostedTo |
|
369 //It is dangerous to use this overload for peers when the relation with these peers |
|
370 //is being terminated. the PostedTo facility is also used to forward TCancel in |
|
371 //the automatic calencallation handling. No message can be posted to a leaving peer |
|
372 //but only peers (Messages::RNodeInterfaces) can be recognised as leaving. |
|
373 // |
|
374 //ASSERT temporarily commened out as it is a behavioural break. A Polonium BR |
|
375 //has been drafted and will be raised when the RNodeInterface overloads end up in the |
|
376 //codeline. http://polonium.ext.nokia.com/changerequests/cr/601/ |
|
377 //__ASSERT_DEBUG(iNode.FindClient(aNodeId) == NULL, User::Panic(KSpecAssert_ElemMeshMachActC, 14)); |
|
378 |
|
379 if (aNodeId == Messages::TNodeId::NullId()) |
|
380 { |
|
381 ClearPostedTo(); |
|
382 return; |
|
383 } |
|
384 iPostedToId.Open(aNodeId); |
|
385 } |
|
386 |
|
387 EXPORT_C void CNodeActivityBase::SetPostedTo(const Messages::RNodeInterface& aRecepient) |
|
388 { |
|
389 iPostedToId.Open(aRecepient); |
367 } |
390 } |
368 |
391 |
369 EXPORT_C void CNodeActivityBase::ClearPostedTo() |
392 EXPORT_C void CNodeActivityBase::ClearPostedTo() |
370 { |
393 { |
371 iPostedToId.SetNull(); |
394 iPostedToId.Close(); |
|
395 } |
|
396 |
|
397 EXPORT_C const Messages::TNodeId& CNodeActivityBase::PostedToNodeId() const |
|
398 { |
|
399 return iPostedToId.NodeId(); |
|
400 } |
|
401 |
|
402 EXPORT_C const Messages::RNodeInterface* CNodeActivityBase::PostedToPeer() const |
|
403 { |
|
404 return iPostedToId.Peer(); |
372 } |
405 } |
373 |
406 |
374 EXPORT_C void CNodeActivityBase::PostRequestTo(const RNodeInterface& aRecipient, const TSignalBase& aMessage, const TBool aRecipientIdCritical) |
407 EXPORT_C void CNodeActivityBase::PostRequestTo(const RNodeInterface& aRecipient, const TSignalBase& aMessage, const TBool aRecipientIdCritical) |
375 { |
408 { |
376 aRecipient.PostMessage(TNodeCtxId(ActivityId(), iNode.Id()), aMessage); |
409 aRecipient.PostMessage(TNodeCtxId(ActivityId(), iNode.Id()), aMessage); |
377 |
410 |
378 // Provide the option for the identity of the receipient to be unimportant when the response arrives |
411 // Provide the option for the identity of the receipient to be unimportant when the response arrives |
379 iPostedToId = aRecipientIdCritical ? aRecipient.RecipientId() : TNodeId::NullId(); |
412 ClearPostedTo(); |
|
413 if (aRecipientIdCritical) |
|
414 { |
|
415 SetPostedTo(aRecipient); |
|
416 } |
380 } |
417 } |
381 |
418 |
382 //Avoid using this function, always prefer PostRequestTo(const RNodeInterface& aRecipient, const TNodeSignal& aMessage) |
419 //Avoid using this function, always prefer PostRequestTo(const RNodeInterface& aRecipient, const TNodeSignal& aMessage) |
383 EXPORT_C void CNodeActivityBase::PostRequestTo(const TNodeId& aRecipient, const TSignalBase& aMessage, const TBool aRecipientIdCritical) |
420 EXPORT_C void CNodeActivityBase::PostRequestTo(const TNodeId& aRecipient, const TSignalBase& aMessage, const TBool aRecipientIdCritical) |
384 { |
421 { |
385 RClientInterface::OpenPostMessageClose(TNodeCtxId(ActivityId(), iNode.Id()), aRecipient, aMessage); |
422 RClientInterface::OpenPostMessageClose(TNodeCtxId(ActivityId(), iNode.Id()), aRecipient, aMessage); |
386 |
423 |
387 // Provide the option for the identity of the receipient to be unimportant when the response arrives |
424 // Provide the option for the identity of the receipient to be unimportant when the response arrives |
388 iPostedToId = aRecipientIdCritical ? aRecipient : TNodeId::NullId(); |
425 ClearPostedTo(); |
|
426 if (aRecipientIdCritical) |
|
427 { |
|
428 SetPostedTo(aRecipient); |
|
429 } |
389 } |
430 } |
390 |
431 |
391 EXPORT_C TBool CNodeActivityBase::IsIdle() const |
432 EXPORT_C TBool CNodeActivityBase::IsIdle() const |
392 { |
433 { |
393 return NetStateMachine::ACore::IsIdle(); |
434 return NetStateMachine::ACore::IsIdle(); |
416 } |
457 } |
417 RemoveOriginator(n); //Do not allow ~CNodeActivityBase to post as client's might be already gone |
458 RemoveOriginator(n); //Do not allow ~CNodeActivityBase to post as client's might be already gone |
418 } |
459 } |
419 } |
460 } |
420 } |
461 } |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 //-========================================================= |
|
467 // |
|
468 //CNodeActivityBase::RPostedToNodeOrPeer |
|
469 // |
|
470 //-========================================================= |
|
471 CNodeActivityBase::RPostedToNodeOrPeer::RPostedToNodeOrPeer() |
|
472 { |
|
473 Close(); |
|
474 } |
|
475 |
|
476 void CNodeActivityBase::RPostedToNodeOrPeer::Open(const Messages::RNodeInterface& aPeer) |
|
477 { |
|
478 Close(); |
|
479 *_Peer() = const_cast<Messages::RNodeInterface*>(&aPeer); |
|
480 } |
|
481 |
|
482 void CNodeActivityBase::RPostedToNodeOrPeer::Open(const Messages::TNodeId& aNode) |
|
483 { |
|
484 __ASSERT_DEBUG(aNode.Ptr(), User::Panic(KSpecAssert_ElemMeshMachActC, 15)); |
|
485 //see Messages::TNodeId::operator= (snapping size is essential in case aNode is more than just plain TNodeId). |
|
486 *_Node() = Messages::TNodeId(); |
|
487 |
|
488 //normal assigment |
|
489 *_Node() = aNode; |
|
490 } |
|
491 void CNodeActivityBase::RPostedToNodeOrPeer::Close() |
|
492 { |
|
493 Mem::FillZ(iBuf, sizeof(iBuf)); |
|
494 } |
|
495 |
|
496 const Messages::RNodeInterface* CNodeActivityBase::RPostedToNodeOrPeer::Peer() const |
|
497 { |
|
498 return _Node()->Ptr() ? NULL : *_Peer(); |
|
499 } |
|
500 const Messages::TNodeId& CNodeActivityBase::RPostedToNodeOrPeer::NodeId() const |
|
501 { |
|
502 return (_Node()->Ptr() ? *_Node() : (*_Peer() ? (*_Peer())->RecipientId() : Messages::TNodeId::NullId())); |
|
503 } |
|
504 |
421 |
505 |
422 //-========================================================= |
506 //-========================================================= |
423 // |
507 // |
424 //CNodeRetryActivity |
508 //CNodeRetryActivity |
425 // |
509 // |