commsfwsupport/commselements/meshmachine/inc/mm_activities.h
changeset 32 d2396c80c344
parent 30 df67dc5d759e
child 68 5da8188e392b
equal deleted inserted replaced
31:f5b12b673c07 32:d2396c80c344
   635 
   635 
   636 	/**
   636 	/**
   637 	Get the id of the node that the last request from this activity was sent to.
   637 	Get the id of the node that the last request from this activity was sent to.
   638 	   @return Node id of the last node the activity has posted a request to
   638 	   @return Node id of the last node the activity has posted a request to
   639 	*/
   639 	*/
   640 	const Messages::TNodeId PostedToId() const
   640 	IMPORT_C const Messages::TNodeId& PostedToNodeId() const;
   641 		{
   641 	
   642 		return iPostedToId;
   642     /**
   643 		}
   643     Get the id of the node that the last request from this activity was sent to.
       
   644        @return Node id of the last node the activity has posted a request to
       
   645     */
       
   646 	IMPORT_C const Messages::RNodeInterface* PostedToPeer() const;
   644 
   647 
   645 	/**
   648 	/**
   646 	Get the id of the message that started this activity.
   649 	Get the id of the message that started this activity.
   647 	   @return Message id of message that kicked off this activity
   650 	   @return Message id of message that kicked off this activity
   648 	*/
   651 	*/
   695 	   Manually set the postedTo id
   698 	   Manually set the postedTo id
   696 
   699 
   697 	   @param aNodeId Node id to set the postedTo id to
   700 	   @param aNodeId Node id to set the postedTo id to
   698 	*/
   701 	*/
   699 	IMPORT_C void SetPostedTo(const Messages::TNodeId& aNodeId);
   702 	IMPORT_C void SetPostedTo(const Messages::TNodeId& aNodeId);
       
   703 	
       
   704     /**
       
   705        Manually set the postedTo id
       
   706 
       
   707        @param aNodeId Node id to set the postedTo id to
       
   708     */
       
   709 	IMPORT_C void SetPostedTo(const Messages::RNodeInterface& aRecipient);
   700 
   710 
   701 	/**
   711 	/**
   702 	   Clear the postedTo id
   712 	   Clear the postedTo id
   703 	*/
   713 	*/
   704 	IMPORT_C void ClearPostedTo();
   714 	IMPORT_C void ClearPostedTo();
   928 	                    //iError must be cleared before the activity goes out of scope
   938 	                    //iError must be cleared before the activity goes out of scope
   929 	                    //to indicate the error has been handled.
   939 	                    //to indicate the error has been handled.
   930 
   940 
   931 	const TNodeActivity& iActivitySig;
   941 	const TNodeActivity& iActivitySig;
   932 
   942 
   933 	// Last node a message was sent to
   943 	class RPostedToNodeOrPeer
   934 	Messages::TNodeId iPostedToId;
   944 	/*
       
   945 	 * Class is used to store the recipient of the last request sent from the 'this' 
       
   946 	 * (the activity). This recipient can be represented either by its TNodeId address 
       
   947 	 * or, if it's a peer of the local node, by RNodeInterface. 
       
   948      * The implementation may seem awkward or overengineered. This is to protect binary
       
   949      * compatibility (it used to be TNodeId here and sizeof TNodeId was all there was at hand).
       
   950      * 
       
   951      * Rules of the game are that RPostedToNodeOrPeer:iBuf is a shared dwelling for either:
       
   952      * - address of an RNodeInterface (in case posted to is a peer)
       
   953      * - TNodeId (in case posted to is not a peer)
       
   954      * Inspecting the content of iBuf and the assumptions around it are a little fragile 
       
   955      * (based on TNodeId class layout a bit), so the code must be viligent. 
       
   956      * _Node and _Peer perform arbitral happy conversion, so there can be 3 reasons why _Node()->Ptr() is NULL:
       
   957      * (1) iBuf stores a 4 byte ptr to RNodeInterface and what Ptr normally returns is beyond these 4 bytes in a land hopefully zeroed by ::Close
       
   958      * (2) iBuf stores nothing. 
       
   959      * (3) iBuf stores a TNodeId pointing a NULL node (effectivelly TNodeId::NullId()). (3) is only theoretical as Open(TNodeId) prevens Ptr be NULL
       
   960      * Therefore it is safe to assume that if Ptr() is NULL, it is either a valid pointer to a peer or NULL.
       
   961      * Happily _Peer() will return that pointer or NULL respectivelly.* 
       
   962 	 */
       
   963 	    {
       
   964 	private:
       
   965 	    typedef Messages::RNodeInterface* TPeerType;
       
   966     public:
       
   967 	    RPostedToNodeOrPeer();
       
   968 	    void Open(const Messages::RNodeInterface& aPeer);
       
   969 	    void Open(const Messages::TNodeId& aNode);
       
   970 	    void Close();
       
   971 	    
       
   972 	    const Messages::RNodeInterface* Peer() const;
       
   973 	    const Messages::TNodeId& NodeId() const;
       
   974 	    
       
   975 	private:
       
   976 	    TPeerType* _Peer() 
       
   977 	        {
       
   978             return reinterpret_cast<TPeerType*>(&iBuf[0]);
       
   979 	        }
       
   980         
       
   981 	    const TPeerType* _Peer() const 
       
   982             {
       
   983             return reinterpret_cast<const TPeerType*>(&iBuf[0]);
       
   984             }	    
       
   985 	    
       
   986 	    Messages::TNodeId* _Node()
       
   987 	        {
       
   988 	        return reinterpret_cast<Messages::TNodeId*>(&iBuf[0]);
       
   989 	        }
       
   990 	    
       
   991         const Messages::TNodeId* _Node() const
       
   992             {
       
   993             return reinterpret_cast<const Messages::TNodeId*>(&iBuf[0]);
       
   994             }
       
   995         TUint8 iBuf[__Align8(sizeof(Messages::TNodeId))];	    
       
   996 	    } iPostedToId;
   935 	};
   997 	};
   936 
   998 
   937 
   999 
   938 /**
  1000 /**
   939 Activity type that generates a unique activity id every time it is instantiated.
  1001 Activity type that generates a unique activity id every time it is instantiated.