pimprotocols/phonebooksync/Server/DeleteContactFromICC.cpp
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 // Contains the implementation for the Active Object class used by the
       
    15 // Phonebook Synchroniser to delete an ICC Contact.
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalComponent
       
    22 */
       
    23 
       
    24 #include "common.h"
       
    25 #include "Phonebook.h"
       
    26 #include "PhonebookManager.h"
       
    27 #include "SyncContactICCEntry.h"
       
    28 #include "phbksyncsvr.h"
       
    29 #include "phbksynclog.h"
       
    30 #include "SyncEngineSession.h"
       
    31 #include "SyncEngineServer.h"
       
    32 #include "phbksyncsess.h"
       
    33 #include "DeleteContactFromICC.h"
       
    34 
       
    35 
       
    36 /**
       
    37  *  Static factory method used to create a CDeleteContactFromICC object.
       
    38  *
       
    39  *  @param aSession           Reference to the engine session.
       
    40  *  @param aPhonebookManager  Reference to the Phonebook Manager which stores
       
    41  *                            all the phonebook parameters.
       
    42  *  @param aDb                Reference to the database.
       
    43  *  @param aPhone             Handle to the phone object.
       
    44  *  @param aPhonebookUid      Phonebook UID for the contact to be deleted from.
       
    45  *  @param aClientMessage     Handle to the engine message request.
       
    46  */
       
    47 CDeleteContactFromICC* CDeleteContactFromICC::NewL(CSyncEngineSession& aSession,
       
    48 												   CPhoneBookManager& aPhonebookManager,
       
    49 												   CContactDatabase& aDb,
       
    50 												   RMobilePhone& aPhone,
       
    51 												   TUid aPhonebookUid,
       
    52 												   const RMessage2& aClientMessage)
       
    53 	{
       
    54 	CDeleteContactFromICC*  self = new(ELeave) CDeleteContactFromICC(aSession,
       
    55 																	 aPhonebookManager,
       
    56 																	 aDb,
       
    57 																	 aPhone,
       
    58 																	 aPhonebookUid,
       
    59 																	 aClientMessage);
       
    60 	CleanupStack::PushL(self);
       
    61 	self->ConstructL();
       
    62 	CleanupStack::Pop(self);
       
    63 
       
    64 	return self;
       
    65 	} // CDeleteContactFromICC::NewL
       
    66 
       
    67 
       
    68 /**
       
    69  *  Standard constructor.
       
    70  *
       
    71  *  @param aSession           Reference to the engine session.
       
    72  *  @param aPhonebookManager  Reference to the Phonebook Manager which stores
       
    73  *                            all the phonebook parameters.
       
    74  *  @param aPhone             Handle to the phone object.
       
    75  *  @param aDb                Reference to the database.
       
    76  *  @param aPhonebookUid      Phonebook UID for the contact to be deleted from.
       
    77  *  @param aClientMessage     Handle to the engine message request.
       
    78  */
       
    79 CDeleteContactFromICC::CDeleteContactFromICC(CSyncEngineSession& aSession,
       
    80 											 CPhoneBookManager& aPhonebookManager,
       
    81 											 CContactDatabase& aDb,
       
    82 											 RMobilePhone& aPhone,
       
    83 											 TUid aPhonebookUid,
       
    84 											 const RMessage2& aClientMessage)
       
    85   : CActive(EPriorityNormal),
       
    86 	iSession(aSession),
       
    87 	iPhonebookManager(aPhonebookManager),
       
    88 	iDb(aDb),
       
    89 	iPhone(aPhone),
       
    90 	iPhonebookUid(aPhonebookUid),
       
    91 	iClientMessage(aClientMessage),
       
    92 	iState(EDeleteContactFromICCStateIdle),
       
    93 	iContactId(KNullContactId),
       
    94 	iSlotNum(0)
       
    95 	{
       
    96 	// NOP
       
    97 	} // CDeleteContactFromICC::CDeleteContactFromICC
       
    98 
       
    99 
       
   100 /**
       
   101  *  Standard destructor. This will cancel any pending active requests.
       
   102  */
       
   103 CDeleteContactFromICC::~CDeleteContactFromICC()
       
   104 	{
       
   105 	LOGACTIVE1(_L8("~CDeleteContactFromICC()"));
       
   106 
       
   107  	Cancel();
       
   108 	} // CDeleteContactFromICC::~CDeleteContactFromICC
       
   109 
       
   110 
       
   111 /**
       
   112  *  Second phase constructor.
       
   113  */
       
   114 void CDeleteContactFromICC::ConstructL()
       
   115 	{
       
   116 	User::LeaveIfError(iPhonebookManager.GetPhoneBookStore(iPhonebookUid, iPhone, iPhonebookStore));
       
   117 
       
   118 	CActiveScheduler::Add(this);
       
   119 	} // CDeleteContactFromICC::ConstructL
       
   120 
       
   121 
       
   122 /** 
       
   123  *  Delete an ICC entry.
       
   124  *
       
   125  *  @param aContactId  TContactItemId item to delete from the ICC.
       
   126  */
       
   127 void CDeleteContactFromICC::DoIccDelete(TContactItemId aContactId)
       
   128 	{
       
   129 	LOGACTIVE2(_L8("CDeleteContactFromICC::DoIccDelete(0x%08x)"), aContactId);
       
   130 
       
   131 	//
       
   132 	// Check that we are not in use!
       
   133 	//
       
   134 	if (iState != EDeleteContactFromICCStateIdle)
       
   135 		{
       
   136 		PhBkSyncPanic(EPhBkSyncPanicDoIccDeleteError);
       
   137 		}
       
   138 
       
   139 	//
       
   140 	// Store the Contact UID for later and find the slot number.
       
   141 	//
       
   142 	TInt  result;
       
   143 	
       
   144 	iContactId = aContactId;
       
   145 
       
   146 	result = iPhonebookManager.GetSlotNumFromContactId(iPhonebookUid, aContactId, iSlotNum);
       
   147 	if (result != KErrNone)
       
   148 		{
       
   149 		iSession.Server().CompleteDoIccDelete(result);
       
   150 		return;
       
   151 		}
       
   152 
       
   153 	//
       
   154 	// Request the slot entry to be deleted from the phonebook store...
       
   155 	//
       
   156 	iPhonebookStore.Delete(iStatus, iSlotNum);
       
   157 	iState = EDeleteContactFromICCStateWaitForDelete;
       
   158 	SetActive();
       
   159 
       
   160 	LOGACTIVETIMESTAMP();
       
   161 	} // CDeleteContactFromICC::DoIccDelete
       
   162 
       
   163 
       
   164 /** 
       
   165  *  Standard Active Object RunL() method to process delete requests.
       
   166  */
       
   167 void CDeleteContactFromICC::RunL()
       
   168 	{
       
   169 	LOGACTIVE2(_L8("CDeleteContactFromICC::RunL(): iStatus=%d"),
       
   170 			   iStatus.Int());
       
   171 	LOGACTIVETIMESTAMP();
       
   172 
       
   173 	switch (iState)
       
   174 		{
       
   175 		case EDeleteContactFromICCStateWaitForDelete:
       
   176 			{
       
   177 			if (iStatus.Int() == KErrNone  ||
       
   178 				iStatus.Int() == KErrCancel)
       
   179 				{
       
   180 				//
       
   181 				// Update the entry in the table...
       
   182 				//
       
   183 				TInt  result;
       
   184 				
       
   185 				result = iPhonebookManager.UpdateEntryInTable(iPhonebookUid, iSlotNum,
       
   186 															  KNullContactId, ESlotEmpty);
       
   187  				if (result != KErrNone)
       
   188  					{
       
   189  					PhBkSyncPanic(EPhBkSyncPanicUpdateEntryInTableError);
       
   190  					}
       
   191 
       
   192 				//
       
   193 				// Decrement the number of used entries for this phonebook...
       
   194 				//
       
   195 				result = iPhonebookManager.AdjustPhoneBookInfoUsedEntries(iPhonebookUid, -1);
       
   196  				if (result != KErrNone)
       
   197  					{
       
   198  					PhBkSyncPanic(EPhBkSyncPanicUpdateEntryInTableError);
       
   199  					}
       
   200  				}
       
   201 
       
   202 			//
       
   203 			// Return to the idle state and complete the request...
       
   204 			//
       
   205 			iState = EDeleteContactFromICCStateIdle;
       
   206 			iSession.Server().CompleteDoIccDelete(iStatus.Int());
       
   207 			}
       
   208 			break;
       
   209 
       
   210 		case EDeleteContactFromICCStateWaitForCancel:
       
   211 			{
       
   212 			//
       
   213 			// Return to the idle state and complete the request...
       
   214 			//
       
   215 			iState = EDeleteContactFromICCStateIdle;
       
   216 			iSession.Server().CompleteDoIccDelete(iStatus.Int());
       
   217 			}
       
   218 			break;
       
   219 
       
   220 		default:
       
   221 			{
       
   222 			PhBkSyncPanic(EPhBkSyncPanicDoIccDeleteError);
       
   223 			}
       
   224 			break;
       
   225 		}
       
   226 	} // CDeleteContactFromICC::RunL
       
   227 
       
   228 
       
   229 /** 
       
   230  *  Standard Active Object DoCancel method called when the objects Cancel()
       
   231  *  method is called.
       
   232  */
       
   233 void CDeleteContactFromICC::DoCancel()
       
   234 	{
       
   235 	LOGACTIVE1(_L8("CDeleteContactFromICC::DoCancel()"));
       
   236 
       
   237  	if (iState == EDeleteContactFromICCStateWaitForDelete)
       
   238 		{
       
   239 		iPhonebookStore.CancelAsyncRequest(EMobilePhoneStoreDelete);
       
   240  		iState = EDeleteContactFromICCStateWaitForCancel;
       
   241 		}
       
   242 	} // CDeleteContactFromICC::DoCancel
       
   243 
       
   244 
       
   245 /**
       
   246  *  Standard Active Object RunError method called when the objects RunL()
       
   247  *  method leaves.
       
   248  *
       
   249  *  Hopefully this method should never be called.
       
   250  *
       
   251  *  @param aError  Leave code from the RunL().
       
   252  *
       
   253  *  @return  KErrNone is returned although the server will panic first.
       
   254  */
       
   255 TInt CDeleteContactFromICC::RunError(TInt aError)
       
   256 	{
       
   257 #ifdef _DEBUG
       
   258 	LOGACTIVE2(_L8("CDeleteContactFromICC::RunError(%d)"), aError);
       
   259 #else
       
   260 	(void) aError;
       
   261 #endif
       
   262 
       
   263 	PhBkSyncPanic(EPhBkSyncPanicUnexpectedLeave);
       
   264 
       
   265 	return KErrNone;	
       
   266 	} // CDeleteContactFromICC::RunError
       
   267