diff -r c48470be1ba7 -r adbe7d5ba2f5 videocollection/mpxmyvideoscollection/src/vcxmyvideosmdsdb.cpp --- a/videocollection/mpxmyvideoscollection/src/vcxmyvideosmdsdb.cpp Fri Jun 11 13:39:54 2010 +0300 +++ b/videocollection/mpxmyvideoscollection/src/vcxmyvideosmdsdb.cpp Wed Jun 23 18:14:16 2010 +0300 @@ -191,6 +191,8 @@ iMdsShutdownMonitor = CVcxMdsShutdownMonitor::NewL( *this, KHarvesterPSShutdown, KMdSShutdown, EFalse ); + + iEvents.Reset(); MPX_DEBUG1( "CVcxMyVideosMdsDb::ConstructL exit" ); } @@ -256,7 +258,7 @@ TBool aPresent, const RArray& aObjectIdArray) { MPX_DEBUG1( "CVcxMyVideosMdsDb::--------------------------------------------------------------." ); - MPX_DEBUG3( "CVcxMyVideosMdsDb::HandleObjectPresentNotification( aPresent = %1d, count = %3d) |", aPresent, aObjectIdArray.Count() ); + MPX_DEBUG3( "CVcxMyVideosMdsDb::HandleObjectPresentNotification( aPresent = %1d, count = %4d) |", aPresent, aObjectIdArray.Count() ); MPX_DEBUG1( "CVcxMyVideosMdsDb::--------------------------------------------------------------'" ); TObserverNotificationType type; @@ -305,6 +307,9 @@ { MPX_DEBUG1( "CVcxMyVideosMdsDb::~CVcxMyVideosMdsDb() start" ); + delete iEventProcessor; + iEvents.Close(); + Cancel( EGetVideoList ); delete iAlbums; @@ -1026,7 +1031,7 @@ if ( aObject.Property( *iOriginPropertyDef, property, 0 ) != KErrNotFound ) { TUint8 origin = static_cast(property)->Value(); -#ifdef VIDEO_COLLECTION_PLUGIN_TB92 +#ifndef VCX_DOWNLOADS_CATEGORY if( origin != EVcxMyVideosOriginCapturedWithCamera ) { origin = EVcxMyVideosOriginOther; @@ -1604,30 +1609,116 @@ if ( iMdsDbObserver ) { - RArray idArray; - CleanupClosePushL( idArray ); // 1-> - - for ( TInt i = 0; i < aObjectIdArray.Count(); i++ ) + // Let delete events bypass buffer only if it empty. + // This assures that event arriving order stays the same. + if ( aType & ENotifyRemove && iEvents.Count() == 0 ) { - idArray.Append( aObjectIdArray[i] ); + // Delete handling is so fast that we dont buffer them at all. + // Modify and add require fetch from mds -> they are slow. + RArray idArray; + CleanupClosePushL( idArray ); // 1-> + + for ( TInt i = 0; i < aObjectIdArray.Count(); i++ ) + { + idArray.Append( aObjectIdArray[i] ); + } + + iMdsDbObserver->HandleMyVideosDbEvent( EMPXItemDeleted, idArray, iEvents.Count() ); + + CleanupStack::PopAndDestroy( &idArray ); // <-1 } - - if ( aType & ENotifyAdd ) + else { - iMdsDbObserver->HandleMyVideosDbEvent( EMPXItemInserted, idArray ); - } - else if ( aType & ENotifyModify ) - { - iMdsDbObserver->HandleMyVideosDbEvent( EMPXItemModified, idArray ); - } - else if ( aType & ENotifyRemove ) - { - iMdsDbObserver->HandleMyVideosDbEvent( EMPXItemDeleted, idArray ); - } + // Buffer modify & add events, since their handling is slow. + // Process them on background. + TInt count = aObjectIdArray.Count(); + + if ( iEvents.Count() == 0 ) + { + iEvents.ReserveL( count ); + } + + TEvent event; + for ( TInt i = 0; i < count; i++ ) + { + event.iMdsId = aObjectIdArray[i]; + event.iEventType = aType; + iEvents.AppendL( event ); + } + + if ( !iEventProcessor ) + { + iEventProcessor = CIdle::NewL( CActive::EPriorityIdle ); + } + + if ( !iEventProcessor->IsActive() ) + { + iEventProcessor->Start( TCallBack( ProcessEvents, this )); + } + } + } + } + +// --------------------------------------------------------------------------- +// CVcxMyVideosMdsDb::ProcessEvents +// --------------------------------------------------------------------------- +// +TInt CVcxMyVideosMdsDb::ProcessEvents( TAny* aPtr ) + { + return static_cast(aPtr)->DoProcessEvents(); + } - CleanupStack::PopAndDestroy( &idArray ); // <-1 +// --------------------------------------------------------------------------- +// CVcxMyVideosMdsDb::DoProcessEvents +// --------------------------------------------------------------------------- +// +TInt CVcxMyVideosMdsDb::DoProcessEvents() + { + TInt sent = 0; + TInt currentEventType = -1; + const TInt sendAtOnce = 10; + + RArray idArray; + CleanupClosePushL( idArray ); // 1-> + + idArray.Reserve( sendAtOnce ); // may fail, it's ok + + while ( sent < sendAtOnce ) + { + if ( iEvents.Count() == 0 ) + { + break; + } + + if ( iEvents[0].iEventType != currentEventType && + currentEventType != -1 ) + { + break; + } + currentEventType = iEvents[0].iEventType; + idArray.Append( iEvents[0].iMdsId ); // this may fail, it is ok, we can't do anything for it + iEvents.Remove( 0 ); + sent++; } - + + iEvents.Compress(); + + if ( currentEventType & ENotifyAdd ) + { + iMdsDbObserver->HandleMyVideosDbEvent( EMPXItemInserted, idArray, iEvents.Count() ); + } + else if ( currentEventType & ENotifyModify ) + { + iMdsDbObserver->HandleMyVideosDbEvent( EMPXItemModified, idArray, iEvents.Count() ); + } + else if ( currentEventType & ENotifyRemove ) + { + iMdsDbObserver->HandleMyVideosDbEvent( EMPXItemDeleted, idArray, iEvents.Count() ); + } + + CleanupStack::PopAndDestroy( &idArray ); // <-1 + + return iEvents.Count(); } // ---------------------------------------------------------------------------