datacommsserver/esockserver/inc/es_notq.inl
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2002-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 template<class TInfo, TInt QueueSize> TNotificationQueue<TInfo, QueueSize>::TNotificationQueue()
       
    22 /**
       
    23 Constructor
       
    24 */
       
    25 	: iQueueLength(0), iQueueStart(0)
       
    26 	{
       
    27 	}
       
    28 
       
    29 template<class TInfo, TInt QueueSize> void TNotificationQueue<TInfo, QueueSize>::Reset()
       
    30 /**
       
    31 Reset notification queue, throwing away any stored notifications
       
    32 */
       
    33 	{
       
    34 	iQueueLength = 0;
       
    35 	iQueueStart = 0;
       
    36 	}
       
    37 
       
    38 template<class TInfo, TInt QueueSize>
       
    39 void TNotificationQueue<TInfo, QueueSize>::ResetAndDestroy()
       
    40 /**
       
    41 Destroys the pointed memory cells and resets the queue.
       
    42 */
       
    43     {
       
    44     for (TUint i = 0; i < QueueSize; ++i)
       
    45         {
       
    46         delete iQueue[i];
       
    47         iQueue[i] = NULL;
       
    48         }
       
    49     Reset();
       
    50     }
       
    51 
       
    52 template<class TInfo, TInt QueueSize> void TNotificationQueue<TInfo, QueueSize>::Enque(const TInfo& aInfo)
       
    53 /**
       
    54 Place a InterfaceChange notification on the queue
       
    55 @param aInfo notification information
       
    56 */
       
    57 	{
       
    58 	TUint index;
       
    59 
       
    60 	if (IsEmpty())
       
    61 		{
       
    62 		index = iQueueStart;
       
    63 		iQueueLength++;
       
    64 		}
       
    65     else
       
    66 		{
       
    67 		index = (iQueueStart + iQueueLength) % QueueSize;
       
    68 
       
    69 		// Have we reached capacity?
       
    70 		if (index == iQueueStart)	// Yes, so overwrite
       
    71 			iQueueStart = (iQueueStart + 1) % QueueSize;
       
    72 		else
       
    73 			iQueueLength++;
       
    74 
       
    75 		}
       
    76 		
       
    77 	iQueue[index] = aInfo;		// default assignment operator used
       
    78 	}
       
    79 
       
    80 template<class TInfo, TInt QueueSize> TBool TNotificationQueue<TInfo, QueueSize>::Deque(TInfo& aInfo)
       
    81 /**
       
    82 De-queue the next InterfaceChange notification and return it
       
    83 
       
    84 @param aInfo returned notification info
       
    85 @return ETrue if a notification info was returned, EFalse otherwise (ie: queue was empty).
       
    86 */
       
    87 	{
       
    88 	if (!IsEmpty())
       
    89 		{
       
    90 		aInfo = iQueue[iQueueStart];	// default assignment operator used
       
    91 		iQueueLength--;
       
    92 		iQueueStart = (iQueueStart + 1) % QueueSize;
       
    93 		return ETrue;
       
    94 		}
       
    95 	else
       
    96 		return EFalse;
       
    97 	}
       
    98 
       
    99 template<class TInfo, TInt QueueSize>
       
   100 inline TInfo& TNotificationQueue<TInfo, QueueSize>::GetTheOldestElem()
       
   101 /**
       
   102 In the case if pointers are stored in the queue and it is full the oldest
       
   103 element can be deleted with this method to avoid memory leaking.
       
   104 */
       
   105     {    
       
   106     return iQueue[iQueueStart];
       
   107     }
       
   108