serialserver/c32serialserver/SCOMM/cs_std.inl
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 // CC32Server
       
    15 // 
       
    16 //
       
    17 
       
    18 
       
    19 inline CC32WorkerThread& CC32Server::WorkerThread() const 
       
    20 	{
       
    21 	return *iOwnerThread;
       
    22 	};
       
    23 
       
    24 inline CommsFW::TWorkerId CC32Server::WorkerId() const
       
    25 	{
       
    26 	return WorkerThread().WorkerId();
       
    27 	}
       
    28 
       
    29 //
       
    30 // CCommSession
       
    31 //
       
    32 
       
    33 inline const CC32Dealer& CCommSession::Dealer() const 
       
    34 	{ 
       
    35 	return *reinterpret_cast<const CC32Dealer*>(Server());	
       
    36 	}
       
    37 
       
    38 inline CC32SubSessionIx& CCommSession::SubSessions()
       
    39 	{
       
    40 	return iSubSessions;
       
    41 	}
       
    42 
       
    43 inline void CCommSession::CompleteDisconnect()
       
    44 	{
       
    45 	RMessage2 dm = iDisconnectMessage;
       
    46 	inherited::Disconnect(dm);
       
    47 	}
       
    48 
       
    49 
       
    50 //
       
    51 // CCommSubSession
       
    52 //
       
    53 
       
    54 inline void CCommSubSession::Open()
       
    55 	{
       
    56 	iAccessCount++;
       
    57 	}
       
    58 
       
    59 inline void CCommSubSession::Close()
       
    60 	{
       
    61 	iAccessCount--;
       
    62 	ASSERT(iAccessCount >= 0);
       
    63 	if(iAccessCount == 0)
       
    64 		{
       
    65 		RemoveAndDestroy();
       
    66 		}
       
    67 	}
       
    68 
       
    69 inline TInt CCommSubSession::AccessCount() const
       
    70 	{
       
    71 	return iAccessCount;
       
    72 	}
       
    73 
       
    74 inline CCommSession* CCommSubSession::Session() const
       
    75 	{ 
       
    76 	ASSERT(iSession); 
       
    77 	return iSession;
       
    78 	}
       
    79 
       
    80 inline CC32Player& CCommSubSession::Player() const 
       
    81 	{ 
       
    82 	ASSERT(iPlayer); 
       
    83 	return *iPlayer; 
       
    84 	}
       
    85 
       
    86 	
       
    87 //
       
    88 // CC32SubSessionIx
       
    89 // 
       
    90 
       
    91 /**
       
    92 Optional locking. When accessing any of the public methods of this class in a multithreaded 
       
    93 environment, locking is often necessary. This lock does not allow for lock nesting.
       
    94 */
       
    95 inline void CC32SubSessionIx::Lock() const
       
    96 	{ 
       
    97 	iLock.Wait(); 
       
    98 	}
       
    99 
       
   100 /**
       
   101 Unlocking.
       
   102 @see Lock()
       
   103 */
       
   104 inline void CC32SubSessionIx::Unlock() const
       
   105 	{ 
       
   106 	iLock.Signal(); 
       
   107 	}
       
   108 
       
   109 
       
   110 //
       
   111 // RWorkerLock
       
   112 //
       
   113 
       
   114 inline void CC32SubSessionIx::RWorkerLock::Wait()
       
   115 	{
       
   116 #ifdef _DEBUG
       
   117 	TThreadId self = RThread().Id();
       
   118 	// If this faults then you're attempting to claim a lock you already hold. See below
       
   119 	__ASSERT_ALWAYS(self != iHolder,Fault(EBadState,_L8("RWorkerLock::Wait: Attempt to claim a lock twice (self == iHolder(%lu))! Panicking."),&iHolder));
       
   120 #endif
       
   121 	RFastLock::Wait();
       
   122 #ifdef _DEBUG
       
   123 	iHolder = self;
       
   124 #endif
       
   125 	}
       
   126 
       
   127 
       
   128 
       
   129 inline void CC32SubSessionIx::RWorkerLock::Signal()
       
   130 	{
       
   131 #ifdef _DEBUG
       
   132 	TThreadId self = RThread().Id();
       
   133 	// If this faults then you're attempting to release a lock you do not hold.
       
   134 	__ASSERT_ALWAYS(self == iHolder,Fault(EBadState,_L8("RWorkerLock::Signal: Attempt to release a lock not held (self(%lu) != iHolder(%lu))! Panicking."),&self,&iHolder));
       
   135 	iHolder = KNullHandle;
       
   136 #endif
       
   137 	RFastLock::Signal();
       
   138 	}
       
   139 	
       
   140 	
       
   141 		
       
   142 inline void CC32SubSessionIx::RWorkerLock::AssertLockHeld() const
       
   143 	{
       
   144 #ifdef _DEBUG
       
   145 	TThreadId self = RThread().Id();
       
   146 	__ASSERT_ALWAYS(self == iHolder,Fault(EBadState,_L8("RWorkerLock::AssertLockHeld: failed: self(%lu) != iHolder(%lu)! Panicking."),&self,&iHolder));
       
   147 #endif
       
   148 	}
       
   149 	
       
   150 	
       
   151 
       
   152