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