messagingfw/msgsrvnstore/server/src/MSVLOCAL.CPP
changeset 0 8e480a14352b
child 34 b66b8f3a7fd8
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 1998-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 //
       
    15 
       
    16 
       
    17 #include <e32std.h>
       
    18 
       
    19 #include "MSVSTD.H"
       
    20 #include "MSVSTORE.H"
       
    21 #include "MSVIDS.H"
       
    22 
       
    23 #include "MSVENTRY.H"
       
    24 #include "MSVSERV.H"
       
    25 #include "MSVLOPS.H"
       
    26 #include "MSVMOVE.H"
       
    27 #include "MSVCOPY.H"
       
    28 #include "MSVDELET.H"
       
    29 #include "MSVPANIC.H"
       
    30 #include <tmsvsystemprogress.h>
       
    31 #include "msvindexadapter.h"
       
    32 
       
    33 //**********************************
       
    34 // CMsvLocalOperation
       
    35 //**********************************
       
    36 
       
    37 CMsvLocalOperation::CMsvLocalOperation(const RMessage2& aMessage, TMsvOp aId, CMsvServer& aMsvServer)
       
    38 : CMsvServerOperation(aMessage, aId, KUidMsvLocalServiceMtm, KMsvLocalServiceIndexEntryId, -1), iMsvServer(aMsvServer)
       
    39 	{
       
    40 	__DECLARE_NAME(_S("CMsvLocalOperation"));
       
    41 	}
       
    42 
       
    43 const TDesC8& CMsvLocalOperation::Progress()
       
    44 	{
       
    45 	return iProgress;
       
    46 	}
       
    47 
       
    48 /**
       
    49 Obtain the local progress information
       
    50 @param aOutSysProg The TMsvSystemProgress structure to be populated
       
    51 @return system wide error code
       
    52 */
       
    53 TInt CMsvLocalOperation::SystemProgress(TMsvSystemProgress& aSysProgress)
       
    54 	{
       
    55 	aSysProgress.iErrorCode = iProgress().iError;
       
    56 	aSysProgress.iId = iProgress().iId;
       
    57 	return KErrNone;	// This method will not fail
       
    58 	}
       
    59 
       
    60 //**********************************
       
    61 // CMsvLocalCopyOperation
       
    62 //**********************************
       
    63 
       
    64 
       
    65 
       
    66 CMsvLocalCopyOperation::CMsvLocalCopyOperation(const RMessage2& aMessage, TMsvOp aId, CMsvEntrySelection* aSelection, TMsvId aTarget, CMsvServer& aMsvServer)
       
    67 : CMsvLocalOperation(aMessage, aId, aMsvServer), iOrigEntries(aSelection), iTarget(aTarget)
       
    68 //
       
    69 //
       
    70 //
       
    71 	{
       
    72 	__DECLARE_NAME(_S("CMsvLocalCopyOperation"));
       
    73 	// set up the progress
       
    74 	iProgress().iType = TMsvLocalOperationProgress::ELocalCopy;
       
    75 	iProgress().iTotalNumberOfEntries = iOrigEntries->Count();
       
    76 	iProgress().iNumberRemaining = iProgress().iTotalNumberOfEntries;
       
    77 	CActiveScheduler::Add(this);
       
    78 	}
       
    79 
       
    80 
       
    81 CMsvLocalCopyOperation::~CMsvLocalCopyOperation()
       
    82 //
       
    83 //
       
    84 //
       
    85 	{
       
    86 	Cancel();
       
    87 	delete iOrigEntries;
       
    88 	delete iNewEntries;
       
    89 	delete iCopy;
       
    90 	}
       
    91 
       
    92 
       
    93 void CMsvLocalCopyOperation::DoCancel()
       
    94 //
       
    95 //
       
    96 //
       
    97 	{
       
    98 	iCopy->Cancel();
       
    99 	iProgress().iError = KErrCancel;
       
   100 	Completed();
       
   101 	}
       
   102 
       
   103 
       
   104 void CMsvLocalCopyOperation::RunL()
       
   105 //
       
   106 //
       
   107 //
       
   108 	{
       
   109 	// sort out descendent copying
       
   110 	if (iDescendentCopying && iDescendentId == KMsvNullIndexEntryId)
       
   111 		iDescendentId = iCopy->NewEntryId();
       
   112 
       
   113 	// record details of the previous move
       
   114 	iProgress().iNumberRemaining--;
       
   115 	if (iStatus!=KErrNone)
       
   116 		{
       
   117 		iProgress().iNumberFailed++;
       
   118 		iProgress().iError=iStatus.Int();
       
   119 		}
       
   120 	else
       
   121 		{
       
   122 		iNewEntries->AppendL(iCopy->NewEntryId()); // will not fail, as space has been reserved
       
   123 		iProgress().iNumberCompleted++;
       
   124 		}
       
   125 
       
   126 	if (iIndex < iOrigEntries->Count())
       
   127 		{
       
   128 		// start the next move
       
   129 		TInt error =  CopyNextEntry();
       
   130 		if (error==KErrNone)
       
   131 			return; // doing another move
       
   132 		__ASSERT_DEBUG(iProgress().iNumberRemaining==0, PanicServer(EMsvCopyingOperationInvariant));
       
   133 		}
       
   134 
       
   135 	// complete the operation
       
   136 	Completed();
       
   137 	}
       
   138 
       
   139 
       
   140 void CMsvLocalCopyOperation::StartL()
       
   141 //
       
   142 //
       
   143 //
       
   144 	{
       
   145 	iNewEntries = new(ELeave) CMsvEntrySelection;
       
   146 	iCopy = CMsvCopy::NewL(iMsvServer);
       
   147 
       
   148 	iIndex = 0;
       
   149 	iNewEntries->SetReserveL(iOrigEntries->Count());
       
   150 	iDescendentId = KMsvNullIndexEntryId;
       
   151 
       
   152 	// check for copying into a descedent
       
   153 	TInt count = iOrigEntries->Count();
       
   154 	while (count--)
       
   155 		{
       
   156 		TMsvId id = iOrigEntries->At(count);
       
   157 		iDescendentCopying = (id==iTarget);
       
   158 		if (!iDescendentCopying)
       
   159 			{
       
   160 			iMsvServer.IndexAdapter().IsADescendent(id, iTarget, iDescendentCopying); // error ignored
       
   161 			}
       
   162 
       
   163 		if (iDescendentCopying)
       
   164 			{
       
   165 			// has to be done first
       
   166 			iOrigEntries->Delete(count);
       
   167 			iOrigEntries->InsertL(0, id);
       
   168 			break;
       
   169 			}
       
   170 		}
       
   171 
       
   172 
       
   173 	TInt error = CopyNextEntry();
       
   174 	if (error==KErrNone)
       
   175 		SetState(EMsvOperationRunning);
       
   176 	else
       
   177 		{
       
   178 		iProgress().iNumberFailed = iProgress().iTotalNumberOfEntries;
       
   179 		iProgress().iNumberRemaining = 0;
       
   180 		iProgress().iError=error;
       
   181 		Completed();
       
   182 		}
       
   183 	}
       
   184 
       
   185 
       
   186 TInt CMsvLocalCopyOperation::CopyNextEntry()
       
   187 //
       
   188 //
       
   189 //
       
   190 	{
       
   191 	FOREVER
       
   192 		{
       
   193 		TRAPD(error, iCopy->StartL(iOrigEntries->At(iIndex++), iTarget, iStatus, iDescendentCopying));
       
   194 		if (error)
       
   195 			{
       
   196 			iProgress().iNumberRemaining--;
       
   197 			iProgress().iNumberFailed++;
       
   198 			iProgress().iError=error;
       
   199 			if (iIndex==iOrigEntries->Count())
       
   200 				return error;
       
   201 			}
       
   202 		else
       
   203 			{
       
   204 			SetActive();
       
   205 			break;
       
   206 			}
       
   207 		}
       
   208 	return KErrNone;
       
   209 	}
       
   210 
       
   211 
       
   212 void CMsvLocalCopyOperation::Completed()
       
   213 //
       
   214 //
       
   215 //
       
   216 	{
       
   217 	SetState(EMsvOperationCompleted);
       
   218 	if (iNewEntries->Count())
       
   219 		{
       
   220 		iProgress().iId = iNewEntries->At(0);
       
   221 		iMsvServer.NotifyChanged(EMsvEntriesCreated, *iNewEntries, iTarget);
       
   222 		}
       
   223 	iMessage.Complete(KErrNone);
       
   224 	}
       
   225 
       
   226 
       
   227 
       
   228 
       
   229 //**********************************
       
   230 // CMsvLocalMoveOperation
       
   231 //**********************************
       
   232 
       
   233 
       
   234 CMsvLocalMoveOperation::CMsvLocalMoveOperation(const RMessage2& aMessage, TMsvOp aId, CMsvEntrySelection* aSelection, TMsvId aTarget, CMsvServer& aMsvServer)
       
   235 : CMsvLocalOperation(aMessage, aId, aMsvServer), iTarget(aTarget), iParent(KMsvNullIndexEntryId), iOrigEntries(aSelection)
       
   236 	{
       
   237 	__DECLARE_NAME(_S("CMsvLocalMoveOperation"));
       
   238 	// set up the progress
       
   239 	iProgress().iType = TMsvLocalOperationProgress::ELocalMove;
       
   240 	iProgress().iTotalNumberOfEntries = iOrigEntries->Count();
       
   241 	iProgress().iNumberRemaining = iProgress().iTotalNumberOfEntries;
       
   242 	CActiveScheduler::Add(this);
       
   243 	}
       
   244 
       
   245 
       
   246 CMsvLocalMoveOperation::~CMsvLocalMoveOperation()
       
   247 	{
       
   248 	Cancel();
       
   249 	delete iOrigEntries;
       
   250 	delete iMove;
       
   251 	}
       
   252 
       
   253 void CMsvLocalMoveOperation::DoCancel()
       
   254 	{
       
   255 	iMove->Cancel();
       
   256 	iOrigEntries->Delete(0,iNextEntry);
       
   257 	iProgress().iError = KErrCancel;
       
   258 	Completed();
       
   259 	}
       
   260 
       
   261 void CMsvLocalMoveOperation::RunL()
       
   262 //
       
   263 //
       
   264 //
       
   265 	{
       
   266 	// record details of the previous move
       
   267 	iProgress().iNumberRemaining--;
       
   268 	if (iStatus!=KErrNone)
       
   269 		{
       
   270 		iProgress().iNumberFailed++;
       
   271 		iProgress().iError=iStatus.Int();
       
   272 		iOrigEntries->Delete(iNextEntry);
       
   273 		}
       
   274 	else
       
   275 		iProgress().iNumberCompleted++;
       
   276 
       
   277 	TInt error=KErrNone;
       
   278 	if (iNextEntry) // will be zero when completed
       
   279 		{
       
   280 		// start the next move
       
   281 		error =  MoveNextEntry();
       
   282 		if (error==KErrNone)
       
   283 			return; // doing another move
       
   284 		__ASSERT_DEBUG(iProgress().iNumberRemaining==0, PanicServer(EMsvMovingOperationInvariant));
       
   285 		}
       
   286 
       
   287 	// complete the operation
       
   288 	Completed();
       
   289 	}
       
   290 
       
   291 void CMsvLocalMoveOperation::Completed()
       
   292 //
       
   293 //
       
   294 //
       
   295 	{
       
   296 	SetState(EMsvOperationCompleted);
       
   297 	if (iOrigEntries->Count())
       
   298 		{
       
   299 		iProgress().iId = iOrigEntries->At(0);
       
   300 		iMsvServer.NotifyChanged(EMsvEntriesMoved, *iOrigEntries, iTarget, iParent);
       
   301 		}
       
   302 	iMessage.Complete(KErrNone);
       
   303 	}
       
   304 
       
   305 void CMsvLocalMoveOperation::StartFailed(TInt aError)
       
   306 //
       
   307 //
       
   308 //
       
   309 	{
       
   310 	iProgress().iNumberFailed = iProgress().iTotalNumberOfEntries;
       
   311 	iProgress().iNumberRemaining = 0;
       
   312 	iProgress().iError=aError;
       
   313 	iOrigEntries->Reset();
       
   314 	Completed();
       
   315 	}
       
   316 
       
   317 void CMsvLocalMoveOperation::StartL()
       
   318 //
       
   319 //
       
   320 //
       
   321 	{
       
   322 	// check if the target exists
       
   323 	TMsvEntry* entry;
       
   324 	TInt err = KErrNone;
       
   325 	err = iMsvServer.IndexAdapter().GetEntry(iTarget, entry);
       
   326 	if (err !=KErrNone)
       
   327 		{
       
   328 		StartFailed(KErrPathNotFound);
       
   329 		return;
       
   330 		}
       
   331 
       
   332 	// find the current parent
       
   333 	TInt count=iOrigEntries->Count();
       
   334 	while (count--)
       
   335 		{
       
   336 		TInt error = KErrNone;
       
   337 		error = iMsvServer.IndexAdapter().GetEntry(iOrigEntries->At(count), entry);
       
   338 		if (error ==KErrNone)
       
   339 			{
       
   340 			iParent=entry->Parent();
       
   341 			break;
       
   342 			}
       
   343 		}
       
   344 
       
   345 	// nothing to copy
       
   346 	if (count==KErrNotFound)
       
   347 		{
       
   348 		StartFailed(count);
       
   349 		return;
       
   350 		}
       
   351 
       
   352 #if defined(_DEBUG)
       
   353 	// check all the entries are local
       
   354 	TInt dCount=iOrigEntries->Count();
       
   355 	while (dCount--)
       
   356 		{
       
   357 		TInt dSourceLocal;
       
   358 		TInt dError = KErrNone;
       
   359 		dError = iMsvServer.IndexAdapter().IsLocal(iOrigEntries->At(count), dSourceLocal);
       
   360 		__ASSERT_DEBUG(dError!=KErrNone || dSourceLocal,   PanicServer(EMsvMovingLocalEntryIsRemote));
       
   361 		}
       
   362 #endif
       
   363 
       
   364 	// start the copying
       
   365 	iMove = CMsvMove::NewL(iMsvServer);
       
   366 	iNextEntry=iOrigEntries->Count();
       
   367 	TInt error = MoveNextEntry();
       
   368 	if (error==KErrNone)
       
   369 		SetState(EMsvOperationRunning);
       
   370 	else
       
   371 		StartFailed(error);
       
   372 	}
       
   373 
       
   374 
       
   375 TInt CMsvLocalMoveOperation::MoveNextEntry()
       
   376 //
       
   377 //
       
   378 //
       
   379 	{
       
   380 	TInt error=KErrGeneral;
       
   381 	while (error!=KErrNone && iNextEntry)
       
   382 		{
       
   383 		iMove->Reset();
       
   384 		error=KErrNone;
       
   385 		TRAP(error, iMove->StartL(iOrigEntries->At(--iNextEntry), iTarget, iStatus));
       
   386 		if (error)
       
   387 			{
       
   388 			iProgress().iNumberRemaining--;
       
   389 			iProgress().iNumberFailed++;
       
   390 			iProgress().iError=error;
       
   391 			iOrigEntries->Delete(iNextEntry);
       
   392 			}
       
   393 		}
       
   394 	if (error==KErrNone)
       
   395 		SetActive();
       
   396 	return error;
       
   397 	}
       
   398 
       
   399 
       
   400 
       
   401 //**********************************
       
   402 // CMsvLocalDeleteOperation
       
   403 //**********************************
       
   404 
       
   405 
       
   406 CMsvLocalDeleteOperation::CMsvLocalDeleteOperation(const RMessage2& aMessage, TMsvOp aId, CMsvEntrySelection* aSelection, CMsvServer& aMsvServer)
       
   407 : CMsvLocalOperation(aMessage, aId, aMsvServer), iSelection(aSelection)
       
   408 	{
       
   409 	__DECLARE_NAME(_S("CMsvLocalDeleteOperation"));
       
   410 	// set up the progress
       
   411 	iProgress().iType = TMsvLocalOperationProgress::ELocalDelete;
       
   412 	iProgress().iTotalNumberOfEntries = iSelection->Count();
       
   413 	iProgress().iNumberRemaining = iProgress().iTotalNumberOfEntries;
       
   414 	CActiveScheduler::Add(this);
       
   415 	}
       
   416 
       
   417 
       
   418 CMsvLocalDeleteOperation::~CMsvLocalDeleteOperation()
       
   419 	{
       
   420 	Cancel();
       
   421 	delete iSelection;
       
   422 	delete iDeletedEntries;
       
   423 	delete iMovedEntries;
       
   424 	delete iDelete;
       
   425 	delete iWorkSelection1;
       
   426 	delete iWorkSelection2;
       
   427 	}
       
   428 
       
   429 
       
   430 void CMsvLocalDeleteOperation::DoCancel()
       
   431 //
       
   432 //
       
   433 //
       
   434 	{
       
   435 	iDelete->Cancel();
       
   436 	iProgress().iError = KErrCancel;
       
   437 	Completed();
       
   438 	// if the last entry was removed, update the notification selections
       
   439 	TRAP_IGNORE(PartialCompletionNotificationL());
       
   440 	}
       
   441 
       
   442 
       
   443 void CMsvLocalDeleteOperation::PartialCompletionNotificationL()
       
   444 //
       
   445 //
       
   446 //
       
   447 	{
       
   448 	TMsvId id=iSelection->At(iIndex-1);
       
   449 	TBool entryExists = EFalse;
       
   450 	entryExists = iMsvServer.IndexAdapter().EntryExists(id);
       
   451 	if (!entryExists)
       
   452 		id = iParent;
       
   453 
       
   454 	if (iWorkSelection1->Count())
       
   455 		{
       
   456 		iDeletedEntries->Reset();
       
   457 		iDeletedEntries->AppendL(iWorkSelection1->Back(0), iWorkSelection1->Count());
       
   458 		iMsvServer.NotifyChanged(EMsvEntriesDeleted, *iDeletedEntries, id);
       
   459 		}
       
   460 
       
   461 	if (iWorkSelection2->Count())
       
   462 		{
       
   463 		iDeletedEntries->Reset();
       
   464 		iMovedEntries->AppendL(iWorkSelection2->Back(0), iWorkSelection2->Count());
       
   465 		iMsvServer.NotifyChanged(EMsvEntriesMoved, *iMovedEntries, KMsvDeletedEntryFolderEntryId, id);
       
   466 		}
       
   467 	}
       
   468 
       
   469 
       
   470 void CMsvLocalDeleteOperation::RunL()
       
   471 //
       
   472 // Attempts the next delete
       
   473 //
       
   474 	{
       
   475 	TRAPD(leave, DoRunL());
       
   476 	if (leave)
       
   477 		{
       
   478 		// probably OOM so complete the operation
       
   479 		iProgress().iError = leave;
       
   480 		Completed();
       
   481 		}
       
   482 	}
       
   483 
       
   484 
       
   485 void CMsvLocalDeleteOperation::DoRunL()
       
   486 //
       
   487 //
       
   488 //
       
   489 	{
       
   490 	// record the result of the last delete
       
   491 	iProgress().iNumberRemaining--;
       
   492 	if (iStatus.Int()==KErrNone)
       
   493 		{
       
   494 		iProgress().iNumberCompleted++;
       
   495 		iDeletedEntries->AppendL(iWorkSelection1->Back(0), iWorkSelection1->Count());
       
   496 		iMovedEntries->AppendL(iWorkSelection2->Back(0), iWorkSelection2->Count());
       
   497 		}
       
   498 	else
       
   499 		{
       
   500 		iProgress().iNumberFailed++;
       
   501 		if (iProgress().iError==KErrNone)
       
   502 			iProgress().iError = iStatus.Int();
       
   503 		}
       
   504 
       
   505 	// start thje next delete or complete the operation
       
   506 	if (iProgress().iNumberRemaining)
       
   507 		{
       
   508 		iWorkSelection1->Reset();
       
   509 		iWorkSelection2->Reset();
       
   510 		iDelete->StartL(iSelection->At(iIndex++), *iWorkSelection1, *iWorkSelection2, iStatus);
       
   511 		SetActive();
       
   512 		}
       
   513 	else
       
   514 		{
       
   515 		__ASSERT_DEBUG(iIndex==iSelection->Count(), PanicServer(EMsvLocalDeletionMisCount));
       
   516 		Completed();
       
   517 		}
       
   518 	}
       
   519 
       
   520 
       
   521 void CMsvLocalDeleteOperation::Completed()
       
   522 //
       
   523 // The operation has completed
       
   524 //
       
   525 	{
       
   526 /**
       
   527 Added code to commit transaction for bulk deletion.
       
   528 */
       
   529 	TRAP_IGNORE(iMsvServer.IndexAdapter().GetDbAdapter()->CommitTransactionL());
       
   530 
       
   531 	// notify server of any deletions or moves to the deleted folder
       
   532 	if (iDeletedEntries->Count())
       
   533 		iMsvServer.NotifyChanged(EMsvEntriesDeleted, *iDeletedEntries, iParent);
       
   534 	if (iMovedEntries->Count())
       
   535 		iMsvServer.NotifyChanged(EMsvEntriesMoved, *iMovedEntries, KMsvDeletedEntryFolderEntryId, iParent);
       
   536 
       
   537 	// complete the request
       
   538 	SetState(EMsvOperationCompleted);
       
   539 	iMessage.Complete(KErrNone);
       
   540 	}
       
   541 
       
   542 void CMsvLocalDeleteOperation::StartL()
       
   543 	{
       
   544 	// reserve space so we don't manage to delete the entries but run
       
   545 	// out of memory when trying to report the fact.
       
   546 	iDeletedEntries = new(ELeave)CMsvEntrySelection;
       
   547 	iDeletedEntries->SetReserveL(iSelection->Count());
       
   548 	iMovedEntries = new(ELeave)CMsvEntrySelection;
       
   549 	iMovedEntries->SetReserveL(iSelection->Count());
       
   550 	iWorkSelection1 = new(ELeave)CMsvEntrySelection;
       
   551 	iWorkSelection2 = new(ELeave)CMsvEntrySelection;
       
   552 	iDelete = CMsvDelete::NewL(iMsvServer);
       
   553 
       
   554 	// find the parent
       
   555 	TInt count=iSelection->Count();
       
   556 	while (count--)
       
   557 		{
       
   558 		TMsvEntry* entry;
       
   559 		TInt error = KErrNone;
       
   560 		error = iMsvServer.IndexAdapter().GetEntry(iSelection->At(count),entry);
       
   561 		if (error)
       
   562 			{
       
   563 			iSelection->Delete(count);
       
   564 			iProgress().iNumberRemaining--;
       
   565 			iProgress().iNumberCompleted++;
       
   566 			}
       
   567 		else
       
   568 			iParent = entry->Parent();
       
   569 		}
       
   570 
       
   571 	if (iSelection->Count())
       
   572 		{
       
   573 		// start deleting the first entry
       
   574 		iDelete->StartL(iSelection->At(iIndex++), *iWorkSelection1, *iWorkSelection2, iStatus);
       
   575 		SetActive();
       
   576 		SetState(EMsvOperationRunning);
       
   577 		}
       
   578 	else
       
   579 		Completed();
       
   580 	}
       
   581 
       
   582 
       
   583 
       
   584 
       
   585 
       
   586 //**********************************
       
   587 // CMsvLocalChangeOperation
       
   588 //**********************************
       
   589 
       
   590 
       
   591 CMsvLocalChangeOperation::CMsvLocalChangeOperation(const RMessage2& aMessage, TMsvOp aId, const TMsvEntry& aEntry, CMsvServer& aMsvServer)
       
   592 : CMsvLocalOperation(aMessage, aId, aMsvServer), iEntry(aEntry)
       
   593 	{
       
   594 	__DECLARE_NAME(_S("CMsvLocalChangeOperation"));
       
   595 	// set up the progress
       
   596 	iProgress().iType = TMsvLocalOperationProgress::ELocalChanged;
       
   597 	iProgress().iTotalNumberOfEntries = 1;
       
   598 	iProgress().iId = iEntry.Id();
       
   599 	CActiveScheduler::Add(this);
       
   600 	}
       
   601 
       
   602 CMsvLocalChangeOperation::~CMsvLocalChangeOperation()
       
   603 //
       
   604 //
       
   605 //
       
   606 	{
       
   607 	Cancel();
       
   608 	delete iDelete;
       
   609 	delete iWorkSelection1;
       
   610 	delete iWorkSelection2;
       
   611 	}
       
   612 
       
   613 void CMsvLocalChangeOperation::DoCancel()
       
   614 //
       
   615 //
       
   616 //
       
   617 	{
       
   618 	__ASSERT_DEBUG(iDelete!=NULL, PanicServer(EMsvChangeEntryBadState));
       
   619 	iDelete->Cancel();
       
   620 	iProgress().iError = KErrCancel;
       
   621 	Completed();
       
   622 	}
       
   623 
       
   624 void CMsvLocalChangeOperation::RunL()
       
   625 //
       
   626 //
       
   627 //
       
   628 	{
       
   629 	if (iStatus.Int()==KErrNone)
       
   630 		{
       
   631 		iProgress().iNumberCompleted++;
       
   632 		}
       
   633 	else
       
   634 		{
       
   635 		iProgress().iNumberFailed++;
       
   636 		iProgress().iError = iStatus.Int();
       
   637 		}
       
   638 	Completed();
       
   639 	}
       
   640 
       
   641 void CMsvLocalChangeOperation::StartL(TSecureId aOwnerId, TBool aForcedUpdate)
       
   642 //
       
   643 //
       
   644 //
       
   645 	{
       
   646 	iId = iEntry.Id();
       
   647 	iParent = iEntry.Parent();
       
   648 	// check if this is actually a deletion
       
   649 	if (iEntry.Deleted() && iEntry.PcSyncCount()==0)
       
   650 		{
       
   651 		iDelete = CMsvDelete::NewL(iMsvServer);
       
   652 		iWorkSelection1 = new(ELeave)CMsvEntrySelection;
       
   653 		iWorkSelection2 = new(ELeave)CMsvEntrySelection;
       
   654 		iDelete->StartL(iEntry.Id(), *iWorkSelection1, *iWorkSelection2, iStatus, ETrue);
       
   655 		SetActive();
       
   656 		return;
       
   657 		}
       
   658 
       
   659 	// otherwise just changing it
       
   660 	TInt error = KErrNone;
       
   661 	error = iMsvServer.IndexAdapter().LockEntry(iId);
       
   662 	if (error==KErrNone)
       
   663 		{
       
   664 		error = iMsvServer.ChangeEntry(iEntry, aOwnerId, aForcedUpdate);
       
   665 		iMsvServer.IndexAdapter().ReleaseEntry(iId); // error ignored
       
   666 		}
       
   667 
       
   668 	if (error==KErrNone)
       
   669 		iProgress().iNumberCompleted++;
       
   670 	else
       
   671 		{
       
   672 		iProgress().iNumberFailed++;
       
   673 		iProgress().iError = error;
       
   674 		}
       
   675 	Completed();
       
   676 	}
       
   677 
       
   678 
       
   679 void CMsvLocalChangeOperation::Completed()
       
   680 //
       
   681 //
       
   682 //
       
   683 	{
       
   684 	if (iProgress().iError==KErrNone)
       
   685 		iMsvServer.NotifyChanged(iDelete==NULL ? EMsvEntriesChanged : EMsvEntriesDeleted, iId, iParent);
       
   686 	SetState(EMsvOperationCompleted);
       
   687 	iMessage.Complete(KErrNone);
       
   688 	}
       
   689 
       
   690 
       
   691 //**********************************
       
   692 // CMsvLocalCreateOperation
       
   693 //**********************************
       
   694 
       
   695 CMsvLocalCreateOperation::CMsvLocalCreateOperation(const RMessage2& aMessage, TMsvOp aId, const TMsvEntry& aEntry, CMsvServer& aMsvServer)
       
   696 : CMsvLocalOperation(aMessage, aId, aMsvServer), iEntry(aEntry)
       
   697 	{
       
   698 	__DECLARE_NAME(_S("CMsvLocalCreateOperation"));
       
   699 	// set up the progress
       
   700 	iProgress().iType = TMsvLocalOperationProgress::ELocalNew;
       
   701 	iProgress().iTotalNumberOfEntries = 1;
       
   702 	CActiveScheduler::Add(this);
       
   703 	}
       
   704 
       
   705 
       
   706 CMsvLocalCreateOperation::~CMsvLocalCreateOperation()
       
   707 	{}
       
   708 
       
   709 void CMsvLocalCreateOperation::DoCancel()
       
   710 	{}
       
   711 
       
   712 void CMsvLocalCreateOperation::RunL()
       
   713 	{}
       
   714 
       
   715 void CMsvLocalCreateOperation::Start(TSecureId aOwnerId)
       
   716 	{
       
   717 	TMsvEntry entry = iEntry;
       
   718 	TInt error = iMsvServer.AddEntry(entry, aOwnerId, ETrue);
       
   719 
       
   720 	if (error)
       
   721 		{
       
   722 		iProgress().iNumberFailed++;
       
   723 		iProgress().iError = error;
       
   724 		}
       
   725 	else
       
   726 		{
       
   727 		iProgress().iNumberCompleted++;
       
   728 		iProgress().iId = entry.Id();
       
   729 		iMsvServer.NotifyChanged(EMsvEntriesCreated, entry.Id(), entry.Parent());
       
   730 		}
       
   731 
       
   732 	SetState(EMsvOperationCompleted);
       
   733 	iMessage.Complete(KErrNone);
       
   734 	}
       
   735 
       
   736 //**********************************
       
   737 // CMsvChangeDriveOperation
       
   738 //**********************************
       
   739 CMsvChangeDriveOperation::CMsvChangeDriveOperation(const RMessage2& aMessage, TMsvOp aId, TInt aDrive, CMsvServer& aServer)
       
   740 : CMsvServerOperation(aMessage, aId, KUidMsvLocalServiceMtm, KMsvLocalServiceIndexEntryId, -1), iDrive(aDrive), iServer(aServer)
       
   741 	{
       
   742 	CActiveScheduler::Add(this);
       
   743 	}
       
   744 
       
   745 CMsvChangeDriveOperation::~CMsvChangeDriveOperation()
       
   746 	{
       
   747 	Cancel();
       
   748 	}
       
   749 
       
   750 const TDesC8& CMsvChangeDriveOperation::Progress()
       
   751 	{
       
   752 	if (iServer.NewContext())
       
   753 		iProgress() = iServer.NewContext()->Progress();
       
   754 
       
   755 	return iProgress;
       
   756 	}
       
   757 
       
   758 void CMsvChangeDriveOperation::DoCancel()
       
   759 	{
       
   760 	if (iServer.NewContext())
       
   761 		iServer.NewContext()->Cancel();
       
   762 
       
   763 	iProgress().iError = KErrCancel;
       
   764 	Completed();
       
   765 	}
       
   766 
       
   767 void CMsvChangeDriveOperation::RunL()
       
   768 	{
       
   769 	Completed();
       
   770 	}
       
   771 
       
   772 void CMsvChangeDriveOperation::Completed()
       
   773 	{
       
   774 	// Get progress
       
   775 	if (iServer.NewContext())
       
   776 		{
       
   777 		iProgress() = iServer.NewContext()->Progress();
       
   778 
       
   779 		// If an error occurs we have to delete the new context
       
   780 		iServer.DeleteNewContext();
       
   781 		}
       
   782 	else
       
   783 		iProgress() = iServer.Context().Progress();
       
   784 
       
   785 	SetState(EMsvOperationCompleted);
       
   786 	iMessage.Complete(KErrNone);
       
   787 	}
       
   788 
       
   789 TInt CMsvChangeDriveOperation::Start()
       
   790 	{
       
   791 	TInt error = iServer.ChangeDrive(iDrive, &iStatus);
       
   792 	if (!error)
       
   793 		SetActive();
       
   794 	return error;
       
   795 	}
       
   796