diff -r 000000000000 -r dfb7c4ff071f commsfwsupport/commselements/nodemessages/inc/nm_node.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/commsfwsupport/commselements/nodemessages/inc/nm_node.h Thu Dec 17 09:22:25 2009 +0200 @@ -0,0 +1,224 @@ +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + +/** + @file + @publishedPartner + @released +*/ + +#ifndef SYMBIAN_NM_NODE_H +#define SYMBIAN_NM_NODE_H + +#include +#include +#include + + +#ifdef _DEBUG +// Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module +// (if it could happen through user error then you should give it an explicit, documented, category + code) +_LIT(KSpecAssert_ElemNodeMessNodH, "ElemNodeMessNodH"); +#endif + + +namespace Messages +{ + +//-========================================================= +// +//MNodeId +// +//-========================================================= +class MNodeId + { +public: + virtual const TNodeId& NodeId() const = 0; + }; + +class TSignatureBase; +class ANode : public MNodeId + { +public: + //if Received returns != KErrNone than the dispatcher will send a TError to the + //originator of the message + virtual void ReceivedL(const TRuntimeCtxId& aSender, const TNodeId& aRecipient, TSignatureBase& aMessage) = 0; + + IMPORT_C virtual NetInterfaces::TInterfaceControl* FetchNodeInterfaceControlL(TInt aInterfaceId); + IMPORT_C TAny* FetchNodeInterfaceL(TInt aInterfaceId); + }; + +//-========================================================= +// +//ANodeId +// +//-========================================================= +class ANodeId + { +public: + const TNodeId& Id() const + { + return iNodeId; + } + +protected: + explicit ANodeId(ANode& aNode) : + iNodeId(aNode) + { + } + + explicit ANodeId(TAny* aNode) : + iNodeId(aNode) + { + } + + void UnregisterSelf() + { + iNodeId.UnregisterSelf(); + } + +private: + TNodeOid iNodeId; + }; + + +//-========================================================= +// +//ASimpleNodeIdBase - aggregation base class for simple nodes able to receive messages +// +//-========================================================= +class ASimpleNodeIdBase : protected ANode, public ANodeId + { +protected: + explicit ASimpleNodeIdBase() + : ANodeId(*(static_cast(this))) + { + } + + IMPORT_C virtual const TNodeId& NodeId() const; + }; + +//-========================================================= +// +//ANodeBase +// +//-========================================================= +class ANodeBase : protected NetInterfaces::TInterfaceControl, + public ITFHIERARCHY_1(ANodeBase, ANodeBase) + { +public: + typedef ITFHIERARCHY_1(ANodeBase, ANodeBase) TIfStaticFetcherNearestInHierarchy; + +public: + static const TInt KInterfaceId = 10005; //Normally a UID - 10005 for compatibility reasons + IMPORT_C void ReturnInterfacePtrL(ANodeBase*& aInterface); + +public: + IMPORT_C virtual RNodeInterface* NewClientInterfaceL(const TClientType& aClientType, TAny* aClientInfo = NULL); + IMPORT_C RNodeInterface* AddClientL(const TNodeId& aClientId, const TClientType& aClientType, TAny* aClientInfo = NULL); + IMPORT_C void RemoveClient(RNodeInterface& aClient); + IMPORT_C void RemoveClient(TInt aIndex); + inline const TNodeId& Id() const + { + return iSelfInterface.RecipientId(); + } + + template + inline TClientIter GetClientIter(const TClientType& aIncClientType, const TClientType& aExcClientType = TClientType::NullType()) const + { + return TClientIter(iClients, aIncClientType, aExcClientType); + } + + template + inline RNodeInterface* GetFirstClient(const TClientType& aIncClientType, const TClientType& aExcClientType = TClientType::NullType()) const + { + return GetClientIter(aIncClientType, aExcClientType)[0]; + } + + template + inline TInt PostToClients(const TRuntimeCtxId& aPostFrom, const TSignalBase& aMessage, const TClientType& aIncClientType, const TClientType& aExcClientType = TClientType::NullType(), TUint32 aFlagsToSet = 0, TUint32 aFlagsToClear = 0) const + { + TClientIter iter = GetClientIter(aIncClientType, aExcClientType); + return PostToClients(iter, aPostFrom, aMessage, aFlagsToSet, aFlagsToClear); + } + + template + inline TUint CountClients(const TClientType& aIncClientType, const TClientType& aExcClientType = TClientType::NullType()) const + { + TClientIter iter = GetClientIter(aIncClientType, aExcClientType); + return CountClients(iter); + } + + IMPORT_C RNodeInterface* FindClient(const TRuntimeCtxId& aId) const; + IMPORT_C RNodeInterface* FindClientL(const TRuntimeCtxId& aId) const; //Must not return NULL + RNodeInterface& SelfInterface() + { + __ASSERT_DEBUG(iSelfInterface.IsOpen(), User::Panic(KSpecAssert_ElemNodeMessNodH, 1)); //TODO - add panic code + return iSelfInterface; + } + +protected: + IMPORT_C explicit ANodeBase(const TNodeId& aNodeId); + IMPORT_C ~ANodeBase(); + IMPORT_C TInt PostToClients(TClientIterBase& aClientIterator, const TRuntimeCtxId& aPostFrom, const TSignalBase& aMessage, TUint32 aFlagsToSet, TUint32 aFlagsToClear) const; + IMPORT_C TUint CountClients(TClientIterBase& aClientIterator) const; + IMPORT_C RNodeInterface* DoFindClient(const TRuntimeCtxId& aId, TInt& aFoundAtIndex) const; + +protected: + RPointerArray iClients; +//TODO[PROD] - could it be combined with the Id() somehow to optimise for size? + RNodeInterface iSelfInterface; //For posting messages to ourselves + necessary for requests origiated from the same node at the MM level + }; + +//-========================================================= +// +//ANodeIdBase - aggregation base class for nodes able to receive messages +// +//-========================================================= +class ANodeIdBase : protected ANode, public ANodeId, public ANodeBase + { +protected: + explicit ANodeIdBase() + : ANodeId(static_cast(*this)), + ANodeBase(ANodeId::Id()) + { + } + + IMPORT_C virtual const TNodeId& NodeId() const; + }; + +//-========================================================= +// +//mnode_cast +// +//-========================================================= +template +NODE* mnode_cast(Messages::ANode* aNode) + { + return static_cast(aNode); + } + +template +NODE& mnode_cast(Messages::ANode& aNode) + { + return static_cast(aNode); + } + + +} //namespace Messages + + +#endif //SYMBIAN_NM_NODE_H +