wlan_bearer/wlanldd/wlan_symbian/wlanldd_symbian/inc/wllddcircularbuffer.inl
changeset 0 c40eb8fe8501
equal deleted inserted replaced
-1:000000000000 0:c40eb8fe8501
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Implementation of RWlanCircularBuffer inline methods.
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19 * %version: 2 %
       
    20 */
       
    21 
       
    22 #include <kernel.h> // for Kern::SystemTime()
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // 
       
    26 // -----------------------------------------------------------------------------
       
    27 //
       
    28 template <TUint size>
       
    29 inline void RWlanCircularBuffer<size>::DoInit()
       
    30     {
       
    31     iSize = size;
       
    32     iPacketAmount = 0;
       
    33     iGetIndex = 0;
       
    34     iPutIndex = 0;
       
    35     iBecameEmptyAt = 0;
       
    36     }
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // 
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 template <TUint size>
       
    43 inline void RWlanCircularBuffer<size>::Release()
       
    44     {
       
    45     // Do nothing
       
    46     }
       
    47     
       
    48 // -----------------------------------------------------------------------------
       
    49 // 
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 template <TUint size>
       
    53 inline TBool RWlanCircularBuffer<size>::IsEmpty() const
       
    54     {
       
    55     return iPacketAmount == 0 ? ETrue : EFalse;
       
    56     }
       
    57     
       
    58 // -----------------------------------------------------------------------------
       
    59 // 
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 template <TUint size>
       
    63 inline TBool RWlanCircularBuffer<size>::IsFull() const
       
    64     {
       
    65     return iPacketAmount == iSize ? ETrue : EFalse;
       
    66     }
       
    67     
       
    68 // -----------------------------------------------------------------------------
       
    69 // 
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 template <TUint size>
       
    73 inline TDataBuffer* RWlanCircularBuffer<size>::GetPacket()
       
    74     {
       
    75     TDataBuffer* packet = NULL;
       
    76     
       
    77     if ( !IsEmpty() )
       
    78         {
       
    79         packet = iBuffer[iGetIndex];
       
    80         
       
    81         if ( ++iGetIndex == iSize )
       
    82             {
       
    83             iGetIndex = 0;
       
    84             }
       
    85         
       
    86         if ( --iPacketAmount == 0 )
       
    87             {
       
    88             iBecameEmptyAt = Kern::SystemTime();
       
    89             }
       
    90         }
       
    91     
       
    92     return packet;
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // 
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 template <TUint size>
       
   100 inline TBool RWlanCircularBuffer<size>::PutPacket( TDataBuffer* aPacket )
       
   101     {
       
   102     TBool ret( EFalse );
       
   103     
       
   104     if ( !IsFull() )
       
   105         {
       
   106         iBuffer[iPutIndex] = aPacket;
       
   107         
       
   108         if ( ++iPutIndex == iSize )
       
   109             {
       
   110             iPutIndex = 0;
       
   111             }
       
   112         
       
   113         ++iPacketAmount;
       
   114         ret = ETrue;
       
   115         }
       
   116 
       
   117     return ret;
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // 
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 template <TUint size>
       
   125 inline TDataBuffer* RWlanCircularBuffer<size>::PeekPacket()
       
   126     {
       
   127     TDataBuffer* packet = NULL;
       
   128     
       
   129     if ( !IsEmpty() )
       
   130         {
       
   131         packet = iBuffer[iGetIndex];
       
   132         }
       
   133     
       
   134     return packet;
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // 
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 template <TUint size>
       
   142 inline TUint RWlanCircularBuffer<size>::GetLength() const
       
   143     {
       
   144     return iPacketAmount;
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // 
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 template <TUint size>
       
   152 inline TBool RWlanCircularBuffer<size>::IsActive( TInt64 aTimeNow ) const
       
   153     {
       
   154     const TInt64 KActivityThreshold ( 25000 ); // microseconds
       
   155     
       
   156     if ( !IsEmpty() )
       
   157         {
       
   158         return ETrue;
       
   159         }
       
   160     else
       
   161         {
       
   162         if ( aTimeNow - iBecameEmptyAt > KActivityThreshold )
       
   163             {
       
   164             return EFalse;
       
   165             }
       
   166         else
       
   167             {
       
   168             return ETrue;
       
   169             }
       
   170         }
       
   171     }