|
1 /** |
|
2 * Copyright (c) 2005-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 /** |
|
21 @file |
|
22 @internalComponent |
|
23 @released |
|
24 */ |
|
25 |
|
26 |
|
27 #ifndef __PERSISTENCELAYER_H__ |
|
28 #define __PERSISTENCELAYER_H__ |
|
29 |
|
30 #include <cntdef.h> |
|
31 #include <cntitem.h> |
|
32 #include <cntviewbase.h> |
|
33 |
|
34 |
|
35 #ifdef __EABI__ |
|
36 #define NONSHARED __declspec(notshared) |
|
37 #else |
|
38 #define NONSHARED |
|
39 #endif |
|
40 |
|
41 |
|
42 enum TPlReadMode |
|
43 { |
|
44 EPlBlobOnly = 0, |
|
45 EPlIdentityInfo = 1, |
|
46 EPlEmailInfo = 2, |
|
47 EPlGroupMembershipInfo = 4, |
|
48 EPlAllInfo = EPlIdentityInfo | EPlEmailInfo | EPlGroupMembershipInfo |
|
49 }; |
|
50 |
|
51 |
|
52 enum TOpenStates |
|
53 { |
|
54 EPlClosed = 0, |
|
55 EPlFileOpen, |
|
56 EPlRecover, |
|
57 EPlUpgrade, |
|
58 EPlOpened |
|
59 }; |
|
60 |
|
61 |
|
62 /** |
|
63 This interface defines five basic operations on CContactItem objects in the |
|
64 Persistence Layer: |
|
65 |
|
66 - Create |
|
67 - Read |
|
68 - Update |
|
69 - Delete |
|
70 - Change type |
|
71 |
|
72 The methods in this interface provide the only mechanism to change data in the |
|
73 Contacts database. |
|
74 |
|
75 The SetConnectionId() method is a helper function and it is used in the event |
|
76 notification mechanism. |
|
77 */ |
|
78 class MLplPersistenceBroker |
|
79 { |
|
80 public: |
|
81 /** Store a new contact. */ |
|
82 virtual TContactItemId CreateL(CContactItem& aItem, TUint aSessionId)=0; |
|
83 |
|
84 /** Read an existing contact (or parts of it as specified by the view definition). */ |
|
85 virtual CContactItem* ReadLC(TContactItemId aItemId, const CContactItemViewDef& aView, TInt aInfoToRead, TUint aSessionId, TBool aIccOpenCheck = EFalse) const =0; |
|
86 |
|
87 /** Update an existing contact (or parts of it as specified by the view definition). */ |
|
88 virtual void UpdateL(CContactItem& aItem, TUint aSessionId, TBool aSpeeDailUpdate = EFalse) = 0; |
|
89 |
|
90 /** Delete a contact. The deleted contact is read first before the deletion |
|
91 and the object is returned. This is useful for the analysis of the deleted contact. */ |
|
92 virtual CContactItem* DeleteLC(TContactItemId aItemId, TUint aSessionId, TCntSendEventAction aEventType) = 0; |
|
93 |
|
94 /** Change type for the current contact item. */ |
|
95 virtual void ChangeTypeL(TContactItemId aItemId, TUid aNewType) = 0; |
|
96 |
|
97 /** Set connection ID for the notification mechanism. */ |
|
98 virtual void SetConnectionId(TInt aConnectionId) = 0; |
|
99 }; |
|
100 |
|
101 |
|
102 /** |
|
103 The MLplTransactionManager class is part of the Logical sub-layer of the |
|
104 Persistence Layer. |
|
105 |
|
106 The interface offers Logical transactions and it ensures that the write and read |
|
107 operations are atomic, consistent, isolated and durable. |
|
108 |
|
109 The MLplTransactionManager class only provides support for a single transaction. |
|
110 */ |
|
111 class MLplTransactionManager |
|
112 { |
|
113 public: |
|
114 /** Start a new transaction. */ |
|
115 virtual void StartTransactionL() = 0; |
|
116 /** Commit the current transaction. */ |
|
117 virtual void CommitCurrentTransactionL(TUint aSessionId) = 0; |
|
118 /** Rollback the current transaction. */ |
|
119 virtual void RollbackCurrentTransactionL(TUint aSessionId) = 0; |
|
120 /** Returns if a transaction is currently in progress. */ |
|
121 virtual TBool IsTransactionActive() const = 0; |
|
122 }; |
|
123 |
|
124 |
|
125 /** |
|
126 The MLplContactsFile interface defines a set of operation on the Contacts |
|
127 database file, such as opening and closing, compression, recovery, deletion |
|
128 and Contacts Model private directory listing. |
|
129 |
|
130 Note that some operations do not require the Contacts database file to be |
|
131 opened. |
|
132 */ |
|
133 class MLplContactsFile |
|
134 { |
|
135 public: |
|
136 enum TPlCreateMode {EPlLeaveIfExist, EPlOverwrite}; |
|
137 |
|
138 virtual void CreateL(const TDesC& aFileName, TPlCreateMode aMode = EPlLeaveIfExist)=0; |
|
139 virtual void Close(TBool aNotify = ETrue)=0; |
|
140 virtual void DeleteL(const TDesC& aFileName)=0; |
|
141 virtual CDesCArray* ListL(TDriveUnit* aDriveUnit = NULL)=0; |
|
142 virtual TBool DatabaseExistsL(const TDesC& aFileName) = 0; |
|
143 virtual void DatabaseDrive(TDriveUnit& aDriveUnit) = 0; |
|
144 virtual TInt FileSize() const = 0; |
|
145 virtual void CloseTablesL(TBool aNotify) = 0; |
|
146 virtual void OpenTablesL(TBool aNotify = EFalse) = 0; |
|
147 |
|
148 virtual void OpenL(const TDesC& aFileName, TBool aNotify = EFalse)=0; |
|
149 }; |
|
150 |
|
151 |
|
152 // Forward class references. |
|
153 class CContactTemplate; |
|
154 class CContactPhoneParser; |
|
155 |
|
156 |
|
157 /** |
|
158 Originally MLplContactProperties was split into two classes. |
|
159 |
|
160 One was concerned with looking up contact item attributes (type, hint and text) |
|
161 by ID and the other was solely concerned with looking after the Preferences |
|
162 table. |
|
163 |
|
164 The latter was considered to be data that was 'static' to the whole model. |
|
165 |
|
166 Both were merged into MLplContactProperties. |
|
167 */ |
|
168 class MLplContactProperties |
|
169 { |
|
170 public: |
|
171 virtual TInt CardTemplatePrefIdL() const = 0; |
|
172 virtual void SetCardTemplatePrefIdL(TInt aCardTemplatePrefId) = 0; |
|
173 virtual TInt64 MachineIdL() const = 0; |
|
174 virtual CContactIdArray& CardTemplateIdsL() = 0; |
|
175 virtual CContactIdArray& GroupIdListL() = 0; |
|
176 virtual void SetMachineIdL(TInt64 aMachineId) = 0; |
|
177 virtual TPtrC UniqueIdL() = 0; |
|
178 |
|
179 // System template methods. |
|
180 virtual const CContactTemplate& SystemTemplateL() const =0; |
|
181 virtual void RecreateSystemTemplateL() = 0; |
|
182 |
|
183 virtual TContactItemId OwnCardIdL() = 0; |
|
184 virtual void SetOwnCardIdL(TContactItemId aId) = 0; |
|
185 |
|
186 virtual const CArrayFix<CContactDatabase::TSortPref>& SortPrefsL() =0; |
|
187 virtual void SetSortPrefsL(CArrayFix<CContactDatabase::TSortPref>* aPrefs) =0; |
|
188 |
|
189 virtual void SetDbViewContactType(TUid aDbViewContactType) =0; |
|
190 virtual TUid GetDbViewContactType() const =0; |
|
191 |
|
192 virtual TContactItemId ICCTemplateIdL(TUid aPhonebookUid, TUint aSessionId) =0; |
|
193 virtual TContactItemId PhonebookGroupIdL(TUint aSessionId) =0; |
|
194 virtual void DisableSynchroniser(TUint aSessionId) =0; |
|
195 |
|
196 virtual void SessionDeleted(TUint aSessionId) =0; |
|
197 }; |
|
198 |
|
199 class CViewContact; |
|
200 |
|
201 #define KPLViewSessionIdNull 0 |
|
202 |
|
203 /** |
|
204 This interface defines a set of functions for retrieving view contacts from the |
|
205 contacts database.The view item manager have read-only access to the database |
|
206 and supply all the required data for the contact view framework. |
|
207 */ |
|
208 class MLplViewIteratorManager |
|
209 { |
|
210 public: |
|
211 //View session create and close methods |
|
212 virtual TInt OpenViewL(const CContactTextDef& aTextDef, TContactViewPreferences aViewPrefs) =0; |
|
213 virtual void CloseView(TInt aViewId) =0; |
|
214 |
|
215 //Change sort order should be always called when there is not an iteration |
|
216 //started in persistence layer. |
|
217 virtual void ChangeSortOrderL(TInt aViewId, const CContactTextDef& aTextDef) =0; |
|
218 |
|
219 //Iterator Methods |
|
220 virtual void BeginIterateL(TInt aViewId) =0; |
|
221 virtual void EndIterateL(TInt aViewId) =0; |
|
222 virtual CViewContact* NextItemL(TInt aViewId, TContactViewPreferences aViewPrefs) =0; |
|
223 virtual CViewContact* ItemAtL(TContactItemId aContactId, TInt aViewId) =0; |
|
224 |
|
225 //Read content of a contact into descriptor |
|
226 virtual TUid ReadContactTextDefL(TContactItemId aContactId, TDes &aResult,const CContactTextDef& aTextDef) =0; |
|
227 |
|
228 //Get a sortable text field based on field type. |
|
229 virtual void TextFieldL(TInt aCntItemId,TFieldType aFieldType, TDes& aText) =0; |
|
230 }; |
|
231 |
|
232 |
|
233 /** |
|
234 This interface defines a function to Match Phone Numbers in the |
|
235 contacts database. |
|
236 */ |
|
237 class MLplFieldMatcher |
|
238 { |
|
239 public: |
|
240 virtual CContactIdArray* MatchPhoneNumberL(const TDesC& aNumber, TInt aMatchLengthFromRight) = 0; |
|
241 }; |
|
242 |
|
243 |
|
244 /** |
|
245 This interface provides a simplified way of querying the database. The result |
|
246 of the query is typically an array of the contact IDs satisfying the given |
|
247 criteria. For example, IDs of all the contacts changed since the given date. |
|
248 */ |
|
249 class MLplCollection |
|
250 { |
|
251 public: |
|
252 enum TLplViewType |
|
253 { |
|
254 EFilter, |
|
255 EChangedSince, |
|
256 EFindInIdFields, |
|
257 EFindInEmail, |
|
258 EFindInAll, |
|
259 EFindType, |
|
260 EFindGuid, |
|
261 EPhoneMatch, |
|
262 EViewData, |
|
263 EUnfiled, |
|
264 EDeleted, |
|
265 ESortNoText, |
|
266 ESortWithText, |
|
267 EMatchPhoneNos |
|
268 }; |
|
269 public: |
|
270 virtual TBool ContactMatchesHintFieldL (TInt aBitWiseFilter, TContactItemId aContactId) = 0; |
|
271 virtual CContactIdArray* CollectionL(TLplViewType aViewType,TTime aTime = 0, const TDesC& aGuid = KNullDesC)=0; |
|
272 virtual TInt ContactCountL () = 0; |
|
273 virtual CContactIdArray* MatchPhoneNumberL(const TDesC& aNumber, const TInt aMatchLengthFromRight) = 0; |
|
274 virtual CContactIdArray* FindL(const TDesC& aText, const CContactItemFieldDef* aFieldDef, TUint aSessionId) = 0; |
|
275 virtual CContactIdArray* FilterDatabaseL(CCntFilter& aFilter)=0; |
|
276 virtual void Reset()=0; |
|
277 virtual void FindAsyncInitL(const TDesC& aText,CContactItemFieldDef* aFieldDef)=0; |
|
278 virtual void FindAsyncTextDefInitL(const CDesCArray& aWords,CContactTextDef* aTextDef) =0; |
|
279 virtual CContactIdArray* FindAsyncL(TBool& aMoreToGo, TUint aSessionId)=0; |
|
280 virtual TBool UsesIdentityFieldsOnly(TInt aFindFlags) = 0; |
|
281 virtual void ConstructBitwiseFlagsFromTextDef(TInt& aFindFlags,TInt& aIdentityColumnsCount,const CContactTextDef* aTextDef) = 0; |
|
282 |
|
283 virtual TBool SeekContactL(TContactItemId aReqId,TContactItemId& aId,TUid& aContactType, TBool& aDeleted) = 0; |
|
284 }; |
|
285 |
|
286 |
|
287 /** |
|
288 This interface provides a single point of access to the three other interfaces: |
|
289 |
|
290 - View Iterator Manager |
|
291 - Phone Book Synchroniser Plugin |
|
292 - Collection Iterator. |
|
293 |
|
294 This interface is implemented in the Contacts Model twice: once on the client |
|
295 and the once on the server. This allows us to reuse the same code for Local |
|
296 View on both sides of the Contacts Model. |
|
297 */ |
|
298 class MLplPersistenceLayerFactory |
|
299 { |
|
300 public: |
|
301 virtual MLplViewIteratorManager& GetViewIteratorManagerL() = 0; |
|
302 virtual MContactSynchroniser& GetContactSynchroniserL(TUint aSessionId) = 0; |
|
303 virtual MLplCollection& GetCollectorL() = 0; |
|
304 }; |
|
305 |
|
306 |
|
307 class MLplPersistenceLayerTest |
|
308 { |
|
309 public: |
|
310 virtual void MergeContactWithTemplateL(CContactItem& aContact, const CContactItem& aTempl, const CContactItemViewDef& aView) const =0; |
|
311 }; |
|
312 |
|
313 |
|
314 class MIniFileManager |
|
315 { |
|
316 public: |
|
317 virtual void DeleteNotifyL(TContactItemId aContactId) = 0; |
|
318 virtual TContactItemId SetSpeedDialIdForPositionL(const TInt aSpeedDialIndex, const TContactItemId aContactId, const TSpeedDialPhoneNumber& aPhoneNumber, TUint aConnectionId, TBool aSendNotification) = 0; |
|
319 virtual CArrayFix<TInt>* SpeedDialIndicesForContactIdLC(TContactItemId aContactId) = 0; |
|
320 }; |
|
321 |
|
322 |
|
323 // Forward class references. |
|
324 class CPplContactsFile; |
|
325 class CLplContactProperties; |
|
326 class CLplTester; |
|
327 class CLplPersistenceLayerFactory; |
|
328 class CLplAnalyserProxy; |
|
329 |
|
330 |
|
331 class NONSHARED CPersistenceLayer : public CBase |
|
332 { |
|
333 public: |
|
334 IMPORT_C static CPersistenceLayer* NewLC(RFs& aFs, MIniFileManager* aIniFileManager = NULL, MContactDbObserver* aObserver = NULL); |
|
335 |
|
336 virtual ~CPersistenceLayer(); |
|
337 |
|
338 IMPORT_C MLplContactsFile& ContactsFileL(); |
|
339 IMPORT_C MLplPersistenceBroker& PersistenceBroker(); |
|
340 IMPORT_C MLplTransactionManager& TransactionManager(); |
|
341 IMPORT_C MLplContactProperties& ContactProperties(); |
|
342 IMPORT_C MLplPersistenceLayerFactory& FactoryL(); |
|
343 IMPORT_C void RegisterDbObserver(MContactDbObserver& aDbObserver); |
|
344 IMPORT_C MLplPersistenceLayerTest& PersistenceLayerTestL(); |
|
345 |
|
346 private: |
|
347 CPersistenceLayer(RFs& aFs, MIniFileManager* aIniFileManager, MContactDbObserver* aObserver); |
|
348 static void CleanupOperation(TAny* aObject); |
|
349 |
|
350 private: |
|
351 RFs& iFs; |
|
352 CPplContactsFile* iContactsFile; |
|
353 CLplContactProperties* iContactProperties; |
|
354 CLplTester* iTester; |
|
355 CLplAnalyserProxy* iAnalyserProxy; |
|
356 CLplPersistenceLayerFactory* iFactory; |
|
357 MContactDbObserver* iCntDbObserver; //optional |
|
358 MIniFileManager* iIniManager; //optional |
|
359 }; |
|
360 |
|
361 #endif //__PERSISTENCELAYER_H__ |