summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/cntsrv/inc/persistencelayer.h
blob: 7e07b779d11f3d5e9240ce37d8f82ad2d5d406e5 (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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
/*
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* 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
*/


#ifndef __PERSISTENCELAYER_H__
#define __PERSISTENCELAYER_H__

#include <cntdef.h>
#include <cntitem.h>
#include <cntviewbase.h>


#ifdef __EABI__
  #define NONSHARED __declspec(notshared)
#else
  #define NONSHARED
#endif


enum TPlReadMode 
	{
	EPlBlobOnly	  = 0,
	EPlIdentityInfo = 1,
	EPlEmailInfo =	2,
	EPlGroupMembershipInfo =	4,
	EPlAllInfo = EPlIdentityInfo | EPlEmailInfo | EPlGroupMembershipInfo 
	};


enum TOpenStates 
	{
	EPlClosed = 0,
	EPlFileOpen,
	EPlRecover,
	EPlUpgrade,
	EPlOpened
	};


/**
This interface defines five basic operations on CContactItem objects in the
Persistence Layer:

- Create
- Read
- Update
- Delete
- Change type

The methods in this interface provide the only mechanism to change data in the
Contacts database.

The SetConnectionId() method is a helper function and it is used in the event
notification mechanism.
*/
class MLplPersistenceBroker
	{
public:
	/** Store a new contact. */
	virtual TContactItemId CreateL(CContactItem& aItem, TUint aSessionId)=0;

	/** Read an existing contact (or parts of it as specified by the view definition). */
	virtual CContactItem* ReadLC(TContactItemId aItemId, const CContactItemViewDef& aView, TInt aInfoToRead, TUint aSessionId, TBool aIccOpenCheck = EFalse) const =0;

	/** Update an existing contact (or parts of it as specified by the view definition). */
	virtual void UpdateL(CContactItem& aItem, TUint aSessionId, TBool aSpeeDailUpdate = EFalse) = 0;

	/** Delete a contact.  The deleted contact is read first before the deletion 
	and the object is returned.  This is useful for the analysis of the deleted contact. */
	virtual CContactItem* DeleteLC(TContactItemId  aItemId, TUint aSessionId, TCntSendEventAction aEventType) = 0;
	
	/** Change type for the current contact item. */
	virtual void ChangeTypeL(TContactItemId aItemId, TUid aNewType) = 0;

	/** Set connection ID for the notification mechanism. */
	virtual void SetConnectionId(TInt aConnectionId) = 0;
	};


/**
The MLplTransactionManager class is part of the Logical sub-layer of the
Persistence Layer. 

The interface offers Logical transactions and it ensures that the write and read
operations are atomic, consistent, isolated and durable.  

The MLplTransactionManager class only provides support for a single transaction. 
*/
class MLplTransactionManager
	{
public:
	/** Start a new transaction. */
	virtual void StartTransactionL() = 0;
	/** Commit the current transaction. */
	virtual void CommitCurrentTransactionL(TUint aSessionId) = 0;
	/** Rollback the current transaction. */
	virtual void RollbackCurrentTransactionL(TUint aSessionId) = 0;
	/** Returns if a transaction is currently in progress. */
	virtual TBool IsTransactionActive() const = 0;
	};


/**
The MLplContactsFile interface defines a set of operation on the Contacts
database file, such as opening and closing, compression, recovery, deletion
and Contacts Model private directory listing.

Note that some operations do not require the Contacts database file to be
opened.
*/
class MLplContactsFile
	{
public:
	enum TPlCreateMode {EPlLeaveIfExist, EPlOverwrite};
	 
	virtual void CreateL(const TDesC& aFileName, TPlCreateMode aMode = EPlLeaveIfExist)=0;
	virtual void Close(TBool aNotify = ETrue)=0;
	virtual void DeleteL(const TDesC& aFileName)=0;
	virtual CDesCArray* ListL(TDriveUnit* aDriveUnit = NULL)=0;
	virtual TBool DatabaseExistsL(const TDesC& aFileName) = 0;
	virtual void DatabaseDrive(TDriveUnit& aDriveUnit) = 0;
	virtual TInt FileSize() const = 0;
  	virtual void CloseTablesL(TBool aNotify) = 0;
  	virtual void OpenTablesL(TBool aNotify = EFalse) = 0;  	

    virtual void OpenL(const TDesC& aFileName, TBool aNotify = EFalse)=0; 
	};


// Forward class references.
class CContactTemplate;
class CContactPhoneParser;


/**
Originally MLplContactProperties was split into two classes.

One was concerned with looking up contact item attributes (type, hint and text)
by ID and the other was solely concerned with looking after the Preferences
table.

The latter was considered to be data that was 'static' to the whole model.  

Both were merged into MLplContactProperties.
*/
class MLplContactProperties
	{
public:
	virtual TInt CardTemplatePrefIdL() const = 0;
	virtual void SetCardTemplatePrefIdL(TInt aCardTemplatePrefId) = 0;
	virtual TInt64 MachineIdL() const = 0;
	virtual CContactIdArray& CardTemplateIdsL() = 0;
	virtual CContactIdArray& GroupIdListL() = 0;
    virtual CBufSeg* DetailsListL(const TDesC& aSearchQuery) const = 0;
    
	virtual void SetMachineIdL(TInt64 aMachineId) = 0;
	virtual TPtrC UniqueIdL() = 0; 
	
	// System template methods.
	virtual const CContactTemplate& SystemTemplateL() const =0;
	virtual void RecreateSystemTemplateL() = 0;

	virtual TContactItemId OwnCardIdL() = 0;
	virtual void SetOwnCardIdL(TContactItemId aId, TBool aPersist = ETrue) = 0;

	virtual const CArrayFix<CContactDatabase::TSortPref>& SortPrefsL() =0;
	virtual void SetSortPrefsL(CArrayFix<CContactDatabase::TSortPref>* aPrefs) =0;

	virtual void SetDbViewContactType(TUid aDbViewContactType) =0;
	virtual TUid GetDbViewContactType() const =0;

	virtual TContactItemId ICCTemplateIdL(TUid aPhonebookUid, TUint aSessionId) =0;
	virtual TContactItemId PhonebookGroupIdL(TUint aSessionId) =0;
	virtual void DisableSynchroniser(TUint aSessionId) =0;

	virtual void SessionDeleted(TUint aSessionId) =0;
	};

class CViewContact;

#define KPLViewSessionIdNull 0

/**
This interface defines a set of functions for retrieving view contacts from the 
contacts database.The view item manager have read-only access to the database 
and supply all the required data for the contact view framework.
*/
class MLplViewIteratorManager
	{
public:
	//View session create and close methods
	virtual TInt OpenViewL(const CContactTextDef& aTextDef, TContactViewPreferences aViewPrefs) =0;
	virtual void CloseView(TInt aViewId) =0;
	
	//Change sort order should be always called when there is not an iteration 
	//started in persistence layer.
	virtual void ChangeSortOrderL(TInt aViewId, const CContactTextDef& aTextDef) =0;
	
	//Iterator Methods
	virtual void BeginIterateL(TInt aViewId) =0;
	virtual void EndIterateL(TInt aViewId) =0;
	virtual CViewContact* NextItemL(TInt aViewId, TContactViewPreferences aViewPrefs) =0;
	virtual CViewContact* ItemAtL(TContactItemId aContactId, TInt aViewId) =0;
	
	//Read content of a contact into descriptor
	virtual TUid ReadContactTextDefL(TContactItemId aContactId, TDes &aResult,const CContactTextDef& aTextDef) =0;
	
	//Get a sortable text field based on field type.
	virtual void TextFieldL(TInt aCntItemId,TFieldType aFieldType, TDes& aText) =0;
	};


/**
This interface defines a function to Match Phone Numbers in the 
contacts database.
*/
class MLplFieldMatcher
	{
public:
     virtual CContactIdArray* MatchPhoneNumberL(const TDesC& aNumber, TInt aMatchLengthFromRight) = 0;
	};


/**
 * This interface defines a function to close the resource 
 * which is running and depends on RSqlDatabase.
 */
class MLplSqlDatabaseObserver
    {
public:
    virtual void OnCloseL() = 0;
    };
 

/**
This interface provides a simplified way of querying the database.  The result
of the query is typically an array of the contact IDs satisfying the given
criteria.  For example, IDs of all the contacts changed since the given date.
*/
class MLplCollection
    {
public:
    enum TLplViewType
        {
        EFilter,
        EChangedSince,
        EFindInIdFields,
        EFindInEmail,
        EFindInAll,
        EFindType,
        EFindGuid,
        EPhoneMatch,
        EViewData,
        EUnfiled,
        EDeleted,
        ESortNoText,
        ESortWithText,
        EMatchPhoneNos
        };
public:
    virtual TBool ContactMatchesHintFieldL (TInt aBitWiseFilter, TContactItemId aContactId) = 0;
    virtual CContactIdArray* CollectionL(TLplViewType aViewType,TTime aTime = 0, const TDesC& aGuid = KNullDesC)=0;
    virtual TInt  ContactCountL () = 0;
    virtual CContactIdArray* MatchPhoneNumberL(const TDesC& aNumber, const TInt aMatchLengthFromRight) = 0;
    virtual CContactIdArray* FindL(const TDesC& aText, const CContactItemFieldDef* aFieldDef, TUint aSessionId) = 0;
    virtual CContactIdArray* FilterDatabaseL(CCntFilter& aFilter)=0;
    virtual CContactIdArray* FindSpeedDialContactsL() = 0;
    virtual void Reset()=0;
    virtual void FindAsyncInitL(const TDesC& aText,CContactItemFieldDef* aFieldDef)=0;
    virtual void FindAsyncTextDefInitL(const CDesCArray& aWords,CContactTextDef* aTextDef) =0;
    virtual CContactIdArray* FindAsyncL(TBool& aMoreToGo, TUint aSessionId)=0;
    virtual TBool UsesIdentityFieldsOnly(TInt aFindFlags) = 0;
    virtual void ConstructBitwiseFlagsFromTextDef(TInt& aFindFlags,TInt& aIdentityColumnsCount,const CContactTextDef* aTextDef) = 0;
    
    virtual TBool SeekContactL(TContactItemId aReqId,TContactItemId& aId,TUid& aContactType, TBool& aDeleted) = 0;
    };
    

/**
This interface provides a single point of access to the three other interfaces:
	
- View Iterator Manager
- Phone Book Synchroniser Plugin
- Collection Iterator.

This interface is implemented in the Contacts Model twice: once on the client 
and the once on the server.  This allows us to reuse the same code for Local
View on both sides of the Contacts Model.
*/
class MLplPersistenceLayerFactory
	{
public:
	virtual MLplViewIteratorManager& GetViewIteratorManagerL() = 0;
	virtual MContactSynchroniser& GetContactSynchroniserL(TUint aSessionId) = 0;
	virtual MLplCollection& GetCollectorL() = 0;
	};


class MLplPersistenceLayerTest
	{
public:
	virtual void MergeContactWithTemplateL(CContactItem& aContact, const CContactItem& aTempl, const CContactItemViewDef& aView) const =0; 
	};


class MIniFileManager
	{
public:
	virtual void DeleteNotifyL(TContactItemId aContactId) = 0;
	virtual TContactItemId SetSpeedDialIdForPositionL(const TInt aSpeedDialIndex, const TContactItemId aContactId,  const TSpeedDialPhoneNumber& aPhoneNumber, TUint aConnectionId, TBool aSendNotification) = 0;
	virtual CArrayFix<TInt>* SpeedDialIndicesForContactIdLC(TContactItemId aContactId) = 0; 
	};


// Forward class references.
class CPplContactsFile;
class CLplContactProperties;
class CLplTester;
class CLplPersistenceLayerFactory;
class CLplAnalyserProxy;


class NONSHARED CPersistenceLayer : public CBase
	{
public:
	IMPORT_C static CPersistenceLayer* NewLC(RFs& aFs, MIniFileManager* aIniFileManager = NULL, MContactDbObserverV2* aObserver = NULL); 

	virtual ~CPersistenceLayer();

	IMPORT_C MLplContactsFile& ContactsFileL();
	IMPORT_C MLplPersistenceBroker&  PersistenceBroker();
	IMPORT_C MLplTransactionManager&  TransactionManager();
	IMPORT_C MLplContactProperties& ContactProperties();
	IMPORT_C MLplPersistenceLayerFactory& FactoryL();
	IMPORT_C void RegisterDbObserver(MContactDbObserverV2& aDbObserver);
	IMPORT_C MLplPersistenceLayerTest& PersistenceLayerTestL();
			
private:
	CPersistenceLayer(RFs& aFs, MIniFileManager* aIniFileManager, MContactDbObserverV2* aObserver);
	static void CleanupOperation(TAny* aObject);

private:
	RFs& iFs;
	CPplContactsFile* 				iContactsFile;
	CLplContactProperties* 			iContactProperties;
	CLplTester*						iTester;
	CLplAnalyserProxy*				iAnalyserProxy;
	CLplPersistenceLayerFactory*	iFactory;
	MContactDbObserverV2* 			iCntDbObserver; //optional
	MIniFileManager*				iIniManager;	//optional
	};

#endif //__PERSISTENCELAYER_H__