datacommsserver/esockserver/inc/ss_thread.h
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2004-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 #if !defined(__SS_THREAD_H__)
       
    22 #define __SS_THREAD_H__
       
    23 
       
    24 #include <elements/sd_thread.h>
       
    25 
       
    26 #include <es_sock.h>
       
    27 #include <comms-infras/ss_common.h>
       
    28 #include <comms-infras/ss_threadtransport.h>
       
    29 #include <comms-infras/api_ext_msg.h>
       
    30 #include <ss_fact.h>
       
    31 
       
    32 class CSockManData;
       
    33 class CSockManData;
       
    34 class CPlayer;
       
    35 class CPitBoss;
       
    36 class CSockSession;
       
    37 
       
    38 namespace Den
       
    39 	{
       
    40 	class TWorkerTransportMsg;
       
    41 	}
       
    42 
       
    43 NONSHARABLE_CLASS(TCFWorkerThreadPublicInfo) : public Den::TWorkerThreadPublicInfo
       
    44 	{
       
    45 public:
       
    46     enum TType
       
    47         {
       
    48         //see Den::TWorkerThreadPublicInfo
       
    49 		EBtPlayerThread = 2,	//< BT Group Player
       
    50 		EIrPlayerThread = 3,	//< IR Group Player
       
    51 		ESmsWapPlayerThread	= 4,//< SMS + WAP Group Player
       
    52 		EIpPlayerThread = 5		//< IP Group Player
       
    53 		};
       
    54 	};
       
    55 
       
    56 /**
       
    57 Granularity and default number of values in the list of EskMasks.
       
    58 @internalComponent
       
    59 */
       
    60 const TInt KEskMaskListGranularity=2;
       
    61 
       
    62 NONSHARABLE_CLASS(CWorkerThread) : public Den::CCommonWorkerThread
       
    63 /**
       
    64 @internalComponent
       
    65 */
       
    66 	{
       
    67 public:
       
    68 	static CWorkerThread* NewL(CommsFW::TCFModuleInfo* aModuleInfo);
       
    69 	~CWorkerThread();
       
    70 
       
    71 	const CSockManData* SockManGlobals() const
       
    72 		{
       
    73 		return iSockManGlobals;
       
    74 		}
       
    75 
       
    76 	CSockManData* SockManGlobals()
       
    77 		{
       
    78 		return iSockManGlobals;
       
    79 		}
       
    80 
       
    81 	CPlayer* Player() const;
       
    82 	CPitBoss& PitBoss() const;
       
    83 	Den::CCommonWorkerDealer* WorkerDealer() const;
       
    84 
       
    85 	Den::CCommonPitBoss* DoCreatePitBossL(Den::CCommonWorkerThread* aWorkerThread);
       
    86 	Den::CCommonPlayer* DoCreatePlayerL(Den::CCommonWorkerThread* aWorkerThread, Den::TPlayerRole aPlayerRole);
       
    87 	Den::CCommonDealer* DoCreateDealerL(Den::CCommonWorkerThread* aWorkerThread, Den::TPlayerRole aPlayerRole);
       
    88 
       
    89 	void CFBindMessageReceived(const CommsFW::TCFBindMsg& aMsg);
       
    90 	void CFMessageForward(const CommsFW::TCFForwardMsg& aMessage);
       
    91 
       
    92 	// From MLegacyMessageReciever
       
    93 	TBool DoDispatchL(const CommsFW::TCFMessage& aMessage, CommsFW::TWorkerId aSenderId);
       
    94 	void OnDispatchLeave(const CommsFW::TCFMessage& aMessage, CommsFW::TWorkerId aSenderId, TInt aError);
       
    95 	// For external use
       
    96 	IMPORT_C static TInt CookieForProtocol(TUint aAddrFamily, TUint aSockType, TUint aProtocol, Messages::TRuntimeCtxId& aCookie);
       
    97 	IMPORT_C static TInt CookieForProtocolByName(const TProtocolName& aName, Messages::TRuntimeCtxId& aCookie);
       
    98 	IMPORT_C static TBool ResolveWorkerNameToId(const TDesC8& aWorkerName, CommsFW::TWorkerId& aWorkerId);
       
    99 	IMPORT_C static TInt CookieForWorkerId(CommsFW::TWorkerId aWorkerId, Messages::TRuntimeCtxId& aCookie);
       
   100 	IMPORT_C static TInt CurrentWorkerId(CommsFW::TWorkerId& aWorkerId);
       
   101 
       
   102 	/**
       
   103 	This is the main thread function used by the RootServer when creating a new ESock thread.
       
   104 	The RootServer will know the DLL ordinal for it, as specified in the .CMI file, and this is where
       
   105 	an ESock instance starts and ends operation (unless it PANICs).
       
   106 	@param aArg Will be the module info structure from the RootServer.
       
   107 	@see CommsFW::TCFModuleInfo
       
   108 	*/
       
   109 	IMPORT_C static TInt ThreadEntrypoint(TAny* aArg);
       
   110 
       
   111 protected:
       
   112 	void ConstructL(CommsFW::TCFModuleInfo* aModuleInfo);
       
   113 	CWorkerThread();
       
   114 	void CreateTransportUserL(TTransportUser& aTemplateUser);
       
   115 	void DoProcessWorkerIntroductionL(const Den::TWorkerIntroductionMsg& aMessage);
       
   116 	void DoFillIntroMessage(CommsFW::TWorkerId aPeerId, Den::TWorkerIntroductionMsg& aIntroMsg);
       
   117 	void DoCompleteUnbinding(CommsFW::TWorkerId aWorker);
       
   118 	void DoDeterminePlayerRoleL(HBufC8* aIniData, Den::TPlayerRole &aPlayerRole);
       
   119 	void DoSetShuttingDown();
       
   120 	void DoPostMortemCleanup();
       
   121 	void DoSendOtherIntroductionMessagesL(const CommsFW::TWorkerId& aPeerId);
       
   122 
       
   123 private:
       
   124 	void MaybeIncorporateFCL(const Den::TPlayerRole& aPlane, const Messages::TNodeId& aPeerId);
       
   125 	void ProcessMatchingEskFilesL(const CommsFW::COwnEntryList* aEskFiles);
       
   126 	void ProcessIniDataL();
       
   127 	TInt TransportMessageReceived(const Den::TWorkerTransportMsg& aMessage, TRequestWrapper& aRequestWrapper, CommsFW::TWorkerId aWorkerId);
       
   128 
       
   129 	void SendObjectBrokerIntroductionMessage(const CommsFW::TWorkerId& aPeerId);
       
   130 
       
   131 private:
       
   132 	CSockManData* iSockManGlobals;					//< Cache pointer to global variables to avoid TLS lookups
       
   133 
       
   134 	enum
       
   135 		{
       
   136 		/** Max length of the EskMask value */
       
   137 		KMaxEskMaskLength = 16,
       
   138 		/** Max number of optional EskMasks, e.g. EskMask0, EskMask1, etc... */
       
   139 		KEskMaskLabelMax = 8,
       
   140 		/** Max length of label searched for, e.g. length of "EskMask0" */
       
   141 		KEskMaskLabelLength
       
   142 		};
       
   143 
       
   144 	/** Buffer type holding the ESK mask defined in the .CMI files, e.g. "IP.*.ESK". */
       
   145 	typedef TBuf<KMaxEskMaskLength> TEskMask;
       
   146 
       
   147 	/**
       
   148 	Array of ESK masks as defined in the .CMI file loading this instance of ESock.
       
   149 	The Player will load all .ESK files matching these masks.
       
   150 	*/
       
   151 	RArray<TEskMask> iEskMaskList;
       
   152 
       
   153 	/**
       
   154 	A holder of plug-ins capable of consuming transport messages not internal to ESock and
       
   155 	some methods to manage them.
       
   156 	*/
       
   157 	class RTransportUsers : public RArray<TTransportUser>
       
   158 		{
       
   159 	public:
       
   160 		void Shutdown(TBool aAlreadyDead);
       
   161 		void NotifyPeerDeath(CommsFW::TWorkerId aPeer);
       
   162 		};
       
   163 
       
   164 	/**
       
   165 	The array of transport users for this instance of ESock. Will be populated when
       
   166 	the appropriate ECOM plug-ins are loaded on demand (as messages with unknown message ID arrives
       
   167     and causes the appropriate ECOM plugins to be loaded and inserted).
       
   168 	@see TTransportUser
       
   169 	*/
       
   170 	RTransportUsers iTransportUsers;
       
   171 
       
   172 //Keep conditional data members at the end, even if this class is not supposed to be derived from
       
   173 #ifdef ESOCK_HOME_THREAD_CHECK_ENABLED
       
   174 public:
       
   175 	TThreadId OwnThread() const
       
   176 		{
       
   177 		return iOwnThread;
       
   178 		}
       
   179 private:
       
   180 	TThreadId iOwnThread;
       
   181 #endif
       
   182 	};
       
   183 
       
   184 #endif	// __SS_THREAD_H__
       
   185