phonebookengines/contactsmodel/cntsrv/src/CCntEventMsgHandler.cpp
changeset 0 e686773b3f54
child 24 0ba2181d7c28
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/phonebookengines/contactsmodel/cntsrv/src/CCntEventMsgHandler.cpp	Tue Feb 02 10:12:17 2010 +0200
@@ -0,0 +1,103 @@
+// Copyright (c) 2007-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:
+//
+
+/**
+ @file
+ @internalComponent
+*/
+
+#include "CCntMsgHandler.h"
+#include "CCntMsgHandlerFptr.h"
+#include "CCntEventMsgHandler.h"
+#include "CCntEventQueue.h"
+#include "CCntIpcCodes.h"
+#include "CCntServer.h"
+
+const TInt KCntEventIpcCodes[] =
+	{
+	ECntRequestEvent,
+	ECntCancelEventRequest
+	};
+
+CCntEventMsgHandler* CCntEventMsgHandler::NewLC(CCntSession& aSession)
+	{
+	CCntEventMsgHandler* CntEventMsgHandler = new (ELeave) CCntEventMsgHandler(aSession);
+    CleanupStack::PushL(CntEventMsgHandler);	
+    CntEventMsgHandler->ConstructL();	
+	return CntEventMsgHandler;
+	}
+	
+
+CCntEventMsgHandler::CCntEventMsgHandler(CCntSession& aSession)
+:CCntMsgHandler(aSession)
+	{	
+	}
+	
+void CCntEventMsgHandler::ConstructL()
+	{
+	iEventQueue = new (ELeave) CEventQueue;
+	}
+	
+CCntEventMsgHandler::~CCntEventMsgHandler()
+	{
+	delete iEventQueue;
+	}
+	
+/**
+Delegates the incoming op code to a message handling method.
+
+First checks if this class services the op code, it then uses the lookup table and finds 
+function pointer(to message handling method) mapped to the incoming message function (op code)
+and finally delegates the message to handling method.
+
+It returns KErrNotFound if op code not handled.
+*/
+TInt CCntEventMsgHandler::HandleMessageL(const RMessage2& aMessage)
+	{	
+	MsgHandlerFptr func_ptr = LookupHandlerMethodL(aMessage.Function(), KCntEventIpcCodes, sizeof(KCntEventIpcCodes)/sizeof(TInt));
+	
+	if(func_ptr)
+		{
+		EventMsgHandlerFptr mem_func_ptr = static_cast<EventMsgHandlerFptr>(func_ptr);
+		(this->*mem_func_ptr)(aMessage);
+		return (KErrNone);
+		}
+	
+	return (KErrNotFound);
+	}
+	
+/**
+Message handling methods.
+*/
+void CCntEventMsgHandler::RequestEvent(const RMessage2& aMessage)
+	{
+	iEventQueue->RequestEvent(aMessage);
+	}
+	
+void CCntEventMsgHandler::CancelEventRequest(const RMessage2& aMessage)
+	{
+	// Complete the asynchronous request sent by the client-side
+	// database event consumer (the CCntDbNotifyMonitor class).
+	iEventQueue->CancelEventRequest();
+	// Complete the cancelling request (sent to server when we got
+	// here).
+	aMessage.Complete(KErrNone);
+	}
+	
+void CCntEventMsgHandler::QueueEvent(const TContactDbObserverEvent aEvent)
+	{
+	iEventQueue->QueueEvent(aEvent);
+	}
+