datacommsserver/esockserver/inc/ss_dispatchers.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  @internalTechnology
       
    19 */
       
    20 
       
    21 #ifndef SS_DISPATCHERS_H
       
    22 #define SS_DISPATCHERS_H
       
    23 
       
    24 #include <elements/nm_node.h>
       
    25 #include <comms-infras/ss_nodeinterfaces.h>
       
    26 #include <comms-infras/ss_common.h>
       
    27 
       
    28 namespace ESock
       
    29 {
       
    30 
       
    31 //in-process,in/cross-thread node extension message
       
    32 struct TCFItfExt
       
    33     {
       
    34 protected:
       
    35 	explicit TCFItfExt()
       
    36 		{
       
    37 		}
       
    38 
       
    39 	IMPORT_C void ForwardMessageL(const Messages::TRuntimeCtxId& aSender,
       
    40 	                              Messages::TSignalBase& aMessage,
       
    41 	                              Messages::ANode& aNode,
       
    42 	                              const Messages::TClientType& aClientType,
       
    43 	                              const Messages::TClientType& aClientTypeExclude = Messages::TClientType(0, Messages::TClientType::ELeaving));
       
    44     IMPORT_C TAny* FetchInterfaceL(Messages::ANode& aNode, TInt aInterface);
       
    45 	IMPORT_C TAny* FetchInterfaceOrForwardMsgL(const Messages::TRuntimeCtxId& aSender,
       
    46 	                                           Messages::TSignalBase& aMessage,
       
    47 	                                           Messages::ANode& aNode, TInt aInterface,
       
    48 	                                           const Messages::TClientType& aClientType,
       
    49 	                                           const Messages::TClientType& aClientTypeExclude = Messages::TClientType(0, Messages::TClientType::ELeaving));
       
    50 	IMPORT_C NetInterfaces::TInterfaceControl* FetchInterfaceControlOrForwardMsgL(const Messages::TRuntimeCtxId& aSender,
       
    51 	                                                                              Messages::TSignalBase& aMessage,
       
    52 	                                                                              Messages::ANode& aNode,
       
    53 																				  TInt aInterface,
       
    54 									  		   		  							  const Messages::TClientType& aClientType,
       
    55 									  		   		  							  const Messages::TClientType& aClientTypeExclude = Messages::TClientType(0, Messages::TClientType::ELeaving));
       
    56     };
       
    57 
       
    58 template <TUint32 CLIENT_TYPE, TUint32 CLIENT_FLAGS = 0, TUint32 CLIENT_TYPE_EXCLUDE = 0, TUint32 CLIENT_FLAGS_EXCLUDE = Messages::TClientType::ELeaving>
       
    59 struct TCFClientItfExt : protected TCFItfExt
       
    60     {
       
    61 protected:
       
    62 	explicit TCFClientItfExt()
       
    63 	:	TCFItfExt()
       
    64 		{
       
    65 		}
       
    66 
       
    67 	inline void ForwardMessageL(const Messages::TRuntimeCtxId& aSender, Messages::TSignalBase& aMessage, Messages::ANode& aNode)
       
    68 		{
       
    69 		TCFItfExt::ForwardMessageL(aSender, aMessage, aNode, Messages::TClientType(CLIENT_TYPE,CLIENT_FLAGS), Messages::TClientType(CLIENT_TYPE_EXCLUDE,CLIENT_FLAGS_EXCLUDE));
       
    70 		}
       
    71 
       
    72 	inline TAny* FetchInterfaceOrForwardMsgL(const Messages::TRuntimeCtxId& aSender, Messages::TSignalBase& aMessage, Messages::ANode& aNode, TInt aInterface)
       
    73 		{
       
    74 		return TCFItfExt::FetchInterfaceOrForwardMsgL(aSender, aMessage, aNode, aInterface, Messages::TClientType(CLIENT_TYPE,CLIENT_FLAGS), Messages::TClientType(CLIENT_TYPE_EXCLUDE,CLIENT_FLAGS_EXCLUDE));
       
    75 		}
       
    76 
       
    77 	inline NetInterfaces::TInterfaceControl* FetchInterfaceControlOrForwardMsgL(const Messages::TRuntimeCtxId& aSender, Messages::TSignalBase& aMessage, Messages::ANode& aNode, TInt aInterface)
       
    78 		{
       
    79 		return TCFItfExt::FetchInterfaceControlOrForwardMsgL(aSender, aMessage, aNode, aInterface, Messages::TClientType(CLIENT_TYPE,CLIENT_FLAGS), Messages::TClientType(CLIENT_TYPE_EXCLUDE,CLIENT_FLAGS_EXCLUDE));
       
    80 		}
       
    81     };
       
    82 
       
    83 //TCFClientItfExt and its hierarchy is supposed to have 0 lenght (when merged into a hierarchy that is).
       
    84 //There are several functions taking (for example) TCFSigRMessage2Ext as Messages::TSignalBase
       
    85 //which explicitly work with this assumtion. If considering adding data members to TCFClientItfExt
       
    86 //hierarchy, find and fix all of these functions.
       
    87 class TCFClientItfExtSizeTest : public Messages::TSignalBase, public TCFItfExt {};
       
    88 __ASSERT_COMPILE(sizeof(TCFClientItfExtSizeTest)==sizeof(Messages::TSignalBase));
       
    89 
       
    90 /**
       
    91 	Template to assemble a function dispatching message suitable for use as a MESSAGE
       
    92 	template parameter of the TCFMessageDispatcher template.
       
    93 */
       
    94 template <TInt INTERFACE_ID, class INTERFACE, typename PARAM_STRUCT,
       
    95           TUint32 CLIENT_TYPE, TUint32 CLIENT_FLAGS = 0, TUint32 CLIENT_TYPE_EXCLUDE = 0, TUint32 CLIENT_FLAGS_EXCLUDE = 0>
       
    96 struct TCFFunctionDispatcher : public TCFClientItfExt<CLIENT_TYPE, CLIENT_FLAGS, CLIENT_TYPE_EXCLUDE, CLIENT_FLAGS_EXCLUDE>
       
    97     {
       
    98 protected:
       
    99     typedef void (INTERFACE::*TFunction)(PARAM_STRUCT&);
       
   100 
       
   101 public:
       
   102     explicit TCFFunctionDispatcher()
       
   103     :	TCFClientItfExt<CLIENT_TYPE, CLIENT_FLAGS, CLIENT_TYPE_EXCLUDE, CLIENT_FLAGS_EXCLUDE>()
       
   104         {
       
   105         }
       
   106 
       
   107 	explicit TCFFunctionDispatcher(TFunction aFunction, const PARAM_STRUCT& aParams)
       
   108 	:	TCFClientItfExt<CLIENT_TYPE, CLIENT_FLAGS, CLIENT_TYPE_EXCLUDE, CLIENT_FLAGS_EXCLUDE>(),
       
   109 		iParam(aParams),
       
   110 		iFunction(aFunction)
       
   111 		{
       
   112 		}
       
   113 
       
   114 protected:
       
   115 	void DispatchL(Messages::TSignalBase& aThisDispatcher, Messages::ANode* aItf, TPtrC8& /* aParams */)
       
   116         {
       
   117         INTERFACE* itf = reinterpret_cast<INTERFACE*>(TCFClientItfExt<CLIENT_TYPE, CLIENT_FLAGS, CLIENT_TYPE_EXCLUDE, CLIENT_FLAGS_EXCLUDE>::FetchInterfaceOrForwardMsgL(aThisDispatcher, *aItf, INTERFACE_ID));
       
   118         if (itf)
       
   119             {
       
   120             (itf->*iFunction)(iParam);
       
   121             }
       
   122         }
       
   123     PARAM_STRUCT iParam;
       
   124     TFunction iFunction;
       
   125     };
       
   126 
       
   127 /* Example of using TCFFunctionDispatcher in combination with TCFMessageDispatcher
       
   128 Interface Id must be in api_ext_list.h enum TInt.
       
   129 
       
   130 Let's assume it's EApiExtSomeInterface
       
   131 
       
   132 *.h file would contain
       
   133 
       
   134 // The extension interface declaration (functions must follow the signature pattern given by TCFFunctionDispatcher)
       
   135 class MSomeExtensionInterface
       
   136     {
       
   137     public:
       
   138     virtual Fn1(TSomeParametersNotMemoryAllocated& aParam) = 0;
       
   139     virtual Fn2(TSomeOtherParametersNotMemoryAllocated& aParam) = 0;
       
   140     };
       
   141 
       
   142 // The individual structures
       
   143 struct TSomeParametersNotMemoryAllocated
       
   144     {
       
   145     TUint iInt;
       
   146     TBuf8<20> iBuf;
       
   147     };
       
   148 
       
   149 struct TSomeOtherParametersNotMemoryAllocated
       
   150     {
       
   151     };
       
   152 
       
   153 // Declaration of dispatchers
       
   154 typedef TCFFunctionDispatcher<EApiExtSomeInterface, MSomeExtensionInterface, TSomeParametersNotMemoryAllocated,
       
   155                         RNodeInterface::ECtrl> TFDSomeParametersNotMemoryAllocated;
       
   156 
       
   157 typedef TCFMessageDispatcher<ESomeMessageId, TFDSomeParametersNotMemoryAllocated, Messages::ANode> TMDSomeParametersNotMemoryAllocated;
       
   158 
       
   159 // There is a way how to get ESomeMessageId in case it needs to be unique amongst other messages
       
   160 
       
   161 ****.cpp file would contain
       
   162 
       
   163 // The interface Uid
       
   164 const TInt KSomeExtensionInterfaceUid = 0xDEADBEEF
       
   165 
       
   166 // The interface messages implementation table
       
   167 const TImplementationProxy SomeParametersImplementationTable[] =
       
   168 	{
       
   169 	MVIP_CTR_ENTRY(ESomeParam1, TMDSomeParametersNotMemoryAllocated),
       
   170 	MVIP_CTR_ENTRY(ESomeParam2, TMDSomeOtherParametersNotMemoryAllocated),
       
   171 	};
       
   172 
       
   173 // Constructors
       
   174 DEFINE_MVIP_CTR(TMDSomeParametersNotMemoryAllocated);
       
   175 DEFINE_MVIP_CTR(TMDSomeOtherParametersNotMemoryAllocated);
       
   176 
       
   177 // Attribute table(s)
       
   178 START_ATTRIBUTE_TABLE(TMDSomeParametersNotMemoryAllocated, KSomeExtensionInterfaceUid, ESomeParam1)
       
   179 	REGISTER_ATTRIBUTE(TTMDSomeParametersNotMemoryAllocated, iInt, TMetaNumber)
       
   180 	REGISTER_ATTRIBUTE(TMDSomeParametersNotMemoryAllocated, iBuf, TMeta<TBuf8<20>>)
       
   181 END_ATTRIBUTE_TABLE_BASE(Messages::TSignalBase, 0)
       
   182 
       
   183 START_ATTRIBUTE_TABLE(TMDSomeOtherParametersNotMemoryAllocated, KSomeExtensionInterfaceUid, ESomeParam2)
       
   184 END_ATTRIBUTE_TABLE_BASE(Messages::TSignalBase, 0)
       
   185 
       
   186 // The registration functions
       
   187 void TSomeExtInterfaceMessageTables::RegisterL()
       
   188 	{
       
   189 	TlsGlobals().RegisterInterfaceL(TUid::Uid(KSomeExtensionInterfaceUid), sizeof(SomeParametersImplementationTable) / sizeof(SignatureImplementationTable[0]), SomeParametersImplementationTable);
       
   190 	}
       
   191 
       
   192 void TSomeExtInterfaceMessageTables::DeRegister()
       
   193 	{
       
   194 	TlsGlobals().DeregisterInterface(TUid::Uid(KSomeExtensionInterfaceUid));
       
   195 	}
       
   196 
       
   197 **/
       
   198 
       
   199 //most common signature for messages originating on user side
       
   200 class TCFSigRMessage2Ext : public Messages::TSignalBase, public TCFClientItfExt<TCFClientType::ECtrl>
       
   201     {
       
   202 protected:
       
   203     TCFSigRMessage2Ext(const RMessage2& aMessage)
       
   204     :   TCFClientItfExt<TCFClientType::ECtrl>(),
       
   205         iMessage(aMessage)
       
   206             {
       
   207             }
       
   208 
       
   209     TCFSigRMessage2Ext()
       
   210     	{
       
   211     	}
       
   212 
       
   213 protected:
       
   214 	IMPORT_C virtual void Error(const Messages::TRuntimeCtxId& aSender, const Messages::TRuntimeCtxId& aRecipient, TInt aError);
       
   215 
       
   216 protected:
       
   217     RMessage2 iMessage;
       
   218 
       
   219 public:
       
   220     EXPORT_DATA_VTABLE_AND_FN
       
   221     };
       
   222 
       
   223 } //namespace ESock
       
   224 
       
   225 #endif
       
   226 // SS_DISPATCHERS_H
       
   227 
       
   228 
       
   229 
       
   230 
       
   231