sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: #include "mmrcclientmsgqueuehandler.h"
sl@0: #include "mmrcmsgqueuehandlerobserver.h"
sl@0: 
sl@0: /**
sl@0: */
sl@0: CMMRCClientMsgQueueHandler* CMMRCClientMsgQueueHandler::NewL(
sl@0:    RMsgQueue<TMMRCQueueItem>& aMsgQueue,
sl@0:    MMMRCMsgQueueHandlerObserver& aObserver)
sl@0: 	{
sl@0: 	CMMRCClientMsgQueueHandler* self = new(ELeave) CMMRCClientMsgQueueHandler(aMsgQueue,aObserver);
sl@0: 	CleanupStack::PushL(self);
sl@0: 	self->ConstructL();
sl@0: 	CleanupStack::Pop();
sl@0: 	return self;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: */
sl@0: CMMRCClientMsgQueueHandler::CMMRCClientMsgQueueHandler(
sl@0: 			RMsgQueue<TMMRCQueueItem>& aMsgQueue,
sl@0: 			MMMRCMsgQueueHandlerObserver& aObserver) 
sl@0: 	:CActive(EPriorityStandard), 
sl@0: 	iMsgQueue(aMsgQueue),
sl@0: 	iObserver(aObserver)
sl@0: 	{
sl@0: 	CActiveScheduler::Add(this);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: */
sl@0: void CMMRCClientMsgQueueHandler::ConstructL()
sl@0: 	{
sl@0: 	ReceiveEvents();
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: */
sl@0: CMMRCClientMsgQueueHandler::~CMMRCClientMsgQueueHandler()
sl@0: 	{
sl@0: 	Cancel();
sl@0: 	iMsgQueue.Close();
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: */
sl@0: void CMMRCClientMsgQueueHandler::ReceiveEvents()
sl@0: 	{
sl@0: 	if(!IsActive())
sl@0: 		{
sl@0: 		iMsgQueue.NotifyDataAvailable(iStatus);
sl@0: 		SetActive();	   
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: */
sl@0: void CMMRCClientMsgQueueHandler::RunL()
sl@0: 	{
sl@0: 	TMMRCQueueItem message;
sl@0: 	TInt error = iMsgQueue.Receive(message);	
sl@0: 	iObserver.HandleMessage(message);
sl@0: 	ReceiveEvents();
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: */
sl@0: TInt CMMRCClientMsgQueueHandler::RunError(TInt /*aError*/)
sl@0: 	{
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 	
sl@0: /**
sl@0: */
sl@0: void CMMRCClientMsgQueueHandler::DoCancel()
sl@0: 	{
sl@0: 	iMsgQueue.CancelDataAvailable();
sl@0: 	}
sl@0: 
sl@0: //EOF