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