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