commsfwsupport/commselements/serverden/inc/sd_std.h
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 1997-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  @internalComponent
       
    19 */
       
    20 
       
    21 #ifndef SYMBIAN_DEN_COMMONSTD_H
       
    22 #define SYMBIAN_DEN_COMMONSTD_H
       
    23 
       
    24 #include <cflog.h>
       
    25 #include <cfshared.h>
       
    26 #include <elements/h_structures.h>
       
    27 #include <elements/sd_thread.h>
       
    28 #include <elements/sd_apiextensionregister.h>
       
    29 #include <elements/nm_interfaces.h>
       
    30 
       
    31 
       
    32 #ifdef _DEBUG
       
    33 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
       
    34 // (if it could happen through user error then you should give it an explicit, documented, category + code)
       
    35 _LIT(KSpecAssert_ElemSvrDenStdH, "ElemSvrDenStdH");
       
    36 #endif
       
    37 
       
    38 namespace Den
       
    39 {
       
    40 
       
    41 
       
    42 /**
       
    43 @internalComponent
       
    44 */
       
    45 typedef TUint TSessionUniqueId;
       
    46 typedef TUint TSubSessionUniqueId;
       
    47 typedef TUint TScopeUniqueId;
       
    48 
       
    49 class CCommonPlayer;
       
    50 class CWorkerSession;
       
    51 class CCommonSessionProxy;
       
    52 class TIpcExtensionRoutingMessageFromSession;
       
    53 class TIpcExtensionRoutingMessageFromSubSession;
       
    54 
       
    55 _LIT(KDenFaultPanic, "Den");
       
    56 _LIT(KWorkerClientPanic, "Worker client");
       
    57 
       
    58 /** Supplementing RMessage2 with additional methods for transferring handle ownership and completing with
       
    59 logging
       
    60 */
       
    61 class RSafeMessage : public RMessage2
       
    62 /**
       
    63 @internalTechnology
       
    64 */
       
    65 	{
       
    66 public:
       
    67 	/** Only a default constructor is supported; safe messages get initialised by adopting their handle from
       
    68 	another instance, by downcasting from a received RMessage2 (ugly but safe since safe messages never add
       
    69 	members or virtuals), or (rarely) by duplicating another instance, which diminishes safety.
       
    70 	*/
       
    71 	RSafeMessage()
       
    72 		{
       
    73 		iHandle = KNullHandle;
       
    74 		}
       
    75 
       
    76 	IMPORT_C ~RSafeMessage();
       
    77 
       
    78 	IMPORT_C void Complete(TInt aReason) const;
       
    79 
       
    80 	IMPORT_C void PanicClient(const TDesC& aCategory, TInt aReason) const;
       
    81 
       
    82 	IMPORT_C void Adopt(RSafeMessage& aSrc);
       
    83 	IMPORT_C void Duplicate(const RSafeMessage& aSrc);
       
    84 	IMPORT_C void ResetHandle();
       
    85 
       
    86     IMPORT_C void ReadL(TInt aSrcParamIndex,TDes8& aDes,TInt anOffset=0) const;
       
    87 	IMPORT_C TInt Read(TInt aSrcParamIndex,TDes8& aDes,TInt anOffset=0) const;
       
    88 
       
    89     IMPORT_C void WriteL(TInt aDstParamIndex,const TDesC8& aDes,TInt anOffset=0) const;
       
    90     IMPORT_C TInt Write(TInt aDstParamIndex,const TDesC8& aDes,TInt anOffset=0) const;
       
    91 
       
    92     IMPORT_C void WriteL(TInt aDstParamIndex,const TPckg<TUint32>& aDes,TInt anOffset = 0) const;
       
    93 	IMPORT_C TInt Write(TInt aDstParamIndex,const TPckg<TUint32>& aDes,TInt anOffset = 0) const;
       
    94 
       
    95     IMPORT_C void ReadL(TInt aSrcParamIndex,TDes16& aDes,TInt anOffset=0) const;
       
    96     IMPORT_C TInt Read(TInt aSrcParamIndex,TDes16& aDes,TInt anOffset=0) const;
       
    97 
       
    98     IMPORT_C void WriteL(TInt aDstParamIndex,const TDesC16& aDes,TInt anOffset=0) const;
       
    99     IMPORT_C TInt Write(TInt aDstParamIndex,const TDesC16& aDes,TInt anOffset=0) const;
       
   100 
       
   101 
       
   102 	IMPORT_C TInt GetDesLengthL(TInt aParam) const;
       
   103 	IMPORT_C TInt GetDesMaxLengthL(TInt aParam) const;
       
   104 
       
   105 private:
       
   106 	// Conventional assignment and copy construction is not supported because of the likelihood of completing the
       
   107 	// aliased message handle twice, eg storing a copy from a ServiceL() and then leaving, so completing the request
       
   108 	// both from the error handler and the storing object's destructor
       
   109 	RSafeMessage(const RSafeMessage&);
       
   110 	RSafeMessage(const RMessage2&);
       
   111 	RSafeMessage& operator=(const RSafeMessage&);
       
   112 	RSafeMessage& operator=(const RMessage2&);
       
   113 	};
       
   114 
       
   115 class RSettableParameterMessage : public RSafeMessage
       
   116 /**
       
   117 @internalTechnology
       
   118 */
       
   119 	{
       
   120 public:
       
   121 	inline RSettableParameterMessage(TInt aFunction, TInt aInt0 = 0, TInt aInt1 = 0, TInt aInt2 = 0, TInt aInt3 = 0)
       
   122 		{
       
   123 		iFunction = aFunction;
       
   124 		iArgs[0] = aInt0;
       
   125 		iArgs[1] = aInt1;
       
   126 		iArgs[2] = aInt2;
       
   127 		iArgs[3] = aInt3;
       
   128 		}
       
   129 
       
   130 	inline void SetInt0(TInt aInt0)
       
   131 		{
       
   132 		iArgs[0] = aInt0;
       
   133 		}
       
   134 
       
   135 	inline void SetInt1(TInt aInt1)
       
   136 		{
       
   137 		iArgs[1] = aInt1;
       
   138 		}
       
   139 
       
   140 	inline void SetInt2(TInt aInt2)
       
   141 		{
       
   142 		iArgs[2] = aInt2;
       
   143 		}
       
   144 
       
   145 	inline void SetInt3(TInt aInt3)
       
   146 		{
       
   147 		iArgs[3] = aInt3;
       
   148 		}
       
   149 	};
       
   150 
       
   151 /** The panic numbers for panics caused by internal faults in Den
       
   152 @internalComponent */
       
   153 
       
   154 //TODO:
       
   155 enum TDenFault
       
   156 	{
       
   157 	ECommonBadState = 0,
       
   158 	ECommonNegativeSessionCount = 1,  //< Negative Session Count Den  Fault
       
   159 	ECommonBadDescriptorRead = 2,     //< Read Bad Descriptor Den  Fault
       
   160 	ECommonBadDescriptorWrite = 3,    //< Write Bad Descriptor Den  Fault
       
   161 	ECommonBadDescriptorLength = 4,   //< Bad Descriptor Length Den  Fault
       
   162 	ECommonCorruptIniData = 5,        //< Corrupt In Data Den  Fault
       
   163 	ECommonBadSubSessionUniqueId = 6  //< Bad Subsession Unique Id Den  Fault
       
   164 	};
       
   165 
       
   166 class TPlayerRole : public Messages::TClientType
       
   167 /**
       
   168 Can be sent in a message and read as TClientType (for storage in iClients)
       
   169 
       
   170 @internalComponent
       
   171 */
       
   172 	{
       
   173 public:
       
   174 	inline TPlayerRole() //Needed for deserialisation
       
   175 	:	Messages::TClientType()
       
   176 		{
       
   177 		}
       
   178 
       
   179 	inline TBool HasRole(TUint32 aRole) const
       
   180 		{
       
   181 		return iClientType & aRole;
       
   182 		}
       
   183 
       
   184 	inline TUint32 Role() const
       
   185 		{
       
   186 		return iClientType;
       
   187 		}
       
   188 
       
   189 	inline TUint32 Kindex() const
       
   190 		{
       
   191 		return iClientFlags;
       
   192 		}
       
   193 
       
   194 protected:
       
   195 	//This class is meant for derivation only, hence the useful ctr protected
       
   196 	inline TPlayerRole(TUint32 aRole, TUint32 aKindex)
       
   197 	:	Messages::TClientType(aRole, aKindex)
       
   198 		{
       
   199 		}
       
   200 	};
       
   201 
       
   202 /** Describes the type of configuration completed when a TWorkerConfigurationComplete is broadcast. (Although logically
       
   203 associated with the message class putting it there introduces undesirable dependencies)
       
   204 */
       
   205 enum TConfigurationCompletionType
       
   206 /**
       
   207 @internalComponent
       
   208 */
       
   209 	{
       
   210 	EModuleInitialisation,
       
   211 	ETierMapping,
       
   212 	};
       
   213 
       
   214 /**
       
   215 	Type identifier for the derived sub-session objects. Used e.g. in containers to identify
       
   216 	what is stored.
       
   217 	@see CWorkerSubSession::Type()
       
   218 */
       
   219 class TSubSessInfo
       
   220 /**
       
   221 @internalComponent
       
   222 */
       
   223 	{
       
   224 public:
       
   225 	enum TSubSessionType
       
   226 		{
       
   227 		ENull = 0,
       
   228 		EAny = 1
       
   229 		};
       
   230 
       
   231 	TSubSessInfo(TUint8 aType)
       
   232 	:	iType(aType)
       
   233 		{
       
   234 		}
       
   235 
       
   236 	TUint8 iType;
       
   237 	};
       
   238 
       
   239 class CWorkerSubSession : public CBase
       
   240 /**
       
   241 @internalComponent
       
   242 */
       
   243 	{
       
   244 	friend class CWorkerSession;
       
   245 	friend class CCommonPlayer;
       
   246 
       
   247 public:
       
   248 	// Reference counting methods formerly supplied by CObject.
       
   249     IMPORT_C virtual ~CWorkerSubSession();
       
   250 
       
   251 	IMPORT_C void GetOwnerInfo(TProcessId& aProcessId, TUidType& aUidType, TThreadId& aThreadId) const;
       
   252 	inline CWorkerSession* Session();
       
   253 	inline const CWorkerSession* Session() const;
       
   254 	inline CCommonPlayer& Player() const;
       
   255 	inline CCommonSessionProxy* SessionProxy();
       
   256 	inline const CCommonSessionProxy* SessionProxy() const;
       
   257 	inline void SetSessionProxy(CCommonSessionProxy* aProxy);
       
   258 
       
   259 	virtual void DeleteMe() = 0;
       
   260 
       
   261 	void CleanupDeadWorker(CommsFW::TWorkerId aWorkerId);
       
   262 	virtual TSubSessInfo Type() const = 0;
       
   263 
       
   264 	// Some subsessions have opaque "names" that a client can retrieve to use as a reference
       
   265 	// outside the owning session, eg for transferring a socket between sessions.
       
   266 	IMPORT_C static void ComposeSubSessionName(const CWorkerSubSession* aSubSess, TName& aName);
       
   267 	static TInt DecomposeSubSessionName(const TName& aName, CommsFW::TWorkerId& aWorkerId, CWorkerSubSession*& aSubSess);
       
   268 	IMPORT_C static TInt FetchSubSessionFromName(const TName& aName, TSubSessInfo aType, const CCommonWorkerThread& aWorker, CWorkerSubSession*& aSubSess);
       
   269 
       
   270 
       
   271 	IMPORT_C void DontCompleteCurrentRequest() const;
       
   272 
       
   273 	IMPORT_C void SetReturn(TInt aReturnValue/*,TInt anError=0,TUid anOwner=TUid::Null()*/) const;
       
   274 
       
   275 	TBool IsClosing() const { return iClosing; }
       
   276 
       
   277 	/**
       
   278 		Derived objects must implement this to make sure that all RMessage2 resources are completed when called. It
       
   279 		is used in various close/clean-up scenarios.
       
   280 	*/
       
   281 	virtual void FinalCompleteAllBlockedMessages(TInt aResult) = 0;
       
   282 
       
   283 //	virtual inline const RMessage2& Message() const; migrate to using SafeMessage
       
   284 	IMPORT_C const RSafeMessage& SafeMessage() const;
       
   285 
       
   286 	/**
       
   287 		Derived objects must implement this to continue the processing of the current message.
       
   288 	*/
       
   289 	virtual void ProcessMessageL() = 0;
       
   290 
       
   291 	inline const TSubSessionUniqueId& UniqueId() const
       
   292 		{
       
   293 		return iSubSessionUniqueId;
       
   294 		}
       
   295 
       
   296 	IMPORT_C void SetUniqueId(const TSubSessionUniqueId& aUniqueId);
       
   297 
       
   298 	inline TScopeUniqueId NextScopeUniqueId()
       
   299 		{
       
   300 		return static_cast<TScopeUniqueId>(iNextScopeUniqueId++);
       
   301 		}
       
   302 
       
   303 	/** Special non-zero subsession pointer, used in a very few cases to select additional behaviour on a forwarded request. For example on
       
   304 	creating a subsession this flags that tier resolution is first required
       
   305 	*/
       
   306 	static CWorkerSubSession* KFlagSpecialForwardCase();
       
   307 	inline void SetSession(CWorkerSession* aProxy);
       
   308 
       
   309 	IMPORT_C void StoreOwnerInfo();
       
   310 
       
   311 protected:
       
   312 	// API extension support
       
   313 	IMPORT_C TIpcExtensionRoutingMessageFromSubSession* IsSubSessionIpcExtensionSupported(TInt aInterfaceId, TDes8& aBuff);
       
   314 	IMPORT_C void OpenSubSessionIpcExtensionL(const RSafeMessage& aMessage, const TApiExtIdentification& aExtIdentification);
       
   315 	IMPORT_C void SendReceiveSubSessionIpcExtensionL(const RSafeMessage& aMessage, const TApiExtIdentification& aExtIdentification);
       
   316 	IMPORT_C void CloseSubSessionIpcExtension(const RSafeMessage& aMessage, const TApiExtIdentification& aExtIdentification);
       
   317 	IMPORT_C void CloseAllSubSessionIpcExtensions();
       
   318 	virtual TIpcExtensionRoutingMessageFromSubSession* DoIsSubSessionIpcExtensionSupported(TInt /*aInterfaceId*/, TDes8& /*aBuff*/)
       
   319 		{
       
   320 		//Not supported by default
       
   321 		return NULL;
       
   322 		}
       
   323 
       
   324 protected:
       
   325 	IMPORT_C CWorkerSubSession(CWorkerSession* aSession, CCommonPlayer* aPlayer, TSubSessionUniqueId aSubSessionUniqueId);
       
   326 	IMPORT_C void ConstructL();
       
   327 
       
   328 	void SetClosing()
       
   329 		{
       
   330 		iClosing = ETrue;
       
   331 		}
       
   332 
       
   333 	IMPORT_C void CompleteMessage(const RMessage2& aMessage, TInt aResult);
       
   334 	void RemoveAndDestroy();
       
   335 
       
   336 	IMPORT_C void PanicClient(TInt aPanic);
       
   337 	IMPORT_C void PanicClient(const TDesC& aCategory, TInt aPanic);
       
   338 
       
   339 protected:
       
   340 	CWorkerSession* iSession;
       
   341 	/**
       
   342 	The thread id of the creator of the subsession, part of the OwnerInfo. This can be misleading,
       
   343 	since sessions can be shared between threads of a client - to really know what thread is
       
   344 	responsible for the current operator query its RMessage2
       
   345 	*/
       
   346 	TThreadId iThreadId;
       
   347 	TBool iClosing : 1;		//< Set once the client directly closes the object (closing can be asynchronous. Remembering this state avoids a double close if the session then closes)
       
   348 	CCommonPlayer* iPlayer;		//< The Player responsible for this sub-session instance.
       
   349 	TSubSessionUniqueId iSubSessionUniqueId; //Sub session unique id.
       
   350 
       
   351 private:
       
   352 	TApiExtRegister iApiExtRegister;   //Register of opened interfaces (on this subsession only)
       
   353 	CCommonSessionProxy* iSessionProxy;
       
   354 	TUint iNextScopeUniqueId;
       
   355 	};
       
   356 
       
   357 // Subsession index
       
   358 
       
   359 /**
       
   360 class CSubSessionIx
       
   361 This sub-session container will maintain its own array of TEntry cells in memory as arrays provide for
       
   362 quick access in some situations. There will be two types of cells in the array; cells carrying pointers
       
   363 to sub-sessions and a virtual list of free cells.
       
   364 This layout means that with a handle, the entry holding the sub-session can be looked up in the container
       
   365 directly and if needing to insert a new entry the first free cell is indicated by iFreeListHead.
       
   366 The array will grow with EIndexGranularity each time it runs out of free entries. However, it maintains a high
       
   367 watermark and will never shrink.
       
   368 The handles are defined by TSubSessionHandle, which in the current architectures is a 32 bit word, constructed
       
   369 as needed. It is simple to deduct from the context so there is no need to store it.
       
   370 
       
   371 0        8        16              31
       
   372 |--------|--------|----------------|
       
   373    Type     Magic       Index
       
   374 
       
   375 The three components comprising the handle are:
       
   376     - Type	- 8 bit value. One of the members of CSockSubsession::TSubSessionType.
       
   377     - Magic	- 8 bit value. Ensures that handles are not re-used immediately. Each time an entry is re-cycled this value increments, rolling around when reaching max.
       
   378     - Index	- 16 bit value. The position in the array.
       
   379 @see CSockSubsession::TSubSessionType
       
   380 */
       
   381 class CSubSessionIx : public CBase
       
   382 /**
       
   383 @internalComponent
       
   384 */
       
   385 	{
       
   386 	friend class TIter;
       
   387 
       
   388 public:
       
   389 	typedef TInt TSubSessionHandle;
       
   390 	enum { KTypeBits = 8, KMagicBits = 8, KIndexBits = 16 };
       
   391 	enum { KIndexLimit = 1 << KIndexBits };
       
   392 	enum { KMagicMask = (1 << KMagicBits) - 1 };
       
   393 
       
   394 public:
       
   395 	IMPORT_C ~CSubSessionIx();
       
   396 
       
   397 	void InitialiseL();
       
   398 	inline void Lock() const;
       
   399 	inline void Unlock() const;
       
   400 
       
   401 	inline TInt ActiveCount() const;
       
   402 	IMPORT_C CWorkerSubSession* At(TInt aHandle, TSubSessInfo aType) const;
       
   403 	IMPORT_C TInt Find(CWorkerSubSession* aSubSession, TSubSessionHandle& aHandle) const;
       
   404 
       
   405 	TInt Add(CWorkerSubSession* aSubSession, TSubSessionHandle& aHandle);
       
   406 	IMPORT_C CWorkerSubSession* Replace(TSubSessionHandle aHandle, CWorkerSubSession* aSubSession);
       
   407 	IMPORT_C CWorkerSubSession* Remove(TSubSessionHandle aHandle);
       
   408 
       
   409 	NONSHARABLE_CLASS(TIter)
       
   410 		{
       
   411 	public:
       
   412 		TIter(CSubSessionIx& aContainer);
       
   413 		void SetToFirst();
       
   414 		CWorkerSubSession* operator++(TInt);
       
   415 		CWorkerSubSession* Next(TSubSessionHandle& aHandle);
       
   416 	private:
       
   417 		TInt iPos;
       
   418 		CSubSessionIx& iContainer;
       
   419 		};
       
   420 
       
   421 private:
       
   422 	enum { EIndexGranularity = 8 };
       
   423 
       
   424 	/** class CSubSessionIx::TEntry
       
   425 	One entry in the container. If iType is CWorkerSubSession::ENull, then it is a member of the free-list
       
   426 	and iNextFree is the index of the next free TEntry instance otherwise it is an iObject* and points
       
   427 	to a sub-session instance.
       
   428 	iType can be one those defined in CPlayerSubsession::TSubSessionType.
       
   429 	@see CSockSubsession::TSubSessionType
       
   430 	*/
       
   431 	class TEntry
       
   432 		{
       
   433 	public:
       
   434 		union
       
   435 			{
       
   436 			CWorkerSubSession* iObject;
       
   437 			TInt iNextFree;
       
   438 			};
       
   439 		TUint8 iType;
       
   440 		TUint16 iMagic;
       
   441 		};
       
   442 private:
       
   443 	inline TSubSessionHandle MakeHandle(TInt aIndex, TInt aMagic, TInt aType) const
       
   444 		{
       
   445 		return (((aIndex << KMagicBits) | aMagic) << KTypeBits) | aType;
       
   446 		}
       
   447 	inline TInt IndexFromHandle(TInt aHandle) const
       
   448 		{
       
   449 		return aHandle >> (KTypeBits + KMagicBits);
       
   450 		}
       
   451 	IMPORT_C TEntry* At(TSubSessionHandle aHandle) const;
       
   452 	TInt ExpandArray();
       
   453 
       
   454 private:
       
   455 	TEntry* iIx;
       
   456 	TInt iSize;
       
   457 	TInt iActiveCount;			//< Number of active sub-sessions stored in this container.
       
   458 	TInt iFreeListHead;			//< Pointer to the first item/cell in the virtual free list.
       
   459 	mutable RWorkerLock iLock;
       
   460 	};
       
   461 
       
   462 
       
   463 class CWorkerSession: public CSession2
       
   464 /**
       
   465 @internalComponent
       
   466 */
       
   467 	{
       
   468 	friend class CCommonPitBoss;
       
   469 	friend class CCommonDealer;
       
   470 
       
   471 public:
       
   472 	IMPORT_C ~CWorkerSession();
       
   473 	IMPORT_C void ConstructL(TProcessId aProcessId);
       
   474 	// Called by worker when it has received a SessionCloseRespMsg
       
   475 	IMPORT_C void SessionCloseResp(CommsFW::TWorkerId aPlayerId);
       
   476 	TBool IsPlayerInDisconnectList(CommsFW::TWorkerId aPlayerId) const;
       
   477 	IMPORT_C TBool IsDisconnectListEmpty() const;
       
   478 
       
   479 	void CleanupDeadWorker(CommsFW::TWorkerId aPeerId);
       
   480 	void CompleteDisconnect();
       
   481 
       
   482 	IMPORT_C static void PanicClient(const TDesC& aCategory, TInt aPanic);
       
   483 
       
   484 	IMPORT_C void DontCompleteCurrentRequest();
       
   485 	IMPORT_C void SetReturn(TInt aReturn /*,TInt anError=0,TUid anOwner=TUid::Null()*/);
       
   486 
       
   487 	void Disconnect();
       
   488 	// Override of default behaviour for session disconnection
       
   489 	IMPORT_C void Disconnect(const RMessage2& aMessage);
       
   490 
       
   491 	inline const TSessionUniqueId& UniqueId() const
       
   492 		{
       
   493 		return iSessionUniqueId;
       
   494 		}
       
   495 
       
   496 #ifdef SYMBIAN_TRACE_ENABLE
       
   497 	TInt DisconnectPlayers();
       
   498 #endif
       
   499 
       
   500 	IMPORT_C static void LogSubSession(CWorkerSession* aSession, CWorkerSubSession* aSubSession, TInt aSubSessionHandle, TAny* aArg);
       
   501 		// Apply a callback function to subsessions of the session, either matching the worker id, or all
       
   502 	// if aPeerId == ENullWorkerId
       
   503 	typedef void (*TSubSessionProcessor)(CWorkerSession* aSession, CWorkerSubSession* aSubSession, TInt aSubSessionHandle, TAny* aArg);
       
   504 	IMPORT_C void ProcessSubSessions(CommsFW::TWorkerId aPeerId, TSubSessionProcessor aSubSessionProcessor, TAny* aArg);
       
   505 	static void CountSubSessions(CWorkerSession* aSession, CWorkerSubSession* aSubSession, TInt aSubSessionHandle, TAny* aArg);
       
   506 
       
   507 //	[MZ]: Note, needs to be reimplemented properly:
       
   508 //	IMPORT_C static void DebugParkRequestsL(CWorkerSession* aSelf, TInt aSubSessHandle, TInt aCount);
       
   509 //	IMPORT_C static void DebugReleaseParkedRequests(CWorkerSession* aSelf);
       
   510 
       
   511 protected:
       
   512 	IMPORT_C CWorkerSession(TUidType aUid, TSessionUniqueId aSessionUniqueId);
       
   513 
       
   514 	// Callbacks used with ProcessSubSessions()
       
   515 	static void ForgetSubSession(CWorkerSession* aSession, CWorkerSubSession* aSubSession, TInt aSubSessionHandle, TAny* aArg);
       
   516 	static void OrphanSubSession(CWorkerSession* aSession, CWorkerSubSession* aSubSession, TInt aSubSessionHandle, TAny* aArg);
       
   517 
       
   518 	IMPORT_C void ForwardMessageL(const RMessage2& aMessage, CWorkerSubSession* aSS, CommsFW::TWorkerId aWorker);
       
   519 	IMPORT_C void ForwardMessageL(const RMessage2& aMessage, CWorkerSubSession& aSubSess);
       
   520 
       
   521 	IMPORT_C void OrphanSubSessions();
       
   522 	IMPORT_C CWorkerSubSession* SubSessionFromHandle(TUint aHandle, TSubSessInfo aType) const;
       
   523 
       
   524 	/* Disconnect handling: before processing EDisConnect message to destroy session
       
   525 	the Players with subsessions in the session are given the opportunity to cleanup.
       
   526 	Players are tracked in a dirty-bit manner: they're added to the disconnect list
       
   527 	when first referenced by the session and never removed (too much bookwork) */
       
   528 	void AddPlayerToDisconnectList(CommsFW::TWorkerId aPlayerId);
       
   529 	void RemovePlayerFromDisconnectList(CommsFW::TWorkerId aPlayerId);
       
   530 
       
   531 	IMPORT_C void ParkIfIndeterminateRequest(const RMessage2& aMessage, TInt aErrorIfConfigured);
       
   532 
       
   533 	inline const RMessage2& Message() const;
       
   534 	inline RSafeMessage& SafeMessage() const;
       
   535 	inline RSafeMessage& SafeMessage(const RMessage2& aMessage) const;
       
   536 
       
   537 protected:
       
   538 	// API extension support
       
   539 	IMPORT_C TIpcExtensionRoutingMessageFromSession* IsSessionIpcExtensionSupported(TInt aInterfaceId, TDes8& aBuff);
       
   540 	IMPORT_C void OpenSessionIpcExtensionL(const RSafeMessage& aMessage, const TApiExtIdentification& aExtIdentification);
       
   541 	IMPORT_C void SendReceiveSessionIpcExtensionL(const RSafeMessage& aMessage, const TApiExtIdentification& aExtIdentification);
       
   542 	IMPORT_C void CloseSessionIpcExtension(const RSafeMessage& aMessage, const TApiExtIdentification& aExtIdentification);
       
   543 	IMPORT_C void CloseAllSessionIpcExtensions();
       
   544 	virtual TIpcExtensionRoutingMessageFromSession* DoIsSessionIpcExtensionSupported(TInt /*aInterfaceId*/, TDes8& /*aBuff*/)
       
   545 		{
       
   546 		//Not supported by default
       
   547 		return NULL;
       
   548 		}
       
   549 
       
   550 public:
       
   551 	IMPORT_C void GetOwnerInfo(TProcessId& aProcId, TUidType& aUidType) const;
       
   552 	inline CCommonDealer* Dealer() const;
       
   553 	inline CCommonWorkerThread& WorkerThread() const;
       
   554 	inline CommsFW::TWorkerId WorkerId() const;
       
   555 	inline CCommonPitBoss& PitBoss() const;
       
   556 	inline CSubSessionIx& SubSessions();
       
   557 	inline const CSubSessionIx& SubSessions() const;
       
   558 
       
   559 protected:
       
   560 	CSubSessionIx iSubSessions;	//< Container of subsessions belonging to this session. They can potentially belong to different Players.
       
   561 
       
   562 	TBool iComplete;
       
   563 	TInt  iReturn;
       
   564 
       
   565 	const RMessage2* iOurMessage;
       
   566 
       
   567 	RProcess iProcess;
       
   568 	TUidType iUidType;
       
   569 
       
   570 	// Session death
       
   571 	TUint32 iDisconnectPlayers;	    // Set of Players to notify of session death
       
   572 	RMessage2 iDisconnectMessage;	// EDisConnect Message to complete session destruction
       
   573 
       
   574 private:
       
   575 	TSessionUniqueId iSessionUniqueId; //Session unique id.
       
   576 	TApiExtRegister iApiExtRegister;   //Register of opened interfaces (on this session only)
       
   577 	};
       
   578 
       
   579 class CCommonServer : public CPolicyServer
       
   580 /**
       
   581 class CCommonServer
       
   582 @internalComponent
       
   583 */
       
   584 	{
       
   585 	friend class CWorkerSession; //to acess iNumSessions which should be removed along with this line
       
   586 
       
   587 private:
       
   588 	enum {EMaxServerNameLength=32};
       
   589 	typedef TBuf<EMaxServerNameLength> TServerName;
       
   590 
       
   591 public:
       
   592 	enum {EPriority=0};
       
   593 
       
   594 public:
       
   595 	IMPORT_C ~CCommonServer();
       
   596 	IMPORT_C TBool CanShutdown();
       
   597 
       
   598 	inline CCommonWorkerThread& WorkerThread() const;
       
   599 	inline CommsFW::TWorkerId WorkerId() const;
       
   600 
       
   601 	TServerName& ServerName()
       
   602 		{
       
   603 		return iServerName;
       
   604 		}
       
   605 
       
   606 	void SetDealer(CCommonDealer* aDealer)
       
   607 		{
       
   608 		iDealer = aDealer;
       
   609 		}
       
   610 
       
   611 	CCommonDealer* Dealer()
       
   612 		{
       
   613 		return iDealer;
       
   614 		}
       
   615 
       
   616 	TDblQueIter<CSession2>& SessionIterator()
       
   617 		{
       
   618 		return iSessionIter;
       
   619 		}
       
   620 
       
   621 	static void FreeMemory(TAny*);
       
   622 
       
   623 protected:
       
   624 	IMPORT_C virtual CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const;
       
   625 	virtual CSession2* DoNewSessionL(const TProcessId& aProcessId, const TUidType& aProcessUid) const = 0;
       
   626 	virtual TVersion CurrentVersion() const = 0;
       
   627 
       
   628 	void DoFreeMemory();
       
   629 	IMPORT_C CCommonServer(TInt aPriority, CCommonWorkerThread* aOwnerThread, const TPolicy& aPolicy, TServerType aType, const TDesC& aName);
       
   630 
       
   631 private:
       
   632 	CCommonWorkerThread* iOwnerThread;
       
   633 	CCommonDealer* iDealer;
       
   634 	mutable TInt iNumSessions;	//counter of the sessions TODO - use the iSessionIter for that!!!
       
   635 	TServerName iServerName;
       
   636 	};
       
   637 
       
   638 
       
   639 #include <elements/sd_std.inl>
       
   640 
       
   641 } //namespace Den
       
   642 
       
   643 #endif
       
   644 //SYMBIAN_DEN_COMMONSTD_H
       
   645 
       
   646