summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/cntplsql/src/cplplugins.cpp
blob: c4aaf922e169a5c8511a033d8bb0381a09fdb49d (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
* 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
 @released
*/

#include "plplugins.h"
#include "cntviewprivate.h"
#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
#include <cntphonenumparser.h>
#include "cntdb_internal.h"
#include "cntsyncecom.h"
#endif


// The name of the test phone book sync plugin.  This plugin will be used in the
// first instance (i.e. if it exists then use it rather than any other plugin).
_LIT(KTestPluginName,"Test phone book synchronizer Implementation");


CContactPlugin::CContactPlugin()
	{
	}


CContactPlugin::~CContactPlugin()
	{
	iDll.Close();
	}


CContactPhoneParser* CContactPhoneParser::NewL()
	{
	CContactPhoneParser* self=new(ELeave) CContactPhoneParser;
	CleanupStack::PushL(self);
	self->LoadEComPluginL();
	CleanupStack::Pop(self); 
	return self;
	}


CContactPhoneParser::~CContactPhoneParser()
	{
	delete iParser;
	}


void CContactPhoneParser::SetPluginL(TLibraryFunction aGateFunction)
	{
	iParser=REINTERPRET_CAST(CContactPhoneNumberParser*,(*aGateFunction)());
	User::LeaveIfNull(iParser);
	}


void CContactPhoneParser::LoadEComPluginL()
	{
#ifdef __PROFILE__
	RDebug::Print(_L("[CNTMODEL] Entering CContactPhoneParser::LoadEComPluginL\n"));
	TTime now;
	now.UniversalTime();
#endif
	
	RImplInfoPtrArray	implInfoArray;
	CleanupResetAndDestroyPushL(implInfoArray);

	// Use default resolver parameters.
	TEComResolverParams resolverParams;
	
	// List implementations, searching only in ROM for the plugin.
	REComSession::ListImplementationsL(KUidEcomCntPhoneNumberParserInterface,
		resolverParams,	KRomOnlyResolverUid, implInfoArray);

	const TInt count = implInfoArray.Count();
	__ASSERT_ALWAYS( count > 0, User::Leave(KErrNotFound));

	// Create the first implementation found for
	// KUidEcomCntPhoneNumberParserInterface.
	const TUid firstImplementationFound = implInfoArray[0]->ImplementationUid();
	iParser = CContactEcomPhoneNumberParser::NewL(firstImplementationFound);
	CleanupStack::PopAndDestroy(&implInfoArray);

#ifdef __PROFILE__
	TTime now2;
	now2.UniversalTime();
	RDebug::Print(_L("[CNTMODEL] Spend %d microseconds in CContactPhoneParser::LoadEComPluginL\n"), now2.MicroSecondsFrom(now).Int64());
#endif
	}


EXPORT_C CContactSynchroniser::~CContactSynchroniser()
	{
	REComSession::DestroyedImplementation(iDtor_ID_Key);
	}


CContactSynchroniser* CContactSynchroniser::NewL()
	{
#ifdef __PROFILE__
	RDebug::Print(_L("[CNTMODEL] Entering CContactSynchroniser::NewL\n"));
	TTime now;
	now.UniversalTime();
#endif

	RImplInfoPtrArray implInfoArray;
	CleanupResetAndDestroyPushL(implInfoArray);
	REComSession::ListImplementationsL(KUidEcomCntPhBkSyncInterface, implInfoArray);
	// Load the implementation found for KUidEcomCntPhBkSyncInterface, prefer the test plugin
	const TInt count = implInfoArray.Count(); 
	__ASSERT_ALWAYS(count > 0, User::Leave(KErrNotSupported));
	
	TInt pluginToBeUsed = 0;
	CImplementationInformation *info;
	
	// Scan the list of plugins for the test plugin.
	for (TInt plugIn = 0 ; plugIn < count ; ++plugIn)
	{
		info = implInfoArray[plugIn];
		if(info->DisplayName() == KTestPluginName)
		{
			// We have found the test plugin so use it rather than any other
			// plugin.
			pluginToBeUsed = plugIn;
			break;
		}
	}
#ifdef __VERBOSE_DEBUG__
	RDebug::Print(_L("[CNTMODEL] CntServer has loaded syncplugin: %S\n"), &info->DisplayName());
#endif

	// Create the implementation found for KUidEcomCntPhBkSyncInterface.
	const TUid theImplementationID = implInfoArray[pluginToBeUsed]->ImplementationUid();
	TAny* ptr = REComSession::CreateImplementationL(theImplementationID,
		_FOFF(CContactSynchroniser,iDtor_ID_Key));

	CleanupStack::PopAndDestroy(&implInfoArray);

#ifdef __PROFILE__
	TTime now2;
	now2.UniversalTime();
	RDebug::Print(_L("[CNTMODEL] Spend %d microseconds in CContactSynchroniser::NewL()\n"), now2.MicroSecondsFrom(now).Int64());
#endif

	return reinterpret_cast<CContactSynchroniser*>(ptr);
	}


/**
Reserved (private) virtual function to allow further extension of the
MContactSynchroniser interface without requiring changes to all derived classes.
This can be used to return a pointer to an additional extension class.
*/
EXPORT_C void MContactSynchroniser::MContactSynchroniser_Reserved_1()
	{
	}