plugins/contacts/symbian/contactsmodel/cntsrv/src/ccntmsghandler.cpp
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     1 /*
       
     2 * Copyright (c) 2007-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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalComponent
       
    22 */
       
    23 
       
    24 #include "ccntmsghandler.h"
       
    25 
       
    26 #include "ccntsession.h"
       
    27 #include "ccntserver.h"
       
    28 #include "ccntbackuprestoreagent.h"
       
    29 #include "ccntpackager.h"
       
    30 
       
    31 #include "ccntstatemachine.h"
       
    32 #include "ccntdbmanagercontroller.h"
       
    33 	
       
    34 CCntMsgHandler::CCntMsgHandler(CCntSession& aSession)
       
    35 :iManager(aSession.iManager), iPackager(aSession.iPackager), iView(aSession.iView), iTimeOut(aSession.iTimeOut), iSessionId(aSession.iSessionId), iSession(aSession)
       
    36 	{
       
    37 	}
       
    38 
       
    39 CCntMsgHandler::~CCntMsgHandler()
       
    40 	{
       
    41 	}
       
    42 	
       
    43 
       
    44 // Helper methods
       
    45 
       
    46 /**
       
    47 Many operations require a CCntDbManager instance.  This method checks that it
       
    48 exists.
       
    49 */
       
    50 void CCntMsgHandler::CheckForManagerL()
       
    51 	{
       
    52 	if(iManager == NULL) 
       
    53 		{
       
    54 		User::Leave(KErrNotReady);
       
    55 		}	
       
    56 	}
       
    57 	
       
    58 /**
       
    59 Get reference to the parent CServer2 derived class.
       
    60 */
       
    61 CCntServer& CCntMsgHandler::Server()
       
    62 	{
       
    63 	return iSession.Server();
       
    64 	}
       
    65 	
       
    66 /**
       
    67 Read message.
       
    68 
       
    69 @leave KErrBadDescriptor Error occurred with aDes.
       
    70 */
       
    71 void CCntMsgHandler::ReadL(const RMessage2& aMessage, TInt aParam, TDes& aDes)
       
    72 	{
       
    73 	const TInt ret = aMessage.Read(aParam, aDes);
       
    74 	if (ret != KErrNone)
       
    75 		{
       
    76 		User::Leave(KErrBadDescriptor);
       
    77 		}
       
    78 	}
       
    79 	
       
    80 /**
       
    81 Read message.
       
    82 
       
    83 @leave KErrBadDescriptor Error occurred with aDes.
       
    84 */
       
    85 void CCntMsgHandler::WriteL(const RMessage2& aMessage, TInt aParam, const TDesC& aDes, TInt aOffset)
       
    86 	{
       
    87 	const TInt ret = aMessage.Write(aParam, aDes, aOffset);
       
    88 	if	(ret != KErrNone)
       
    89 		{
       
    90 		User::Leave(KErrBadDescriptor);
       
    91 		}
       
    92 	}
       
    93 
       
    94 /** 
       
    95 Session is not going to be interested in database event notifications 
       
    96 so un-register it.
       
    97 */
       
    98 void CCntMsgHandler::UnRegisterDatabaseEventObserver()
       
    99 	{
       
   100 	iSession.UnRegisterDatabaseEventObserver();
       
   101 	}
       
   102 	
       
   103 /** 
       
   104 Get function pointer to message handling method. 
       
   105 */
       
   106 MsgHandlerFptr CCntMsgHandler::LookupHandlerMethodL(TInt aOpCode, const TInt* aOpCodes, const TInt aOpCodesLength)
       
   107 	{	
       
   108 	for(TInt index = 0; index < aOpCodesLength; index++)
       
   109 		{		
       
   110 		if(aOpCode == aOpCodes[index])
       
   111 			{
       
   112 			const RHashMap<TInt,MsgHandlerFptr>& msgLut = Server().MsgLut();
       
   113 			MsgHandlerFptr func_ptr = msgLut.FindL(aOpCode);
       
   114 			return func_ptr;
       
   115 			}
       
   116 		}
       
   117 	
       
   118 	return NULL;
       
   119 	}