PECengine/AttributeLibrary2/SrcTransactions/CPEngOrphanNotificationQue.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2005 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 "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:  Que for orphan presence notifications.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "CPEngOrphanNotificationQue.h"
       
    20 #include "PresenceDebugPrint.h"
       
    21 
       
    22 #include <E32Std.h>
       
    23 
       
    24 
       
    25 
       
    26 // ============================ MEMBER FUNCTIONS ===============================
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // CPEngOrphanNotificationQue::CPEngOrphanNotificationQue
       
    30 // C++ default constructor can NOT contain any code, that
       
    31 // might leave.
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 CPEngOrphanNotificationQue::CPEngOrphanNotificationQue( TInt aQueSize )
       
    35         : iMaxQueSize( aQueSize )
       
    36     {
       
    37     }
       
    38 
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CPEngOrphanNotificationQue::NewL()
       
    42 // Two-phased constructor.
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CPEngOrphanNotificationQue* CPEngOrphanNotificationQue::NewL( TInt aQueSize )
       
    46     {
       
    47     __ASSERT_ALWAYS( aQueSize >= 1, User::Leave( KErrArgument ) );
       
    48     CPEngOrphanNotificationQue* self = new ( ELeave ) CPEngOrphanNotificationQue( aQueSize );
       
    49     return self;
       
    50     }
       
    51 
       
    52 
       
    53 // Destructor
       
    54 CPEngOrphanNotificationQue::~CPEngOrphanNotificationQue()
       
    55     {
       
    56     iQue.ResetAndDestroy();
       
    57     }
       
    58 
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CPEngOrphanNotificationQue::AddToQueL()
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 void CPEngOrphanNotificationQue::AddToQueL( const TDesC8& aPresenceBlock )
       
    65     {
       
    66     PENG_DP( D_PENG_LIT( "CPEngOrphanNotificationQue::AddToQueL() - MaxQueSize[%d], QueSize[%d]" ),
       
    67              iMaxQueSize, iQue.Count() );
       
    68 
       
    69     HBufC8* newEntry = aPresenceBlock.AllocLC();
       
    70 
       
    71     if ( iQue.Count() == iMaxQueSize )
       
    72         {
       
    73         PENG_DP( D_PENG_LIT( "CPEngOrphanNotificationQue::AddToQueL() - discard the oldest element" ) );
       
    74 
       
    75         //Discard the oldest element (the first element at offset 0)
       
    76         delete iQue[ 0 ];
       
    77         iQue.Remove( 0 );
       
    78         }
       
    79 
       
    80     // Add new at the end of array
       
    81     iQue.AppendL( newEntry );
       
    82     CleanupStack::Pop( newEntry );
       
    83 
       
    84     //Reset the iterator
       
    85     iIndex = 0;
       
    86     }
       
    87 
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CPEngOrphanNotificationQue::GetFirst()
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 const TDesC8* CPEngOrphanNotificationQue::GetFirst()
       
    94     {
       
    95     PENG_DP( D_PENG_LIT( "CPEngOrphanNotificationQue::GetFirst() - MaxQueSize[%d], QueSize[%d]" ),
       
    96              iMaxQueSize, iQue.Count() );
       
    97 
       
    98     //Reset the iterator
       
    99     iIndex = 0;
       
   100     return DoGetCurrent();
       
   101     }
       
   102 
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CPEngOrphanNotificationQue::GetNext()
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 const TDesC8* CPEngOrphanNotificationQue::GetNext()
       
   109     {
       
   110     PENG_DP( D_PENG_LIT( "CPEngOrphanNotificationQue::GetNext() - MaxQueSize[%d], QueSize[%d], Index[%d]" ),
       
   111              iMaxQueSize, iQue.Count(), iIndex );
       
   112 
       
   113     //Proceed to next
       
   114     iIndex++;
       
   115     return DoGetCurrent();
       
   116     }
       
   117 
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CPEngOrphanNotificationQue::DeleteCurrentAndGetNext()
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 const TDesC8* CPEngOrphanNotificationQue::DeleteCurrentAndGetNext()
       
   124     {
       
   125     PENG_DP( D_PENG_LIT( "CPEngOrphanNotificationQue::DeleteCurrentAndGetNext() - MaxQueSize[%d], QueSize[%d], Index[%d]" ),
       
   126              iMaxQueSize, iQue.Count(), iIndex );
       
   127 
       
   128     if ( DoIndexValid( iIndex ) )
       
   129         {
       
   130         //Delete current -> array sifts 1 to down -> iIndex points automaticly to next
       
   131         delete iQue[ iIndex ];
       
   132         iQue.Remove( iIndex );
       
   133         }
       
   134     else
       
   135         {
       
   136         //Proceed to next
       
   137         iIndex++;
       
   138         }
       
   139 
       
   140     return DoGetCurrent();
       
   141     }
       
   142 
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CPEngOrphanNotificationQue::DoIndexValid()
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 TBool CPEngOrphanNotificationQue::DoIndexValid( TInt aIndex ) const
       
   149     {
       
   150     if ( ( aIndex >= 0 ) && ( aIndex < iQue.Count() ) )
       
   151         {
       
   152         return ETrue;
       
   153         }
       
   154 
       
   155     return EFalse;
       
   156     }
       
   157 
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CPEngOrphanNotificationQue::DoGetCurrent()
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 const TDesC8* CPEngOrphanNotificationQue::DoGetCurrent() const
       
   164     {
       
   165     if ( DoIndexValid( iIndex ) )
       
   166         {
       
   167         return iQue[ iIndex ];
       
   168         }
       
   169 
       
   170     return NULL;
       
   171     }
       
   172 
       
   173 
       
   174 //  End of File
       
   175 
       
   176