|
1 /* |
|
2 * Copyright (c) 2004-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 @released |
|
23 */ |
|
24 |
|
25 #include "persistencelayerimpl.h" |
|
26 #include <cntfldst.h> // for ccontactfieldstorage. |
|
27 #include "clplcontactproperties.h" |
|
28 #include "clplanalyserproxy.h" |
|
29 #include "cntpplviewmanager.h" |
|
30 |
|
31 /** |
|
32 CLplTester constructor. |
|
33 */ |
|
34 CLplTester::CLplTester(CLplContactProperties& aProps, CPplContactsFile& aFile) |
|
35 : |
|
36 iProps(aProps), |
|
37 iFile(aFile) |
|
38 { |
|
39 } |
|
40 |
|
41 /** |
|
42 Merging pure (minimal) contact with the template should be out of scope of the |
|
43 Persistence Layer. The only reason to have this functions in the test interface |
|
44 is that CContactItem::RestoreTemplateFieldsL() is not exported. |
|
45 */ |
|
46 void CLplTester::MergeContactWithTemplateL(CContactItem& aContact, const CContactItem& aTempl, const CContactItemViewDef& aView) const |
|
47 { |
|
48 if (aContact.TemplateRefId()!=KNullContactId && aContact.Type() != KUidContactCardTemplate) |
|
49 { |
|
50 aContact.RestoreTemplateFieldsL(iProps.SystemTemplateL().CardFields(), aTempl.CardFields(), aView); |
|
51 } |
|
52 } |
|
53 |
|
54 /** |
|
55 CPersistenceLayer object factory. |
|
56 */ |
|
57 EXPORT_C CPersistenceLayer* CPersistenceLayer::NewLC(RFs& aFs, MIniFileManager* aIniFileManager, MContactDbObserverV2* aObserver) |
|
58 { |
|
59 CPersistenceLayer* self = new (ELeave) CPersistenceLayer(aFs, aIniFileManager, aObserver); |
|
60 CleanupStack::PushL(self); |
|
61 return self; |
|
62 } |
|
63 |
|
64 |
|
65 /** |
|
66 CPersistenceLayer first phase constructor. |
|
67 */ |
|
68 CPersistenceLayer::CPersistenceLayer(RFs& aFs, MIniFileManager* aIniFileManager, MContactDbObserverV2* aObserver) |
|
69 : |
|
70 iFs(aFs), |
|
71 iCntDbObserver(aObserver), |
|
72 iIniManager(aIniFileManager) |
|
73 { |
|
74 } |
|
75 |
|
76 |
|
77 |
|
78 /** |
|
79 CPersistenceLayer destructor. |
|
80 */ |
|
81 CPersistenceLayer::~CPersistenceLayer() |
|
82 { |
|
83 if (iFactory) |
|
84 { |
|
85 delete iFactory; |
|
86 } |
|
87 if (iContactProperties) |
|
88 { |
|
89 delete iContactProperties; |
|
90 } |
|
91 if (iAnalyserProxy) |
|
92 { |
|
93 delete iAnalyserProxy; |
|
94 } |
|
95 if (iTester) |
|
96 { |
|
97 delete iTester; |
|
98 } |
|
99 |
|
100 // May not be a file opened by Persistence Layer. |
|
101 if (iContactsFile) |
|
102 { |
|
103 // Don't call iContactsFile.Close() since the destructor does it. |
|
104 delete iContactsFile; |
|
105 } |
|
106 } |
|
107 |
|
108 |
|
109 /** |
|
110 Set the database observer. |
|
111 */ |
|
112 EXPORT_C void CPersistenceLayer::RegisterDbObserver(MContactDbObserverV2& aDbObserver) |
|
113 { |
|
114 // Note the callback interface supplied. |
|
115 iCntDbObserver = &aDbObserver; |
|
116 |
|
117 // Contacts file should always exist. |
|
118 iContactsFile->RegisterDbObserver(aDbObserver); |
|
119 |
|
120 // If the ini manager exists and the analyser proxy does not yet exist then |
|
121 // create the proxy. |
|
122 if (iIniManager && !iAnalyserProxy) |
|
123 { |
|
124 // This used to call new (ELeave). We don't check for NULL afterwards as we |
|
125 // can't do anything about it. If an allocation failure occurs and the users |
|
126 // of iAnalyserProxy do not check for NULL, cntsrv.exe will now panic. |
|
127 iAnalyserProxy = new CLplAnalyserProxy(*iIniManager, |
|
128 *iCntDbObserver, iContactsFile->PersistenceBroker(), |
|
129 iContactsFile->TransactionManager(), *iContactProperties); |
|
130 } |
|
131 } |
|
132 |
|
133 |
|
134 EXPORT_C MLplContactsFile& CPersistenceLayer::ContactsFileL() |
|
135 { |
|
136 if (!iContactsFile) |
|
137 { |
|
138 iContactProperties = new (ELeave) CLplContactProperties(iFs); |
|
139 CleanupStack::PushL(TCleanupItem(CleanupOperation, this)); |
|
140 iContactsFile = CPplContactsFile::NewL(*iContactProperties, iCntDbObserver); |
|
141 CleanupStack::PushL(TCleanupItem(CleanupOperation, this)); |
|
142 |
|
143 if (iIniManager && iCntDbObserver) // Callback interfaces supplied? |
|
144 { |
|
145 iAnalyserProxy = new (ELeave) CLplAnalyserProxy(*iIniManager, |
|
146 *iCntDbObserver, iContactsFile->PersistenceBroker(), |
|
147 iContactsFile->TransactionManager(), *iContactProperties); |
|
148 } |
|
149 CleanupStack::Pop(2); |
|
150 } |
|
151 return *iContactsFile; |
|
152 } |
|
153 |
|
154 void CPersistenceLayer::CleanupOperation(TAny* aObject) |
|
155 { |
|
156 CPersistenceLayer* persitenceLayer = static_cast<CPersistenceLayer*>(aObject); |
|
157 if (persitenceLayer->iContactProperties) |
|
158 { |
|
159 delete persitenceLayer->iContactProperties; |
|
160 persitenceLayer->iContactProperties = NULL; |
|
161 } |
|
162 if (persitenceLayer->iContactsFile) |
|
163 { |
|
164 delete persitenceLayer->iContactsFile; |
|
165 persitenceLayer->iContactsFile = NULL; |
|
166 } |
|
167 } |
|
168 |
|
169 EXPORT_C MLplPersistenceBroker& CPersistenceLayer::PersistenceBroker() |
|
170 { |
|
171 // Use analyser proxy if it exists. |
|
172 if (iAnalyserProxy) |
|
173 { |
|
174 return *iAnalyserProxy; |
|
175 } |
|
176 else |
|
177 { |
|
178 return iContactsFile->PersistenceBroker(); |
|
179 } |
|
180 } |
|
181 |
|
182 |
|
183 EXPORT_C MLplTransactionManager& CPersistenceLayer::TransactionManager() |
|
184 { |
|
185 // In order to use the Persistence Broker you must open the database first. |
|
186 __ASSERT_ALWAYS(iContactsFile && iContactsFile->IsOpened(), User::Leave(KErrNotReady)); |
|
187 |
|
188 // Use analyser proxy if it exists. |
|
189 if (iAnalyserProxy) |
|
190 { |
|
191 return *iAnalyserProxy; |
|
192 } |
|
193 else |
|
194 { |
|
195 return iContactsFile->TransactionManager(); |
|
196 } |
|
197 } |
|
198 |
|
199 |
|
200 EXPORT_C MLplContactProperties& CPersistenceLayer::ContactProperties() |
|
201 { |
|
202 // In order to use Contact Properties you must open the database first. |
|
203 __ASSERT_ALWAYS(iContactProperties, User::Leave(KErrNotReady)); |
|
204 |
|
205 // If contacts file is created iContactProperties is also created. |
|
206 return *iContactProperties; |
|
207 } |
|
208 |
|
209 |
|
210 EXPORT_C MLplPersistenceLayerFactory& CPersistenceLayer::FactoryL() |
|
211 { |
|
212 if(iFactory == NULL) |
|
213 { |
|
214 iFactory = new (ELeave) CLplPersistenceLayerFactory( |
|
215 *iContactsFile,*iContactProperties); |
|
216 } |
|
217 return *iFactory; |
|
218 } |
|
219 |
|
220 |
|
221 CLplPersistenceLayerFactory::~CLplPersistenceLayerFactory() |
|
222 { |
|
223 delete iCollection; |
|
224 delete iManager; |
|
225 } |
|
226 |
|
227 |
|
228 CLplPersistenceLayerFactory::CLplPersistenceLayerFactory(CPplContactsFile& aContactsFile,CLplContactProperties& aContactProperties) : |
|
229 iContactsFile(aContactsFile), |
|
230 iContactProperties(aContactProperties) |
|
231 { |
|
232 } |
|
233 |
|
234 |
|
235 MLplViewIteratorManager& CLplPersistenceLayerFactory::GetViewIteratorManagerL() |
|
236 { |
|
237 if(iManager == NULL) |
|
238 { |
|
239 iManager = CCntPplViewManager::NewL(iContactsFile, iContactProperties); |
|
240 } |
|
241 return *iManager; |
|
242 } |
|
243 |
|
244 |
|
245 MContactSynchroniser& CLplPersistenceLayerFactory::GetContactSynchroniserL(TUint aSessionId) |
|
246 { |
|
247 return iContactProperties.ContactSynchroniserL(aSessionId); |
|
248 } |
|
249 |
|
250 |
|
251 MLplCollection& CLplPersistenceLayerFactory::GetCollectorL() |
|
252 { |
|
253 if(iCollection == NULL) |
|
254 { |
|
255 iCollection = CPlCollection::NewL(iContactsFile); |
|
256 } |
|
257 return *iCollection; |
|
258 } |
|
259 |
|
260 |
|
261 EXPORT_C MLplPersistenceLayerTest& CPersistenceLayer::PersistenceLayerTestL() |
|
262 { |
|
263 if (!iTester) |
|
264 { |
|
265 iTester = new (ELeave) CLplTester(*iContactProperties, *iContactsFile); |
|
266 } |
|
267 return *iTester; |
|
268 } |