Revision: 201015
authorDremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Mon, 03 May 2010 12:55:01 +0300
changeset 23 33ae025ac1e8
parent 21 50bf9db68373
child 25 8e4539ab1889
child 41 2290317b9ec5
Revision: 201015 Kit: 201018
clfwrapper/ClientSrc/CCLFDefaultOperation.cpp
clfwrapper/ClientSrc/CCLFItemListModelImpl.cpp
clfwrapper/ClientSrc/CCLFQueryAdapter.cpp
clfwrapper/ClientSrc/CCLFServerProxy.cpp
contextengine/plugins/calendarplugin/src/CalendarContextPlugin.cpp
contextengine/plugins/locationplugin/src/locationcontextplugin.cpp
harvester/blacklistclient/group/blacklistclient.mmp
harvester/blacklistclient/inc/blacklistclient.h
harvester/blacklistclient/src/blacklistclient.cpp
harvester/blacklistserver/src/blacklistserver.cpp
harvester/client/src/harvesterclient.cpp
harvester/common/group/harvesterdata.mmp
harvester/common/inc/harvestereventmanager.h
harvester/common/src/harvestereventmanager.cpp
harvester/common/src/harvesterexifutil.cpp
harvester/common/src/harvesterplugin.cpp
harvester/common/src/harvesterpluginfactory.cpp
harvester/harvesterplugins/AudioPlugin/inc/harvesteraudioplugin.h
harvester/harvesterplugins/AudioPlugin/src/harvesteraudioplugin.cpp
harvester/harvesterplugins/ImagePlugin/inc/harvesterimageplugin.h
harvester/harvesterplugins/ImagePlugin/src/harvesterimageplugin.cpp
harvester/harvesterplugins/MessagePlugin/group/bld.inf
harvester/harvesterplugins/MessagePlugin/src/harvestermessageplugin.cpp
harvester/harvesterplugins/OMADRMPlugin/inc/harvesteromadrmplugin.h
harvester/harvesterplugins/OMADRMPlugin/src/harvesteromadrmplugin.cpp
harvester/harvesterplugins/VideoPlugin/inc/harvestervideoplugin.h
harvester/harvesterplugins/VideoPlugin/src/harvestervideoplugin.cpp
harvester/harvesterplugins/WMVPlugin/inc/harvesterwmvplugin.h
harvester/harvesterplugins/WMVPlugin/src/harvesterwmvplugin.cpp
harvester/monitorplugins/fileplugin/inc/processoriginmapper.h
harvester/monitorplugins/fileplugin/src/movetimer.cpp
harvester/monitorplugins/fileplugin/src/processoriginmapper.cpp
harvester/monitorplugins/mdsfileserverplugin/inc/mdsfileserverplugin.h
harvester/monitorplugins/mdsfileserverplugin/src/mdsfileserverplugin.cpp
harvester/monitorplugins/messageplugin/group/bld.inf
harvester/monitorplugins/mmcplugin/src/mmcfilelist.cpp
harvester/server/inc/harvesterao.h
harvester/server/inc/harvesterqueue.h
harvester/server/src/harvesterao.cpp
harvester/server/src/harvesterqueue.cpp
harvester/server/src/mdeobjecthandler.cpp
harvester/server/src/reharvesterao.cpp
inc/mdscommoninternal.h
locationmanager/client/src/rlocationmanager.cpp
locationmanager/server/src/clocationmanagerserver.cpp
mds_plat/harvester_framework_api/tsrc/HarvesterClientTest/conf/HarvesterClientTestScripter.cfg
mds_plat/harvester_framework_api/tsrc/HarvesterPluginTest/conf/HarvesterPluginTest.cfg
mds_plat/metadata_engine_api/tsrc/conf/MdETestScripter.cfg
mds_plat/metadata_engine_api/tsrc/inc/MdETestScripter.h
mds_plat/metadata_engine_api/tsrc/src/MdETestScripterBlocks.cpp
mds_plat/metadata_engine_api/tsrc/src/MdETestScripterSchemaCommands.cpp
mds_pub/content_listing_framework_api/tsrc/conf/ContentListingFrameworkTest.cfg
mds_pub/content_listing_framework_api/tsrc/src/ContentListingFrameworkTestBlocks.cpp
metadataengine/client/inc/mdeenginesession.h
metadataengine/client/inc/mdesessionstartupao.h
metadataengine/client/src/mdeenginesession.cpp
metadataengine/client/src/mdenotifierao.cpp
metadataengine/client/src/mdequery.cpp
metadataengine/client/src/mdesessionimpl.cpp
metadataengine/client/src/mdesessionstartupao.cpp
metadataengine/server/inc/mdsnotifier.h
metadataengine/server/inc/mdsserver.h
metadataengine/server/inc/mdsserversession.h
metadataengine/server/src/mdsfindsqlclause.cpp
metadataengine/server/src/mdsmaintenanceengine.cpp
metadataengine/server/src/mdsmanipulationengine.cpp
metadataengine/server/src/mdsnotifier.cpp
metadataengine/server/src/mdsserver.cpp
metadataengine/server/src/mdsserversession.cpp
metadataengine/server/src/mdssqlobjectmanipulate.cpp
rom/ContentListingFramework.iby
sis/mds/mds_stub.sis
sis/mds/package.pkg
sis/mds/package_separate.pkg
sis/mds/stub.pkg
--- a/clfwrapper/ClientSrc/CCLFDefaultOperation.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/clfwrapper/ClientSrc/CCLFDefaultOperation.cpp	Mon May 03 12:55:01 2010 +0300
@@ -26,6 +26,9 @@
 #include    <badesca.h>
 #include    "MGDebugPrint.h"
 
+// for CleanupResetAndDestroyPushL
+#include <mmf/common/mmfcontrollerpluginresolver.h>
+
 // CONSTANTS
 const TInt KCLFGroupedItemArrayGranularity( 4 );
 const TInt KCLFSortingStyleArrayGranularity( 3 );
@@ -475,6 +478,8 @@
                                     const TArray<MCLFItem*>& aSourceList,
                                     RPointerArray<MCLFItem>& aGroupedList )
     {
+    CleanupResetAndDestroyPushL( aGroupedList );
+    
     CDesCArray* tempAlbumNameArray =
                 new (ELeave) CDesCArraySeg( KCLFGroupedItemArrayGranularity );
     CleanupStack::PushL( tempAlbumNameArray );
@@ -511,6 +516,8 @@
             }
         }
     CleanupStack::PopAndDestroy( tempAlbumNameArray );
+    
+    CleanupStack::Pop( &aGroupedList );
     }
 
 //  End of File
--- a/clfwrapper/ClientSrc/CCLFItemListModelImpl.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/clfwrapper/ClientSrc/CCLFItemListModelImpl.cpp	Mon May 03 12:55:01 2010 +0300
@@ -29,6 +29,9 @@
 #include    <collate.h>
 #include    "MGDebugPrint.h"
 
+// for CleanupResetAndDestroyPushL
+#include <mmf/common/mmfcontrollerpluginresolver.h>
+
 // CONSTANTS
 const TInt KCLFResourceVersionNumber( 1 );
 const TInt KCLFEmptyArrayGranularity( 1 );
@@ -443,10 +446,12 @@
 void CCLFItemListModelImpl::CopyArrayL( const TArray<MCLFItem*>& aSource,
                                         RPointerArray<MCLFItem>& aDest )
     {
+    CleanupResetAndDestroyPushL( aDest );
     for( TInt i = aSource.Count() - 1; i >=0; i--)
         {
         aDest.AppendL( aSource[i] );
         }
+    CleanupStack::Pop( &aDest );
     }
 
 // -----------------------------------------------------------------------------
--- a/clfwrapper/ClientSrc/CCLFQueryAdapter.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/clfwrapper/ClientSrc/CCLFQueryAdapter.cpp	Mon May 03 12:55:01 2010 +0300
@@ -205,8 +205,8 @@
         }
 
     aStatus = KRequestPending;
-    iStatusArray.Append( &aStatus );
-    iQueryArray.Append( aQuery );
+    iStatusArray.AppendL( &aStatus );
+    iQueryArray.AppendL( aQuery );
 
     // Check that we can actually execute the query. We can if we have at least one query condition.
     if ( rootCondition.Count() > 0 )
--- a/clfwrapper/ClientSrc/CCLFServerProxy.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/clfwrapper/ClientSrc/CCLFServerProxy.cpp	Mon May 03 12:55:01 2010 +0300
@@ -187,7 +187,7 @@
     {
     iWasNotificationHandled = EFalse;
 
-    const TInt index = iIdsPendingUpdate.Find( aId );
+    const TInt index = iIdsPendingUpdate.FindInOrder( aId );
     if ( index != KErrNotFound )
         {
         iWasNotificationHandled = ETrue;
@@ -213,9 +213,9 @@
     const TInt idCount( aItemIDArray.Count() );
     for ( TInt i = 0; i < idCount; ++i )
         {
-        if ( iIdsPendingUpdate.Find( aItemIDArray[ i ] ) == KErrNotFound )
+        if ( iIdsPendingUpdate.FindInOrder( aItemIDArray[ i ] ) == KErrNotFound )
             {
-            iIdsPendingUpdate.Append( aItemIDArray[ i ] );
+            iIdsPendingUpdate.InsertInOrder( aItemIDArray[ i ] );
             }
         }
     }
@@ -271,7 +271,7 @@
         
         if ( id != KNoId )
             {
-            iIdsPendingRemoval.Append( id );
+            iIdsPendingRemoval.InsertInOrder( id );
             }
         }
     iObjectsPendingRemoval.ResetAndDestroy();
@@ -287,7 +287,7 @@
 
     if ( aType == ENotifyRemove )
         {
-        const TInt index = iIdsPendingRemoval.Find( aId );
+        const TInt index = iIdsPendingRemoval.FindInOrder( aId );
         if ( index != KErrNotFound )
             {
             iWasNotificationHandled = ETrue;
@@ -420,7 +420,7 @@
 
     if ( aType == ENotifyRemove )
         {
-        const TInt index = iIdsPendingRemoval.Find( aId );
+        const TInt index = iIdsPendingRemoval.FindInOrder( aId );
         
         if ( index != KErrNotFound )
             {
@@ -430,12 +430,12 @@
         }
     else if ( aType == ENotifyAdd || aType == ENotifyModify )
         {
-        const TInt index = iIdsPendingUpdate.Find( aId );
+        const TInt index = iIdsPendingUpdate.FindInOrder( aId );
         
         if ( index != KErrNotFound )
             {
             iIdsPendingUpdate.Remove( index );
-            const TInt handledIndex = iIdsHandled.Find( aId );
+            const TInt handledIndex = iIdsHandled.FindInOrder( aId );
             if( handledIndex != KErrNotFound )
                 {
                 iIdsHandled.Remove( handledIndex );
@@ -444,7 +444,7 @@
             }
         else if( iHarvestingOngoing )
             { 
-            iIdsHandled.Append( aId );
+            iIdsHandled.InsertInOrder( aId );
             iWasNotificationHandled = ETrue;
             }
         }
@@ -596,7 +596,7 @@
                 id = iMdESession.RemoveObjectL( object.Id() );
                 if ( id != KNoId )
                     {
-                    iIdsPendingRemoval.Append( id );
+                    iIdsPendingRemoval.InsertInOrder( id );
                     }
                 }
             }
@@ -687,14 +687,14 @@
         object = iMdESession.GetObjectL( aUri );
         if( object )
             {
-            const TInt index = iIdsHandled.Find( object->Id() );
+            const TInt index = iIdsHandled.FindInOrder( object->Id() );
             if( index != KErrNotFound )
                 {
                 iIdsHandled.Remove( index );
                 }
             else
                 {
-                iIdsPendingUpdate.Append( object->Id() ); 
+                iIdsPendingUpdate.InsertInOrder( object->Id() ); 
                 }
             }
         }
--- a/contextengine/plugins/calendarplugin/src/CalendarContextPlugin.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/contextengine/plugins/calendarplugin/src/CalendarContextPlugin.cpp	Mon May 03 12:55:01 2010 +0300
@@ -240,6 +240,14 @@
 
 	WRITELOG1( "CCalendarContextPlugin::AddMetaDataL -- instanceCount: %d", instanceCount );
 
+	if( instanceCount == 0 )
+	    {
+        CleanupStack::PopAndDestroy( &instances );
+
+        WRITELOG( "CCalendarContextPlugin::AddMetaDataL - no calendar items found -- RETURN" );	
+        return;
+	    }
+	
 	// required object properties
 	WRITELOG( "CCalendarContextPlugin::AddMetaDataL" );
 	User::LeaveIfNull( iMdeSession );
--- a/contextengine/plugins/locationplugin/src/locationcontextplugin.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/contextengine/plugins/locationplugin/src/locationcontextplugin.cpp	Mon May 03 12:55:01 2010 +0300
@@ -235,7 +235,6 @@
 	        	{
 	        	ret = KErrNone;
 	        	}
-
     		}
         }
 
@@ -255,6 +254,7 @@
 void CLocationContextPlugin::GetMdeObjectCreationTimeL( CMdEObject& aObject, 
 	CMdEProperty*& aProperty )
     {
+    User::LeaveIfNull( iMdeSession );
     CMdENamespaceDef& namespaceDef = iMdeSession->GetDefaultNamespaceDefL();
 
     CMdEObjectDef& objectDef = namespaceDef.GetObjectDefL( Object::KBaseObject );
--- a/harvester/blacklistclient/group/blacklistclient.mmp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/blacklistclient/group/blacklistclient.mmp	Mon May 03 12:55:01 2010 +0300
@@ -37,6 +37,7 @@
 
 LIBRARY        	  euser.lib
 LIBRARY           mdccommon.lib
+LIBRARY           efsrv.lib
 
 #if defined(WINSCW)
 deffile ../bwincw/blacklistclientwinscw.def
--- a/harvester/blacklistclient/inc/blacklistclient.h	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/blacklistclient/inc/blacklistclient.h	Mon May 03 12:55:01 2010 +0300
@@ -147,6 +147,11 @@
   
     private: // private data
        
+        /** 
+         * Handle to File server session.
+         */
+        RFs iFs;
+        
         /*! @var iSessionOk flag to indicate if session is ok or not.*/
         TBool iSessionOk;
        
--- a/harvester/blacklistclient/src/blacklistclient.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/blacklistclient/src/blacklistclient.cpp	Mon May 03 12:55:01 2010 +0300
@@ -43,6 +43,7 @@
     iBlacklistMemoryTable.ResetAndDestroy();
     iBlacklistMemoryTable.Close();
 	iBlacklistChunk.Close();
+	iFs.Close();
 
     WRITELOG( "RBlacklistClient::~RBlacklistClient - end" );
     }
@@ -56,8 +57,15 @@
     WRITELOG( "RBlacklistClient::Connect - begin" );
 
     iSessionOk = EFalse;
+    
+    TInt error = iFs.Connect();
+    
+    if( error != KErrNone )
+        {
+        return error;
+        }
       
-    TInt error = StartServer();
+    error = StartServer();
 
     if ( error == KErrNone || error == KErrAlreadyExists )
         {
@@ -69,6 +77,10 @@
         {
         iSessionOk = ETrue;
         }
+    else
+        {
+        iFs.Close();
+        }
     
     WRITELOG( "RBlacklistClient::Connect - end" );
 
@@ -116,7 +128,7 @@
         }
 
     User::WaitForRequest( status );
-    error = server.ExitType() == EExitPanic ? KErrGeneral : status.Int();
+    error = server.ExitType() == EExitPanic ? KErrCommsBreak : status.Int();
     server.Close();
 
     WRITELOG( "RBlacklistClient::StartServer - end" );
@@ -273,21 +285,37 @@
 // RBlacklistClient::IsBlacklistedL()
 // ---------------------------------------------------------------------------
 //
-EXPORT_C TBool RBlacklistClient::IsBlacklistedL( const TDesC& aUri, TUint32 aMediaId, TTime aLastModifiedTime )
+EXPORT_C TBool RBlacklistClient::IsBlacklistedL( const TDesC& aUri, TUint32 aMediaId, TTime /*aLastModifiedTime*/ )
     {
     WRITELOG( "RBlacklistClient::IsBlacklistedL - begin" );
 
+    if ( !iSessionOk )
+        {
+        return EFalse;
+        }
+    
     const TInt index = GetListIndex( aUri, aMediaId );
     if ( index >= 0 )
         {
+        TEntry entry;
+        const TInt errorcode = iFs.Entry( aUri, entry );
+        
+        if ( errorcode != KErrNone )
+            {
+            return EFalse;
+            }
+        
+        TTime fileLastModified( 0 );
+        fileLastModified = entry.iModified;
+    
         TInt64 modified( 0 );
         modified = iBlacklistMemoryTable[index]->Modified();
         
         if( modified > 0 )
             {
-            if ( modified == aLastModifiedTime.Int64() )
+            if ( modified == fileLastModified.Int64() )
                 {
-                WRITELOG( "RBlacklistClient::IsBlacklistedL - file is blacklisted, modification time is different" );
+                WRITELOG( "RBlacklistClient::IsBlacklistedL - file is blacklisted, modification time is the same" );
                 return ETrue;
                 }
             else
--- a/harvester/blacklistserver/src/blacklistserver.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/blacklistserver/src/blacklistserver.cpp	Mon May 03 12:55:01 2010 +0300
@@ -154,13 +154,8 @@
     {
     WRITELOG( "CBlacklistServer::ConstructL - begin" );
 
-    const TInt error = Start( KBlacklistServerName );
+    StartL( KBlacklistServerName );
 
-    if ( error != KErrNone )
-        {
-        __ASSERT_DEBUG( EFalse, User::Panic( KBlacklistServerName, error ));
-        }
-    
     iSqLiteConnection = CMdSSqLiteConnection::NewL();
     
     WRITELOG( "CBlacklistServer::ConstructL - end" );
@@ -232,21 +227,25 @@
 void CBlacklistServer::ExeMainL()
     {
     WRITELOG( "CBlacklistServer::ExeMainL - begin" );
+    User::LeaveIfError( User::RenameThread(KBlacklistServerName) );
+    // Construct active scheduler
+    CActiveScheduler* activeScheduler = new ( ELeave ) CActiveScheduler;
+    CleanupStack::PushL( activeScheduler );
 
     // Install active scheduler
-    CActiveScheduler* scheduler = new( ELeave ) CActiveScheduler;
-    CleanupStack::PushL( scheduler );
-    CActiveScheduler::Install( scheduler );
+    // We don't need to check whether an active scheduler is already installed
+    // as this is a new thread, so there won't be one
+    CActiveScheduler::Install( activeScheduler );
 
-    CBlacklistServer::NewLC();
+    // Construct our server
+    CBlacklistServer::NewLC();    // Anonymous
 
-    User::LeaveIfError( User::RenameThread( KBlacklistServerName ) );
     RProcess::Rendezvous( KErrNone );
 
+    // Start handling requests
     CActiveScheduler::Start();
 
-    CleanupStack::PopAndDestroy( 2, scheduler );  
-
+    CleanupStack::PopAndDestroy( 2, activeScheduler );  
     WRITELOG( "CBlacklistServer::ExeMainL - end" );
     }
 
@@ -256,21 +255,18 @@
 //
 TInt E32Main()
     {
-    WRITELOG( "CBlacklistServer::E32Main - begin" );
- 
+    WRITELOG( "CBlacklistServer::E32Main - begin" );   
     __UHEAP_MARK;
-
-    CTrapCleanup* cleanup = CTrapCleanup::New();
-    
-    TRAPD( error, CBlacklistServer::ExeMainL() );
-    __ASSERT_ALWAYS( !error, User::Panic( KBlacklistServerName, error ) );
-
-    delete cleanup;
+    CTrapCleanup* cleanup=CTrapCleanup::New();
+    TInt result = KErrNoMemory;
+    if (cleanup)
+        {
+        TRAP(result, CBlacklistServer::ExeMainL());
+        delete cleanup;
+        }
     __UHEAP_MARKEND;
-
     WRITELOG( "CBlacklistServer::E32Main - end" );
-
-    return 0;
+    return result;
     }
 
 
--- a/harvester/client/src/harvesterclient.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/client/src/harvesterclient.cpp	Mon May 03 12:55:01 2010 +0300
@@ -523,19 +523,14 @@
     {
     WRITELOG( "CreateServerProcess() - begin" );
     RProcess server;
-    TInt result = server.Create( KHarvesterServerExe, KNullDesC );
-
-    if( result == KErrAlreadyExists )
-    	{
-    	return KErrNone;
-    	}
-    
+    TInt result = server.Create( KHarvesterServerExe, KNullDesC );   
     if ( result != KErrNone )
         {
         WRITELOG1( "CreateServerProcess() - failed to create server process, error: %d", result );
         return result;
         }
  
+    // Process created successfully
     TRequestStatus stat( 0 );
     server.Rendezvous( stat );
     
--- a/harvester/common/group/harvesterdata.mmp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/common/group/harvesterdata.mmp	Mon May 03 12:55:01 2010 +0300
@@ -47,5 +47,5 @@
 
 PAGED
 BYTEPAIRCOMPRESSTARGET
-OPTION ARMCC -O3 -OTime
+OPTION ARMCC -O2 -OTime
 
--- a/harvester/common/inc/harvestereventmanager.h	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/common/inc/harvestereventmanager.h	Mon May 03 12:55:01 2010 +0300
@@ -129,6 +129,8 @@
 			HarvesterEventObserverType aObserverType, 
 			HarvesterEventState aEventState, TUint aItemsLeft );
 
+	static TInt CompareProperties(const THarvesterEventQueue& aFirst, const THarvesterEventQueue& aSecond);
+	
 private:
 
 	RArray<TEventStatus> iEventStatuses;
--- a/harvester/common/src/harvestereventmanager.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/common/src/harvestereventmanager.cpp	Mon May 03 12:55:01 2010 +0300
@@ -329,11 +329,10 @@
 		THarvesterEventQueue* msgQueue = new (ELeave) THarvesterEventQueue;
 		CleanupStack::PushL( msgQueue );
 
-		TInt err = msgQueue->Open( aMessage, 1 );
+		User::LeaveIfError( msgQueue->Open( aMessage, 1 ) );
 
-		User::LeaveIfError( err );
-
-		iEventQueues.AppendL( msgQueue );
+		User::LeaveIfError( iEventQueues.InsertInOrderAllowRepeats(msgQueue, 
+		                                 TLinearOrder<THarvesterEventQueue>(CHarvesterEventManager::CompareProperties))); 
 		observerInfo->iQueuePtr = msgQueue;
 		
 		CleanupStack::Pop( msgQueue );
@@ -396,17 +395,31 @@
 		// was the last observer which used it
 		if( !otherObserverFound )
 			{
-			for(TInt i = iEventQueues.Count(); --i >= 0;)
-				{
-				THarvesterEventQueue* queue = iEventQueues[i];
-				if( queue->Handle() == serverQueueHandle )
-					{
-					iEventQueues.Remove( i );
-					queue->Close();
-					delete queue;
-					break;
-					}
-				}
+	        TInt low( 0 );
+	        TInt high( iEventQueues.Count() );
+	    
+	        while( low < high )
+	            {
+	            TInt mid( (low+high)>>1 );
+	        
+	            const TInt compare( serverQueueHandle - iEventQueues[mid]->Handle() );
+	            if( compare == 0 )
+	                {
+	                THarvesterEventQueue* queue = iEventQueues[mid];
+                    iEventQueues.Remove( mid );
+                    queue->Close();
+                    delete queue;
+                    break;
+	                }
+	            else if( compare > 0 )
+	                {
+	                low = mid + 1;
+	                }
+	            else
+	                {
+	                high = mid;
+	                }
+	            }
 			iEventQueues.Compress();
 			}
 
@@ -460,3 +473,9 @@
 	// deprecated method, just return something
 	return 0;
 	}
+
+TInt CHarvesterEventManager::CompareProperties(const THarvesterEventQueue& aFirst, const THarvesterEventQueue& aSecond)
+    {
+    return aFirst.Handle() - aSecond.Handle();
+    }
+
--- a/harvester/common/src/harvesterexifutil.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/common/src/harvesterexifutil.cpp	Mon May 03 12:55:01 2010 +0300
@@ -1817,7 +1817,7 @@
     
         const CExifTag* refTag = aReader->GetTagL(
                 EIfdGps, KIdGpsAltitudeRef );
-        TBuf8<1> altitudeRef = refTag->Data();
+        TBuf8<2> altitudeRef = refTag->Data();
         const CExifTag* altitudeTag = aReader->GetTagL(
                 EIfdGps, KIdGpsAltitude );
         TBuf8<KAltitudeBufferSize> altitudeBuf = altitudeTag->Data();
--- a/harvester/common/src/harvesterplugin.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/common/src/harvesterplugin.cpp	Mon May 03 12:55:01 2010 +0300
@@ -220,6 +220,7 @@
 //
 EXPORT_C void CHarvesterPlugin::DoCancel()
     {
+    iState = EHarvesterIdle;
     }
 
 // ---------------------------------------------------------------------------
--- a/harvester/common/src/harvesterpluginfactory.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/common/src/harvesterpluginfactory.cpp	Mon May 03 12:55:01 2010 +0300
@@ -28,6 +28,9 @@
 #include "mdsutils.h"
 #include "harvesterlog.h"
 
+// for CleanupResetAndDestroyPushL
+#include <mmf/common/mmfcontrollerpluginresolver.h>
+
 const TInt KCacheItemCountForEventCaching = 1;
 
 // ---------------------------------------------------------------------------
@@ -36,7 +39,7 @@
 //
 CHarvesterPluginFactory::CHarvesterPluginFactory() :
     iBlacklist( NULL ),
-    iHarvesting( NULL ),
+    iHarvesting( EFalse ),
     iHarvesterEventManager( NULL )
 	{
 	WRITELOG( "CHarvesterPluginFactory::CHarvesterPluginFactory()" );
@@ -338,6 +341,8 @@
 void CHarvesterPluginFactory::GetSupportedPluginsL(
 		RPointerArray<CHarvesterPluginInfo>& aSupportedPlugins, const TDesC& aExt )
 	{
+    CleanupResetAndDestroyPushL( aSupportedPlugins );
+    
 	const TInt pluginInfoCount = iHarvesterPluginInfoArray.Count();
 	TInt extCount = 0;
 	for ( TInt i = pluginInfoCount; --i >= 0; )
@@ -358,6 +363,8 @@
                 }
             }
         }	
+	
+	CleanupStack::Pop( &aSupportedPlugins );
 	}
 
 EXPORT_C TBool CHarvesterPluginFactory::IsSupportedFileExtension( const TDesC& aFileName )
--- a/harvester/harvesterplugins/AudioPlugin/inc/harvesteraudioplugin.h	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/harvesterplugins/AudioPlugin/inc/harvesteraudioplugin.h	Mon May 03 12:55:01 2010 +0300
@@ -154,6 +154,8 @@
 		
 		CThumbnailManager* iTNM;
 		TBool iHarvestAlbumArt;
+		
+		TInt iMaxTextLength;
 	};
 
 
--- a/harvester/harvesterplugins/AudioPlugin/src/harvesteraudioplugin.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/harvesterplugins/AudioPlugin/src/harvesteraudioplugin.cpp	Mon May 03 12:55:01 2010 +0300
@@ -276,6 +276,8 @@
 		{
 		CMdEObjectDef& objectDef = mdeObject.Def();
 		iPropDefs = CHarvesterAudioPluginPropertyDefs::NewL( objectDef );
+		// Prefetch max text lengt for validity checking
+		iMaxTextLength = iPropDefs->iCopyrightPropertyDef->MaxTextLengthL();
 		}
 	
 	CMdeObjectWrapper::HandleObjectPropertyL(
@@ -309,6 +311,8 @@
     		{
     		CMdEObjectDef& objectDef = mdeObject.Def();
     		iPropDefs = CHarvesterAudioPluginPropertyDefs::NewL( objectDef );
+    		// Prefetch max text lengt for validity checking
+    		iMaxTextLength = iPropDefs->iCopyrightPropertyDef->MaxTextLengthL();
     		}
         
     	CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
@@ -339,6 +343,8 @@
         {
         CMdEObjectDef& audioObjectDef = mdeObject.Def();
         iPropDefs = CHarvesterAudioPluginPropertyDefs::NewL( audioObjectDef );
+        // Prefetch max text lengt for validity checking
+        iMaxTextLength = iPropDefs->iCopyrightPropertyDef->MaxTextLengthL();
         }
     
     TPtrC ext;
@@ -390,35 +396,35 @@
     CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iTimeOffsetPropertyDef, &timeOffsetMinutes, aIsAdd );
 	
     if ( song.Length() > 0
-        && song.Length() < iPropDefs->iTitlePropertyDef->MaxTextLengthL() )
+        && song.Length() < iMaxTextLength )
         {    
         CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
         		*iPropDefs->iTitlePropertyDef, &song, EFalse );
         }
 
     if ( artist.Length() > 0
-        && artist.Length() < iPropDefs->iArtistPropertyDef->MaxTextLengthL() )
+        && artist.Length() < iMaxTextLength )
         {
         CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
         		*iPropDefs->iArtistPropertyDef, &artist, aIsAdd );
         }
 
     if ( album.Length() > 0
-        && album.Length() < iPropDefs->iAlbumPropertyDef->MaxTextLengthL() )
+        && album.Length() < iMaxTextLength )
         {
         CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
         		*iPropDefs->iAlbumPropertyDef, &album, aIsAdd );
         }
  
     if ( genre.Length() > 0
-        && genre.Length() < iPropDefs->iGenrePropertyDef->MaxTextLengthL() )
+        && genre.Length() < iMaxTextLength )
         {
         CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
         		*iPropDefs->iGenrePropertyDef, &genre, aIsAdd );
         }
 
     if ( composer.Length() > 0
-        && composer.Length() < iPropDefs->iComposerPropertyDef->MaxTextLengthL() )
+        && composer.Length() < iMaxTextLength )
         {
         CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
         		*iPropDefs->iComposerPropertyDef, &composer, aIsAdd );
@@ -437,7 +443,7 @@
         }
     
     if ( orgArtist.Length() > 0
-        && orgArtist.Length() < iPropDefs->iOriginalArtistPropertyDef->MaxTextLengthL() )
+        && orgArtist.Length() < iMaxTextLength )
         {
         CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
         		*iPropDefs->iOriginalArtistPropertyDef, &orgArtist, aIsAdd );
@@ -468,7 +474,7 @@
         }
     
     if ( copyright.Length() > 0
-        && copyright.Length() < iPropDefs->iCopyrightPropertyDef->MaxTextLengthL() )
+        && copyright.Length() < iMaxTextLength )
         {
         CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
         		*iPropDefs->iCopyrightPropertyDef, &copyright, aIsAdd );
--- a/harvester/harvesterplugins/ImagePlugin/inc/harvesterimageplugin.h	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/harvesterplugins/ImagePlugin/inc/harvesterimageplugin.h	Mon May 03 12:55:01 2010 +0300
@@ -197,6 +197,8 @@
         RArray< TMimeTypeMapping<TImageMetadataHandling> > iMimeTypeMappings;
         
         CHarvesterImagePluginPropertyDefs* iPropDefs;
+        
+        TInt iMaxTextLength;
 	};
 
 #endif
--- a/harvester/harvesterplugins/ImagePlugin/src/harvesterimageplugin.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/harvesterplugins/ImagePlugin/src/harvesterimageplugin.cpp	Mon May 03 12:55:01 2010 +0300
@@ -385,6 +385,8 @@
         if( !iPropDefs )
         	{
         	iPropDefs = CHarvesterImagePluginPropertyDefs::NewL( objectDef );
+        	// Prefetch max text lengt for validity checking
+        	iMaxTextLength = iPropDefs->iCopyrightPropertyDef->MaxTextLengthL();
         	}
         
         aMetadataObject.Property( *iPropDefs->iSizePropertyDef, prop );
@@ -679,6 +681,8 @@
     if( !iPropDefs )
     	{
     	iPropDefs = CHarvesterImagePluginPropertyDefs::NewL( mdeObject.Def() );
+    	// Prefetch max text lengt for validity checking
+    	iMaxTextLength = iPropDefs->iCopyrightPropertyDef->MaxTextLengthL();
     	}
 
     TTimeIntervalSeconds timeOffsetSeconds = User::UTCOffset();
@@ -775,16 +779,25 @@
     if ( aFileData.iExifSupported )
         {
        	// MediaObject - Description
-       	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iDescriptionPropertyDef, aHd.iDescription16, aIsAdd );
+        if( aHd.iDescription16 && aHd.iDescription16->Length() < iMaxTextLength )
+            {
+            CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iDescriptionPropertyDef, aHd.iDescription16, aIsAdd );
+            }     	
 
         // MediaObject - Comment (user comment)
-    	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iCommentPropertyDef, aHd.iComment16, aIsAdd );
+        if( aHd.iComment16 && aHd.iComment16->Length() < iMaxTextLength )
+            {
+            CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iCommentPropertyDef, aHd.iComment16, aIsAdd );
+            }
         
         // MediaObject - Release date
     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iReleaseDatePropertyDef, &localModifiedDate, aIsAdd );
 
         // MediaObject - Copyright
-    	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iCopyrightPropertyDef, aHd.iCopyright16, aIsAdd );
+        if( aHd.iCopyright16 && aHd.iCopyright16->Length() < iMaxTextLength )
+            {
+            CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iCopyrightPropertyDef, aHd.iCopyright16, aIsAdd );
+            }
         
         // Data & time original
         if ( aHd.iDateOriginal8 )
@@ -818,7 +831,10 @@
             }
         
         // Artist    
-        CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iArtistPropertyDef, aHd.iArtist, aIsAdd );
+        if( aHd.iArtist && aHd.iArtist->Length() < iMaxTextLength )
+            {
+            CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iArtistPropertyDef, aHd.iArtist, aIsAdd );
+            }
 
         // Image - White balance
         if ( aHd.iStoreWhiteBalance )
@@ -838,11 +854,17 @@
             CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iExposureProgramPropertyDef, &aHd.iExposureProgram, aIsAdd );
             }     
          
-         // Make string            
-        CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iMakePropertyDef, aHd.iMake, aIsAdd );
+         // Make string   
+        if( aHd.iMake && aHd.iMake->Length() < iMaxTextLength )
+            {
+            CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iMakePropertyDef, aHd.iMake, aIsAdd );
+            }
             
         // Model string
-        CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iModelPropertyDef, aHd.iModel, aIsAdd );
+        if( aHd.iModel && aHd.iModel->Length() < iMaxTextLength )
+            {
+            CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iModelPropertyDef, aHd.iModel, aIsAdd );
+            }
                     
         // Orientation
         if ( aHd.iStoreOrientation )
@@ -980,7 +1002,7 @@
             }
             
         // Related soundfile            
-        if ( aHd.iRelatedSoundFile && aHd.iRelatedSoundFile->Length() > 0 )
+        if ( aHd.iRelatedSoundFile && aHd.iRelatedSoundFile->Length() > 0 && aHd.iRelatedSoundFile->Length() < iMaxTextLength )
             {
             CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iRelatedSoundFilePropertyDef, aHd.iRelatedSoundFile, aIsAdd );
             }
--- a/harvester/harvesterplugins/MessagePlugin/group/bld.inf	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/harvesterplugins/MessagePlugin/group/bld.inf	Mon May 03 12:55:01 2010 +0300
@@ -22,7 +22,7 @@
 PRJ_EXPORTS
 
 PRJ_MMPFILES
-//harvestermessageplugin.mmp
+harvestermessageplugin.mmp
 
 PRJ_TESTMMPFILES
 
--- a/harvester/harvesterplugins/MessagePlugin/src/harvestermessageplugin.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/harvesterplugins/MessagePlugin/src/harvestermessageplugin.cpp	Mon May 03 12:55:01 2010 +0300
@@ -30,7 +30,6 @@
 #include <mdetextproperty.h>
 
 #include "harvestermessageplugin.h"
-#include "harvestercommon.h"
 #include "harvesterlog.h"
 #include "mdsutils.h"
 #include "mdeobjectdef.h"
--- a/harvester/harvesterplugins/OMADRMPlugin/inc/harvesteromadrmplugin.h	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/harvesterplugins/OMADRMPlugin/inc/harvesteromadrmplugin.h	Mon May 03 12:55:01 2010 +0300
@@ -155,6 +155,8 @@
 
 	private:
 		CHarvesterOmaDrmPluginPropertyDefs* iPropDefs;
+		
+		TInt iMaxTextLength;
 	};
 
 #endif // __CHarvesterOMADRMPlugin_H__
--- a/harvester/harvesterplugins/OMADRMPlugin/src/harvesteromadrmplugin.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/harvesterplugins/OMADRMPlugin/src/harvesteromadrmplugin.cpp	Mon May 03 12:55:01 2010 +0300
@@ -262,6 +262,8 @@
     	{
     	CMdEObjectDef& objectDef = mdeObject.Def();
     	iPropDefs = CHarvesterOmaDrmPluginPropertyDefs::NewL( objectDef );
+    	// Prefetch max text lengt for validity checking
+    	iMaxTextLength = iPropDefs->iGenrePropertyDef->MaxTextLengthL();
     	}
     
     TTimeIntervalSeconds timeOffset = User::UTCOffset();
@@ -299,25 +301,25 @@
     		*iPropDefs->iDrmPropertyDef, &aVHD.iDrmProtected, aIsAdd );
     
     // Title (is set from URI by default)
-    if(aVHD.iTitle.Length() > 0)
+    if( aVHD.iTitle.Length() > 0 && aVHD.iTitle.Length() < iMaxTextLength )
     	{
     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
     			*iPropDefs->iTitlePropertyDef, &aVHD.iTitle, EFalse );
     	}
     // Description
-    if(aVHD.iDescription.Length() > 0)
+    if( aVHD.iDescription.Length() > 0 && aVHD.iDescription.Length() < iMaxTextLength )
     	{
     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
     			*iPropDefs->iDescriptionPropertyDef, &aVHD.iDescription, aIsAdd );
     	}   
     // Author
-    if(aVHD.iAuthor.Length() > 0)
+    if( aVHD.iAuthor.Length() > 0 && aVHD.iAuthor.Length() < iMaxTextLength )
     	{
     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
     			*iPropDefs->iAuthorPropertyDef, &aVHD.iAuthor, aIsAdd );
     	}
     // Genre
-    if(aVHD.iGenre.Length() > 0)
+    if( aVHD.iGenre.Length() > 0 && aVHD.iGenre.Length() < iMaxTextLength )
         {
         CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
                 *iPropDefs->iGenrePropertyDef, &aVHD.iGenre, aIsAdd );
--- a/harvester/harvesterplugins/VideoPlugin/inc/harvestervideoplugin.h	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/harvesterplugins/VideoPlugin/inc/harvestervideoplugin.h	Mon May 03 12:55:01 2010 +0300
@@ -22,6 +22,7 @@
 #include "harvesterplugin.h"
 
 #include "mimetypemapping.h"
+#include "harvestermediaidutil.h"
 
 // FORWARD DECLARATION
 class CMdEObjectDef;
@@ -228,6 +229,11 @@
 		RArray<THarvestingHandling> iMimeTypeMappings;
 		
 		CHarvesterVideoPluginPropertyDefs* iPropDefs;
+		
+		TInt iMaxTextLength;
+		
+		// not own
+		CHarvesterMediaIdUtil* iMediaIdUtil;
 	};
 
 #endif // __CHARVESTERVIDEOPLUGIN_H__
--- a/harvester/harvesterplugins/VideoPlugin/src/harvestervideoplugin.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/harvesterplugins/VideoPlugin/src/harvestervideoplugin.cpp	Mon May 03 12:55:01 2010 +0300
@@ -161,6 +161,7 @@
 	{
 	delete iPropDefs;
 	iMimeTypeMappings.Close();
+    RMediaIdUtil::ReleaseInstance();
 
 	WRITELOG("CHarvesterVideoPlugin::CHarvesterVideoPlugin()");
 	}
@@ -177,44 +178,44 @@
 	// MPEG4
 	User::LeaveIfError( iMimeTypeMappings.InsertInOrder( THarvestingHandling(
     		KExtensionMp4(), KNullDesC(), 
-    		TVideoMetadataHandling( TVideoMetadataHandling::EMp4LibHandling, KNullDesC(),
+    		TVideoMetadataHandling( TVideoMetadataHandling::EHexilMetadataHandling, KNullDesC(),
     				KMimeTypeVideoMp4(), KMimeTypeAudioMp4() ) ), 
     		cmp ) );
 	User::LeaveIfError( iMimeTypeMappings.InsertInOrder( THarvestingHandling(
     		KExtensionMpg4(), KNullDesC(), 
-    		TVideoMetadataHandling( TVideoMetadataHandling::EMp4LibHandling, KNullDesC(),
+    		TVideoMetadataHandling( TVideoMetadataHandling::EHexilMetadataHandling, KNullDesC(),
     				KMimeTypeVideoMp4(), KMimeTypeAudioMp4() ) ), 
     		cmp ) );
 	User::LeaveIfError( iMimeTypeMappings.InsertInOrder( THarvestingHandling(
     		KExtensionMpeg4(), KNullDesC(), 
-    		TVideoMetadataHandling( TVideoMetadataHandling::EMp4LibHandling, KNullDesC(),
+    		TVideoMetadataHandling( TVideoMetadataHandling::EHexilMetadataHandling, KNullDesC(),
     				KMimeTypeVideoMp4(), KMimeTypeAudioMp4() ) ), 
     		cmp ) );
 	User::LeaveIfError( iMimeTypeMappings.InsertInOrder( THarvestingHandling(
     		KExtensionM4v(), KMimeTypeVideoMp4(), 
-    		TVideoMetadataHandling( TVideoMetadataHandling::EMp4LibHandling, KVideo(),
+    		TVideoMetadataHandling( TVideoMetadataHandling::EHexilMetadataHandling, KVideo(),
     				KMimeTypeVideoMp4(), KMimeTypeAudioMp4() ) ), 
     		cmp ) );
 	User::LeaveIfError( iMimeTypeMappings.InsertInOrder( THarvestingHandling(
     		KExtensionM4a(), KMimeTypeAudioMp4(), 
-    		TVideoMetadataHandling( TVideoMetadataHandling::EMp4LibHandling, KAudio(),
+    		TVideoMetadataHandling( TVideoMetadataHandling::EHexilMetadataHandling, KAudio(),
     				KMimeTypeVideoMp4(), KMimeTypeAudioMp4() ) ), 
     		cmp ) );
 
 	// 3GP
 	User::LeaveIfError( iMimeTypeMappings.InsertInOrder( THarvestingHandling(
     		KExtension3gp(), KNullDesC(), 
-    		TVideoMetadataHandling( TVideoMetadataHandling::EMp4LibHandling, KNullDesC(),
+    		TVideoMetadataHandling( TVideoMetadataHandling::EHexilMetadataHandling, KNullDesC(),
     				KMimeTypeVideo3gpp(), KMimeTypeAudio3gpp() ) ), 
     		cmp ) );
 	User::LeaveIfError( iMimeTypeMappings.InsertInOrder( THarvestingHandling(
     		KExtension3gpp(), KNullDesC(), 
-    		TVideoMetadataHandling( TVideoMetadataHandling::EMp4LibHandling, KNullDesC(),
+    		TVideoMetadataHandling( TVideoMetadataHandling::EHexilMetadataHandling, KNullDesC(),
     				KMimeTypeVideo3gpp(), KMimeTypeAudio3gpp() ) ), 
     		cmp ) );
 	User::LeaveIfError( iMimeTypeMappings.InsertInOrder( THarvestingHandling(
     		KExtension3g2(), KNullDesC(), 
-    		TVideoMetadataHandling( TVideoMetadataHandling::EMp4LibHandling, KNullDesC(),
+    		TVideoMetadataHandling( TVideoMetadataHandling::EHexilMetadataHandling, KNullDesC(),
     				KMimeTypeVideo3gpp(), KMimeTypeAudio3gpp() ) ), 
     		cmp ) );
 
@@ -268,6 +269,7 @@
                     KMimeTypeWmv(), KMimeTypeWmv() ) ), 
             cmp ) );
     
+    iMediaIdUtil = &RMediaIdUtil::GetInstanceL();
     }
 
 
@@ -835,6 +837,7 @@
         }
     else if( mapping->iHandler.iLibrary == TVideoMetadataHandling::EMp4LibHandling )
         {
+#ifdef MDS_MP4LIB_USAGE
         MP4Handle handle( 0 );
         MP4Err mp4err = MP4_OK;
         
@@ -924,6 +927,7 @@
             {
             WRITELOG( "CHarvesterVideoPlugin - Error closing file handle" );
             }
+#endif
         }
     WRITELOG( "CHarvesterVideoPlugin - Closing file" );        
     CleanupStack::PopAndDestroy( &file );        
@@ -948,6 +952,8 @@
     	{
     	CMdEObjectDef& objectDef = mdeObject.Def();
     	iPropDefs = CHarvesterVideoPluginPropertyDefs::NewL( objectDef );
+    	// Prefetch max text lengt for validity checking
+    	iMaxTextLength = iPropDefs->iCopyrightPropertyDef->MaxTextLengthL();
     	}
 
     TTimeIntervalSeconds timeOffsetSeconds = User::UTCOffset();
@@ -1047,31 +1053,31 @@
     	}
 
     // Copyright
-    if( aVHD.iCopyright )
+    if( aVHD.iCopyright && aVHD.iCopyright->Length() < iMaxTextLength )
     	{
     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iCopyrightPropertyDef, aVHD.iCopyright, aIsAdd );
     	}
 
     // Author
-    if( aVHD.iAuthor )
+    if( aVHD.iAuthor && aVHD.iAuthor->Length() < iMaxTextLength )
     	{
     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iAuthorPropertyDef, aVHD.iAuthor, aIsAdd );
     	}
 
     // Genre
-    if( aVHD.iGenre )
+    if( aVHD.iGenre && aVHD.iGenre->Length() < iMaxTextLength )
     	{
     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iGenrePropertyDef, aVHD.iGenre, aIsAdd );
     	}
 
     // Artist
-    if( aVHD.iPerformer )
+    if( aVHD.iPerformer && aVHD.iPerformer->Length() < iMaxTextLength )
     	{
     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iArtistPropertyDef, aVHD.iPerformer, aIsAdd );
     	}
 
     // Description
-    if( aVHD.iDescription )
+    if( aVHD.iDescription && aVHD.iDescription->Length() < iMaxTextLength )
     	{
     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iDescriptionPropertyDef, aVHD.iDescription, aIsAdd );
     	}
@@ -1083,7 +1089,7 @@
         }
     
     // Title
-    if( aVHD.iTitle )
+    if( aVHD.iTitle && aVHD.iTitle->Length() < iMaxTextLength )
         {
         CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iTitlePropertyDef, aVHD.iTitle, EFalse );
         }
@@ -1095,8 +1101,9 @@
         }
     }
 
+#ifdef MDS_MP4LIB_USAGE 
 void CHarvesterVideoPlugin::GetMp4Type( RFile64& aFile, TDes& aType )
-	{
+    {
     WRITELOG( "CHarvesterVideoPlugin::GetMp4Mime - MP4ParseOpenFileHandle - start" );
     MP4Handle handle;
 
@@ -1135,6 +1142,11 @@
 
     MP4ParseClose( handle );
 	}
+#else
+void CHarvesterVideoPlugin::GetMp4Type( RFile64& /*aFile*/, TDes& /*aType*/ )
+    {
+    }
+#endif
 
 void CHarvesterVideoPlugin::GetRmTypeL( RFile64& aFile, TDes& aType )
 	{
@@ -1143,6 +1155,29 @@
 	CHXMetaDataUtility* helixMetadata = CHXMetaDataUtility::NewL();
 	CleanupStack::PushL( helixMetadata );
 
+	TFileName tempName;
+	TUint32 mediaId( 0 );
+	TInt blackListError( KErrNone );
+	
+    if( iBlacklist )
+        {
+        WRITELOG( "CHarvesterVideoPlugin::GetRmTypeL - Adding URI to blacklist" );
+        blackListError = aFile.FullName( tempName );
+        if( blackListError == KErrNone )
+            {
+            blackListError = iMediaIdUtil->GetMediaId( tempName, mediaId );
+            if( blackListError == KErrNone )
+                {
+                TTime modified ( 0 );
+                blackListError = iFs.Modified( tempName, modified );
+                if( blackListError == KErrNone )
+                    {
+                    iBlacklist->AddFile( tempName, mediaId, modified );
+                    }
+                }
+            }
+        }
+	
 	TRAPD( err, helixMetadata->OpenFileL( aFile ) );
 
 	if( err == KErrNone )
@@ -1226,6 +1261,12 @@
 		{
 		aType.Copy( KVideo );
 		}
+	
+    if ( iBlacklist && blackListError == KErrNone )
+        {
+        WRITELOG( "CHarvesterVideoPlugin::GetRmTypeL - Removing URI from blacklist" );
+        iBlacklist->RemoveFile( tempName, mediaId );
+        }
     
 	helixMetadata->ResetL();
     CleanupStack::PopAndDestroy( helixMetadata );
--- a/harvester/harvesterplugins/WMVPlugin/inc/harvesterwmvplugin.h	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/harvesterplugins/WMVPlugin/inc/harvesterwmvplugin.h	Mon May 03 12:55:01 2010 +0300
@@ -182,6 +182,8 @@
 
 private: // data
 	CHarvesterWmvPluginPropertyDefs* iPropDefs;
+	
+	TInt iMaxTextLength;
     };
 
 #endif // C_HARVESTERWMVPLUGIN_H
--- a/harvester/harvesterplugins/WMVPlugin/src/harvesterwmvplugin.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/harvesterplugins/WMVPlugin/src/harvesterwmvplugin.cpp	Mon May 03 12:55:01 2010 +0300
@@ -281,6 +281,8 @@
 		{
 		CMdEObjectDef& objectDef = mdeObject.Def();
 		iPropDefs = CHarvesterWmvPluginPropertyDefs::NewL( objectDef );
+		// Prefetch max text lengt for validity checking
+		iMaxTextLength = iPropDefs->iGenrePropertyDef->MaxTextLengthL();
 		}
     
     if( ! mdeObject.Placeholder() )
@@ -308,25 +310,25 @@
                 *iPropDefs->iDrmPropertyDef, &aClipDetails.iDrmProtected, aIsAdd );
         } 
     // Title (is set from URI by default)
-    if(aClipDetails.iTitle.Length() > 0)
+    if( aClipDetails.iTitle.Length() > 0 && aClipDetails.iTitle.Length() < iMaxTextLength )
         {
         CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
                 *iPropDefs->iTitlePropertyDef, &aClipDetails.iTitle, EFalse );
         }
     // Description
-    if(aClipDetails.iDescription.Length() > 0)
+    if( aClipDetails.iDescription.Length() > 0 && aClipDetails.iDescription.Length() < iMaxTextLength )
         {
         CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
                 *iPropDefs->iDescriptionPropertyDef, &aClipDetails.iDescription, aIsAdd );
         }   
     // Author
-    if(aClipDetails.iAuthor.Length() > 0)
+    if( aClipDetails.iAuthor.Length() > 0 && aClipDetails.iAuthor.Length() < iMaxTextLength )
         {
         CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
                 *iPropDefs->iAuthorPropertyDef, &aClipDetails.iAuthor, aIsAdd );
         }
     // Genre
-    if(aClipDetails.iGenre.Length() > 0)
+    if( aClipDetails.iGenre.Length() > 0 && aClipDetails.iGenre.Length() < iMaxTextLength )
         {
         CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
                 *iPropDefs->iGenrePropertyDef, &aClipDetails.iGenre, aIsAdd );
--- a/harvester/monitorplugins/fileplugin/inc/processoriginmapper.h	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/monitorplugins/fileplugin/inc/processoriginmapper.h	Mon May 03 12:55:01 2010 +0300
@@ -162,6 +162,8 @@
          */
         void WriteProcessOriginPairL( TUid& aProcessId, TOrigin& aOrigin );
 
+        static TInt Compare(const TProcessOriginPair& aFirst, const TProcessOriginPair& aSecond);
+        
     private: // data
 
         /**
--- a/harvester/monitorplugins/fileplugin/src/movetimer.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/monitorplugins/fileplugin/src/movetimer.cpp	Mon May 03 12:55:01 2010 +0300
@@ -55,11 +55,10 @@
 	TPtrC nameExt;
 	
 	if( MdsUtils::GetNameExt( aUri, nameExt ) )
-		{
-		
+		{		
 		// check if harvester queue contains harvesting request 
 		// with same file name and extension 
-		for (int i = iHDArray.Count(); --i >= 0; )
+		for (TInt i = iHDArray.Count(); --i >= 0; )
 			{
 			CHarvesterData* hd = iHDArray[i];
 			
--- a/harvester/monitorplugins/fileplugin/src/processoriginmapper.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/monitorplugins/fileplugin/src/processoriginmapper.cpp	Mon May 03 12:55:01 2010 +0300
@@ -99,7 +99,7 @@
     if ( index < 0 ) // not found
         {
         TProcessOriginPair pair = { aProcessId, aOrigin };
-        iProcessOriginMap.AppendL( pair );
+        User::LeaveIfError( iProcessOriginMap.InsertInOrder(pair, TLinearOrder<TProcessOriginPair>(CProcessOriginMapper::Compare))); 
         }
     else if ( index < iProcessOriginMap.Count() )
         {
@@ -320,12 +320,25 @@
 //
 TInt CProcessOriginMapper::FindProcess( const TUid& aProcessId )
     {
-    const TInt count = iProcessOriginMap.Count();
-    for ( TInt i( 0 ); i < count; i++ )
+    TInt low( 0 );
+    TInt high( iProcessOriginMap.Count() );
+    
+    while( low < high )
         {
-        if ( iProcessOriginMap[i].iProcessId == aProcessId )
+        TInt mid( (low+high)>>1 );
+        
+        const TInt compare( aProcessId.iUid - iProcessOriginMap[mid].iProcessId.iUid );
+        if( compare == 0 )
             {
-            return i;
+            return mid;
+            }
+        else if( compare > 0 )
+            {
+            low = mid + 1;
+            }
+        else
+            {
+            high = mid;
             }
         }
 
@@ -419,3 +432,8 @@
     iWriteStream.WriteL( KLineFeed );
     }
 
+TInt CProcessOriginMapper::Compare(const TProcessOriginPair& aFirst, const TProcessOriginPair& aSecond)
+    {
+    return aFirst.iProcessId.iUid - aSecond.iProcessId.iUid;
+    }
+
--- a/harvester/monitorplugins/mdsfileserverplugin/inc/mdsfileserverplugin.h	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/monitorplugins/mdsfileserverplugin/inc/mdsfileserverplugin.h	Mon May 03 12:55:01 2010 +0300
@@ -134,6 +134,8 @@
         void PrintDebugEvents( TInt aFunction );
 #endif
     	
+        static TInt Compare(const TDesC& aFirst, const TDesC& aSecond);
+        
     private:
 
         CFsPluginConnRequest* iNotification;
--- a/harvester/monitorplugins/mdsfileserverplugin/src/mdsfileserverplugin.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/monitorplugins/mdsfileserverplugin/src/mdsfileserverplugin.cpp	Mon May 03 12:55:01 2010 +0300
@@ -25,7 +25,7 @@
 /* Server name */
 _LIT( KHarvesterServerName, "HarvesterServer" );
 
-const TInt KCleanQueueTreshoald( 1000 );
+const TInt KCleanQueueTreshold( 1000 );
 
 //-----------------------------------------------------------------------------
 // CMdsFileServerPlugin implementation
@@ -753,7 +753,7 @@
 TInt CMdsFileServerPlugin::AddNotificationPath( const CFsPluginConnRequest& aRequest )
     {
     WRITELOG( "CMdsFileServerPlugin::AddNotificationPath()" );
-    TInt err = KErrNone;
+    TInt err( KErrNone );
     
     TMdsFSPStatusPckg pckg;
     TRAP( err, aRequest.ReadParam1L(pckg) );
@@ -767,22 +767,20 @@
     
     if ( status.iFileName.Length() > 0 )
         {
-        // check if already exists
-        const TInt count( iPaths.Count() );
-        for ( TInt i = count; --i >= 0; )
+        // check if already exist
+        const TInt ret = iPaths.FindInOrder(&status.iFileName,
+                                     TLinearOrder<TDesC>(CMdsFileServerPlugin::Compare));
+
+        if( ret >= 0 )
             {
-            TDesC* tf = iPaths[i];
-            if ( MdsUtils::Compare( status.iFileName, *tf ) == 0 )
-                {
-                return KErrNone;
-                }
-            }
+            return KErrNone;
+            }     
 
         WRITELOG1( "CMdsFileServerPlugin::AddNotificationPath() - add path: %S", &status.iFileName );
         HBufC* fn = status.iFileName.Alloc();
         if ( fn )
             {
-            iPaths.Append( fn );
+            iPaths.InsertInOrder(fn, TLinearOrder<TDesC>(CMdsFileServerPlugin::Compare)); 
             }
         else
             {
@@ -804,7 +802,7 @@
 TInt CMdsFileServerPlugin::RemoveNotificationPath( const CFsPluginConnRequest& aRequest )
     {
     WRITELOG( "CMdsFileServerPlugin::RemoveNotificationPath()" );
-    TInt err = KErrNone;
+    TInt err( KErrNone );
     
     TMdsFSPStatusPckg pckg;
     TRAP( err, aRequest.ReadParam1L(pckg) );
@@ -818,17 +816,16 @@
     
     if ( status.iFileName.Length() > 0 )
         {
-        for ( TInt i = iPaths.Count(); --i >= 0; )
+        const TInt ret = iPaths.FindInOrder(&status.iFileName,
+                                     TLinearOrder<TDesC>(CMdsFileServerPlugin::Compare));
+
+        if( ret >= 0 )
             {
-            TDesC* tf = iPaths[i];
-            if ( MdsUtils::Compare( status.iFileName, *tf ) == 0 )
-                {
-                WRITELOG1( "CMdsFileServerPlugin::RemoveNotificationPath() - remove path: %S", &status.iFileName );
-                delete tf;
-                tf = NULL;
-                iPaths.Remove( i );
-                }
-            }
+            WRITELOG1( "CMdsFileServerPlugin::RemoveNotificationPath() - remove path: %S", &status.iFileName );
+            delete iPaths[ret];
+            iPaths[ret] = NULL;
+            iPaths.Remove( ret );
+            }    
         iPaths.Compress();
         }
     else
@@ -846,7 +843,7 @@
 TInt CMdsFileServerPlugin::AddIgnorePath( const CFsPluginConnRequest& aRequest )
     {
     WRITELOG( "CMdsFileServerPlugin::AddIgnorePath()" );
-    TInt err = KErrNone;
+    TInt err( KErrNone );
     
     TMdsFSPStatusPckg pckg;
     TRAP( err, aRequest.ReadParam1L(pckg) );
@@ -861,20 +858,19 @@
     if ( status.iFileName.Length() > 0 )
         {
         // check if already exist
-        for ( TInt i = iIgnorePaths.Count(); --i >= 0; )
+        const TInt ret = iIgnorePaths.FindInOrder(&status.iFileName,
+                                     TLinearOrder<TDesC>(CMdsFileServerPlugin::Compare));
+    
+        if( ret >= 0 )
             {
-            TDesC* tf = iIgnorePaths[i];
-            if ( MdsUtils::Compare( status.iFileName, *tf ) == 0 )
-                {
-                return KErrNone;
-                }
+            return KErrNone;
             }
             
         WRITELOG1( "CMdsFileServerPlugin::AddIgnorePath() - add path: %S", &status.iFileName );
         HBufC* fn = status.iFileName.Alloc();
         if ( fn )
             {
-            iIgnorePaths.Append( fn ); // ownership is transferred
+            iIgnorePaths.InsertInOrder(fn, TLinearOrder<TDesC>(CMdsFileServerPlugin::Compare)); 
             }
         else
             {
@@ -896,7 +892,7 @@
 TInt CMdsFileServerPlugin::RemoveIgnorePath( const CFsPluginConnRequest& aRequest )
     {
     WRITELOG( "CMdsFileServerPlugin::RemoveIgnorePath()" );
-    TInt err = KErrNone;
+    TInt err( KErrNone );
     
     TMdsFSPStatusPckg pckg;
     TRAP( err, aRequest.ReadParam1L(pckg) );
@@ -910,18 +906,16 @@
     
     if ( status.iFileName.Length() > 0 )
         {
-        // check if already exist
-        for ( TInt i = iIgnorePaths.Count(); --i >= 0; )
+        const TInt ret = iIgnorePaths.FindInOrder(&status.iFileName,
+                                     TLinearOrder<TDesC>(CMdsFileServerPlugin::Compare));
+
+        if( ret >= 0 )
             {
-            TDesC* tf = iIgnorePaths[i];
-            if ( MdsUtils::Compare(status.iFileName, *tf ) == 0 )
-                {
-                WRITELOG1( "CMdsFileServerPlugin::RemoveIgnorePath() - remove path: %S", &status.iFileName );
-                delete tf;
-                tf = NULL;
-                iIgnorePaths.Remove( i );
-                }
-            }
+            WRITELOG1( "CMdsFileServerPlugin::RemoveIgnorePath() - remove path: %S", &status.iFileName );
+            delete iIgnorePaths[ret];
+            iIgnorePaths[ret] = NULL;
+            iIgnorePaths.Remove( ret );
+            }    
         iIgnorePaths.Compress();
         }
     else
@@ -938,8 +932,15 @@
 //
 TBool CMdsFileServerPlugin::CheckPath( const TDesC& aFilename ) const
     {
-    // check if ignored pathlist
-    for ( TInt i = iIgnorePaths.Count(); --i >= 0; )
+    // check if ignored pathlist   
+#ifdef __WINSCW__
+    // start checking from beginning of list as if the path is ignored, there
+    // is higher possibility that it is located on beginning side of the list
+    const TInt count( iIgnorePaths.Count() );
+    for ( TInt i = 0; i < count; i++ )   
+#else    
+    for ( TInt i = iIgnorePaths.Count(); --i >= 0; )    
+#endif
         {    
         TDesC* pathName = iIgnorePaths[i];
         if ( MdsUtils::Find( aFilename, *pathName ) != KErrNotFound )
@@ -951,7 +952,14 @@
     // check if notification path
     if ( iPaths.Count() > 0 )
         {
+#ifdef __WINSCW__
+        // start checking from beginning of list as if the path is supported, there
+        // is higher possibility that it is located on beginning side of the list
+        const TInt count( iPaths.Count() );
+        for ( TInt i = 0; i < count; i++ )   
+#else            
         for ( TInt i = iPaths.Count(); --i >= 0; )
+#endif
             {
             TDesC* pathName = iPaths[i];
             if ( MdsUtils::Find( aFilename, *pathName ) != KErrNotFound )
@@ -1042,7 +1050,7 @@
     {
     WRITELOG( "CMdsFileServerPlugin::CheckHarvesterStatus() - begin" );
 
-    if( iPendingEvents <= KCleanQueueTreshoald )
+    if( iPendingEvents <= KCleanQueueTreshold )
         {
         WRITELOG( "CMdsFileServerPlugin::CheckHarvesterStatus() - end" );
         return ETrue;
@@ -1287,3 +1295,9 @@
         }
     }
 #endif
+
+TInt CMdsFileServerPlugin::Compare(const TDesC& aFirst, const TDesC& aSecond)
+    {
+    return aFirst.CompareF( aSecond );
+    }
+
--- a/harvester/monitorplugins/messageplugin/group/bld.inf	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/monitorplugins/messageplugin/group/bld.inf	Mon May 03 12:55:01 2010 +0300
@@ -22,7 +22,7 @@
 PRJ_EXPORTS
 
 PRJ_MMPFILES
-//messagemonitorplugin.mmp
+messagemonitorplugin.mmp
 
 PRJ_TESTMMPFILES
 
--- a/harvester/monitorplugins/mmcplugin/src/mmcfilelist.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/monitorplugins/mmcplugin/src/mmcfilelist.cpp	Mon May 03 12:55:01 2010 +0300
@@ -31,6 +31,9 @@
 #include <harvesterdata.h>
 #include "harvesterpluginfactory.h"
 
+// for CleanupResetAndDestroyPushL
+#include <mmf/common/mmfcontrollerpluginresolver.h>
+
 _LIT( KBackslash, "\\");
 
 const TInt KEntryBufferSize = 100;
@@ -87,6 +90,9 @@
 		RPointerArray<CPlaceholderData>& aEntryArray )
 	{
 	WRITELOG( "CMmcFileList::BuildFileListL - start" );
+	
+	CleanupResetAndDestroyPushL( aEntryArray );
+	
 	CDesCArrayFlat* path = new(ELeave) CDesCArrayFlat( 10 );
 	CleanupStack::PushL( path );
 	TFileName firstPath;
@@ -180,6 +186,8 @@
 	
 	CleanupStack::PopAndDestroy( path );
 	
+	CleanupStack::Pop( &aEntryArray );
+	
 	WRITELOG( "CMmcFileList::BuildFileListL - end" );
 	}
 
--- a/harvester/server/inc/harvesterao.h	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/server/inc/harvesterao.h	Mon May 03 12:55:01 2010 +0300
@@ -299,6 +299,8 @@
          * From MHarvesterOomObserver
          */
         void MemoryGood();
+        
+        void RemoveBlacklistedFile( CHarvesterData* aItem );
 		
     private:
         
--- a/harvester/server/inc/harvesterqueue.h	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/server/inc/harvesterqueue.h	Mon May 03 12:55:01 2010 +0300
@@ -19,6 +19,7 @@
 
 #include <monitorplugin.h>
 #include "harvestermediaidutil.h"
+#include "harvestereventmanager.h"
 
 // FORWARD DECLARATION
 class CHarvesterAO;
@@ -118,6 +119,8 @@
         
         // not own
         CHarvesterMediaIdUtil* iMediaIdUtil;
+        
+        CHarvesterEventManager* iHEM;
     };
 
 #endif
--- a/harvester/server/src/harvesterao.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/server/src/harvesterao.cpp	Mon May 03 12:55:01 2010 +0300
@@ -232,12 +232,9 @@
     CActiveScheduler::Add( this );
 
 	User::LeaveIfError( iFs.Connect() );
-
+	
     // Setting up MdE Session
 	iMdESession = CMdESession::NewL( *this );
- 	
-    // Setting up context Engine (initialization is ready when ContextInitializationStatus -callback is called)
-    iCtxEngine = CContextEngine::GetInstanceL( this ); // Create the context engine
 
     iBackupSubscriber = CBackupSubscriber::NewL( *this );
 	
@@ -265,6 +262,9 @@
     iHarvesterPluginFactory = CHarvesterPluginFactory::NewL();
     iHarvesterPluginFactory->SetBlacklist( *iBlacklist );
     
+    // Reset harvesting status for clients in case blacklisted file was handled
+    iHarvesterPluginFactory->SendHarvestingStatusEventL( EFalse );
+    
     iCameraExtensionArray = new ( ELeave ) CDesCArraySeg( 6 );
     iCameraExtensionArray->InsertIsqL( KExtensionMp4 );
     iCameraExtensionArray->InsertIsqL( KExtensionMpg4 );
@@ -526,8 +526,6 @@
         TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeMMC, removed ) );
 	    }
 	
-	iMediaIdUtil->RemoveMediaId( aMediaId );
-	
 	removed = 0;
 	
 	RPointerArray<CHarvesterPluginInfo>& hpiArray = iHarvesterPluginFactory->GetPluginInfos();
@@ -573,6 +571,8 @@
 		    }
 		}
 	
+    iMediaIdUtil->RemoveMediaId( aMediaId );
+	
 	// resume harvesting from last state
     if( !iRamFull && !iDiskFull )
         {
@@ -821,6 +821,7 @@
 		CMdEObjectDef& mdeObjectDef = defNS.GetObjectDefL( objDefStr );
 
 		CMdEObject* mdeObject = iMdESession->NewObjectL( mdeObjectDef, hd->Uri() );
+		CleanupStack::PushL( mdeObject );
 		
 		CPlaceholderData* phData = NULL;
 
@@ -956,9 +957,12 @@
 		
 		hd->SetMdeObject( mdeObject );
 		
-		mdeObjectArray.Append( mdeObject );
+		// Ownership of mdeObject transferred to the array
+		mdeObjectArray.AppendL( mdeObject );
 		
 	    CleanupStack::PopAndDestroy( phData );
+	    
+	    CleanupStack::Pop( mdeObject );
 		
 		iReadyPHArray.Append( hd );
 		iPHArray.Remove( i );
@@ -1259,6 +1263,7 @@
 void CHarvesterAO::HandleSessionOpened( CMdESession& aSession, TInt aError )
     {
     WRITELOG( "HarvesterThread::HandleSessionOpened()" );
+    
     if ( KErrNone == aError )
         {
         TBool isTNMDaemonEnabled( EFalse );
@@ -1279,6 +1284,13 @@
             WRITELOG( "CHarvesterAO::HandleSessionOpened() - error creating mde harvester session" );
         	}
 
+        // Setting up context Engine (initialization is ready when ContextInitializationStatus -callback is called)
+        TRAP( errorTrap, iCtxEngine = CContextEngine::GetInstanceL( this ) ); // Create the context engine 
+        if ( errorTrap != KErrNone )
+                {
+                WRITELOG( "CHarvesterAO::HandleSessionOpened() - Context Engine creation failed" );
+                }
+        
 #ifdef _DEBUG        
         TRAP( errorTrap, iMdeObjectHandler = CMdeObjectHandler::NewL( *iMdESession ) );
         if ( errorTrap != KErrNone )
@@ -1314,11 +1326,6 @@
         TRAP_IGNORE( StartComposersL() );        
 #endif
 
-        if ( iContextEngineInitialized )
-            {
-            iCtxEngine->SetMdeSession( iMdESession );
-            }
-
             // Starting monitor plugins
         StartMonitoring();
 
@@ -1413,7 +1420,7 @@
 // ---------------------------------------------------------------------------
 //
 void CHarvesterAO::HandleSessionError( CMdESession& /*aSession*/, TInt aError )
-    {    
+    {       
     if ( KErrNone != aError )
         {
         WRITELOG1( "HarvesterThread::HandleSessionError() - Error: %d!", aError );        
@@ -2823,3 +2830,11 @@
     return EFalse;
     }
 
+void CHarvesterAO::RemoveBlacklistedFile( CHarvesterData* aItem )
+    {
+    if( iMdeSessionInitialized )
+        {
+        TRAP_IGNORE( iMdESession->RemoveObjectL( aItem->Uri() ) );
+        }
+    }
+
--- a/harvester/server/src/harvesterqueue.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/server/src/harvesterqueue.cpp	Mon May 03 12:55:01 2010 +0300
@@ -75,6 +75,11 @@
     iItemQueue.Close();
     iFs.Close();
     RMediaIdUtil::ReleaseInstance();
+    
+    if (iHEM)
+        {
+        iHEM->ReleaseInstance();
+        }
     }
 
 // ---------------------------------------------------------------------------
@@ -86,6 +91,7 @@
     WRITELOG( "CHarvesterQueue::ConstructL()" );
     User::LeaveIfError( iFs.Connect() );
 	iMediaIdUtil = &RMediaIdUtil::GetInstanceL();
+    iHEM = CHarvesterEventManager::GetInstanceL();
     }
 
 // ---------------------------------------------------------------------------
@@ -148,6 +154,13 @@
         		aItem->Uri(), mediaId, time ) )
             {
             WRITELOG( "CHarvesterQueue::Append() - found a blacklisted file" );
+            TRAP_IGNORE( iHEM->DecreaseItemCountL( EHEObserverTypePlaceholder ) );
+            TRAP_IGNORE( iHEM->DecreaseItemCountL( EHEObserverTypeMMC ) );
+            if( aItem->EventType() == EHarvesterEdit )
+                {
+                // Remove possible placeholder items from DB if file was blacklisted during harvesting
+                iHarvesterAO->RemoveBlacklistedFile( aItem );
+                }
             delete aItem;
             aItem = NULL;
             return;
--- a/harvester/server/src/mdeobjecthandler.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/server/src/mdeobjecthandler.cpp	Mon May 03 12:55:01 2010 +0300
@@ -187,7 +187,7 @@
                 if( error != KErrNone )
                     {
 #ifdef _DEBUG
-                    if( error == KErrInUse || error || KErrLocked )
+                    if( error == KErrInUse || error == KErrLocked )
                         {
                         TPtrC fileName( aHD.Uri().Mid(2) );
                         WRITELOG1( "CMdeObjectHandler :: Checking open file handles to %S", &fileName );
--- a/harvester/server/src/reharvesterao.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/harvester/server/src/reharvesterao.cpp	Mon May 03 12:55:01 2010 +0300
@@ -199,7 +199,7 @@
     for( TInt i = iItems.Count(); --i >= 0; )
         {
         CHarvesterData* item = iItems[i];
-        if ( aItem.Uri().CompareC( item->Uri(), 1, NULL ) != 0 )
+        if ( aItem.Uri().CompareF( item->Uri() ) != 0 )
             {
             continue;
             }
--- a/inc/mdscommoninternal.h	Fri Apr 16 15:23:55 2010 +0300
+++ b/inc/mdscommoninternal.h	Mon May 03 12:55:01 2010 +0300
@@ -47,6 +47,7 @@
 const TInt KMaxUint64ValueLength = 20;
 
 _LIT( KMdSServerName,"MdSServer" ); // Server name
+_LIT( KMdSServerProcessString,"MdSServer*" ); 
 _LIT( KSchemaChunkName, "MdSSchema" );
 
 _LIT( KCMediaIdKey, "CDriveMediaId" );
--- a/locationmanager/client/src/rlocationmanager.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/locationmanager/client/src/rlocationmanager.cpp	Mon May 03 12:55:01 2010 +0300
@@ -32,12 +32,10 @@
 TInt LaunchServer()
     {
     LOG( "RLocationManager::LaunchServer begin" );
-    TParse parser;
-    parser.Set( KLocServerFileName, &KDC_PROGRAMS_DIR, NULL );
 
     // DLL launch
     RProcess server;
-    const TInt ret = server.Create( parser.FullName(), KNullDesC );
+    TInt ret = server.Create( KLocServerFileName, KNullDesC );
 
     if ( ret != KErrNone )  // Loading failed.
         {
@@ -51,18 +49,20 @@
         {
         LOG( "RLocationManager::LaunchServer Failed" );
         server.Kill( 0 );     // Abort startup.
-        server.Close();
-        return KErrGeneral;
         }
     else
         {
         server.Resume();    // Logon OK - start the server.
         }
         
-    User::WaitForRequest( status );
+    User::WaitForRequest( status ); // wait for start or death
+    // we can't use the 'exit reason' if the server panicked as this
+    // is the panic 'reason' and may be '0' wehich cannot be distinguished
+    // from KErrNone
+    ret = ( server.ExitType() == EExitPanic ) ? KErrCommsBreak : status.Int();
     server.Close();
     LOG( "RLocationManager::LaunchServer end" );
-    return status.Int();    
+    return ret;    
     }
 
 // --------------------------------------------------------------------------
@@ -82,17 +82,17 @@
 EXPORT_C TInt RLocationManager::Connect()
     {
     LOG( "RLocationManager::Connect(), begin" );
-    TInt ret = CreateSession( KLocServerName, Version(), KSessionSlotCount);
-    if ( ret != KErrNone )
+      
+    TInt error = LaunchServer();
+
+    if ( error == KErrNone || error == KErrAlreadyExists )
         {
-        ret = LaunchServer();
-        if ( ret == KErrNone )
-            {
-            ret = CreateSession( KLocServerName, Version() );    
-            }       
+        error = CreateSession( KLocServerName, Version(), KSessionSlotCount );
         }
+    
     LOG( "RLocationManager::Connect(), end" );
-    return ret;
+
+    return error;
     }
     
 // --------------------------------------------------------------------------
--- a/locationmanager/server/src/clocationmanagerserver.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/locationmanager/server/src/clocationmanagerserver.cpp	Mon May 03 12:55:01 2010 +0300
@@ -155,6 +155,14 @@
         iLocManStopRemapDelay = KLocationTrailRemapShutdownDelay;
         }
     
+    TRAPD( error, iTimer = CPeriodic::NewL( CActive::EPriorityUserInput ) );    
+    if ( error != KErrNone )
+        {
+        LOG("CLocationManagerServer::ConstructL - iTimer not created");
+        iTimer = NULL;
+        }  
+    
+    
     LOG ("CLocationManagerServer::ConstructL() end");
     }
 
@@ -326,8 +334,7 @@
     
     if ( iTimer )
     	{
-    	delete iTimer;
-    	iTimer = NULL;
+    	iTimer->Cancel();
     	}
     
     iLocationRecord->StartL( aCaptureSetting );
@@ -348,19 +355,26 @@
      
     if( state != RLocationTrail::ETrailStopped && state != RLocationTrail::ETrailStopping )
         {
-        TRAPD( error, iTimer = CPeriodic::NewL( CActive::EPriorityUserInput ) );
-        
-        if ( error != KErrNone )
+        if(!iTimer)
             {
-            // If timer can't be created we stop the location trail immediately.
+            TRAPD( error, iTimer = CPeriodic::NewL( CActive::EPriorityUserInput ) );    
+            if ( error != KErrNone )
+                {
+                LOG("CLocationManagerServer::StopGPSPositioningL() - iTimer not created");
+                iTimer = NULL;
+                }
+            }        
+        if(iTimer)
+            {
+			iTimer->Cancel();
+            iLocationRecord->SetStateToStopping();
+            iTimer->Start( iLocManStopDelay * 1000000, 0, TCallBack( CheckForRemappingCallback, this ) );
+            }
+        else
+            {
             iLocationRecord->Stop();
-            StopTrackLogL();
-            return;
-            }   
-        
-        iLocationRecord->SetStateToStopping();
-        iTimer->Start( iLocManStopDelay * 1000000, 0, TCallBack( CheckForRemappingCallback, this ) );
-    	}
+            }
+        }
     
     // Always stop tracklog.
     StopTrackLogL();
@@ -375,8 +389,11 @@
     LOG( "CLocationManagerServer::StopRecording()" );    
     iWaitForPositioningStopTimeout = EFalse;
     iLocationRecord->Stop();		
-	delete iTimer;
-	iTimer = NULL;
+	if(iTimer)
+	    {
+        iTimer->Cancel();
+	    }
+	
 	}
 
 // --------------------------------------------------------------------------
--- a/mds_plat/harvester_framework_api/tsrc/HarvesterClientTest/conf/HarvesterClientTestScripter.cfg	Fri Apr 16 15:23:55 2010 +0300
+++ b/mds_plat/harvester_framework_api/tsrc/HarvesterClientTest/conf/HarvesterClientTestScripter.cfg	Mon May 03 12:55:01 2010 +0300
@@ -93,7 +93,7 @@
 
 [Test]
 title HarvestFile 1
-timeout 180000
+timeout 500000
 create HarvesterClientTestScripter test
 request Session
 test SetUp
@@ -122,7 +122,7 @@
 
 [Test]
 title HarvestFile 2
-timeout 300000
+timeout 500000
 create HarvesterClientTestScripter test
 request Session
 test SetUp
@@ -151,7 +151,7 @@
 
 [Test]
 title HarvestFile 3
-timeout 180000
+timeout 500000
 create HarvesterClientTestScripter test
 request Session
 test SetUp
@@ -180,7 +180,7 @@
 
 [Test]
 title HarvestFile 4
-timeout 200000
+timeout 500000
 create HarvesterClientTestScripter test
 request Session
 test SetUp
@@ -210,7 +210,7 @@
 
 [Test]
 title HarvestFile 5
-timeout 180000
+timeout 500000
 create HarvesterClientTestScripter test
 request Session
 test SetUp
@@ -239,7 +239,7 @@
 
 [Test]
 title HarvestFile 6
-timeout 180000
+timeout 500000
 create HarvesterClientTestScripter test
 request Session
 test SetUp
@@ -268,7 +268,7 @@
 
 [Test]
 title HarvestFileWithUID 1
-timeout 180000
+timeout 500000
 create HarvesterClientTestScripter test
 request Session
 test SetUp
@@ -298,7 +298,7 @@
 
 [Test]
 title HarvestFileWithUID 2
-timeout 180000
+timeout 500000
 create HarvesterClientTestScripter test
 request Session
 test SetUp
@@ -365,3 +365,48 @@
 delete test
 [Endtest]
 
+[Test]
+title Harvester Client Long Session
+timeout 500000
+create HarvesterClientTestScripter test
+request Session
+test SetUp
+wait Session
+test HarvesterClientConnect
+test SetHarvesterObserver
+test AddHarvesterEventObserver 1
+test AddObjectObserver
+test SetUpHarvesting e:\testing\data\GIF87testimage.gif
+request Continue
+test HarvestFile e:\testing\data\GIF87testimage.gif
+wait Continue
+test EndHarvesterSession
+test HarvesterClientPause
+test HarvesterClientResume
+request Query
+test QueryImageObjectByIdIndex 0
+wait Query
+test RemoveObject e:\testing\data\GIF87testimage.gif
+test Results
+test SetUpHarvesting e:\testing\data\bmp_burst.bmp
+test SetUpHarvesting e:\testing\data\MBMtestimage.mbm
+test HarvestFile e:\testing\data\bmp_burst.bmp
+test HarvestFile e:\testing\data\MBMtestimage.mbm
+test HarvestFileWithUID e:\testing\data\00001.mp3
+test EndHarvesterSession
+test RemoveObject e:\testing\data\bmp_burst.bmp
+test RemoveObject e:\testing\data\G4.TIF
+test RemoveObject e:\testing\data\PNGtestimage.png
+test RemoveObject e:\testing\data\GIF87testimage.gif
+test RemoveObject e:\testing\data\ota_bmpiso.ota
+test RemoveObject e:\testing\data\MBMtestimage.mbm
+test RemoveObject e:\testing\data\Liverpool.jpg
+test RemoveObject e:\testing\data\00001.mp3
+test RemoveHarvesterEventObserver 1
+test RemoveHarvesterObserver
+test RemoveObjectObserver
+test HarvesterClientClose
+test TearDown
+delete test
+[Endtest]
+
--- a/mds_plat/harvester_framework_api/tsrc/HarvesterPluginTest/conf/HarvesterPluginTest.cfg	Fri Apr 16 15:23:55 2010 +0300
+++ b/mds_plat/harvester_framework_api/tsrc/HarvesterPluginTest/conf/HarvesterPluginTest.cfg	Mon May 03 12:55:01 2010 +0300
@@ -34,21 +34,13 @@
 test BeginTestSession
 wait Session
 test LoadPlugins
-request Harvest
 test TestFunctions e:\testing\data\Jpg.jpg
-wait Harvest
 test TestFunctions e:\testing\data\Animated.gif
-wait Harvest
 test TestFunctions e:\testing\data\Mbm.mbm
-wait Harvest
 test TestFunctions e:\testing\data\H263.3gp
-wait Harvest
 test TestFunctions e:\testing\data\MPEG4.3gp
-wait Harvest
 test TestFunctions e:\testing\data\MPEG4.mp4
-wait Harvest
 test TestFunctions e:\testing\data\00001.mp3
-wait Harvest
 test EndTestSession
 delete test
 [Endtest]
--- a/mds_plat/metadata_engine_api/tsrc/conf/MdETestScripter.cfg	Fri Apr 16 15:23:55 2010 +0300
+++ b/mds_plat/metadata_engine_api/tsrc/conf/MdETestScripter.cfg	Mon May 03 12:55:01 2010 +0300
@@ -115,6 +115,10 @@
 test RemoveObjectObserverL
 allownextresult KErrNotFound
 test RemoveObjectObserverL
+test AddObjectObserverWithUriL
+test RemoveObjectObserverWithUriL
+allownextresult KErrNotFound
+test RemoveObjectObserverWithUriL
 test AddObjectPresentObserverL
 test RemoveObjectPresentObserverL
 allownextresult KErrNotFound
@@ -1880,6 +1884,77 @@
 [Endtest]
 
 [Test]
+title Edit Object 36: AddObjectL, AddObjectsL, RemoveObjectL, UriL, SetUriL
+create MdETestScripter test
+waittestclass test
+test GetDefaultNamespaceDefL defaultNs
+
+// Create four objects.
+test GetObjectDefL videoObjDef defaultNs Video
+test NewObjectL obj0 videoObjDef KL
+test GetPropertyDefL creaDatePropDef0 videoObjDef CreationDate
+test AddTimePropertyL obj0 creaDatePropDef0 20081130:235959.999999
+test GetPropertyDefL lastModDatePropDef0 videoObjDef LastModifiedDate
+test AddTimePropertyL obj0 lastModDatePropDef0 20081130:235959.999999
+test SetGuidL EObject obj0 000007 000001
+test NewObjectL obj1 videoObjDef KL
+test GetPropertyDefL creaDatePropDef1 videoObjDef CreationDate
+test AddTimePropertyL obj1 creaDatePropDef1 20081130:235959.999999
+test GetPropertyDefL lastModDatePropDef1 videoObjDef LastModifiedDate
+test AddTimePropertyL obj1 lastModDatePropDef1 20081130:235959.999999
+test SetGuidL EObject obj1 000007 000002
+test NewObjectL obj2 videoObjDef KL
+test GetPropertyDefL creaDatePropDef2 videoObjDef CreationDate
+test AddTimePropertyL obj2 creaDatePropDef2 20081130:235959.999999
+test GetPropertyDefL lastModDatePropDef2 videoObjDef LastModifiedDate
+test AddTimePropertyL obj2 lastModDatePropDef2 20081130:235959.999999
+test SetGuidL EObject obj2 000007 000003
+test NewObjectL obj3 videoObjDef KL
+test GetPropertyDefL creaDatePropDef3 videoObjDef CreationDate
+test AddTimePropertyL obj3 creaDatePropDef3 20081130:235959.999999
+test GetPropertyDefL lastModDatePropDef3 videoObjDef LastModifiedDate
+test AddTimePropertyL obj3 lastModDatePropDef3 20081130:235959.999999
+test SetGuidL EObject obj3 000007 000004
+
+// Test objects' SetUri & Uri
+//test SetUriL obj0 e:\testing\data\TestVideo1.3gp
+//test UriL obj0 e:\testing\data\testvideo1.3gp
+//test SetUriL obj1 e:\testing\data\TestVideo2.mp4
+//test UriL obj1 e:\testing\data\testvideo2.mp4
+
+// Add the objects to the database, observe the additions and verify the observed results.
+test AddObjectObserverWithUriL
+test AddObjectL obj0
+waittestclass test
+test VerifyObserverNotificationTypeL ENotifyAdd
+test AddObjectsL obj1 3
+waittestclass test
+test VerifyObserverNotificationTypeL ENotifyAdd
+test RemoveObjectObserverWithUriL
+test VerifyTItemIdsL EObject 0 4
+
+// Remove the objects, observe the removals and verify the observed results.
+test AddObjectObserverWithUriL
+test RemoveObjectL obj0 KById
+waittestclass test
+test VerifyObserverNotificationTypeL ENotifyRemove
+test RemoveObjectL obj1 KById
+waittestclass test
+test VerifyObserverNotificationTypeL ENotifyRemove
+test RemoveObjectL obj2 KById
+waittestclass test
+test VerifyObserverNotificationTypeL ENotifyRemove
+test RemoveObjectL obj3 KById
+waittestclass test
+test VerifyObserverNotificationTypeL ENotifyRemove
+test RemoveObjectObserverWithUriL
+test VerifyTItemIdsL EObject 0 4
+
+// Final cleanup.
+delete test
+[Endtest]
+
+[Test]
 title Query 1: Object 
 create MdETestScripter test
 waittestclass test
--- a/mds_plat/metadata_engine_api/tsrc/inc/MdETestScripter.h	Fri Apr 16 15:23:55 2010 +0300
+++ b/mds_plat/metadata_engine_api/tsrc/inc/MdETestScripter.h	Mon May 03 12:55:01 2010 +0300
@@ -115,6 +115,7 @@
 NONSHARABLE_CLASS(CMdETestScripter) : public CScriptBase,
                                       public MMdESchemaObserver,
                                       public MMdEObjectObserver,
+                                      public MMdEObjectObserverWithUri,
                                       public MMdEObjectPresentObserver,
                                       public MMdERelationObserver,
                                       public MMdERelationItemObserver,
@@ -193,6 +194,8 @@
         virtual TInt RemoveSchemaObserverL( CStifItemParser& aItem );
         virtual TInt AddObjectObserverL( CStifItemParser& aItem );
         virtual TInt RemoveObjectObserverL( CStifItemParser& aItem );
+        virtual TInt AddObjectObserverWithUriL( CStifItemParser& aItem );
+        virtual TInt RemoveObjectObserverWithUriL( CStifItemParser& aItem );
         virtual TInt AddObjectPresentObserverL( CStifItemParser& aItem );
         virtual TInt RemoveObjectPresentObserverL( CStifItemParser& aItem );
         virtual TInt AddRelationObserverL( CStifItemParser& aItem );
@@ -377,6 +380,10 @@
         void HandleObjectNotification( CMdESession& aSession, 
             TObserverNotificationType aType,
             const RArray<TItemId>& aObjectIdArray );
+        void HandleUriObjectNotification(CMdESession& aSession, 
+            TObserverNotificationType aType,
+            const RArray<TItemId>& aObjectIdArray,
+            const RPointerArray<HBufC>& aObjectUriArray);
         void HandleObjectPresentNotification(CMdESession& aSession, 
             TBool aPresent, const RArray<TItemId>& aObjectIdArray);
         void HandleRelationNotification( CMdESession& aSession, 
--- a/mds_plat/metadata_engine_api/tsrc/src/MdETestScripterBlocks.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/mds_plat/metadata_engine_api/tsrc/src/MdETestScripterBlocks.cpp	Mon May 03 12:55:01 2010 +0300
@@ -188,6 +188,8 @@
         ENTRY( "RemoveSchemaObserverL", CMdETestScripter::RemoveSchemaObserverL ),
         ENTRY( "AddObjectObserverL", CMdETestScripter::AddObjectObserverL ),
         ENTRY( "RemoveObjectObserverL", CMdETestScripter::RemoveObjectObserverL ),
+        ENTRY( "AddObjectObserverWithUriL", CMdETestScripter::AddObjectObserverWithUriL ),
+        ENTRY( "RemoveObjectObserverWithUriL", CMdETestScripter::RemoveObjectObserverWithUriL ),
         ENTRY( "AddObjectPresentObserverL", CMdETestScripter::AddObjectPresentObserverL ),
         ENTRY( "RemoveObjectPresentObserverL", CMdETestScripter::RemoveObjectPresentObserverL ),
         ENTRY( "AddRelationObserverL", CMdETestScripter::AddRelationObserverL ),
@@ -421,6 +423,27 @@
     }
 
 // -----------------------------------------------------------------------------
+// CHarvesterPluginTestScripter::HandleUriObjectNotification
+// -----------------------------------------------------------------------------
+//
+void CMdETestScripter::HandleUriObjectNotification( CMdESession& aSession, 
+    TObserverNotificationType aType,
+    const RArray<TItemId>& aObjectIdArray,
+    const RPointerArray<HBufC>& /* aObjectUriArray */ )
+    {
+    iLog->Log(_L( "HandleUriObjectNotification" ));
+    
+    iNotificationSession = &aSession;
+    iNotificationType = aType;
+    for ( TInt i = 0; i < aObjectIdArray.Count(); ++i )
+        {
+        iNotificationItemIdArray.Append( aObjectIdArray[ i ] );
+        }
+
+    Signal();
+    }
+
+// -----------------------------------------------------------------------------
 // CHarvesterPluginTestScripter::HandleObjectPresentNotification
 // -----------------------------------------------------------------------------
 //
--- a/mds_plat/metadata_engine_api/tsrc/src/MdETestScripterSchemaCommands.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/mds_plat/metadata_engine_api/tsrc/src/MdETestScripterSchemaCommands.cpp	Mon May 03 12:55:01 2010 +0300
@@ -68,6 +68,28 @@
     }
 
 // -----------------------------------------------------------------------------
+// CMdETestScripter::AddObjectObserverWithUriL
+// -----------------------------------------------------------------------------
+//
+TInt CMdETestScripter::AddObjectObserverWithUriL( CStifItemParser& /* aItem */ )
+    {
+    iMdeSession->AddObjectObserverWithUriL( *this );
+
+    return KErrNone;
+    }
+
+// -----------------------------------------------------------------------------
+// CMdETestScripter::RemoveObjectObserverWithUriL
+// -----------------------------------------------------------------------------
+//
+TInt CMdETestScripter::RemoveObjectObserverWithUriL( CStifItemParser& /* aItem */ )
+    {
+    iMdeSession->RemoveObjectObserverWithUriL( *this );
+
+    return KErrNone;
+    }
+
+// -----------------------------------------------------------------------------
 // CMdETestScripter::AddObjectPresentObserverL
 // -----------------------------------------------------------------------------
 //
--- a/mds_pub/content_listing_framework_api/tsrc/conf/ContentListingFrameworkTest.cfg	Fri Apr 16 15:23:55 2010 +0300
+++ b/mds_pub/content_listing_framework_api/tsrc/conf/ContentListingFrameworkTest.cfg	Mon May 03 12:55:01 2010 +0300
@@ -82,14 +82,14 @@
 delete test
 [Endtest]
 
-[Test]
-title Engine update test
-create ContentListingFrameworkTest test
-test EngineTestSetup
-test UpdateItemsTest
-test Teardown
-delete test
-[Endtest]
+#[Test]
+#title Engine update test
+#create ContentListingFrameworkTest test
+#test EngineTestSetup
+#test UpdateItemsTest
+#test Teardown
+#delete test
+#[Endtest]
 
 #[Test]
 #title Engine update test
--- a/mds_pub/content_listing_framework_api/tsrc/src/ContentListingFrameworkTestBlocks.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/mds_pub/content_listing_framework_api/tsrc/src/ContentListingFrameworkTestBlocks.cpp	Mon May 03 12:55:01 2010 +0300
@@ -1497,7 +1497,7 @@
     CreateNewFileL( 5, iFileName );
 
 // update server
-// to aTInt incorrect test result
+// to avoid incorrect test result
     CreateNewFileL( 0, iFileName );
     iEngine->UpdateItemsL();
 
--- a/metadataengine/client/inc/mdeenginesession.h	Fri Apr 16 15:23:55 2010 +0300
+++ b/metadataengine/client/inc/mdeenginesession.h	Mon May 03 12:55:01 2010 +0300
@@ -33,10 +33,6 @@
 // 27 = 1 asynchronous find + max.25 pending notifier hooks + 1 extra
 const TUint KMetadataMessageSlots = 27;
 
-const TUid KServerUid3 = { 0x0765EEC3 }; // Server UID
-
-_LIT( KMdSServerFilename, "MdSServer" );
-
 // FORWARD DECLARATIONS
 class CMdESessionImpl;
 class CMdESchemaItem;
@@ -68,14 +64,14 @@
         * Connects to the server.
         * @return Error code.
         */
-        void OpenL(TRequestStatus& aStatus);
+        void OpenL();
         
         /**
         * Cancel server opening.
         * Cancels server opening.
         * @return Error code.
         */
-       void OpenCancel(TRequestStatus& aStatus);
+       void OpenCancel();
 
         /**
         * Connect session to server.
@@ -87,9 +83,8 @@
         /**
         * Shut down session
         * Performs session shutdown activities in server end
-        * @return Error code.
         */
-        TInt Shutdown();
+        void Shutdown();
 
         /**
         * Version.
--- a/metadataengine/client/inc/mdesessionstartupao.h	Fri Apr 16 15:23:55 2010 +0300
+++ b/metadataengine/client/inc/mdesessionstartupao.h	Mon May 03 12:55:01 2010 +0300
@@ -108,6 +108,8 @@
 
         /** the session */
         RMdEEngineSession& iSession;
+        
+        RTimer iTimer;
     };
 
 #endif //__MDESESSIONSTARTUPAO_H__
--- a/metadataengine/client/src/mdeenginesession.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/metadataengine/client/src/mdeenginesession.cpp	Mon May 03 12:55:01 2010 +0300
@@ -32,46 +32,57 @@
    	iIsSessionProcessOpen = EFalse;
     }
 
-void RMdEEngineSession::OpenL(TRequestStatus& aStatus)
+void RMdEEngineSession::OpenL()
     {
     TFindServer findMdEServer( KMdSServerName );
     TFullName name;
-
-    const TInt result = findMdEServer.Next( name );
+    
+    TInt result = findMdEServer.Next( name );
+    // Server already running
     if( result == KErrNone )
         {
-        // Server already running
-		iIsSessionProcessOpen = ETrue;
-
-		TRequestStatus* status = &aStatus;
-        User::RequestComplete( status, KErrNone );
-
-        return;
+        TFindProcess findProcess( KMdSServerProcessString );
+        result = findProcess.Next( name );
+        if ( result == KErrNone )
+            {
+            result = iServerProcess.Open( name );
+            if( result != KErrNone )
+                {
+                User::Leave( KErrNotReady );
+                }
+            iIsSessionProcessOpen = ETrue;
+            return;
+            }
+        else
+            {
+            User::Leave( KErrNotReady );
+            }
         }
 
-    User::LeaveIfError( iServerProcess.Create( KMdSServerFilename, 
-    		KNullDesC ) );
-
-	iIsSessionProcessOpen = ETrue;
-
-    iServerProcess.Rendezvous( aStatus );
-
-    if( aStatus != KRequestPending )
+    User::LeaveIfError( iServerProcess.Create( KMdSServerName, 
+    		KNullDesC ) );  
+     
+    TRequestStatus stat( 0 );
+    iServerProcess.Rendezvous( stat );
+	
+    if( stat != KRequestPending )
     	{
         iServerProcess.Kill( 0 );   // abort startup
     	}
     else
     	{
         iServerProcess.Resume();    // logon OK - start the server   
-    	}
+    	}	
+
+    User::WaitForRequest( stat ); 
+    
+    iIsSessionProcessOpen = ETrue;
     }
 
-void RMdEEngineSession::OpenCancel(TRequestStatus& aStatus)
+void RMdEEngineSession::OpenCancel()
 	{
 	if( iIsSessionProcessOpen )
 		{		
-		iServerProcess.RendezvousCancel( aStatus );
-
 		iServerProcess.Close();
 	
 		iIsSessionProcessOpen = EFalse;
@@ -82,7 +93,7 @@
     {
     if( iIsSessionProcessOpen )
     	{
-	    TBool error = (iServerProcess.ExitType() != EExitPending);
+	    const TBool error = (iServerProcess.ExitType() != EExitPending);
 
     	iServerProcess.Close();
 
@@ -109,23 +120,17 @@
     	}
     }
 
-TInt RMdEEngineSession::Shutdown()
+void RMdEEngineSession::Shutdown()
     {
-    TInt err = KErrNone;
-
     if( iIsSessionOpen )
     	{
-	    err = SendReceive( EShutdown );
+	    SendReceive( EShutdown );
     	}
 
 	if( iIsSessionProcessOpen )
 		{		
 		iServerProcess.Close();
-
-		iIsSessionProcessOpen = EFalse;
 		}
-
-    return err;
     }
 
 TVersion RMdEEngineSession::Version() const
--- a/metadataengine/client/src/mdenotifierao.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/metadataengine/client/src/mdenotifierao.cpp	Mon May 03 12:55:01 2010 +0300
@@ -126,7 +126,6 @@
 void CMdENotifierAO::DoCancel()
     {
     TRAP_IGNORE( iSession.DoUnregisterL( Id() ) );
-    // the current pending call will return with KErrCancel
     }
 
 void CMdENotifierAO::RunL()
--- a/metadataengine/client/src/mdequery.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/metadataengine/client/src/mdequery.cpp	Mon May 03 12:55:01 2010 +0300
@@ -409,10 +409,8 @@
         {
         iResults[firstNewItemIndex + i].iOwned = ETrue;
         }
-
-    const TInt observerCount = iObservers.Count();
     
-	for (i = 0; i < observerCount; i++)
+    for( TInt i = iObservers.Count() - 1; i >=0; i-- )
 		{
 		MMdEQueryObserver* observer = iObservers[i];
 		observer->HandleQueryNewResults( *this, firstNewItemIndex, newCount );
@@ -426,7 +424,6 @@
                     TMdEPanic::Panic(TMdEPanic::EInternal));
 
 	TInt firstNewItemIndex = iIdResults.Count();
-	TInt i = 0;
 
     const TInt oldCount = iIdResults.Count();
 
@@ -441,10 +438,8 @@
         // Leave with the same error.
         User::Leave(err);
         }
-
-    const TInt observerCount = iObservers.Count();
     
-	for (i = 0; i < observerCount; i++)
+    for( TInt i = iObservers.Count() - 1; i >=0; i-- )
 		{
 		MMdEQueryObserver* observer = iObservers[i];
 		observer->HandleQueryNewResults(*this, firstNewItemIndex, 
@@ -455,7 +450,6 @@
 void CMdEQuery::NotifyNewResultsL( const CDesCArray& aNewResults )
     {
 	TInt firstNewItemIndex = aNewResults.Count();
-	TInt i = 0;
 
 	TInt oldCount = 0;
 	if( iDistinctResults )
@@ -479,9 +473,7 @@
         User::Leave(err);
         }
 
-    const TInt observerCount = iObservers.Count();
-    
-	for (i = 0; i < observerCount; i++)
+    for( TInt i = iObservers.Count() - 1; i >=0; i-- )
 		{
 		MMdEQueryObserver* observer = iObservers[i];
 		observer->HandleQueryNewResults( *this, firstNewItemIndex, 
--- a/metadataengine/client/src/mdesessionimpl.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/metadataengine/client/src/mdesessionimpl.cpp	Mon May 03 12:55:01 2010 +0300
@@ -42,6 +42,9 @@
 #include "mdeobjectcondition.h"
 #include "mdscommoninternal.h"
 
+// for CleanupResetAndDestroyPushL
+#include <mmf/common/mmfcontrollerpluginresolver.h>
+
 RMdESessionAsyncRequest::RMdESessionAsyncRequest( TRequestType aRequestType, 
 	CMdCSerializationBuffer* aBuffer, CMdCSerializationBuffer& aResultBuffer,
 	TRequestStatus& aRequestStatus) : 
@@ -1840,6 +1843,8 @@
 		CMdCSerializationBuffer& aBuffer, 
 		RPointerArray<CMdEInstanceItem>& aItems )
 	{
+    CleanupResetAndDestroyPushL( aItems );
+    
 	const TMdCItems& items = TMdCItems::GetFromBufferL( aBuffer );
 
     CMdENamespaceDef& namespaceDef = GetNamespaceDefL( items.iNamespaceDefId );
@@ -1881,6 +1886,8 @@
 			CleanupStack::Pop( relation );
 			}
 		}
+	
+	CleanupStack::Pop( &aItems );
 	}
 
 TItemId CMdESessionImpl::AddObjectL( CMdEObject& aObject )
@@ -2276,8 +2283,8 @@
     CMdENotifierAO* notifier = CMdENotifierAO::NewLC( *this, iSession );
     notifier->RegisterL( type, &aObserver, aCondition, *namespaceDef );
 
+    iNotifiers.AppendL( notifier );
     CleanupStack::Pop( notifier );
-    iNotifiers.AppendL( notifier );
     
     CleanupStack::PopAndDestroy( aCondition );
     }
@@ -2303,8 +2310,8 @@
     notifier->RegisterL( EObjectNotifyPresent | EObjectNotifyNotPresent,
     		&aObserver, NULL, namespaceDef );
 
+    iNotifiers.AppendL( notifier );
     CleanupStack::Pop( notifier );
-    iNotifiers.AppendL( notifier );
 	}
 
 void CMdESessionImpl::AddRelationObserverL( MMdERelationObserver& aObserver,
@@ -2359,8 +2366,8 @@
     CMdENotifierAO* notifier = CMdENotifierAO::NewLC( *this, iSession );
     notifier->RegisterL( type, &aObserver, aCondition, *namespaceDef );
 
+    iNotifiers.AppendL( notifier );
     CleanupStack::Pop( notifier );
-    iNotifiers.AppendL( notifier );
     
     CleanupStack::PopAndDestroy( aCondition );
     }
@@ -2416,8 +2423,8 @@
 	CMdENotifierAO* notifier = CMdENotifierAO::NewLC( *this, iSession );
 	notifier->RegisterL( type, &aObserver, aCondition, *namespaceDef );
 	
+	iNotifiers.AppendL( notifier );
 	CleanupStack::Pop( notifier );
-	iNotifiers.AppendL( notifier );
 	
     CleanupStack::PopAndDestroy( aCondition );
 	}
@@ -2445,8 +2452,8 @@
     notifier->RegisterL( ERelationNotifyPresent | ERelationNotifyNotPresent,
     		&aObserver, NULL, namespaceDef );
 
+    iNotifiers.AppendL( notifier );
     CleanupStack::Pop( notifier );
-    iNotifiers.AppendL( notifier );
 	}
 
 void CMdESessionImpl::AddEventObserverL( MMdEEventObserver& aObserver,
@@ -2502,8 +2509,8 @@
     CMdENotifierAO* notifier = CMdENotifierAO::NewLC( *this, iSession );
     notifier->RegisterL( type, &aObserver, aCondition, *namespaceDef );
 
+    iNotifiers.AppendL( notifier );
     CleanupStack::Pop( notifier );
-    iNotifiers.AppendL( notifier );
     
     CleanupStack::PopAndDestroy( aCondition );
     }
@@ -2527,7 +2534,6 @@
     		&aObserver, *namespaceDef );
     if ( index != KErrNotFound )
         {
-    	iNotifiers[index]->Cancel();
     	delete iNotifiers[index];
     	iNotifiers[index] = NULL;
     	iNotifiers.Remove( index );
@@ -2549,7 +2555,6 @@
     		&aObserver, namespaceDef );
     if ( index != KErrNotFound )
         {
-    	iNotifiers[index]->Cancel();
     	delete iNotifiers[index];
     	iNotifiers[index] = NULL;
     	iNotifiers.Remove( index );
@@ -2580,7 +2585,6 @@
     		&aObserver, *namespaceDef );
     if ( index != KErrNotFound )
         {
-    	iNotifiers[index]->Cancel();
     	delete iNotifiers[index];
     	iNotifiers[index] = NULL;
     	iNotifiers.Remove( index );
@@ -2612,7 +2616,6 @@
     		&aObserver, *namespaceDef );
     if ( index != KErrNotFound )
         {
-    	iNotifiers[index]->Cancel();
     	delete iNotifiers[index];
     	iNotifiers[index] = NULL;
     	iNotifiers.Remove( index );
@@ -2634,7 +2637,6 @@
     		&aObserver, namespaceDef );
     if ( index != KErrNotFound )
         {
-    	iNotifiers[index]->Cancel();
     	delete iNotifiers[index];
     	iNotifiers[index] = NULL;
     	iNotifiers.Remove( index );
@@ -2664,7 +2666,6 @@
     		&aObserver, *namespaceDef );
     if ( index != KErrNotFound )
         {
-	    iNotifiers[index]->Cancel();
 	    delete iNotifiers[index];
 	    iNotifiers[index] = NULL;
 	    iNotifiers.Remove( index );
@@ -2891,6 +2892,8 @@
 void CMdESessionImpl::GetItemIdL( CMdCSerializationBuffer* aBuffer, 
 		RArray<TItemId>& aIdArray )
 	{
+    CleanupClosePushL( aIdArray );
+    
 	const TMdCItemIds& itemIds = TMdCItemIds::GetFromBufferL( *aBuffer );
 
 	if( itemIds.iObjectIds.iPtr.iCount > 0 ) 
@@ -2917,6 +2920,8 @@
 	    aBuffer->ReceiveL( id );
 	    aIdArray.AppendL( id );
 	    }
+	
+	CleanupStack::Pop( &aIdArray );
 	}
 
 void CMdESessionImpl::GetDistinctValuesL( CMdCSerializationBuffer& aBuffer, 
@@ -2996,8 +3001,8 @@
     CMdENotifierAO* notifier = CMdENotifierAO::NewLC( *this, iSession );
     notifier->RegisterL( type, &aObserver, aCondition, *namespaceDef );
 
+    iNotifiers.AppendL( notifier );
     CleanupStack::Pop( notifier );
-    iNotifiers.Append( notifier );
     
     CleanupStack::PopAndDestroy( aCondition );
     }
@@ -3021,7 +3026,6 @@
             &aObserver, *namespaceDef );
     if ( index != KErrNotFound )
         {
-        iNotifiers[index]->Cancel();
         delete iNotifiers[index];
         iNotifiers[index] = NULL;
         iNotifiers.Remove( index );
--- a/metadataengine/client/src/mdesessionstartupao.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/metadataengine/client/src/mdesessionstartupao.cpp	Mon May 03 12:55:01 2010 +0300
@@ -20,6 +20,9 @@
 #include "mdeenginesession.h"
 #include "mdesessionimpl.h"
 
+const TInt KRetryDelay = 2; //  2 seconds
+const TInt KMillion = 1000000;
+
 // ========================= MEMBER FUNCTIONS ==================================
 
 CMdESessionStartupAO* CMdESessionStartupAO::NewL(
@@ -54,6 +57,7 @@
 
 void CMdESessionStartupAO::ConstructL()
     {
+    iTimer.CreateLocal();
 	SetActive();
 	TRequestStatus* status = &iStatus;
 	User::RequestComplete( status, KErrNone );
@@ -62,26 +66,28 @@
 CMdESessionStartupAO::~CMdESessionStartupAO()
     {
     Cancel(); // Causes call to DoCancel()
+    iTimer.Close();
     }
 
 void CMdESessionStartupAO::DoCancel()
     {
-    iSession.OpenCancel( iStatus );
+    iTimer.Cancel();
+    iSession.OpenCancel();
     }
 
 void CMdESessionStartupAO::RunL()
     {
-    const TInt status = iStatus.Int();
-    
     switch ( iState )
         {
         case EStartupOpenServer:
         	{
-        	iSession.OpenL( iStatus );
+        	iSession.OpenL();
 
 			iState = EStartupConnect;
 
         	SetActive();
+            TRequestStatus* status = &iStatus;
+            User::RequestComplete( status, KErrNone );
 
         	break;
         	}
@@ -125,7 +131,41 @@
 
 TInt CMdESessionStartupAO::RunError(TInt aError)
     {
-    iSessionImpl.NotifyError( aError );
+    // If server was not fully initialized when session was tried to be
+    // created, try to establish session again
+    if( iState == EStartupOpenServer &&
+        (aError == KErrNotReady ||
+         aError == KErrAlreadyExists ) )
+        {
+        TTimeIntervalMicroSeconds32 delay( KRetryDelay * KMillion ); 
+        iState = EStartupOpenServer;
+        iTimer.After( iStatus, delay );
+        SetActive();    
+        }        
+    else if( iState == EStartupConnect &&
+        ( aError == KErrCommsBreak ||
+          aError == KErrServerTerminated ||
+          aError == KErrNotReady ) )
+        {
+        TTimeIntervalMicroSeconds32 delay( KRetryDelay * KMillion ); 
+        iState = EStartupOpenServer;
+        iTimer.After( iStatus, delay );
+        SetActive();
+        }
+    // If schema was not loaded already when it was
+    // attempted to be loaded, try to load schema again
+    else if( iState == EStartupLoadSchema &&
+                aError == KErrNotReady )
+        {
+        TTimeIntervalMicroSeconds32 delay( KRetryDelay * KMillion ); 
+        iState = EStartupLoadSchema;
+        iTimer.After( iStatus, delay );
+        SetActive();
+        }       
+    else
+        {
+        iSessionImpl.NotifyError( aError );
+        }
 
     return KErrNone;
     }
--- a/metadataengine/server/inc/mdsnotifier.h	Fri Apr 16 15:23:55 2010 +0300
+++ b/metadataengine/server/inc/mdsnotifier.h	Mon May 03 12:55:01 2010 +0300
@@ -100,7 +100,7 @@
 				*	Return the id of this entry
 				*	@return The id
 				*/
-				TInt Id()
+				TInt Id() const
 					{
 					return iId;
 					}
@@ -355,7 +355,11 @@
 		void NotifySchemaAddedL();
 		
 		TBool CheckForNotifier( TUint32 aNotifyTypes );
-	
+
+    private:
+		
+		static TInt Compare( const TEntry& aFirst, const TEntry& aSecond );
+		
 	private: // data members
 
         /** the entry array */
--- a/metadataengine/server/inc/mdsserver.h	Fri Apr 16 15:23:55 2010 +0300
+++ b/metadataengine/server/inc/mdsserver.h	Mon May 03 12:55:01 2010 +0300
@@ -101,19 +101,6 @@
         static TInt ThreadFunction( TAny* aStarted );
 
         /**
-        * IncrementSessions.
-        * Increments the count of the active sessions for this server.
-        */
-        void IncrementSessions();
-
-        /**
-        * DecrementSessions.
-        * Decrements the count of the active sessions for this server.
-        * If no more sessions are in use the server terminates.
-        */
-        void DecrementSessions();
-
-        /**
         * Reference to the schema
         */
         CMdsSchema& Schema();
--- a/metadataengine/server/inc/mdsserversession.h	Fri Apr 16 15:23:55 2010 +0300
+++ b/metadataengine/server/inc/mdsserversession.h	Mon May 03 12:55:01 2010 +0300
@@ -436,6 +436,10 @@
         * Cache of notification events
         */        
     	RPointerArray<CNotificationCacheItem> iNotificationCache;
+    	
+	private: // Compare methods
+    	
+        static TInt ComparePropertiesCacheItem( const CNotificationCacheItem& aFirst, const CNotificationCacheItem& aSecond );
     };
 
 #endif // __MDESERVERSESSION_H__
--- a/metadataengine/server/src/mdsfindsqlclause.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/metadataengine/server/src/mdsfindsqlclause.cpp	Mon May 03 12:55:01 2010 +0300
@@ -15,6 +15,7 @@
 */
 
 // INCLUDE FILES
+#include <mdequery.h>
 #include "mdsfindsqlclause.h"
 #include "mdsfindsqlclausedef.h"
 #include "mdsclausebuffer.h"
@@ -2642,10 +2643,13 @@
 			{
 			case EQueryResultModeItem:
 			case EQueryResultModeId:
+                {
+                // "GROUP BY BO.ObjectId "
+                iQueryBuf->AppendL( KGroupByObjectId );
+                }
+                break;
 			case EQueryResultModeCount:
 				{
-				// "GROUP BY BO.ObjectId "
-				iQueryBuf->AppendL( KGroupByObjectId );
 				}
 				break;
 
@@ -2664,6 +2668,12 @@
 //
 void CMdSFindSqlClause::AppendOrderByL()
     {
+    if( iSearchCriteria->iQueryResultType == EQueryResultModeCount )
+        {
+        // No need to sort or group if only one count is returned
+        return;
+        }
+    
 	if( iSearchCriteria->iOrderRules.iPtr.iCount > 0 )
 		{
 		iQueryBuf->AppendL( KOrderBy );
@@ -2828,7 +2838,7 @@
     	iQueryBuf->AppendL( KComma );
     	iQueryBuf->BufferL().AppendNum( iSearchCriteria->iOffset );
     	}
-    else if ( iSearchCriteria->iLimit != KMaxTUint32 )
+    else if ( iSearchCriteria->iLimit != KMdEQueryDefaultMaxCount )
     	{
     	// 10 is maximum length of text format TUint32
     	iQueryBuf->ReserveSpaceL( iQueryBuf->ConstBufferL().Length() + 
--- a/metadataengine/server/src/mdsmaintenanceengine.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/metadataengine/server/src/mdsmaintenanceengine.cpp	Mon May 03 12:55:01 2010 +0300
@@ -119,6 +119,12 @@
     __LOG1( ELogAlways, "Trying to validate MDS DB, error expected if not created(first boot): %d", 0 );
     if ( !(iMaintenance->ValidateL( ) ) )
         {
+        // Pump up priority to load the MDS DB up as fast as possible to
+        // enable client side session connections
+        RProcess process;
+        process.SetPriority( EPriorityForeground );
+    
+        __LOG1( ELogAlways, "MDS DB not valid, creating tables: %d", 0 );
         // first-time init: re-form the database completely
     	iMaintenance->CreateDatabaseL( );
 		const TUint KMdSServerUid = 0x0320e65f; // temporal uid
@@ -156,6 +162,12 @@
        		TRAP_IGNORE( ImportMetadataL( aManipulate, aSchema, KMdsDefaultRomImportFile ) );
        		}
        	
+       	__LOG1( ELogAlways, "MDS DB tables created %d", 0 );
+
+        // Revert back to default MDS server priority when server is up and running
+        process.SetPriority( EPriorityBackground );
+        process.Close();
+       	
        	StoreDriveMediaIdsL();
         }
     else
@@ -168,6 +180,7 @@
 			User::Leave( err );
         	}
         }
+    __LOG1( ELogAlways, "CMdSMaintenanceEngine::InstallL complete: %d", 0 );
     }
 
 // ------------------------------------------------
@@ -247,17 +260,22 @@
     if( massStorageError == KErrNone )
         {
         TVolumeInfo massStorageVolumeInfo;
-        User::LeaveIfError( fs.Volume( massStorageVolumeInfo, drive ) );
-        const TUint32 massStorageMediaId( massStorageVolumeInfo.iUniqueID );
-        massStorageError = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRemovableMassStorage, drive );
+        massStorageError = fs.Volume( massStorageVolumeInfo, drive );
         if( massStorageError == KErrNone )
             {
-            User::LeaveIfError( fs.Volume( massStorageVolumeInfo, drive ) );
-            // Update mass storage media id if the mass storage is not memory card
-            if( massStorageVolumeInfo.iUniqueID != massStorageMediaId && massStorageMediaId != 0 )
+            const TUint32 massStorageMediaId( massStorageVolumeInfo.iUniqueID );
+            massStorageError = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRemovableMassStorage, drive );
+            if( massStorageError == KErrNone )
                 {
-                MMdsPreferences::InsertL( KMassStorageMediaIdKey, MMdsPreferences::EPreferenceValueSet,
-                        (TUint32) massStorageMediaId );
+                massStorageError = fs.Volume( massStorageVolumeInfo, drive );
+                // Update mass storage media id if the mass storage is not memory card
+                if( massStorageError == KErrNone &&
+                    massStorageVolumeInfo.iUniqueID != massStorageMediaId &&
+                    massStorageMediaId != 0 )
+                    {
+                    MMdsPreferences::InsertL( KMassStorageMediaIdKey, MMdsPreferences::EPreferenceValueSet,
+                            (TUint32) massStorageMediaId );
+                    }        
                 }
             }
         }
--- a/metadataengine/server/src/mdsmanipulationengine.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/metadataengine/server/src/mdsmanipulationengine.cpp	Mon May 03 12:55:01 2010 +0300
@@ -812,7 +812,7 @@
 
     	TFilePresentStates placeHolder;
     	TBool notPresentState( EFalse );
-    	const TItemId objectId = iManipulate->SearchNotPresentFileL( /*reservation(), */
+    	const TItemId objectId = iManipulate->SearchNotPresentFileL( 
     			aMediaId, uri, fileInfo, placeHolder, notPresentState );
     	if ( placeHolder != EMdsNotFound )
     		{
--- a/metadataengine/server/src/mdsnotifier.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/metadataengine/server/src/mdsnotifier.cpp	Mon May 03 12:55:01 2010 +0300
@@ -465,10 +465,10 @@
     TConditionType aType, CMdCSerializationBuffer* aSerializedBuffer,
     TDefId aNamespaceDefId, CMdSServerSession& aSession, TBool aConfidential )
     {
-
-    User::LeaveIfError( iEntries.Append(
-        TEntry( aId, aType, aSerializedBuffer, aNamespaceDefId, aSession, aConfidential ) ) );
-    return iEntries[ iEntries.Count() - 1 ];
+    TEntry entry = TEntry( aId, aType, aSerializedBuffer, aNamespaceDefId, aSession, aConfidential ); 
+    User::LeaveIfError( iEntries.InsertInOrderAllowRepeats( entry, TLinearOrder<TEntry>(CMdSNotifier::Compare) ) ); 
+    
+    return FindEntryL( aId );
     }
 
 // ------------------------------------------------
@@ -478,17 +478,29 @@
 CMdSNotifier::TEntry& CMdSNotifier::FindEntryL( TInt aId )
     {
     CMdSNotifier::TEntry* entry = NULL;
-    
-    const TInt count = iEntries.Count();
+
+    TInt low( 0 );
+    TInt high( iEntries.Count() );
     
-    for ( TInt i = 0; i < count; ++i )
+    while( low < high )
         {
-        if ( iEntries[i].iId == aId )
+        TInt mid( (low+high)>>1 );
+        
+        const TInt compare( aId - iEntries[mid].Id() );
+        if( compare == 0 )
             {
-            entry = &iEntries[i];
+            entry = &iEntries[mid];
             break;
             }
-        }
+        else if( compare > 0 )
+            {
+            low = mid + 1;
+            }
+        else
+            {
+            high = mid;
+            }
+        }    
 
     if( !entry )
     	{
@@ -504,33 +516,54 @@
 //
 void CMdSNotifier::RemoveEntryL( TInt aId )
     {
-    const TInt count = iEntries.Count();
+    CMdSNotifier::TEntry* e = NULL;
+
+    TInt low( 0 );
+    TInt mid( 0 );
+    TInt high( iEntries.Count() );
     
-    for ( TInt i = 0; i < count; ++i )
+    while( low < high )
         {
-        TEntry& e = iEntries[i];
-        if ( e.iId == aId )
+        mid = (low+high)>>1;
+        
+        const TInt compare( aId - iEntries[mid].Id() );
+        if( compare == 0 )
             {
-            if ( e.IsPending() )
-                {
-                e.TriggerError( KErrCancel );
-                }
-            
-            if ( e.iSerializedCondition )
-            	{
-            	delete e.iSerializedCondition;
-            	e.iSerializedCondition = NULL;
-            	}
-            if ( e.iDataBuffer )
-            	{
-            	delete e.iDataBuffer;
-            	e.iDataBuffer = NULL;
-            	}
-            iEntries.Remove( i );
-            return;
+            e = &iEntries[mid];
+            break;
+            }
+        else if( compare > 0 )
+            {
+            low = mid + 1;
+            }
+        else
+            {
+            high = mid;
             }
         }
-    User::Leave( KErrNotFound );
+    
+    if( e )
+        {
+        if ( e->IsPending() )
+            {
+            e->TriggerError( KErrCancel );
+            }
+        if ( e->iSerializedCondition )
+            {
+            delete e->iSerializedCondition;
+            e->iSerializedCondition = NULL;
+            }
+        if ( e->iDataBuffer )
+            {
+            delete e->iDataBuffer;
+            e->iDataBuffer = NULL;
+            }
+        iEntries.Remove( mid );
+        }
+    else
+        {
+        User::Leave( KErrNotFound );
+        }
     }
 
 // ------------------------------------------------
@@ -1335,6 +1368,10 @@
             	}
 	        }
 		}
-
 	}
 
+TInt CMdSNotifier::Compare( const TEntry& aFirst, const TEntry& aSecond )
+    {
+    return aFirst.Id() - aSecond.Id();
+    }
+
--- a/metadataengine/server/src/mdsserver.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/metadataengine/server/src/mdsserver.cpp	Mon May 03 12:55:01 2010 +0300
@@ -354,10 +354,6 @@
     __INIT_LOGGER;
     StartL( KMdSServerName );
     __LOGLB( ELogAlways, "Server start" );
-
-    RProcess process;
-    process.SetPriority( EPriorityBackground );
-    process.Close();
     
     CheckInitSriptL();
     
@@ -388,7 +384,7 @@
     
     // create shutdown observer
     iShutdownObserver = CMDSShutdownObserver::NewL( *this );
-    iShutdown = EFalse;    
+    iShutdown = EFalse;   
     }
 
 void CMdSServer::InitializeL()
@@ -495,26 +491,6 @@
     return CMdSServerSession::NewL( *const_cast<CMdSServer*> ( this ) );
     }
 
-
-void CMdSServer::IncrementSessions()
-    {
-    iSessionCount++;
-    }
-
-
-void CMdSServer::DecrementSessions()
-    {
-    iSessionCount--;
-    if ( iSessionCount <= 0 )
-        {        
-        if (!iShutdown)
-            {
-            CActiveScheduler::Stop();
-            iShutdown = ETrue;
-            }
-        }
-    }
-
 CMdsSchema& CMdSServer::Schema()
     {
     return *iSchema;
--- a/metadataengine/server/src/mdsserversession.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/metadataengine/server/src/mdsserversession.cpp	Mon May 03 12:55:01 2010 +0300
@@ -69,7 +69,6 @@
 //
 void CMdSServerSession::ConstructL()
     {
-    iServer.IncrementSessions();
     }
 
 // ---------------------------------------------------------------------------
@@ -92,7 +91,6 @@
 
 	iServer.LockList().UnlockBySession( *this );
 	iServer.Notifier().RemoveEntriesBySession( *this );
-    iServer.DecrementSessions();
     
     // purge any pending notifications
 	iNotificationCache.ResetAndDestroy();
@@ -105,12 +103,25 @@
 //
 void CMdSServerSession::ServiceL( const RMessage2& aMessage )
     {
-    __LOG2( ELogServer, "ServiceL message: %d uid: %.8x", 
+    __LOG2( ELogServer, "ServiceL message: %d uid: %d", 
     		aMessage.Function(),
-    		aMessage.Identity());
-
+    		aMessage.Identity().iUid);
+    
 	if( iServer.BackupOrRestoreRunning() )
 		{
+        // Open client applications are closed during backup/restore,
+        // thus registered observers that would be removed during
+        // shutdown on clients, must be allowed to be removed even
+        // if backup/restore is running
+	    if( aMessage.Function() == EUnregister )
+	        {
+            TRAPD( err, ServiceFunctionL( aMessage ) );
+            if( err != KErrNone )
+                {
+                aMessage.Complete( err );
+                }
+            return;
+	        }
 		aMessage.Complete( KErrServerBusy );
 		return;
 		}
@@ -957,30 +968,42 @@
 
     CMdSNotifier::TEntry& entry = iServer.Notifier().FindEntryL( notifierId );
     entry.SetupForCallback( aMsg, 1 );
+
+    const TInt entryId = entry.Id();    
+
+    TInt low( 0 );
+    TInt high( iNotificationCache.Count() );
     
-	const TInt count = iNotificationCache.Count();
-	for( TInt i = 0; i < count; ++i )
-		{
-		const TInt notificationCacheId = iNotificationCache[i]->iId;
-		const TInt entryId = entry.Id();
+    while( low < high )
+        {
+        TInt mid( (low+high)>>1 );
+        
+        const TInt compare( entryId - iNotificationCache[mid]->iId );
+        if( compare == 0 )
+            {
+            // The cache holds a new notification for this notifier, trigger it
+            CNotificationCacheItem* item = iNotificationCache[mid];
+            iNotificationCache.Remove(mid);
 
-		if( notificationCacheId == entryId )
-			{
-			// The cache holds a new notification for this notifier, trigger it
-			CNotificationCacheItem* item = iNotificationCache[i];
-			iNotificationCache.Remove(i);
-
-			CleanupStack::PushL( item );
+            CleanupStack::PushL( item );
 
-			entry.TriggerCachedL( item->iCode, item->iData );
-			
-			// take ownership of iData from item and delete it
-			item->iData = NULL;
-			CleanupStack::PopAndDestroy( item );
-			
-			return;
-			}
-		}
+            entry.TriggerCachedL( item->iCode, item->iData );
+        
+            // take ownership of iData from item and delete it
+            item->iData = NULL;
+            CleanupStack::PopAndDestroy( item );
+        
+            return;
+            }
+        else if( compare > 0 )
+            {
+            low = mid + 1;
+            }
+        else
+            {
+            high = mid;
+            }
+        }
     }
 
 // ---------------------------------------------------------------------------
@@ -1180,7 +1203,8 @@
 	CleanupStack::Pop( aData );
 	CleanupStack::PushL( item );
 
-	iNotificationCache.AppendL( item );
+	iNotificationCache.InsertInOrderAllowRepeats( item, 
+	                              TLinearOrder<CNotificationCacheItem>(CMdSServerSession::ComparePropertiesCacheItem)); 
 
 	CleanupStack::Pop( item );
 	}
@@ -1640,3 +1664,8 @@
 	return KErrNone;
 	}
 
+TInt CMdSServerSession::ComparePropertiesCacheItem(const CNotificationCacheItem& aFirst, const CNotificationCacheItem& aSecond)
+    {
+    return aFirst.iId - aSecond.iId;
+    }
+
--- a/metadataengine/server/src/mdssqlobjectmanipulate.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/metadataengine/server/src/mdssqlobjectmanipulate.cpp	Mon May 03 12:55:01 2010 +0300
@@ -647,23 +647,31 @@
 		aObjectIds.AppendL( objectId );
 		}
 
-	_LIT( KSetFilesToNotPresent, "UPDATE Object%u SET Flags=Flags|? WHERE MediaId=?;" );
-	clauseBuffer.ReserveSpaceL( 
-			KSetFilesToNotPresent.iTypeLength + 
-			KMaxUintValueLength ); // TUint32 max value's lenght is 10 numbers so %u + 8
-	clauseBuffer.BufferL().Format( KSetFilesToNotPresent, KDefaultNamespaceDefId );
-
-	var.Free(); 
-	var.Reset();
-
+    var.Free(); 
+    var.Reset();
+	
 	if( aStartUp )
-		{
-		var.AppendL( TColumn( EMdEObjectFlagStartUpNotPresent ) ); // set not present flag
-		}
-	else 
-		{
-		var.AppendL( TColumn( EMdEObjectFlagNotPresent ) ); // set not present flag
-		}
+	    {
+        _LIT( KSetFilesToNotPresentBoot, "UPDATE Object%u SET Flags=Flags|? WHERE MediaId=?;" );
+        clauseBuffer.ReserveSpaceL( 
+                KSetFilesToNotPresentBoot.iTypeLength + 
+                KMaxUintValueLength ); // TUint32 max value's lenght is 10 numbers so %u + 8
+        clauseBuffer.BufferL().Format( KSetFilesToNotPresentBoot, KDefaultNamespaceDefId );
+
+        var.AppendL( TColumn( EMdEObjectFlagStartUpNotPresent ) ); // set not present flag
+	    }
+	else
+	    {
+        _LIT( KSetFilesToNotPresent, "UPDATE Object%u SET Flags=Flags|? WHERE NOT (Flags&?)<>0 AND MediaId=?;" );
+        clauseBuffer.ReserveSpaceL( 
+                KSetFilesToNotPresent.iTypeLength + 
+                KMaxUintValueLength ); // TUint32 max value's lenght is 10 numbers so %u + 8
+        clauseBuffer.BufferL().Format( KSetFilesToNotPresent, KDefaultNamespaceDefId );
+
+        var.AppendL( TColumn( EMdEObjectFlagNotPresent ) ); // set not present flag	
+        var.AppendL( TColumn( EMdEObjectFlagNotPresent ) ); // check not present flag 
+	    }
+
 	var.AppendL( TColumn( aMediaId ) );
 
     connection.ExecuteL( clauseBuffer.ConstBufferL(), var );
@@ -681,7 +689,7 @@
 	// RelationIDs query sql statement
 	RClauseBuffer commonClauseOne(*this, 
 			KSearchPresentRelations.iTypeLength + 
-			2*KMaxUintValueLength  );
+			10*KMaxUintValueLength  );
     CleanupClosePushL( commonClauseOne );
 	CMdsClauseBuffer& clauseBufferOne = commonClauseOne.BufferL();
 	clauseBufferOne.BufferL().Format( KSearchPresentRelations, 
@@ -718,7 +726,8 @@
 	
     // Set objects' relations not present by MediaID
 	RClauseBuffer commonClauseTwo(*this, 
-			KSetRelationsToPresent.iTypeLength + 
+			KSetRelationsToPresent.iTypeLength + 			 
+            KMaxUintValueLength +
 			clauseBufferOne.ConstBufferL().Length() );
 	
     CleanupClosePushL( commonClauseTwo );
@@ -1058,9 +1067,8 @@
         CleanupClosePushL( objectIds );
         MMdsPreferences::UpdateL( KMassStorageMediaIdKey, MMdsPreferences::EPreferenceValueSet, (TUint32) aMediaId );
         SetFilesToNotPresentL( oldMediaId, EFalse, objectIds );
-        objectIds.Reset();
-        RemoveFilesNotPresentL( oldMediaId, &objectIds );
         CleanupStack::PopAndDestroy( &objectIds );
+        RemoveFilesNotPresentL( oldMediaId, NULL );
         }
     }
 
@@ -2039,7 +2047,7 @@
 
 	CMdSSqLiteConnection& connection = MMdSDbConnectionPool::GetDefaultDBL();
 	
-	const TInt clauseSize( KCollectGetDeleteId1().Length() + KMaxUintValueLength +
+	const TInt clauseSize( KCollectGetDeleteId1().Length() + 2*KMaxUintValueLength +
                                       (removeIdsCount-1) * KCollectMiddle().Length() +
                                       KCollectEnd1().Length() +
                                       KCollectGetDeleteId2().Length() + KMaxUintValueLength +
--- a/rom/ContentListingFramework.iby	Fri Apr 16 15:23:55 2010 +0300
+++ b/rom/ContentListingFramework.iby	Mon May 03 12:55:01 2010 +0300
@@ -21,9 +21,6 @@
 file=ABI_DIR\BUILD_DIR\ContentListingFramework.dll                     SHARED_LIB_DIR\ContentListingFramework.dll
 file=ABI_DIR\BUILD_DIR\MediaCollectionManager.dll                      SHARED_LIB_DIR\MediaCollectionManager.dll
 
-// Backup registration
-data=ZPRIVATE\101F8857\backup_registration.xml                         	private\101F8857\backup_registration.xml
-
 // Stubs
 //data=ZSYSTEM\install\ContentListingFrameworkStub.sis    System\Install\ContentListingFrameworkStub.sis
 
Binary file sis/mds/mds_stub.sis has changed
--- a/sis/mds/package.pkg	Fri Apr 16 15:23:55 2010 +0300
+++ b/sis/mds/package.pkg	Mon May 03 12:55:01 2010 +0300
@@ -17,7 +17,7 @@
 &EN
 
 ;packet-header (name, uid, major, minor, build, type)
-#{"Metadata System Upgrade"},(0x200009F5), 10, 10, 5, TYPE=SA, RU
+#{"Metadata System Upgrade"},(0x200009F5), 10, 10, 6, TYPE=SA, RU
 
 ; Localised vendor name
 %{"Nokia"}
--- a/sis/mds/package_separate.pkg	Fri Apr 16 15:23:55 2010 +0300
+++ b/sis/mds/package_separate.pkg	Mon May 03 12:55:01 2010 +0300
@@ -17,7 +17,7 @@
 &EN
 
 ;packet-header (name, uid, major, minor, build, type)
-#{"Metadata System Upgrade"},(0x200009F5), 10, 10, 5, TYPE=SA, RU
+#{"Metadata System Upgrade"},(0x200009F5), 10, 10, 6, TYPE=SA, RU
 
 ; Localised vendor name
 %{"Nokia"}
--- a/sis/mds/stub.pkg	Fri Apr 16 15:23:55 2010 +0300
+++ b/sis/mds/stub.pkg	Mon May 03 12:55:01 2010 +0300
@@ -17,7 +17,7 @@
 &EN
 
 ; Header
-#{"Metadata System"}, (0x200009F5), 10, 10, 5, TYPE=SA
+#{"Metadata System"}, (0x200009F5), 10, 10, 6, TYPE=SA
 
 ; Localised Vendor name
 %{"Nokia"}