hti/HtiFramework/src/HtiMessageQueue.cpp
changeset 0 a03f92240627
equal deleted inserted replaced
-1:000000000000 0:a03f92240627
       
     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 "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:  CHtiMessageQueue implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "HtiMessageQueue.h"
       
    20 
       
    21 CHtiMessageQueue* CHtiMessageQueue::NewL()
       
    22     {
       
    23     return new (ELeave) CHtiMessageQueue;
       
    24     }
       
    25 
       
    26 CHtiMessageQueue::CHtiMessageQueue():
       
    27     iQueue( CHtiMessage::iLinkOffset ),
       
    28     iMemoryAllocated( 0 ),
       
    29     iQueueIter( iQueue ),
       
    30     iIsFirst ( ETrue )
       
    31     {
       
    32     }
       
    33 
       
    34 CHtiMessageQueue::~CHtiMessageQueue()
       
    35     {
       
    36     RemoveAll();
       
    37     }
       
    38 
       
    39 void CHtiMessageQueue::RemoveAll()
       
    40     {
       
    41     if ( !IsEmpty() )
       
    42         {
       
    43         CHtiMessage* msg;
       
    44 
       
    45         iQueueIter.SetToFirst();
       
    46         while ( ( msg = iQueueIter++ ) != NULL )
       
    47             {
       
    48             iQueue.Remove( *msg );
       
    49             delete msg;
       
    50             }
       
    51         }
       
    52         iMemoryAllocated = 0;
       
    53     }
       
    54 
       
    55 CHtiMessage* CHtiMessageQueue::Remove()
       
    56     {
       
    57     CHtiMessage* msg = NULL;
       
    58     if ( !IsEmpty() )
       
    59         {
       
    60         msg = iQueue.First();
       
    61         iQueue.Remove( *msg );
       
    62         iMemoryAllocated -= msg->Size();
       
    63         }
       
    64     return msg;
       
    65     }
       
    66 
       
    67 CHtiMessage* CHtiMessageQueue::Remove( CHtiMessage* aMsg)
       
    68     {
       
    69     if ( aMsg && !IsEmpty() )
       
    70         {
       
    71         iQueue.Remove( *aMsg );
       
    72         iMemoryAllocated -= aMsg->Size();
       
    73         return aMsg;
       
    74         }
       
    75     return NULL;
       
    76     }
       
    77 
       
    78 void CHtiMessageQueue::StartServiceIteration()
       
    79     {
       
    80     if ( !IsEmpty() )
       
    81         {
       
    82         iQueueIter.SetToFirst();
       
    83         iIsFirst = ETrue;
       
    84         }
       
    85     }
       
    86 
       
    87 CHtiMessage* CHtiMessageQueue::GetNext()
       
    88     {
       
    89     CHtiMessage* msg = NULL;
       
    90     if ( !IsEmpty() )
       
    91         {
       
    92         while ( ( msg = iQueueIter++ ) != NULL )
       
    93             {
       
    94             if ( iIsFirst )
       
    95                 {
       
    96                 iIsFirst = EFalse;
       
    97                 iLastServiceUid = msg->DestinationServiceUid();
       
    98                 return msg;
       
    99                 }
       
   100             else if ( msg->DestinationServiceUid() != iLastServiceUid )
       
   101                 {
       
   102                 iLastServiceUid = msg->DestinationServiceUid();
       
   103                 return msg;
       
   104                 }
       
   105             }
       
   106         }
       
   107     return msg;
       
   108     }
       
   109 
       
   110 
       
   111 void CHtiMessageQueue::Add( CHtiMessage& aMessage )
       
   112     {
       
   113     iQueue.AddLast( aMessage );
       
   114     iMemoryAllocated += aMessage.Size();
       
   115     }
       
   116 
       
   117 TBool CHtiMessageQueue::IsEmpty() const
       
   118     {
       
   119     return iQueue.IsEmpty();
       
   120     }
       
   121 
       
   122 TInt CHtiMessageQueue::QueueSize() const
       
   123     {
       
   124     return iMemoryAllocated;
       
   125     }