commsfwsupport/commselements/meshmachine/inc/mm_activities.h
branchRCL_3
changeset 18 9644881fedd0
parent 0 dfb7c4ff071f
child 23 cbb19216b74d
equal deleted inserted replaced
17:9ddb1d67ebaf 18:9644881fedd0
    89 @see DEFINE_CUSTOM_NODEACTIVITY
    89 @see DEFINE_CUSTOM_NODEACTIVITY
    90 */
    90 */
    91 	#define DEFINE_EXPORT_CUSTOM_NODEACTIVITY( id, name, msgtype, ctor ) \
    91 	#define DEFINE_EXPORT_CUSTOM_NODEACTIVITY( id, name, msgtype, ctor ) \
    92 		EXPORT_C const MeshMachine::TNodeActivity& name :: Self() {return iSelf;} \
    92 		EXPORT_C const MeshMachine::TNodeActivity& name :: Self() {return iSelf;} \
    93 		EXPORT_C const NetStateMachine::TStateTriple& name :: FirstTriple() {return iData[1];} \
    93 		EXPORT_C const NetStateMachine::TStateTriple& name :: FirstTriple() {return iData[1];} \
    94 		const MeshMachine::TNodeActivity name :: iSelf = {id, msgtype::EId, msgtype::ERealm, name :: iData[1], &ctor, _S8(#name)}; \
    94 		const MeshMachine::TNodeActivity name :: iSelf = {id, 0, msgtype::EId, msgtype::ERealm, name :: iData[1], (TAny*)&ctor, _S8(#name)}; \
    95 		DEFINE_TRIPLES_TABLE( name :: iData )
    95 		DEFINE_TRIPLES_TABLE( name :: iData )
    96 
    96 
    97 /**
    97 /**
    98 Define a custom node activity. A custom node activity is a node activity which defines its own
    98 Define a custom node activity. A custom node activity is a node activity which defines its own
    99 node activity class. This is used, for example, if the activity wishes to share some custom context
    99 node activity class. This is used, for example, if the activity wishes to share some custom context
   108 
   108 
   109 @see DEFINE_NODEACTIVITY
   109 @see DEFINE_NODEACTIVITY
   110 @see CNodeActivityBase
   110 @see CNodeActivityBase
   111 */
   111 */
   112 	#define DEFINE_CUSTOM_NODEACTIVITY( id, name, msgtype, ctor ) \
   112 	#define DEFINE_CUSTOM_NODEACTIVITY( id, name, msgtype, ctor ) \
   113 		const MeshMachine::TNodeActivity name :: iSelf = {id, msgtype::EId, msgtype::ERealm, name :: iData[1], &ctor, _S8(#name)}; \
   113 		const MeshMachine::TNodeActivity name :: iSelf = {id, 0, msgtype::EId, msgtype::ERealm, name :: iData[1], (TAny*)&ctor, _S8(#name)}; \
   114 		DEFINE_TRIPLES_TABLE( name :: iData )
   114 		DEFINE_TRIPLES_TABLE( name :: iData )
   115 
   115 
   116 #else
   116 #else
   117 
   117 
   118 /**
   118 /**
   126 @see DEFINE_CUSTOM_NODEACTIVITY
   126 @see DEFINE_CUSTOM_NODEACTIVITY
   127 */
   127 */
   128 	#define DEFINE_EXPORT_CUSTOM_NODEACTIVITY( id, name, msgtype, ctor ) \
   128 	#define DEFINE_EXPORT_CUSTOM_NODEACTIVITY( id, name, msgtype, ctor ) \
   129 		EXPORT_C const MeshMachine::TNodeActivity& name :: Self() {return iSelf;} \
   129 		EXPORT_C const MeshMachine::TNodeActivity& name :: Self() {return iSelf;} \
   130 		EXPORT_C const NetStateMachine::TStateTriple& name :: FirstTriple() {return iData[1];} \
   130 		EXPORT_C const NetStateMachine::TStateTriple& name :: FirstTriple() {return iData[1];} \
   131 		const MeshMachine::TNodeActivity name :: iSelf = {id, msgtype::EId, msgtype::ERealm, name :: iData[1], &ctor, NULL}; \
   131 		const MeshMachine::TNodeActivity name :: iSelf = {id, 0, msgtype::EId, msgtype::ERealm, name :: iData[1], (TAny*)&ctor, NULL}; \
   132 		DEFINE_TRIPLES_TABLE( name :: iData )
   132 		DEFINE_TRIPLES_TABLE( name :: iData )
   133 
   133 
   134 /**
   134 /**
   135 Define a custom node activity. A custom node activity is a node activity which defines its own
   135 Define a custom node activity. A custom node activity is a node activity which defines its own
   136 node activity class. This is used, for example, if the activity wishes to share some custom context
   136 node activity class. This is used, for example, if the activity wishes to share some custom context
   145 
   145 
   146 @see DEFINE_NODEACTIVITY
   146 @see DEFINE_NODEACTIVITY
   147 @see CNodeActivityBase
   147 @see CNodeActivityBase
   148 */
   148 */
   149 	#define DEFINE_CUSTOM_NODEACTIVITY( id, name, msgtype, ctor ) \
   149 	#define DEFINE_CUSTOM_NODEACTIVITY( id, name, msgtype, ctor ) \
   150 		const MeshMachine::TNodeActivity name :: iSelf = {id, msgtype::EId, msgtype::ERealm, name :: iData[1], &ctor, NULL}; \
   150 		const MeshMachine::TNodeActivity name :: iSelf = {id, 0, msgtype::EId, msgtype::ERealm, name :: iData[1], (TAny*)&ctor, NULL}; \
   151 		DEFINE_TRIPLES_TABLE( name :: iData )
   151 		DEFINE_TRIPLES_TABLE( name :: iData )
   152 
   152 
   153 #endif
   153 #endif
   154 
   154 
   155 /**
   155 /**
   415 	NULL, \
   415 	NULL, \
   416 	NULL \
   416 	NULL \
   417 	};
   417 	};
   418 
   418 
   419 /**
   419 /**
       
   420 RESERVED MACROS NOT TO BE USED.
       
   421 The following are new macro definitions allowing the context to be passed as a parameter rather than the node.
       
   422 In time the ability to pass context rather than node will be placed in the original macros. For the meantime,
       
   423 only critical commsFw activities which must have the context passed instead of the node should use these macros.
       
   424 All other activities should continue to use original macros declared above.
       
   425 */
       
   426 /**
       
   427 Declare and export a node activity.
       
   428 
       
   429 @param name  The name of the activity, which will be used to put it into the node's activity map
       
   430 
       
   431 @see DECLARE_NODEACTIVITY
       
   432 */
       
   433 #define DECLARE_RESERVED_EXPORT_NODEACTIVITY( name ) \
       
   434 	struct name \
       
   435 		{ \
       
   436 		IMPORT_C static const MeshMachine::TNodeActivity& Self(); \
       
   437 		IMPORT_C static const NetStateMachine::TStateTriple& FirstTriple(); \
       
   438 		static const MeshMachine::TNodeActivity iSelf; \
       
   439 		static const NetStateMachine::TStateTriple iData[]; \
       
   440 		};
       
   441 
       
   442 /**
       
   443 Declares a node activity. A node activity is a state machine. It contains multiple nodeactivity
       
   444 entries, which respresent the states, transitions and forks of the state machine.
       
   445 
       
   446 @param name  The name of the activity, which will be used to put it into the node's activity map
       
   447 
       
   448 @see DEFINE_NODEACTIVITY
       
   449 @see NODEACTIVITY_ENTRY
       
   450 */
       
   451 #define DECLARE_RESERVED_NODEACTIVITY( name ) \
       
   452 	struct name \
       
   453 		{ \
       
   454 		inline static const MeshMachine::TNodeActivity& Self() {return iSelf;} \
       
   455 		inline static const NetStateMachine::TStateTriple& FirstTriple() {return iData[1];} \
       
   456 		static const MeshMachine::TNodeActivity iSelf; \
       
   457 		static const NetStateMachine::TStateTriple iData[]; \
       
   458 		};
       
   459 
       
   460 #ifdef SYMBIAN_TRACE_ENABLE
       
   461 
       
   462 /**
       
   463 Define a custom node activity. A custom node activity is a node activity which defines its own
       
   464 node activity class. This is used, for example, if the activity wishes to share some custom context
       
   465 information between the states and transition in the activity.
       
   466 
       
   467 Node activity class must derive from CNodeActivityBase.
       
   468 
       
   469 @param id        Identifier for the activity
       
   470 @param name      The name of the activity
       
   471 @param msgtype   Message which will kickoff this activity
       
   472 @param ctor      Constructor for the custom activity class
       
   473 
       
   474 @see DEFINE_RESERVED_NODEACTIVITY
       
   475 @see CNodeActivityBase
       
   476 	
       
   477 */
       
   478 	#define DEFINE_RESERVED_CUSTOM_NODEACTIVITY( id, name, msgtype, ctor ) \
       
   479 		const MeshMachine::TNodeActivity name :: iSelf = {id, 1, msgtype::EId, msgtype::ERealm, name :: iData[1], (TAny*)&ctor, _S8(#name)}; \
       
   480 		DEFINE_TRIPLES_TABLE( name :: iData )
       
   481 
       
   482 #else
       
   483 
       
   484 /**
       
   485 Define and export a custom node activity.
       
   486 
       
   487 @param id        Identifier for the activity
       
   488 @param name      The name of the activity
       
   489 @param msgtype   Message which will kickoff this activity
       
   490 @param ctor      Constructor for the custom activity class
       
   491 
       
   492 @see DEFINE_RESERVED_CUSTOM_NODEACTIVITY
       
   493 */
       
   494 	#define DEFINE_RESERVED_EXPORT_CUSTOM_NODEACTIVITY( id, name, msgtype, ctor ) \
       
   495 		EXPORT_C const MeshMachine::TNodeActivity& name :: Self() {return iSelf;} \
       
   496 		EXPORT_C const NetStateMachine::TStateTriple& name :: FirstTriple() {return iData[1];} \
       
   497 		const MeshMachine::TNodeActivity name :: iSelf = {id, 1, msgtype::EId, msgtype::ERealm, name :: iData[1], (TAny*)&ctor, NULL}; \
       
   498 		DEFINE_TRIPLES_TABLE( name :: iData )
       
   499 
       
   500 /**
       
   501 Define a custom node activity. A custom node activity is a node activity which defines its own
       
   502 node activity class. This is used, for example, if the activity wishes to share some custom context
       
   503 information between the states and transition in the activity.
       
   504 
       
   505 Node activity class must derive from CNodeActivityBase.
       
   506 
       
   507 @param id        Identifier for the activity
       
   508 @param name      The name of the activity
       
   509 @param msgtype   Message which will kickoff this activity
       
   510 @param ctor      Constructor for the custom activity class
       
   511 
       
   512 @see DEFINE_RESERVED_NODEACTIVITY
       
   513 @see CNodeActivityBase
       
   514 */
       
   515 	#define DEFINE_RESERVED_CUSTOM_NODEACTIVITY( id, name, msgtype, ctor ) \
       
   516 		const MeshMachine::TNodeActivity name :: iSelf = {id, 1, msgtype::EId, msgtype::ERealm, name :: iData[1], (TAny*)&ctor, NULL}; \
       
   517 		DEFINE_TRIPLES_TABLE( name :: iData )
       
   518 
       
   519 #endif
       
   520 
       
   521 /**
       
   522 Define and declare a custom node activity
       
   523 
       
   524 @param id        Identifier for the activity
       
   525 @param name      The name of the activity
       
   526 @param msgtype   Message which will kickoff this activity
       
   527 @param ctor      Constructor for the custom activity class
       
   528 
       
   529 @see DEFINE_RESERVED_CUSTOM_NODEACTIVITY
       
   530 */
       
   531 #define DECLARE_DEFINE_RESERVED_CUSTOM_NODEACTIVITY( id, name, msgtype, ctor ) \
       
   532 	DECLARE_RESERVED_NODEACTIVITY( name ) \
       
   533 	DEFINE_RESERVED_CUSTOM_NODEACTIVITY( id, name, msgtype, ctor )
       
   534 
       
   535 /**
       
   536 END OF RESERVED MACROS
       
   537 */
       
   538 
       
   539 /**
   420 Mark the end of an activity map. This macro should be used for an activity map based
   540 Mark the end of an activity map. This macro should be used for an activity map based
   421 on other activity maps.
   541 on other activity maps.
   422 
   542 
   423 @param name_space The namespace of the base map
   543 @param name_space The namespace of the base map
   424 @param base_map   The name of the base map
   544 @param base_map   The name of the base map
   430 	(MeshMachine::TNodeActivityMap::TStaticNodeActivity)&name_space::base_map::Self \
   550 	(MeshMachine::TNodeActivityMap::TStaticNodeActivity)&name_space::base_map::Self \
   431 	};
   551 	};
   432 
   552 
   433 namespace MeshMachine
   553 namespace MeshMachine
   434 {
   554 {
       
   555 
   435 /**
   556 /**
   436 Base class for all node activity objects. Non custom node activities will use this by default.
   557 Base class for all node activity objects. Non custom node activities will use this by default.
   437 **/
   558 **/
   438 class CNodeActivityBase : public CBase,
   559 class CNodeActivityBase : public CBase,
   439                           public NetInterfaces::AApiExtBase,
   560                           public NetInterfaces::AApiExtBase,
   514 
   635 
   515 	/**
   636 	/**
   516 	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.
   517 	   @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
   518 	*/
   639 	*/
   519 	const Messages::TNodeId PostedToId() const
   640 	IMPORT_C const Messages::TNodeId& PostedToNodeId() const;
   520 		{
   641 	
   521 		return iPostedToId;
   642     /**
   522 		}
   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;
   523 
   647 
   524 	/**
   648 	/**
   525 	Get the id of the message that started this activity.
   649 	Get the id of the message that started this activity.
   526 	   @return Message id of message that kicked off this activity
   650 	   @return Message id of message that kicked off this activity
   527 	*/
   651 	*/
   574 	   Manually set the postedTo id
   698 	   Manually set the postedTo id
   575 
   699 
   576 	   @param aNodeId Node id to set the postedTo id to
   700 	   @param aNodeId Node id to set the postedTo id to
   577 	*/
   701 	*/
   578 	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);
   579 
   710 
   580 	/**
   711 	/**
   581 	   Clear the postedTo id
   712 	   Clear the postedTo id
   582 	*/
   713 	*/
   583 	IMPORT_C void ClearPostedTo();
   714 	IMPORT_C void ClearPostedTo();
   807 	                    //iError must be cleared before the activity goes out of scope
   938 	                    //iError must be cleared before the activity goes out of scope
   808 	                    //to indicate the error has been handled.
   939 	                    //to indicate the error has been handled.
   809 
   940 
   810 	const TNodeActivity& iActivitySig;
   941 	const TNodeActivity& iActivitySig;
   811 
   942 
   812 	// Last node a message was sent to
   943 	class RPostedToNodeOrPeer
   813 	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;
   814 	};
   997 	};
   815 
   998 
   816 
   999 
   817 /**
  1000 /**
   818 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.
   844 	For use by custom activity NewLs to generate the unique part of the activity id.
  1027 	For use by custom activity NewLs to generate the unique part of the activity id.
   845 	@param aActivitySig Context information about how the activity is to be started
  1028 	@param aActivitySig Context information about how the activity is to be started
   846 	@param aNode        The node to which this activity will belong.
  1029 	@param aNode        The node to which this activity will belong.
   847 	@return Generated unique component of activity id
  1030 	@return Generated unique component of activity id
   848 	*/
  1031 	*/
   849 	IMPORT_C static TUint GetNextActivityCountL( const TNodeActivity& aActivitySig, const AMMNodeBase& aNode );
  1032 	static TUint GetNextActivityCountL( const TNodeActivity& aActivitySig, const AMMNodeBase& aNode );
       
  1033 	/**
       
  1034 	For use by custom activity News to generate the unique part of the activity id.
       
  1035 	@param aActivitySig Context information about how the activity is to be started
       
  1036 	@param aNode        The node to which this activity will belong.
       
  1037 	@return Generated unique component of activity id
       
  1038 	*/
       
  1039 	IMPORT_C static TUint GetNextActivityCount( const TNodeActivity& aActivitySig, const AMMNodeBase& aNode );
   850 
  1040 
   851 	/**
  1041 	/**
   852 	Constructor for CNodeParallelActivityBase
  1042 	Constructor for CNodeParallelActivityBase
   853 	@param aActivitySig Context information about how the activity is to be started
  1043 	@param aActivitySig Context information about how the activity is to be started
   854 	@param aNode        The node to which this activity will belong.
  1044 	@param aNode        The node to which this activity will belong.
  1385 	Private NewL with no implementation to hide the CNodeActivityBase::NewL
  1575 	Private NewL with no implementation to hide the CNodeActivityBase::NewL
  1386 	Creation of preallocated activities doesn't fail and hence a non-leaving ::New should be used instead*/
  1576 	Creation of preallocated activities doesn't fail and hence a non-leaving ::New should be used instead*/
  1387     static MeshMachine::CNodeActivityBase* NewL(const MeshMachine::TNodeActivity& aActivitySig, MeshMachine::AMMNodeBase& aNode);
  1577     static MeshMachine::CNodeActivityBase* NewL(const MeshMachine::TNodeActivity& aActivitySig, MeshMachine::AMMNodeBase& aNode);
  1388 	};
  1578 	};
  1389 
  1579 
       
  1580 
       
  1581 inline TUint CNodeParallelActivityBase::GetNextActivityCountL( const TNodeActivity& aActivitySig, const AMMNodeBase& aNode )
       
  1582     {
       
  1583     //Historical. Method ceased to leave, but must keep the old, L-ending overload.
       
  1584     return GetNextActivityCount(aActivitySig, aNode);
       
  1585     }
       
  1586 
  1390 } //namespace MeshMachine
  1587 } //namespace MeshMachine
  1391 
  1588 
  1392 #endif //SYMBIAN_MM_ACTIVITIES_H
  1589 #endif //SYMBIAN_MM_ACTIVITIES_H
  1393 
  1590