pimprotocols/phonebooksync/inc/Phonebook.h
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2002-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 // Header file for Phonebook Synchroniser's CPhoneBook class which stores
       
    15 // the parameters for each phonebook, including the Look-Up Table, Phonebook
       
    16 // store handle and flags for the synchroniser engine.
       
    17 // This class can be accessed from either the server side or engine side.
       
    18 // 
       
    19 //
       
    20 
       
    21 /**
       
    22  @file
       
    23  @internalComponent
       
    24 */
       
    25 
       
    26 #ifndef __PHONEBOOK_H__
       
    27 #define __PHONEBOOK_H__
       
    28 
       
    29 #include <etelmm.h>
       
    30 
       
    31 #include "phbksync.h"
       
    32 #include "phbksynclog.h"
       
    33 
       
    34 
       
    35 /**
       
    36  *  Default identity for a phonebook before its identity is read.
       
    37  */
       
    38 _LIT8(KPhonebookIdUnknown, "unknown");
       
    39 
       
    40 
       
    41 /**
       
    42  *  State of a slot in the Look-Up Table.
       
    43  */
       
    44 enum TPhonebookSlotState
       
    45 	{
       
    46 	ESlotUnconfirmed,
       
    47 	ESlotEmpty,
       
    48 	ESlotUsedAvailable,
       
    49 	ESlotUsedNotAvailable,
       
    50 	ESlotHiddenAvailable,
       
    51 	ESlotHiddenNotAvailable
       
    52 	};
       
    53 
       
    54 
       
    55 /**
       
    56  *  This class is used to store the Phonebook Sync Server's internal phonebook
       
    57  *  parameters and Look-Up Table. The Look-Up Table is used to store the Contacts
       
    58  *  UID, slot number and slot state.
       
    59  */
       
    60 class CPhoneBook : public CBase 
       
    61 	{
       
    62 private:
       
    63 	class TLookUpTableEntry
       
    64 		{
       
    65 	public:
       
    66 		TLookUpTableEntry();
       
    67 	
       
    68 	public:
       
    69 		TContactItemId  iContactId;
       
    70 		TPhonebookSlotState  iSlotState;
       
    71 		};
       
    72 
       
    73 public:
       
    74 	static CPhoneBook* NewL(TUid aPhonebookUid);
       
    75 	void ConstructL();
       
    76 	~CPhoneBook();
       
    77 	
       
    78 	inline TUid GetPhonebookUid() const;
       
    79 	
       
    80 	inline RPhoneBookSession::TPhonebookSyncMode GetSyncMode() const;
       
    81 	inline void SetSyncMode(RPhoneBookSession::TPhonebookSyncMode aSyncMode);
       
    82 	
       
    83 	inline TInt GetPhBkInfoRetrievedResult() const;
       
    84 	inline void SetPhBkInfoRetrievedResult(TInt aErrorCode);
       
    85 	
       
    86 	inline RPhoneBookSession::TSyncState GetSyncState() const;
       
    87 	inline void SetSyncState(RPhoneBookSession::TSyncState aSyncState);
       
    88 
       
    89 	inline TInt GetLastSyncError() const;
       
    90 	inline void SetLastSyncError(TInt aLastSyncError);
       
    91 
       
    92 	inline TContactItemId GetTemplateId() const;
       
    93 	inline void SetTemplateId(TContactItemId aId);
       
    94 
       
    95 	inline TContactItemId GetGroupId() const;
       
    96 	inline void SetGroupId(TContactItemId aId);
       
    97 
       
    98 	inline const RPhoneBookSession::TContactFieldsV3& GetContactFields() const;
       
    99 	inline void SetContactFields(const RPhoneBookSession::TContactFieldsV3& aContactFields);
       
   100 
       
   101 	inline const RMobilePhoneBookStore& GetPhoneBookStore(RMobilePhone& aPhone);
       
   102 	inline void ClosePhoneBookStore();
       
   103 
       
   104 	inline const RMobilePhoneBookStore::TMobilePhoneBookInfoV5& GetPhoneBookInfo() const;
       
   105 	inline void SetPhoneBookInfo(const RMobilePhoneBookStore::TMobilePhoneBookInfoV5& aPhBkInfo);
       
   106 	inline void AdjustPhoneBookInfoUsedEntries(TInt aChange);
       
   107 
       
   108 	inline TInt GetLookUpTableSize() const;
       
   109 	void SetLookUpTableSizeL(TInt aSize);
       
   110 	void ClearLookUpTable();
       
   111 
       
   112 	TInt IsEntryInTable(TContactItemId aContactId) const;
       
   113 	TInt UpdateEntryInTable(TInt aSlotNum, TContactItemId aContactId);
       
   114 	TInt UpdateEntryInTable(TInt aSlotNum, TContactItemId aContactId,
       
   115 							TPhonebookSlotState aSlotState);
       
   116 	TContactItemId  GetContactIdFromSlotNum(TInt aSlotNum) const;
       
   117 	TInt GetSlotNumFromContactId(TContactItemId aContactId) const;
       
   118 
       
   119 	TInt GetNumFreeSlots() const;
       
   120 	TInt GetFirstEmptySlot() const;
       
   121 	void GetMatchingEntries(TPhonebookSlotState aSlotState,
       
   122 							RArray<TInt>& aEntries) const;
       
   123 
       
   124 	void LogLookUpTable() const;
       
   125 
       
   126 private:
       
   127 	CPhoneBook(TUid aPhonebookUid);
       
   128 
       
   129 private:
       
   130 	TUid  iPhonebookUid;
       
   131 	RPhoneBookSession::TPhonebookSyncMode  iSyncMode;
       
   132 	TInt  iPhBkInfoRetrievedResult;
       
   133 	RPhoneBookSession::TSyncState  iSyncState;
       
   134 	TInt  iLastSyncError;
       
   135 	TContactItemId  iTemplateId;
       
   136 	TContactItemId  iGroupId;
       
   137 	RPhoneBookSession::TContactFieldsV3  iContactFieldsV3;
       
   138 	RMobilePhoneBookStore  iPhonebookStore;
       
   139 	RMobilePhoneBookStore::TMobilePhoneBookInfoV5  iPhBkInfoV5;
       
   140 	CArrayFixFlat<TLookUpTableEntry>  iLookUpTable;
       
   141 	};
       
   142 
       
   143 
       
   144 /**
       
   145  *  Return the ICC phonebook type. This will be one of the supported
       
   146  *  phonebooks. 
       
   147  *
       
   148  *  @return UID value used for this phone store.
       
   149  */
       
   150 inline TUid CPhoneBook::GetPhonebookUid() const
       
   151 	{
       
   152 	return iPhonebookUid;
       
   153 	} // CPhoneBook::GetPhonebookUid
       
   154 
       
   155 
       
   156 /**
       
   157  *  Return the phonebook cache state.
       
   158  *
       
   159  *  @return The RPhoneBookSession::TSyncState cache state for this phonebook.
       
   160  */
       
   161 inline RPhoneBookSession::TSyncState CPhoneBook::GetSyncState() const
       
   162 	{
       
   163 	return iSyncState;
       
   164 	} // CPhoneBook::GetSyncState
       
   165 
       
   166 
       
   167 /**
       
   168  *  Set the phonebook cache state.
       
   169  *
       
   170  *  @param aSyncState  The phonebook cache state.
       
   171  */
       
   172 inline void CPhoneBook::SetSyncState(RPhoneBookSession::TSyncState aSyncState)
       
   173 	{
       
   174 	iSyncState = aSyncState;
       
   175 	} // CPhoneBook::SetSyncState
       
   176 
       
   177 
       
   178 /**
       
   179  *  Return last error from phone sync operation.
       
   180  *
       
   181  *  @return Returns the error stored during the last synchronisation.
       
   182  */
       
   183 inline TInt CPhoneBook::GetLastSyncError() const
       
   184 	{
       
   185 	return iLastSyncError;
       
   186 	} // CPhoneBook::GetLastSyncError
       
   187 
       
   188 
       
   189 /**
       
   190  *  Set last error from a synchronisation operation for this phonebook.
       
   191  *
       
   192  *  @param aLastSyncError  New last error value.
       
   193  */
       
   194 inline void CPhoneBook::SetLastSyncError(TInt aLastSyncError)
       
   195 	{
       
   196 	iLastSyncError = aLastSyncError;
       
   197 	} // CPhoneBook::SetLastSyncError
       
   198 
       
   199 
       
   200 /**
       
   201  *  Provides the contact fields supported by the phonebook.
       
   202  *
       
   203  *  @return Returns a RPhoneBookSession::TContactFieldsV3 field format object.
       
   204  */
       
   205 inline const RPhoneBookSession::TContactFieldsV3& CPhoneBook::GetContactFields() const
       
   206 	{
       
   207 	return iContactFieldsV3;
       
   208 	} // CPhoneBook::GetContactFields
       
   209 
       
   210 
       
   211 /**
       
   212  *  Sets the contact fields supported by the phonebook.
       
   213  *
       
   214  *  @param aContactFields  Contacts field format data.
       
   215  */
       
   216 inline void CPhoneBook::SetContactFields(const RPhoneBookSession::TContactFieldsV3& aContactFields)
       
   217 	{
       
   218 	iContactFieldsV3 = aContactFields;
       
   219 	} // CPhoneBook::SetContactFields
       
   220 
       
   221 
       
   222 /**
       
   223  *  Get the Phonebook Store used by the engine for the phonebook.
       
   224  *
       
   225  *  @param aPhone  Handle to the mobile phone, used to open the store if needed.
       
   226  *
       
   227  *  @return The mobile phone store handle.
       
   228  */
       
   229 inline const RMobilePhoneBookStore& CPhoneBook::GetPhoneBookStore(RMobilePhone& aPhone)
       
   230 	{
       
   231 	//
       
   232 	// Make sure the store is open...
       
   233 	//
       
   234 	if (iPhBkInfoRetrievedResult == KErrNone  &&
       
   235 		iPhonebookStore.SubSessionHandle() == 0)
       
   236 		{
       
   237 		TInt  result(KErrNotSupported);
       
   238 
       
   239 		if (iPhonebookUid == KUidIccGlobalAdnPhonebook)
       
   240 			{
       
   241 			result = iPhonebookStore.Open(aPhone,
       
   242 										  KETelIccAdnPhoneBook,
       
   243 										  KEtelGsmPhoneBookType);
       
   244 			LOGPARAMS2(_L8("OpenPhoneBookStore(): ADN result=%d"), result);
       
   245 			}
       
   246 		else if (iPhonebookUid == KUidIccGlobalSdnPhonebook)
       
   247 			{
       
   248 			result = iPhonebookStore.Open(aPhone,
       
   249 										  KETelIccSdnPhoneBook,
       
   250 										  KEtelGsmPhoneBookType);
       
   251 			LOGPARAMS2(_L8("OpenPhoneBookStore(): SDN result=%d"), result);
       
   252 			}
       
   253 		else if (iPhonebookUid == KUidIccGlobalLndPhonebook)
       
   254 			{
       
   255 			result = iPhonebookStore.Open(aPhone,
       
   256 										  KETelIccLndPhoneBook,
       
   257 										  KEtelGsmPhoneBookType);
       
   258 			LOGPARAMS2(_L8("OpenPhoneBookStore(): LND result=%d"), result);
       
   259 			}
       
   260 		else if (iPhonebookUid == KUidUsimAppAdnPhonebook)
       
   261 			{
       
   262 			result = iPhonebookStore.Open(aPhone,
       
   263 										  KETelIccAdnPhoneBook,
       
   264 										  KEtelUSimPhoneBookType);
       
   265 			LOGPARAMS2(_L8("OpenPhoneBookStore(): USIM ADN result=%d"), result);
       
   266 			}
       
   267 		else if (iPhonebookUid == KUidIccGlobalFdnPhonebook)
       
   268 			{
       
   269 			result = iPhonebookStore.Open(aPhone,
       
   270 										  KETelIccFdnPhoneBook,
       
   271 										  KEtelGsmPhoneBookType);
       
   272 			LOGPARAMS2(_L8("OpenPhoneBookStore(): FDN result=%d"), result);
       
   273 			}
       
   274 
       
   275 		//
       
   276 		// Store any failures so that store will not be reopened later...
       
   277 		//
       
   278 		if (result != KErrNone)
       
   279 			{
       
   280 			iPhBkInfoRetrievedResult = result;
       
   281 			}
       
   282 		else if (iPhonebookStore.SubSessionHandle() == 0)
       
   283 			{
       
   284 			iPhBkInfoRetrievedResult = KErrNotSupported;
       
   285 			}
       
   286 		}
       
   287 
       
   288 	//
       
   289 	// Return the phone store. A check is made later to ensure it is valid
       
   290 	// before use.
       
   291 	//
       
   292 	return iPhonebookStore;
       
   293 	} // CPhoneBook::GetPhoneBookStore
       
   294 
       
   295 
       
   296 /**
       
   297  *  Closes the Phonebook Store used by the engine for this phonebook.
       
   298  */
       
   299 inline void CPhoneBook::ClosePhoneBookStore()
       
   300 	{
       
   301 	iPhonebookStore.Close();
       
   302 	} // CPhoneBook::ClosePhoneBookStore
       
   303 
       
   304 
       
   305 /**
       
   306  *  Returns the ICC entry template ID for this phonebook.
       
   307  *
       
   308  *  @return Contacts Id representing the template UID.
       
   309  */
       
   310 inline TContactItemId CPhoneBook::GetTemplateId() const
       
   311 	{
       
   312 	return iTemplateId;
       
   313 	} // CPhoneBook::GetTemplateId
       
   314 
       
   315 
       
   316 /**
       
   317  *  Sets the ICC entry template ID for this phonebook.
       
   318  *
       
   319  *  @param aId  Contacts Id representing the template UID.
       
   320  */
       
   321 inline void CPhoneBook::SetTemplateId(TContactItemId aId)
       
   322 	{
       
   323 	iTemplateId = aId;
       
   324 	} // CPhoneBook::SetTemplateId
       
   325 
       
   326 
       
   327 /**
       
   328  *  Returns the ICC entry group ID.
       
   329  *
       
   330  *  @return Contacts Id representing the group UID.
       
   331  */
       
   332 inline TContactItemId CPhoneBook::GetGroupId() const
       
   333 	{
       
   334 	return iGroupId;
       
   335 	} // CPhoneBook::GetGroupId
       
   336 
       
   337 
       
   338 /**
       
   339  *  Sets the ICC entry group ID for this phonebook.
       
   340  *
       
   341  *  @param aId  Contacts Id representing the group UID.
       
   342  */
       
   343 inline void CPhoneBook::SetGroupId(TContactItemId aId)
       
   344 	{
       
   345 	iGroupId = aId;
       
   346 	} // CPhoneBook::SetGroupId
       
   347 
       
   348 
       
   349 /**
       
   350  *  Returns the result for this phonebook which specifies if the PhBkInfo data
       
   351  *  has been stored or if the phonebook is not supported.
       
   352  *
       
   353  *  @return The PhBkInfo retrieved result.
       
   354  */
       
   355 inline TInt CPhoneBook::GetPhBkInfoRetrievedResult() const
       
   356 	{
       
   357 	return iPhBkInfoRetrievedResult;
       
   358 	} // CPhoneBook::GetPhBkInfoRetrievedResult
       
   359 
       
   360 
       
   361 /**
       
   362  *  Sets the PhBkInfo retrieved results to say if the data has been retrieved
       
   363  *  and stored, or if the phonebook is not supported.
       
   364  *
       
   365  *  @param aFlag  PhBkInfo retrieved result.
       
   366  */
       
   367 inline void CPhoneBook::SetPhBkInfoRetrievedResult(TInt aErrorCode)
       
   368 	{
       
   369 	iPhBkInfoRetrievedResult = aErrorCode;
       
   370 	} // CPhoneBook::SetPhBkInfoRetrievedResult
       
   371 
       
   372 
       
   373 /**
       
   374  *  Return the current setting for the phonebook synchronisation mode.
       
   375  *
       
   376  *  @return A RPhoneBookSession::TPhonebookSyncMode phonebook synchronisation mode.
       
   377  */
       
   378 inline RPhoneBookSession::TPhonebookSyncMode CPhoneBook::GetSyncMode() const
       
   379 	{
       
   380 	return iSyncMode;
       
   381 	} // CPhoneBook::GetSyncMode
       
   382 
       
   383 
       
   384 /**
       
   385  *  Set a new value for the phonebook synchronisation mode.
       
   386  *
       
   387  *  @param aSyncMode  Phonebook synchronisation mode.
       
   388  */
       
   389 inline void CPhoneBook::SetSyncMode(RPhoneBookSession::TPhonebookSyncMode aSyncMode)
       
   390 	{
       
   391 	iSyncMode = aSyncMode;
       
   392 	} // CPhoneBook::SetSyncMode
       
   393 
       
   394 
       
   395 /**
       
   396  *  Get the PhBkInfo parameter data for this phonebook.
       
   397  *
       
   398  *  @return A RMobilePhoneBookStore::TMobilePhoneBookInfoV5 structure containing
       
   399  *          information about the phonebook.
       
   400  */
       
   401 inline const RMobilePhoneBookStore::TMobilePhoneBookInfoV5& CPhoneBook::GetPhoneBookInfo() const
       
   402 	{
       
   403 	return iPhBkInfoV5;
       
   404 	} // CPhoneBook::GetPhoneBookInfo
       
   405 
       
   406 
       
   407 /**
       
   408  *  Set the Phonebook Info parameter for this phonebook. This function can safely accept
       
   409  *  a V1 and V2 structures if they are cast to a V5.
       
   410  *
       
   411  *  @param aPhBkInfo  The PhBkInfo for this phonebook. 
       
   412  */
       
   413 inline void CPhoneBook::SetPhoneBookInfo(const RMobilePhoneBookStore::TMobilePhoneBookInfoV5& aPhBkInfo)
       
   414 	{
       
   415 	//
       
   416 	// For the V1 and V2 format info we need to safely initialise V5 attributes that
       
   417 	// are not handled by static cast copy...
       
   418 	//	
       
   419 	if (aPhBkInfo.ExtensionId() == RMobilePhoneStore::KETelMobilePhonebookStoreV1)
       
   420 		{
       
   421 		static_cast<RMobilePhoneBookStore::TMobilePhoneBookInfoV1&>(iPhBkInfoV5) =
       
   422 				static_cast<const RMobilePhoneBookStore::TMobilePhoneBookInfoV1&>(aPhBkInfo);
       
   423 
       
   424 		iPhBkInfoV5.iPhBkMode.Zero();
       
   425 		iPhBkInfoV5.iMaxSecondNames = -1;
       
   426 		iPhBkInfoV5.iMaxTextLengthSecondName = -1;
       
   427 		iPhBkInfoV5.iMaxAdditionalNumbers = -1;
       
   428 		iPhBkInfoV5.iMaxNumLengthAdditionalNumber = -1;
       
   429 		iPhBkInfoV5.iMaxGroupNames = -1;
       
   430 		iPhBkInfoV5.iMaxTextLengthGroupName = -1;
       
   431 		iPhBkInfoV5.iMaxEmailAddr = -1;
       
   432 		iPhBkInfoV5.iMaxTextLengthEmailAddr = -1;
       
   433 		}
       
   434 	else if (aPhBkInfo.ExtensionId() == RMobilePhoneStore::KETelMobilePhonebookStoreV2)
       
   435 		{
       
   436 		static_cast<RMobilePhoneBookStore::TMobilePhoneBookInfoV2&>(iPhBkInfoV5) =
       
   437 				static_cast<const RMobilePhoneBookStore::TMobilePhoneBookInfoV2&>(aPhBkInfo);
       
   438 		
       
   439 		iPhBkInfoV5.iMaxSecondNames = -1;
       
   440 		iPhBkInfoV5.iMaxTextLengthSecondName = -1;
       
   441 		iPhBkInfoV5.iMaxAdditionalNumbers = -1;
       
   442 		iPhBkInfoV5.iMaxNumLengthAdditionalNumber = -1;
       
   443 		iPhBkInfoV5.iMaxGroupNames = -1;
       
   444 		iPhBkInfoV5.iMaxTextLengthGroupName = -1;
       
   445 		iPhBkInfoV5.iMaxEmailAddr = -1;
       
   446 		iPhBkInfoV5.iMaxTextLengthEmailAddr = -1;
       
   447 				
       
   448 		iPhBkInfoV5 = aPhBkInfo;
       
   449 		}
       
   450 	else
       
   451 		{
       
   452 		iPhBkInfoV5 = aPhBkInfo;
       
   453 		}
       
   454 	} // CPhoneBook::SetPhoneBookInfo
       
   455 
       
   456 
       
   457 /**
       
   458  *  Adjusted the count of used entries in the PhBkInfo data. This
       
   459  *  is the same as performing a get and set combination.
       
   460  *
       
   461  *  @note The data can only be updated if the phone TSY supports it in the
       
   462  *        first place.
       
   463  *
       
   464  *  @param aChange  The modification value (e.g. -1 or 1).
       
   465  */
       
   466 inline void CPhoneBook::AdjustPhoneBookInfoUsedEntries(TInt aChange)
       
   467 	{
       
   468 	if (iPhBkInfoV5.iUsedEntries != -1)
       
   469 		{
       
   470 		iPhBkInfoV5.iUsedEntries += aChange;
       
   471 		}
       
   472 	} // CPhoneBook::AdjustPhoneBookInfoUsedEntries
       
   473 
       
   474 
       
   475 /**
       
   476  *  Returns the current size of the Look-Up Table.
       
   477  */
       
   478 inline TInt CPhoneBook::GetLookUpTableSize() const
       
   479 	{
       
   480 	return iLookUpTable.Count();
       
   481 	} // CPhoneBook::GetLookUpTableSize
       
   482 
       
   483 
       
   484 #endif // __PHONEBOOK_H__