metadataengine/server/src/mdsmanipulationengine.cpp
branchRCL_3
changeset 15 3cebc1a84278
parent 14 646a02f170b9
child 19 82c0024438c8
equal deleted inserted replaced
14:646a02f170b9 15:3cebc1a84278
    29 #include "mdssqliteconnection.h"
    29 #include "mdssqliteconnection.h"
    30 #include "mdsnamespacedef.h"
    30 #include "mdsnamespacedef.h"
    31 #include "mdcserializationbuffer.h"
    31 #include "mdcserializationbuffer.h"
    32 #include "mdeinternalerror.h"
    32 #include "mdeinternalerror.h"
    33 #include "mdeerror.h"
    33 #include "mdeerror.h"
       
    34 
       
    35 // for CleanupResetAndDestroyPushL
       
    36 #include <mmf/common/mmfcontrollerpluginresolver.h>
    34 
    37 
    35 __USES_LOGGER
    38 __USES_LOGGER
    36 
    39 
    37 // ---------------------------------------------------------------------------
    40 // ---------------------------------------------------------------------------
    38 // NewL
    41 // NewL
   324 	CleanupClosePushL( idArray );
   327 	CleanupClosePushL( idArray );
   325 	RArray<TItemId> removedRelations;
   328 	RArray<TItemId> removedRelations;
   326 	CleanupClosePushL( removedRelations );
   329 	CleanupClosePushL( removedRelations );
   327 	RArray<TItemId> removedEvents;
   330 	RArray<TItemId> removedEvents;
   328 	CleanupClosePushL( removedEvents );
   331 	CleanupClosePushL( removedEvents );
       
   332 	RPointerArray<HBufC> removedItemUriArray;
       
   333 	CleanupResetAndDestroyPushL( removedItemUriArray );
   329 
   334 
   330     CMdSSqLiteConnection& connection = MMdSDbConnectionPool::GetDefaultDBL();
   335     CMdSSqLiteConnection& connection = MMdSDbConnectionPool::GetDefaultDBL();
       
   336     
       
   337     const TBool uriNotify = iNotifier.CheckForNotifier(EObjectNotifyRemoveWithUri);
   331 
   338 
   332     // Remove objects by id or URI.
   339     // Remove objects by id or URI.
   333     if (itemIds.iObjectIds.iPtr.iCount + itemIds.iObjectUris.iPtr.iCount > 0)
   340     if (itemIds.iObjectIds.iPtr.iCount + itemIds.iObjectUris.iPtr.iCount > 0)
   334 		{
   341 		{
   335 	    RMdSTransaction transaction( connection );
   342 	    RMdSTransaction transaction( connection );
   338 
   345 
   339 		if (itemIds.iObjectUris.iPtr.iCount > 0)
   346 		if (itemIds.iObjectUris.iPtr.iCount > 0)
   340 			{
   347 			{
   341 			aBuffer.PositionL( itemIds.iObjectUris.iPtr.iOffset );
   348 			aBuffer.PositionL( itemIds.iObjectUris.iPtr.iOffset );
   342 			iManipulate->RemoveObjectsByUriL( aBuffer, itemIds.iObjectUris.iPtr.iCount,
   349 			iManipulate->RemoveObjectsByUriL( aBuffer, itemIds.iObjectUris.iPtr.iCount,
   343 					idArray, removedRelations, removedEvents );
   350 					idArray, removedRelations, removedEvents, uriNotify, removedItemUriArray );
   344 			}
   351 			}
   345 		else
   352 		else
   346 			{
   353 			{
       
   354 		    // pause garbage collector so it does not remove the objects
       
   355 			// before uris are read
       
   356 		    if( iGarbageCollector && uriNotify )
       
   357 		        {
       
   358 		        iGarbageCollector->Pause();
       
   359 		        }
   347 			aBuffer.PositionL( itemIds.iObjectIds.iPtr.iOffset );
   360 			aBuffer.PositionL( itemIds.iObjectIds.iPtr.iOffset );
   348 			iManipulate->RemoveObjectsByIdL( aBuffer, itemIds.iObjectIds.iPtr.iCount,
   361 			iManipulate->RemoveObjectsByIdL( aBuffer, itemIds.iObjectIds.iPtr.iCount,
   349 					idArray, removedRelations, removedEvents );
   362 					idArray, removedRelations, removedEvents, uriNotify, removedItemUriArray );
   350 			}
   363 			}
   351 
   364 
   352 	    transaction.CommitL();
   365 	    transaction.CommitL();
   353 		CleanupStack::PopAndDestroy( &transaction );
   366 		CleanupStack::PopAndDestroy( &transaction );
   354 
   367 
   443 		}
   456 		}
   444 
   457 
   445 	aResultBuffer.PositionL( KNoOffset );
   458 	aResultBuffer.PositionL( KNoOffset );
   446 	resultIds.SerializeL( aResultBuffer );
   459 	resultIds.SerializeL( aResultBuffer );
   447 
   460 
   448 	// notify about items removed
   461 	TBool notify = iNotifier.CheckForNotifier(EObjectNotifyRemove|EEventNotifyRemove|ERelationNotifyRemove);
   449 	const TBool notify = iNotifier.CheckForNotifier(EObjectNotifyRemove|EEventNotifyRemove|ERelationNotifyRemove);
   462 	
   450 	if (notify)
   463 	// notify about items removed 
   451 		{
   464 	if( uriNotify || notify )
   452 		iNotifier.NotifyRemovedL( aResultBuffer, EFalse );
   465 	    {
   453 		}
   466 	    iNotifier.NotifyRemovedL( aResultBuffer, EFalse, removedItemUriArray, this );
   454 
   467 		notify = ETrue;
       
   468 	    }
       
   469 	
   455 	// notify about additional items removed
   470 	// notify about additional items removed
   456 	const TInt KRemovedItemsCount = removedRelations.Count() + removedEvents.Count();
   471 	const TInt KRemovedItemsCount = removedRelations.Count() + removedEvents.Count();
   457     if ( notify && KRemovedItemsCount > 0 )
   472     if ( notify && KRemovedItemsCount > 0 )
   458     	{
   473     	{
   459     	const TInt32 bufferSize = sizeof(TMdCItemIds)
   474     	const TInt32 bufferSize = sizeof(TMdCItemIds)
   503 			additResultIds.iRelationIds.iPtr.iOffset = KNoOffset;
   518 			additResultIds.iRelationIds.iPtr.iOffset = KNoOffset;
   504 			}
   519 			}
   505 
   520 
   506 		buffer->PositionL( KNoOffset );
   521 		buffer->PositionL( KNoOffset );
   507 		additResultIds.SerializeL( *buffer );
   522 		additResultIds.SerializeL( *buffer );
   508 		iNotifier.NotifyRemovedL( *buffer, EFalse );
   523 		const TBool notifyEnabled = iNotifier.CheckForNotifier(EEventNotifyRemove|ERelationNotifyRemove);
       
   524 		if (notifyEnabled)
       
   525 		    {
       
   526 	        RPointerArray<HBufC> nullArray; // For when uris are not available or needed
       
   527 	        CleanupResetAndDestroyPushL( nullArray );
       
   528 		    iNotifier.NotifyRemovedL( *buffer, EFalse, nullArray, this );
       
   529 		    CleanupStack::PopAndDestroy( &nullArray );
       
   530 		    }
   509 		CleanupStack::PopAndDestroy( buffer );
   531 		CleanupStack::PopAndDestroy( buffer );
   510     	}
   532     	}
   511 
   533 
   512     // notify about removed relation items
   534     // notify about removed relation items
   513 	const TInt relationsCount = removedRelations.Count() + idArray.Count();
   535 	const TInt relationsCount = removedRelations.Count() + idArray.Count();
   530 	if( iGarbageCollector )
   552 	if( iGarbageCollector )
   531 		{
   553 		{
   532 		iGarbageCollector->Start( KGarbageCollectionDelay );
   554 		iGarbageCollector->Start( KGarbageCollectionDelay );
   533 		}
   555 		}
   534 
   556 
   535 	// removedEvents, removedRelations, idArray
   557 	// removedItemUriArray, removedEvents, removedRelations, idArray
   536     CleanupStack::PopAndDestroy( 3, &idArray );
   558     CleanupStack::PopAndDestroy( 4, &idArray );
   537     }
   559     }
   538 
   560 
   539 void CMdSManipulationEngine::UpdateL( CMdCSerializationBuffer& aBuffer, 
   561 void CMdSManipulationEngine::UpdateL( CMdCSerializationBuffer& aBuffer, 
   540 		CMdCSerializationBuffer& aResultBuffer )
   562 		CMdCSerializationBuffer& aResultBuffer )
   541 	{
   563 	{
   609 	if ( items.iRelations.iPtr.iCount > 0 )
   631 	if ( items.iRelations.iPtr.iCount > 0 )
   610 		{
   632 		{
   611 		resultIds.iRelationIds.iPtr.iOffset = aResultBuffer.Position();
   633 		resultIds.iRelationIds.iPtr.iOffset = aResultBuffer.Position();
   612 		resultIds.iRelationIds.iPtr.iCount = items.iRelations.iPtr.iCount;
   634 		resultIds.iRelationIds.iPtr.iCount = items.iRelations.iPtr.iCount;
   613 
   635 
       
   636         RMdSTransaction transaction( connection );
       
   637         CleanupClosePushL(transaction);
       
   638         const TInt beginError( transaction.Error() );
       
   639         if( beginError != KErrNone )
       
   640             {
       
   641             CleanupStack::PopAndDestroy( &transaction );
       
   642             }
       
   643 		
   614 		for ( TInt i = 0; i < items.iRelations.iPtr.iCount; ++i )
   644 		for ( TInt i = 0; i < items.iRelations.iPtr.iCount; ++i )
   615 			{
   645 			{
   616 			aBuffer.PositionL( items.iRelations.iPtr.iOffset + i * sizeof(TMdCRelation) );
   646 			aBuffer.PositionL( items.iRelations.iPtr.iOffset + i * sizeof(TMdCRelation) );
   617 
   647 
   618 			TItemId id = KNoId;
   648 			TItemId id = KNoId;
   628 					{
   658 					{
   629 					resultIds.iErrorCode = err;
   659 					resultIds.iErrorCode = err;
   630 					}
   660 					}
   631 				}
   661 				}
   632 			}
   662 			}
       
   663         if( beginError == KErrNone )
       
   664             {
       
   665             transaction.CommitL();
       
   666             CleanupStack::PopAndDestroy( &transaction );
       
   667             }
   633 		}
   668 		}
   634 	else
   669 	else
   635 		{
   670 		{
   636 		resultIds.iRelationIds.iPtr.iOffset = KNoOffset;
   671 		resultIds.iRelationIds.iPtr.iOffset = KNoOffset;
   637 		resultIds.iRelationIds.iPtr.iCount = 0;
   672 		resultIds.iRelationIds.iPtr.iCount = 0;
   877 
   912 
   878 		iManipulate->RemoveFilesNotPresentL( aMediaId, &objectIds );
   913 		iManipulate->RemoveFilesNotPresentL( aMediaId, &objectIds );
   879 		
   914 		
   880 		if( objectIds.Count() > 0 )
   915 		if( objectIds.Count() > 0 )
   881 			{
   916 			{
   882 			iNotifier.NotifyRemovedL( objectIds );
   917 			iNotifier.NotifyRemovedL( objectIds, this );
   883 			}
   918 			}
   884 		
   919 		
   885 		CleanupStack::PopAndDestroy( &objectIds );
   920 		CleanupStack::PopAndDestroy( &objectIds );
   886 		}
   921 		}
   887 	else
   922 	else
   961 	RArray<TItemId> objectIds;
   996 	RArray<TItemId> objectIds;
   962 	CleanupClosePushL( objectIds );
   997 	CleanupClosePushL( objectIds );
   963 
   998 
   964 	iManipulate->ChangePathL( aOldPath, aNewPath, objectIds );
   999 	iManipulate->ChangePathL( aOldPath, aNewPath, objectIds );
   965 
  1000 
   966 	iNotifier.NotifyModifiedL( objectIds );
  1001 	iNotifier.NotifyModifiedL( objectIds, this );
   967 	
  1002 	
   968 	CleanupStack::PopAndDestroy( &objectIds );
  1003 	CleanupStack::PopAndDestroy( &objectIds );
   969 	
  1004 	
   970 	transaction.CommitL();
  1005 	transaction.CommitL();
   971     CleanupStack::PopAndDestroy( &transaction );
  1006     CleanupStack::PopAndDestroy( &transaction );
  1057 TInt CMdSManipulationEngine::GetPendingL( TDefId aObjectDefId, 
  1092 TInt CMdSManipulationEngine::GetPendingL( TDefId aObjectDefId, 
  1058 		TInt aBufferSize, RArray<TItemId>& aObjectIds )
  1093 		TInt aBufferSize, RArray<TItemId>& aObjectIds )
  1059 	{
  1094 	{
  1060 	return iManipulate->GetPendingL( aObjectDefId, aBufferSize, aObjectIds );
  1095 	return iManipulate->GetPendingL( aObjectDefId, aBufferSize, aObjectIds );
  1061 	}
  1096 	}
       
  1097 
       
  1098 void CMdSManipulationEngine::GetObjectUrisByIdsL( const RArray<TItemId>& aObjectIds, 
       
  1099                                                                                    RPointerArray<HBufC>& aUriArray )
       
  1100     {
       
  1101     const TInt count( aObjectIds.Count() );
       
  1102     for( TInt i( 0 ); i < count; i++ )
       
  1103         {
       
  1104         TUint32 flags;
       
  1105         HBufC* uri = iManipulate->SearchObjectUriByIdL( aObjectIds[i], flags );
       
  1106         aUriArray.AppendL( uri );
       
  1107         uri = NULL;
       
  1108         }
       
  1109     }
       
  1110