summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/cntsrv/src/ccnttransactionmsghandler.cpp
blob: 0f038122db33aeba927fbbda12b520f88f8a3daf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
* Contact: http://www.qt-project.org/legal
* 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 "ccnttransactionmsghandler.h"

#include "ccntserver.h"
#include "ccntipccodes.h"
#include "ccntrequest.h"
#include "ccntdbmanager.h"
#include "ccntstatemachine.h"

const TInt KCntTransactionIpcCodes[] =
	{
	EBeginDbTransaction,
	EEndDbTransaction,
	ERollbackDbTransaction
	};

CCntTransactionMsgHandler* CCntTransactionMsgHandler::NewLC(CCntSession& aSession)
	{
	CCntTransactionMsgHandler* CntTransactionMsgHandler = new (ELeave) CCntTransactionMsgHandler(aSession);
	CleanupStack::PushL(CntTransactionMsgHandler);
	return CntTransactionMsgHandler;
	}
	

CCntTransactionMsgHandler::CCntTransactionMsgHandler(CCntSession& aSession)
:CCntMsgHandler(aSession)
	{		
	}
	
CCntTransactionMsgHandler::~CCntTransactionMsgHandler()
	{
	}
	
/**
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 CCntTransactionMsgHandler::HandleMessageL(const RMessage2& aMessage)
	{	
	MsgHandlerFptr func_ptr = LookupHandlerMethodL(aMessage.Function(), KCntTransactionIpcCodes, sizeof(KCntTransactionIpcCodes)/sizeof(TInt));
	
	if(func_ptr)
		{
		TransactionMsgHandlerFptr mem_func_ptr = static_cast<TransactionMsgHandlerFptr>(func_ptr);
		(this->*mem_func_ptr)(aMessage);
		return (KErrNone);
		}
	
	return (KErrNotFound);
	}
	
/**
Message handling methods.
*/
void CCntTransactionMsgHandler::BeginDbTransactionL(const RMessage2& aMessage)
	{
	// Maps to RCntModel::BeginDbTransaction().

	CheckForManagerL();
	CReqDbBeginTrans* request = CReqDbBeginTrans::NewLC(iSessionId, aMessage, iTimeOut);
	iManager->StateMachineL().ProcessRequestL(request);  // ownership transferred
	
	// ProcessRequestL received ownership of the request, the request only need
	// to be popped from CleanupStack.		
	CleanupStack::Pop(request);
	}
	
void CCntTransactionMsgHandler::EndDbTransactionL(const RMessage2& aMessage)
	{
	// Maps to RCntModel::CommitDbTransaction().

	CheckForManagerL();
	CReqDbCommitTrans* request = CReqDbCommitTrans::NewLC(iSessionId, aMessage, iTimeOut);
	iManager->StateMachineL().ProcessRequestL(request);  // ownership transferred
	
	// ProcessRequestL received ownership of the request, the request only need
	// to be popped from CleanupStack.	
	CleanupStack::Pop(request);	
	}
	
void CCntTransactionMsgHandler::RollbackDbTransactionL(const RMessage2& aMessage)
	{
	// Maps to RCntModel::RollbackDbTransaction().

	CheckForManagerL();
	CReqDbRollbackTrans* request = CReqDbRollbackTrans::NewLC(iSessionId, aMessage, iTimeOut);
	iManager->StateMachineL().ProcessRequestL(request);  // ownership transferred
	
	// ProcessRequestL received ownership of the request, the request only need
	// to be popped from CleanupStack.		
	CleanupStack::Pop(request);		
	}