harvester/common/src/harvesterpluginfactory.cpp
branchRCL_3
changeset 53 29d87345eaeb
parent 50 85f623e1ef41
child 63 e538444823de
equal deleted inserted replaced
50:85f623e1ef41 53:29d87345eaeb
    65 // ---------------------------------------------------------------------------
    65 // ---------------------------------------------------------------------------
    66 //
    66 //
    67 CHarvesterPluginFactory::~CHarvesterPluginFactory()
    67 CHarvesterPluginFactory::~CHarvesterPluginFactory()
    68 	{
    68 	{
    69 	WRITELOG( "CHarvesterPluginFactory::~CHarvesterPluginFactory()" );
    69 	WRITELOG( "CHarvesterPluginFactory::~CHarvesterPluginFactory()" );
       
    70 	
       
    71 	delete iLastConfirmedContainerExt;
       
    72 	iLastConfirmedContainerExt = NULL;
       
    73 	
       
    74 	delete iLastConfirmedSupportedExt;
       
    75 	iLastConfirmedSupportedExt = NULL;
    70 	
    76 	
    71     if (iHarvesterEventManager)
    77     if (iHarvesterEventManager)
    72         {
    78         {
    73         iHarvesterEventManager->ReleaseInstance();
    79         iHarvesterEventManager->ReleaseInstance();
    74         }
    80         }
   328 EXPORT_C TBool CHarvesterPluginFactory::IsSupportedFileExtension( const TDesC& aFileName )
   334 EXPORT_C TBool CHarvesterPluginFactory::IsSupportedFileExtension( const TDesC& aFileName )
   329 	{
   335 	{
   330 	TPtrC extPtr;
   336 	TPtrC extPtr;
   331 	if( MdsUtils::GetExt( aFileName, extPtr ) )
   337 	if( MdsUtils::GetExt( aFileName, extPtr ) )
   332 		{
   338 		{
       
   339         if( iLastConfirmedSupportedExt &&
       
   340             extPtr.CompareF( iLastConfirmedSupportedExt->Des() ) == 0 )
       
   341             {
       
   342             // Extension has previously been confirmed to be 
       
   343             // supported file extension, no need to ask from plugins
       
   344             return ETrue;
       
   345             }
   333 		TInt pluginInfoCount = iHarvesterPluginInfoArray.Count();
   346 		TInt pluginInfoCount = iHarvesterPluginInfoArray.Count();
   334 		TInt extCount = 0;
   347 		TInt extCount = 0;
   335 		for ( TInt i = pluginInfoCount; --i >= 0; )
   348 		for ( TInt i = pluginInfoCount; --i >= 0; )
   336 			{
   349 			{
   337 			CHarvesterPluginInfo* info = iHarvesterPluginInfoArray[i];
   350 			CHarvesterPluginInfo* info = iHarvesterPluginInfoArray[i];
   341 				TDesC* ext = info->iExtensions[k];
   354 				TDesC* ext = info->iExtensions[k];
   342 				// checking against supported plugin file extensions
   355 				// checking against supported plugin file extensions
   343 				TInt result = MdsUtils::Compare( *ext, extPtr );
   356 				TInt result = MdsUtils::Compare( *ext, extPtr );
   344 				if ( result == 0 )
   357 				if ( result == 0 )
   345 					{
   358 					{
       
   359                     delete iLastConfirmedSupportedExt;
       
   360                     iLastConfirmedSupportedExt = NULL;
       
   361                     iLastConfirmedSupportedExt = extPtr.Alloc();				    
   346 					return ETrue;
   362 					return ETrue;
   347 					}
   363 					}
   348 				}
   364 				}
   349 			}
   365 			}
   350 		}
   366 		}
   356 	TBool isContainerFile = EFalse;
   372 	TBool isContainerFile = EFalse;
   357 	TPtrC extPtr;
   373 	TPtrC extPtr;
   358 	
   374 	
   359 	if( MdsUtils::GetExt( aURI, extPtr ) )
   375 	if( MdsUtils::GetExt( aURI, extPtr ) )
   360 		{
   376 		{
       
   377 	    if( iLastConfirmedContainerExt &&
       
   378 	        extPtr.CompareF( iLastConfirmedContainerExt->Des() ) == 0 )
       
   379 	        {
       
   380 	        // Extension has previously been confirmed to be 
       
   381 	        // container file extension, no need to ask from plugins
       
   382 	        return ETrue;
       
   383 	        }
       
   384 	
   361 		RPointerArray<CHarvesterPluginInfo> supportedPlugins;
   385 		RPointerArray<CHarvesterPluginInfo> supportedPlugins;
   362 		CleanupClosePushL( supportedPlugins );
   386 		CleanupClosePushL( supportedPlugins );
   363 		GetSupportedPluginsL( supportedPlugins, extPtr );
   387 		GetSupportedPluginsL( supportedPlugins, extPtr );
   364 		for( TInt i = supportedPlugins.Count() - 1; i >=0; i-- )
   388 		for( TInt i = supportedPlugins.Count() - 1; i >=0; i-- )
   365 			{
   389 			{
   366 			CHarvesterPluginInfo* info = supportedPlugins[i];
   390 			CHarvesterPluginInfo* info = supportedPlugins[i];
   367 			if( info->iObjectTypes.Count() >  1 )
   391 			if( info->iObjectTypes.Count() >  1 )
   368 				{
   392 				{
   369 				isContainerFile = ETrue;
   393 				isContainerFile = ETrue;
       
   394 				delete iLastConfirmedContainerExt;
       
   395 				iLastConfirmedContainerExt = NULL;
       
   396 				iLastConfirmedContainerExt = extPtr.Alloc();
   370 				break;
   397 				break;
   371 				}
   398 				}
   372 			}
   399 			}
   373 		CleanupStack::PopAndDestroy( &supportedPlugins );
   400 		CleanupStack::PopAndDestroy( &supportedPlugins );
   374 		}
   401 		}
   393         }
   420         }
   394     }
   421     }
   395 
   422 
   396 EXPORT_C void CHarvesterPluginFactory::SendHarvestingStatusEventL( TBool aStarted )
   423 EXPORT_C void CHarvesterPluginFactory::SendHarvestingStatusEventL( TBool aStarted )
   397     {
   424     {
       
   425     WRITELOG( "CHarvesterPluginFactory::SendHarvestingStatusEventL" );
   398     const TInt pluginInfoCount = iHarvesterPluginInfoArray.Count();
   426     const TInt pluginInfoCount = iHarvesterPluginInfoArray.Count();
   399     TBool itemsLeft( EFalse );
   427     TBool itemsLeft( EFalse );
   400     TBool allPluginsOnIdle( ETrue );
   428     TBool allPluginsOnIdle( ETrue );
   401     for ( TInt i = pluginInfoCount; --i >= 0; )
   429     for ( TInt i = pluginInfoCount; --i >= 0; )
   402         {
   430         {
   416             }
   444             }
   417         }
   445         }
   418     
   446     
   419     if( !iHarvesting && itemsLeft && aStarted )
   447     if( !iHarvesting && itemsLeft && aStarted )
   420         {
   448         {
       
   449         WRITELOG( "CHarvesterPluginFactory::SendHarvestingStatusEventL - overall started" );
   421         iHarvesting = ETrue;
   450         iHarvesting = ETrue;
   422         iHarvesterEventManager->SendEventL( EHEObserverTypeOverall, EHEStateStarted );
   451         iHarvesterEventManager->SendEventL( EHEObserverTypeOverall, EHEStateStarted );
   423         // This next line is for caching the harvester started event for observers registering
   452         // This next line is for caching the harvester started event for observers registering
   424         // after harvesting has already started
   453         // after harvesting has already started
   425         iHarvesterEventManager->IncreaseItemCount( EHEObserverTypeOverall, KCacheItemCountForEventCaching );
   454         iHarvesterEventManager->IncreaseItemCount( EHEObserverTypeOverall, KCacheItemCountForEventCaching );
   426         return;
   455         return;
   427         }
   456         }
   428     else if( iHarvesting && (!itemsLeft || allPluginsOnIdle) && !aStarted )
   457     else if( iHarvesting && (!itemsLeft || allPluginsOnIdle) && !aStarted )
   429         {
   458         {
       
   459         WRITELOG( "CHarvesterPluginFactory::SendHarvestingStatusEventL - overall finished" );
   430         iHarvesting = EFalse;                       
   460         iHarvesting = EFalse;                       
   431         iHarvesterEventManager->SendEventL( EHEObserverTypeOverall, EHEStateFinished );
   461         iHarvesterEventManager->SendEventL( EHEObserverTypeOverall, EHEStateFinished );
   432         iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeOverall, KCacheItemCountForEventCaching );
   462         iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeOverall, KCacheItemCountForEventCaching );
   433         }
   463         }
   434     }
   464     }
   438     const TInt count = iHarvesterPluginInfoArray.Count();
   468     const TInt count = iHarvesterPluginInfoArray.Count();
   439     for ( TInt i = count; --i >= 0; )
   469     for ( TInt i = count; --i >= 0; )
   440         {
   470         {
   441         if( iHarvesterPluginInfoArray[i]->iPlugin && aPaused )
   471         if( iHarvesterPluginInfoArray[i]->iPlugin && aPaused )
   442             {
   472             {
   443             iHarvesterPluginInfoArray[i]->iPlugin->Cancel();
   473             iHarvesterPluginInfoArray[i]->iPlugin->StopHarvest();
   444             }
   474             }
   445         else if( iHarvesterPluginInfoArray[i]->iPlugin )
   475         else if( iHarvesterPluginInfoArray[i]->iPlugin )
   446             {
   476             {
   447             iHarvesterPluginInfoArray[i]->iPlugin->StartHarvest();
   477             iHarvesterPluginInfoArray[i]->iPlugin->StartHarvest();
   448             }
   478             }
   479                 info->iPlugin->SetQueue( info->iQueue );
   509                 info->iPlugin->SetQueue( info->iQueue );
   480                 info->iPlugin->SetHarvesterPluginFactory( *this );  
   510                 info->iPlugin->SetHarvesterPluginFactory( *this );  
   481                 info->iPlugin->SetBlacklist( *iBlacklist );
   511                 info->iPlugin->SetBlacklist( *iBlacklist );
   482                 }
   512                 }
   483             info->iPlugin->GetObjectType( aHD->Uri(), aObjectDef );
   513             info->iPlugin->GetObjectType( aHD->Uri(), aObjectDef );
       
   514             // It is possible for unmount to occure while we are waiting
       
   515             // for GetObjectType to return, thus check aHD for validity
   484             if( aHD && aObjectDef.Length() > 0 )
   516             if( aHD && aObjectDef.Length() > 0 )
   485                 {
   517                 {
   486                 aHD->SetHarvesterPluginInfo( info );
   518                 aHD->SetHarvesterPluginInfo( info );
   487                 break;
   519                 break;
   488                 }
   520                 }