diff -r fd64c38c277d -r b46a585f6909 phonebookengines_old/contactsmodel/tsrc/CContactDbEventQueue.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/phonebookengines_old/contactsmodel/tsrc/CContactDbEventQueue.cpp Fri Jun 11 13:29:23 2010 +0300 @@ -0,0 +1,115 @@ +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + +// INCLUDES +#include "CContactDbEventQueue.h" +#include + +CContactDbEventQueue* CContactDbEventQueue::NewL + (CContactDatabase* aDb, TInt aMaxQueueSize) + { + CContactDbEventQueue* self = new(ELeave) CContactDbEventQueue; + CleanupStack::PushL(self); + self->ConstructL(aDb,aMaxQueueSize); + CleanupStack::Pop(self); + return self; + } + +CContactDbEventQueue::~CContactDbEventQueue() + { + CTimer::Cancel(); + if (iNotifier) + { + delete iNotifier; + } + } + +void CContactDbEventQueue::PopEvent() + { + if (!iQueue.IsEmpty()) + { + iQueue.PopHead(); + } + } + +void CContactDbEventQueue::Clear() + { + while(!iQueue.IsEmpty()) + { + iQueue.PopHead(); + } + } + +TBool CContactDbEventQueue::ListenForEvent(TTimeIntervalSeconds aTimeOut, TContactDbObserverEvent& aEvent) + { + CTimer::Cancel(); + if (iQueue.IsEmpty()) + { + CTimer::After(aTimeOut.Int() * 1000000); + CActiveScheduler::Start(); + } + if (!iQueue.IsEmpty()) + { + aEvent = iQueue.Head(); + iQueue.PopHead(); + return ETrue; + } + else + { + return EFalse; + } + } + +void CContactDbEventQueue::RunL() + { + // Timer expired + CActiveScheduler::Stop(); + } + +void CContactDbEventQueue::HandleDatabaseEventL + (TContactDbObserverEvent aEvent) + { + const TBool KTimerActive = CTimer::IsActive(); + CTimer::Cancel(); + TBool eventPushed = iQueue.Push(aEvent); + __ASSERT_ALWAYS(eventPushed,User::Invariant()); // ensure push was successful + + if (KTimerActive) + { + CActiveScheduler::Stop(); + } + } + +CContactDbEventQueue::CContactDbEventQueue() + : CTimer(CActive::EPriorityStandard) + { + } + +void CContactDbEventQueue::ConstructL + (CContactDatabase* aDb, TInt aMaxQueueSize) + { + CTimer::ConstructL(); + iQueue.ConstructL(aMaxQueueSize); + CActiveScheduler::Add(this); + + if (aDb) + { + iNotifier = CContactChangeNotifier::NewL(*aDb, this); + } + } + + + +