phonebookengines_old/contactsmodel/tsrc/CContactDbEventQueue.cpp
changeset 40 b46a585f6909
equal deleted inserted replaced
37:fd64c38c277d 40:b46a585f6909
       
     1 // Copyright (c) 2003-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 // INCLUDES
       
    17 #include "CContactDbEventQueue.h"
       
    18 #include <cntdb.h>
       
    19 
       
    20 CContactDbEventQueue* CContactDbEventQueue::NewL
       
    21         (CContactDatabase* aDb, TInt aMaxQueueSize)
       
    22     {
       
    23     CContactDbEventQueue* self = new(ELeave) CContactDbEventQueue;
       
    24     CleanupStack::PushL(self);
       
    25     self->ConstructL(aDb,aMaxQueueSize);
       
    26     CleanupStack::Pop(self);
       
    27     return self;
       
    28     }
       
    29 
       
    30 CContactDbEventQueue::~CContactDbEventQueue()
       
    31     {
       
    32     CTimer::Cancel();
       
    33     if (iNotifier)
       
    34         {
       
    35         delete iNotifier;
       
    36         }
       
    37     }
       
    38     
       
    39 void CContactDbEventQueue::PopEvent()
       
    40 	{	
       
    41 	 if (!iQueue.IsEmpty())
       
    42      	{
       
    43      	iQueue.PopHead();
       
    44      	}
       
    45 	}
       
    46 
       
    47 void CContactDbEventQueue::Clear()
       
    48 	{	
       
    49 	 while(!iQueue.IsEmpty())
       
    50      	{
       
    51      	iQueue.PopHead();
       
    52      	}
       
    53 	}
       
    54 
       
    55 TBool CContactDbEventQueue::ListenForEvent(TTimeIntervalSeconds aTimeOut, TContactDbObserverEvent& aEvent)
       
    56     {
       
    57     CTimer::Cancel();
       
    58     if (iQueue.IsEmpty())
       
    59         {
       
    60         CTimer::After(aTimeOut.Int() * 1000000);
       
    61         CActiveScheduler::Start();
       
    62         }
       
    63     if (!iQueue.IsEmpty())
       
    64         {
       
    65         aEvent = iQueue.Head();
       
    66         iQueue.PopHead();
       
    67         return ETrue;
       
    68         }
       
    69     else
       
    70         {
       
    71         return EFalse;
       
    72         }
       
    73     }
       
    74 
       
    75 void CContactDbEventQueue::RunL()
       
    76     {
       
    77     // Timer expired
       
    78     CActiveScheduler::Stop();
       
    79     }
       
    80 
       
    81 void CContactDbEventQueue::HandleDatabaseEventL
       
    82         (TContactDbObserverEvent aEvent)
       
    83     {
       
    84     const TBool KTimerActive = CTimer::IsActive();
       
    85     CTimer::Cancel();
       
    86 	TBool eventPushed = iQueue.Push(aEvent);
       
    87 	__ASSERT_ALWAYS(eventPushed,User::Invariant());  // ensure push was successful
       
    88     
       
    89     if (KTimerActive)
       
    90         {
       
    91         CActiveScheduler::Stop();
       
    92         }
       
    93     }
       
    94 
       
    95 CContactDbEventQueue::CContactDbEventQueue()
       
    96     : CTimer(CActive::EPriorityStandard)
       
    97     {
       
    98     }
       
    99 
       
   100 void CContactDbEventQueue::ConstructL
       
   101         (CContactDatabase* aDb, TInt aMaxQueueSize)
       
   102     {
       
   103     CTimer::ConstructL();
       
   104     iQueue.ConstructL(aMaxQueueSize);
       
   105     CActiveScheduler::Add(this);
       
   106     
       
   107     if (aDb)
       
   108         {
       
   109         iNotifier = CContactChangeNotifier::NewL(*aDb, this);
       
   110         }
       
   111     }
       
   112 
       
   113 
       
   114 
       
   115