commsfwsupport/commselements/nodemessages/inc/nm_node.h
changeset 0 dfb7c4ff071f
child 18 9644881fedd0
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2006-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_NM_NODE_H
       
    23 #define SYMBIAN_NM_NODE_H
       
    24 
       
    25 #include <elements/nm_address_internal.h>
       
    26 #include <elements/nm_log.h>
       
    27 #include <elements/interfacetable.h>
       
    28 
       
    29 
       
    30 #ifdef _DEBUG
       
    31 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
       
    32 // (if it could happen through user error then you should give it an explicit, documented, category + code)
       
    33 _LIT(KSpecAssert_ElemNodeMessNodH, "ElemNodeMessNodH");
       
    34 #endif
       
    35 
       
    36 
       
    37 namespace Messages
       
    38 {
       
    39 
       
    40 //-=========================================================
       
    41 //
       
    42 //MNodeId
       
    43 //
       
    44 //-=========================================================
       
    45 class MNodeId
       
    46 	{
       
    47 public:
       
    48 	virtual const TNodeId& NodeId() const = 0;
       
    49 	};
       
    50 
       
    51 class TSignatureBase;
       
    52 class ANode : public MNodeId
       
    53 	{
       
    54 public:
       
    55     //if Received returns != KErrNone than the dispatcher will send a TError to the
       
    56     //originator of the message
       
    57 	virtual void ReceivedL(const TRuntimeCtxId& aSender, const TNodeId& aRecipient, TSignatureBase& aMessage) = 0;
       
    58 
       
    59 	IMPORT_C virtual NetInterfaces::TInterfaceControl* FetchNodeInterfaceControlL(TInt aInterfaceId);
       
    60 	IMPORT_C TAny* FetchNodeInterfaceL(TInt aInterfaceId);
       
    61 	};
       
    62 
       
    63 //-=========================================================
       
    64 //
       
    65 //ANodeId
       
    66 //
       
    67 //-=========================================================
       
    68 class ANodeId
       
    69 	{
       
    70 public:
       
    71 	const TNodeId& Id() const
       
    72 		{
       
    73 		return iNodeId;
       
    74 		}
       
    75 
       
    76 protected:
       
    77 	explicit ANodeId(ANode& aNode) :
       
    78 		iNodeId(aNode)
       
    79 		{
       
    80 		}
       
    81 
       
    82 	explicit ANodeId(TAny* aNode) :
       
    83 		iNodeId(aNode)
       
    84 		{
       
    85 		}
       
    86 
       
    87 	void UnregisterSelf()
       
    88 		{
       
    89 		iNodeId.UnregisterSelf();
       
    90 		}
       
    91 
       
    92 private:
       
    93     TNodeOid iNodeId;
       
    94 	};
       
    95 
       
    96 
       
    97 //-=========================================================
       
    98 //
       
    99 //ASimpleNodeIdBase - aggregation base class for simple nodes able to receive messages
       
   100 //
       
   101 //-=========================================================
       
   102 class ASimpleNodeIdBase : protected ANode, public ANodeId
       
   103 	{
       
   104 protected:
       
   105     explicit ASimpleNodeIdBase()
       
   106     :	ANodeId(*(static_cast<ANode*>(this)))
       
   107         {
       
   108         }
       
   109 
       
   110     IMPORT_C virtual const TNodeId& NodeId() const;
       
   111 	};
       
   112 
       
   113 //-=========================================================
       
   114 //
       
   115 //ANodeBase
       
   116 //
       
   117 //-=========================================================
       
   118 class ANodeBase : protected NetInterfaces::TInterfaceControl,
       
   119                   public ITFHIERARCHY_1(ANodeBase, ANodeBase)
       
   120 	{
       
   121 public:
       
   122 	typedef ITFHIERARCHY_1(ANodeBase, ANodeBase) TIfStaticFetcherNearestInHierarchy;
       
   123 
       
   124 public:
       
   125 	static const TInt KInterfaceId = 10005; //Normally a UID - 10005 for compatibility reasons
       
   126 	IMPORT_C void ReturnInterfacePtrL(ANodeBase*& aInterface);
       
   127 
       
   128 public:
       
   129     IMPORT_C virtual RNodeInterface* NewClientInterfaceL(const TClientType& aClientType, TAny* aClientInfo = NULL);
       
   130     IMPORT_C RNodeInterface* AddClientL(const TNodeId& aClientId, const TClientType& aClientType, TAny* aClientInfo = NULL);
       
   131     IMPORT_C void RemoveClient(RNodeInterface& aClient);
       
   132     IMPORT_C void RemoveClient(TInt aIndex);
       
   133     inline const TNodeId& Id() const
       
   134     	{
       
   135     	return iSelfInterface.RecipientId();
       
   136     	}
       
   137 
       
   138     template<class TTYPEMATCHPOLICY>
       
   139     inline TClientIter<TTYPEMATCHPOLICY> GetClientIter(const TClientType& aIncClientType, const TClientType& aExcClientType = TClientType::NullType()) const
       
   140     	{
       
   141     	return TClientIter<TTYPEMATCHPOLICY>(iClients, aIncClientType, aExcClientType);
       
   142     	}
       
   143 
       
   144 	template<class TTYPEMATCHPOLICY>
       
   145     inline RNodeInterface* GetFirstClient(const TClientType& aIncClientType, const TClientType& aExcClientType = TClientType::NullType()) const
       
   146         {
       
   147         return GetClientIter<TTYPEMATCHPOLICY>(aIncClientType, aExcClientType)[0];
       
   148         }
       
   149 
       
   150 	template<class TTYPEMATCHPOLICY>
       
   151     inline TInt PostToClients(const TRuntimeCtxId& aPostFrom, const TSignalBase& aMessage, const TClientType& aIncClientType, const TClientType& aExcClientType = TClientType::NullType(), TUint32 aFlagsToSet = 0, TUint32 aFlagsToClear = 0) const
       
   152         {
       
   153         TClientIter<TTYPEMATCHPOLICY> iter = GetClientIter<TTYPEMATCHPOLICY>(aIncClientType, aExcClientType);
       
   154         return PostToClients(iter, aPostFrom, aMessage, aFlagsToSet, aFlagsToClear);
       
   155         }
       
   156 
       
   157 	template<class TTYPEMATCHPOLICY>
       
   158     inline TUint CountClients(const TClientType& aIncClientType, const TClientType& aExcClientType = TClientType::NullType()) const
       
   159         {
       
   160         TClientIter<TTYPEMATCHPOLICY> iter = GetClientIter<TTYPEMATCHPOLICY>(aIncClientType, aExcClientType);
       
   161         return CountClients(iter);
       
   162         }
       
   163 
       
   164     IMPORT_C RNodeInterface* FindClient(const TRuntimeCtxId& aId) const;
       
   165     IMPORT_C RNodeInterface* FindClientL(const TRuntimeCtxId& aId) const; //Must not return NULL
       
   166     RNodeInterface& SelfInterface()
       
   167     	{
       
   168     	__ASSERT_DEBUG(iSelfInterface.IsOpen(), User::Panic(KSpecAssert_ElemNodeMessNodH, 1)); //TODO - add panic code
       
   169     	return iSelfInterface;
       
   170     	}
       
   171 
       
   172 protected:
       
   173 	IMPORT_C explicit ANodeBase(const TNodeId& aNodeId);
       
   174 	IMPORT_C ~ANodeBase();
       
   175 	IMPORT_C TInt PostToClients(TClientIterBase& aClientIterator, const TRuntimeCtxId& aPostFrom, const TSignalBase& aMessage, TUint32 aFlagsToSet, TUint32 aFlagsToClear) const;
       
   176 	IMPORT_C TUint CountClients(TClientIterBase& aClientIterator) const;
       
   177 	IMPORT_C RNodeInterface* DoFindClient(const TRuntimeCtxId& aId, TInt& aFoundAtIndex) const;
       
   178 
       
   179 protected:
       
   180     RPointerArray<RNodeInterface> iClients;
       
   181 //TODO[PROD] - could it be combined with the Id() somehow to optimise for size?
       
   182    	RNodeInterface iSelfInterface; //For posting messages to ourselves + necessary for requests origiated from the same node at the MM level
       
   183 	};
       
   184 
       
   185 //-=========================================================
       
   186 //
       
   187 //ANodeIdBase - aggregation base class for nodes able to receive messages
       
   188 //
       
   189 //-=========================================================
       
   190 class ANodeIdBase : protected ANode, public ANodeId, public ANodeBase
       
   191 	{
       
   192 protected:
       
   193     explicit ANodeIdBase()
       
   194     :   ANodeId(static_cast<ANode&>(*this)),
       
   195     	ANodeBase(ANodeId::Id())
       
   196         {
       
   197         }
       
   198 
       
   199     IMPORT_C virtual const TNodeId& NodeId() const;
       
   200 	};
       
   201 
       
   202 //-=========================================================
       
   203 //
       
   204 //mnode_cast
       
   205 //
       
   206 //-=========================================================
       
   207 template<class NODE>
       
   208 NODE* mnode_cast(Messages::ANode* aNode)
       
   209     {
       
   210    	return static_cast<NODE*>(aNode);
       
   211     }
       
   212 
       
   213 template <class NODE>
       
   214 NODE& mnode_cast(Messages::ANode& aNode)
       
   215     {
       
   216     return static_cast<NODE&>(aNode);
       
   217     }
       
   218 
       
   219 
       
   220 } //namespace Messages
       
   221 
       
   222 
       
   223 #endif //SYMBIAN_NM_NODE_H
       
   224