commsfwsupport/commselements/meshmachine/inc/mm_node.h
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file 
       
    18  @publishedPartner
       
    19  @released
       
    20 */
       
    21 
       
    22 #ifndef SYMBIAN_MM_NODE_H
       
    23 #define SYMBIAN_MM_NODE_H
       
    24 
       
    25 #include <elements/nm_node.h>
       
    26 #include <elements/sm_core.h>
       
    27 #include <elements/nm_signatures.h>
       
    28 
       
    29 namespace MeshMachine
       
    30 {
       
    31 
       
    32 static const TInt KUseDefaultPreallocatedSize = -1;
       
    33 
       
    34 class CNodeActivityBase;
       
    35 struct TNodeActivity;
       
    36 struct TNodeActivityMap;
       
    37 class TNodeContextBase;
       
    38 
       
    39 //-=========================================================
       
    40 //
       
    41 //AMMNodeBase
       
    42 //
       
    43 //-=========================================================
       
    44 class AMMNodeBase : public Messages::ANodeBase,
       
    45                     public ITFHIERARCHY_LINK_1(AMMNodeBase, Messages::ANodeBase, AMMNodeBase)
       
    46 /**
       
    47 @internalTechnology
       
    48 */
       
    49 	{
       
    50 	friend class CNodeActivityBase;
       
    51 	friend class AContextStore; //to access HandleMessageReturnValue from Retry
       
    52 	friend class AActivitySemaphore; //to access HandleMessageReturnValue from Retry
       
    53 
       
    54 public:
       
    55 	typedef ITFHIERARCHY_LINK_1(AMMNodeBase, Messages::ANodeBase, AMMNodeBase) TIfStaticFetcherNearestInHierarchy;
       
    56 
       
    57     static const TInt KInterfaceId = 0x102864E5;
       
    58 
       
    59 	/**	@internalAll */
       
    60     IMPORT_C void ReturnInterfacePtrL(AMMNodeBase*& aInterface);
       
    61 
       
    62 protected:
       
    63 	IMPORT_C explicit AMMNodeBase(const TNodeActivityMap& aActivityMap, const Messages::TNodeId& aNodeId);
       
    64 	IMPORT_C ~AMMNodeBase();
       
    65     IMPORT_C void ConstructL(TInt aSize = KUseDefaultPreallocatedSize); //When KUseDefaultPreallocatedSize, KDefaultMaxPreallocatedActivitySize will be used
       
    66 
       
    67 public:
       
    68 	/**	@internalAll */
       
    69 	IMPORT_C void Received(const Messages::TNodeSignal::TMessageId aNoPeerMsgIds[], TNodeContextBase& aContext);
       
    70 
       
    71 	/**
       
    72 	This function may delete the object pointed to by aCurrentActivity. So don't use it after this function is called.
       
    73 	@internalAll
       
    74 	*/
       
    75 	IMPORT_C void PostReceived(TNodeContextBase& aContext);
       
    76 
       
    77 	/**	@publishedPartner @released */
       
    78 	IMPORT_C void RemoveClient(const Messages::TRuntimeCtxId& aClientId, TNodeContextBase& aContext);
       
    79 
       
    80 public:
       
    81 	/**	@internalAll */
       
    82 	IMPORT_C void RemoveClient(const Messages::TRuntimeCtxId& aClientId);
       
    83 
       
    84 	/**	@publishedPartner @released */
       
    85     IMPORT_C TUint CountActivities(TUint8 aActivitySigId) const; //Counts only active activities (not idle)
       
    86 	/**	@publishedPartner @released */
       
    87     IMPORT_C TUint CountAllActivities(TUint8 aActivitySigId) const;  //Counts all activities with the specified sig id
       
    88 	/**	@publishedPartner @released */
       
    89     IMPORT_C TUint CountAllActivities() const; //Count all activities
       
    90 	/**	@publishedPartner @released */
       
    91 	IMPORT_C CNodeActivityBase* FindActivityById(TUint aActivityId) const;
       
    92 
       
    93     /**	@internalAll */
       
    94     IMPORT_C const RPointerArray<CNodeActivityBase>& Activities() const;
       
    95 	/**	@internalAll */
       
    96     IMPORT_C CNodeActivityBase* FindAddressedActivity(const TNodeContextBase& aContext) const;
       
    97 	/**	@internalAll */
       
    98 	IMPORT_C CNodeActivityBase* FindActivityOriginatedBy(const Messages::TRuntimeCtxId& aPeerId);
       
    99 	/**	@internalAll */
       
   100     IMPORT_C void AbortActivitiesOriginatedBy(TNodeContextBase& aContext, const Messages::TNodeId& aNodeId = Messages::TNodeId::NullId(), TBool aIsNodeBeingDestroyed = EFalse);
       
   101 
       
   102 protected:
       
   103 	/**	@internalAll */
       
   104 	IMPORT_C virtual void HandlePassThroughMessage(TNodeContextBase& aContext);
       
   105 	/**	@internalAll */
       
   106 	IMPORT_C virtual void HandleMessageReturnValue(TNodeContextBase& aContext);
       
   107 	/**	@internalAll */	
       
   108 	void SignalActivities();
       
   109 
       
   110 private:
       
   111 	/**	@internalAll */
       
   112     void StartNewActivitiesL(TNodeContextBase& aContext, CNodeActivityBase* aSendersActivity);
       
   113 	/**	@internalAll */
       
   114     void StartActivityL(TNodeContextBase& aContext, const TNodeActivity& aActivitySig, const NetStateMachine::TStateTriple& aFirst);
       
   115 	/**	@internalAll */
       
   116     TBool Accept(TNodeContextBase& aContext, CNodeActivityBase*& aFoundActivity);
       
   117 	/**	@internalAll */
       
   118     TAny* BorrowPreallocatedSpace(TUint aSize);
       
   119 	/**	@internalAll */
       
   120     void ReturnPreallocatedSpace(TAny* aSpace);
       
   121 
       
   122 protected:
       
   123 	/**	@internalAll */
       
   124 	const TNodeActivityMap& iActivityMap;
       
   125 
       
   126 private:
       
   127 	/**	@internalAll */
       
   128 	RPointerArray<CNodeActivityBase> iActivities;
       
   129 
       
   130 	//-===============================================================================
       
   131     //PREALLOCATION:
       
   132     //This facility is designed to assist in securing sensitive behaviour that
       
   133     //shouldn't fail and/but needs to allocate memory (usually cleanup tasks).
       
   134     //
       
   135     //The memory is allocated using User::AllocZL(aSize), the same way the CBase new
       
   136     //operator does it. CBase doesn't override delete operator and hence makes the same
       
   137     //assumption we make herein.
       
   138     //-===============================================================================
       
   139 	/**	@internalAll */
       
   140 	void PreallocateSpaceL(TUint aSize); //Utility function
       
   141 	TUint MaxPreallocatedActivityCount() const;
       
   142 	TAny* GetPreallocatedCell(TUint aIndex) const;
       
   143 	/**	@internalAll */
       
   144 	TAny* iPreallocatedSpace;
       
   145 	};
       
   146 
       
   147 //-=========================================================
       
   148 //
       
   149 //AMMNodeIdBase
       
   150 //
       
   151 //-=========================================================
       
   152 
       
   153 class AMMNodeIdBase : protected Messages::ANode, public Messages::ANodeId, public AMMNodeBase
       
   154 /**
       
   155 @publishedPartner
       
   156 @released
       
   157 
       
   158 Aggregation base class for mesh-machine based nodes.
       
   159 */
       
   160 	{
       
   161 protected:
       
   162     explicit AMMNodeIdBase(const TNodeActivityMap& aActivityMap)
       
   163     :	Messages::ANodeId(static_cast<Messages::ANode&>(*this)),
       
   164     	AMMNodeBase(aActivityMap, Messages::ANodeId::Id())
       
   165         {
       
   166         }
       
   167 
       
   168     IMPORT_C virtual const Messages::TNodeId& NodeId() const;
       
   169 public:
       
   170 	//this needs to be here provisionally - subclasses complain about imbiguous access to ::Id()
       
   171 	const Messages::TNodeId& Id() const
       
   172 		{
       
   173 		return NodeId();	
       
   174 		}    
       
   175 	};
       
   176 
       
   177 } //namespace MeshMachine
       
   178 
       
   179 #endif //SYMBIAN_NM_NODE_H
       
   180