harvester/common/src/harvesterpluginfactory.cpp
changeset 54 a3cc46f37772
parent 36 aa5a574040a4
equal deleted inserted replaced
36:aa5a574040a4 54:a3cc46f37772
    66 //
    66 //
    67 CHarvesterPluginFactory::~CHarvesterPluginFactory()
    67 CHarvesterPluginFactory::~CHarvesterPluginFactory()
    68 	{
    68 	{
    69 	WRITELOG( "CHarvesterPluginFactory::~CHarvesterPluginFactory()" );
    69 	WRITELOG( "CHarvesterPluginFactory::~CHarvesterPluginFactory()" );
    70 	
    70 	
       
    71 	delete iLastConfirmedContainerExt;
       
    72 	iLastConfirmedContainerExt = NULL;
       
    73 	
       
    74 	delete iLastConfirmedSupportedExt;
       
    75 	iLastConfirmedSupportedExt = NULL;
       
    76 	
    71     if (iHarvesterEventManager)
    77     if (iHarvesterEventManager)
    72         {
    78         {
    73         iHarvesterEventManager->ReleaseInstance();
    79         iHarvesterEventManager->ReleaseInstance();
    74         }
    80         }
    75 	
    81 	
    91 
    97 
    92 // ---------------------------------------------------------------------------
    98 // ---------------------------------------------------------------------------
    93 // GetObjectDef
    99 // GetObjectDef
    94 // ---------------------------------------------------------------------------
   100 // ---------------------------------------------------------------------------
    95 //
   101 //
    96 EXPORT_C void CHarvesterPluginFactory::GetObjectDefL( CHarvesterData& aHD, TDes& aObjectDef )
   102 EXPORT_C void CHarvesterPluginFactory::GetObjectDefL( CHarvesterData& /*aHD*/, TDes& aObjectDef )
    97 	{
   103 	{
    98 	TPtrC extPtr;
   104 	aObjectDef.Zero();
    99 	if( MdsUtils::GetExt( aHD.Uri(), extPtr ) )
       
   100 		{
       
   101 		RPointerArray<CHarvesterPluginInfo> supportedPlugins;
       
   102 		CleanupClosePushL( supportedPlugins );
       
   103 		GetSupportedPluginsL( supportedPlugins, extPtr );
       
   104 		
       
   105 		const TInt sCount = supportedPlugins.Count();
       
   106 		if( sCount == 1 )
       
   107 			{
       
   108 			CHarvesterPluginInfo* info = supportedPlugins[0];
       
   109 			if( info->iObjectTypes.Count() == 1 )
       
   110 				{
       
   111 				aObjectDef.Copy( *(info->iObjectTypes[0]) );
       
   112 				aHD.SetHarvesterPluginInfo( info );
       
   113 				CleanupStack::PopAndDestroy( &supportedPlugins );
       
   114 				return;
       
   115 				}
       
   116 			}
       
   117 		for( TInt i = sCount - 1; i >=0; i-- )
       
   118 			{
       
   119 			CHarvesterPluginInfo* info = supportedPlugins[i];
       
   120 			if ( !(info->iPlugin) )
       
   121 				{
       
   122 				info->iPlugin = CHarvesterPlugin::NewL( info->iPluginUid );
       
   123 				info->iPlugin->SetQueue( info->iQueue );
       
   124 				info->iPlugin->SetHarvesterPluginFactory( *this );  
       
   125 				info->iPlugin->SetBlacklist( *iBlacklist );
       
   126 				}
       
   127 			info->iPlugin->GetObjectType( aHD.Uri(), aObjectDef );
       
   128 			if( aObjectDef.Length() > 0 )
       
   129 				{
       
   130 				aHD.SetHarvesterPluginInfo( info );
       
   131 				break;
       
   132 				}
       
   133 			}
       
   134 		CleanupStack::PopAndDestroy( &supportedPlugins );
       
   135 		}
       
   136 	else
       
   137 		{
       
   138 		aObjectDef.Zero();
       
   139 		}
       
   140 	}
   105 	}
   141 	
   106 	
   142 // ---------------------------------------------------------------------------
   107 // ---------------------------------------------------------------------------
   143 // GetMimeType
   108 // GetMimeType
   144 // ---------------------------------------------------------------------------
   109 // ---------------------------------------------------------------------------
   207 	   		hpi->iPlugin->SetBlacklist( *iBlacklist );
   172 	   		hpi->iPlugin->SetBlacklist( *iBlacklist );
   208 	   		}
   173 	   		}
   209 			
   174 			
   210 		if( aHD->ObjectType() == EFastHarvest || aHD->Origin() == MdeConstants::Object::ECamera )
   175 		if( aHD->ObjectType() == EFastHarvest || aHD->Origin() == MdeConstants::Object::ECamera )
   211 		   	{
   176 		   	{
   212 		   	hpi->iQueue.Insert( aHD, 0 );
   177 		   	hpi->iQueue.InsertL( aHD, 0 );
       
   178 		   	
   213 		   	if( !hpi->iPlugin->IsActive() )
   179 		   	if( !hpi->iPlugin->IsActive() )
   214 		   	    {
   180 		   	    {
   215 	            hpi->iPlugin->SetPriority( KHarvesterPriorityHarvestingPlugin + 1 );
   181 	            hpi->iPlugin->SetPriority( KHarvesterPriorityHarvestingPlugin + 1 );
   216 		   	    }
   182 		   	    }
   217 		    }
   183 		    }
   326         CleanupStack::Pop( str );
   292         CleanupStack::Pop( str );
   327         }
   293         }
   328     
   294     
   329     pluginInfo->iPluginUid = aPluginUid;
   295     pluginInfo->iPluginUid = aPluginUid;
   330     
   296     
   331 #ifdef MDS_HARVESTERPLUGINS_ON_BOOT
       
   332     pluginInfo->iPlugin = CHarvesterPlugin::NewL( pluginInfo->iPluginUid );
   297     pluginInfo->iPlugin = CHarvesterPlugin::NewL( pluginInfo->iPluginUid );
   333     pluginInfo->iPlugin->SetQueue( pluginInfo->iQueue );
   298     pluginInfo->iPlugin->SetQueue( pluginInfo->iQueue );
   334     pluginInfo->iPlugin->SetHarvesterPluginFactory( *this );
   299     pluginInfo->iPlugin->SetHarvesterPluginFactory( *this );
   335 #endif
       
   336     
   300     
   337     iHarvesterPluginInfoArray.AppendL( pluginInfo );
   301     iHarvesterPluginInfoArray.AppendL( pluginInfo );
   338     CleanupStack::Pop( pluginInfo );
   302     CleanupStack::Pop( pluginInfo );
   339     }
   303     }
   340 
   304 
   370 EXPORT_C TBool CHarvesterPluginFactory::IsSupportedFileExtension( const TDesC& aFileName )
   334 EXPORT_C TBool CHarvesterPluginFactory::IsSupportedFileExtension( const TDesC& aFileName )
   371 	{
   335 	{
   372 	TPtrC extPtr;
   336 	TPtrC extPtr;
   373 	if( MdsUtils::GetExt( aFileName, extPtr ) )
   337 	if( MdsUtils::GetExt( aFileName, extPtr ) )
   374 		{
   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             }
   375 		TInt pluginInfoCount = iHarvesterPluginInfoArray.Count();
   346 		TInt pluginInfoCount = iHarvesterPluginInfoArray.Count();
   376 		TInt extCount = 0;
   347 		TInt extCount = 0;
   377 		for ( TInt i = pluginInfoCount; --i >= 0; )
   348 		for ( TInt i = pluginInfoCount; --i >= 0; )
   378 			{
   349 			{
   379 			CHarvesterPluginInfo* info = iHarvesterPluginInfoArray[i];
   350 			CHarvesterPluginInfo* info = iHarvesterPluginInfoArray[i];
   383 				TDesC* ext = info->iExtensions[k];
   354 				TDesC* ext = info->iExtensions[k];
   384 				// checking against supported plugin file extensions
   355 				// checking against supported plugin file extensions
   385 				TInt result = MdsUtils::Compare( *ext, extPtr );
   356 				TInt result = MdsUtils::Compare( *ext, extPtr );
   386 				if ( result == 0 )
   357 				if ( result == 0 )
   387 					{
   358 					{
       
   359                     delete iLastConfirmedSupportedExt;
       
   360                     iLastConfirmedSupportedExt = NULL;
       
   361                     iLastConfirmedSupportedExt = extPtr.Alloc();				    
   388 					return ETrue;
   362 					return ETrue;
   389 					}
   363 					}
   390 				}
   364 				}
   391 			}
   365 			}
   392 		}
   366 		}
   398 	TBool isContainerFile = EFalse;
   372 	TBool isContainerFile = EFalse;
   399 	TPtrC extPtr;
   373 	TPtrC extPtr;
   400 	
   374 	
   401 	if( MdsUtils::GetExt( aURI, extPtr ) )
   375 	if( MdsUtils::GetExt( aURI, extPtr ) )
   402 		{
   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 	
   403 		RPointerArray<CHarvesterPluginInfo> supportedPlugins;
   385 		RPointerArray<CHarvesterPluginInfo> supportedPlugins;
   404 		CleanupClosePushL( supportedPlugins );
   386 		CleanupClosePushL( supportedPlugins );
   405 		GetSupportedPluginsL( supportedPlugins, extPtr );
   387 		GetSupportedPluginsL( supportedPlugins, extPtr );
   406 		for( TInt i = supportedPlugins.Count() - 1; i >=0; i-- )
   388 		for( TInt i = supportedPlugins.Count() - 1; i >=0; i-- )
   407 			{
   389 			{
   408 			CHarvesterPluginInfo* info = supportedPlugins[i];
   390 			CHarvesterPluginInfo* info = supportedPlugins[i];
   409 			if( info->iObjectTypes.Count() >  1 )
   391 			if( info->iObjectTypes.Count() >  1 )
   410 				{
   392 				{
   411 				isContainerFile = ETrue;
   393 				isContainerFile = ETrue;
       
   394 				delete iLastConfirmedContainerExt;
       
   395 				iLastConfirmedContainerExt = NULL;
       
   396 				iLastConfirmedContainerExt = extPtr.Alloc();
   412 				break;
   397 				break;
   413 				}
   398 				}
   414 			}
   399 			}
   415 		CleanupStack::PopAndDestroy( &supportedPlugins );
   400 		CleanupStack::PopAndDestroy( &supportedPlugins );
   416 		}
   401 		}
   435         }
   420         }
   436     }
   421     }
   437 
   422 
   438 EXPORT_C void CHarvesterPluginFactory::SendHarvestingStatusEventL( TBool aStarted )
   423 EXPORT_C void CHarvesterPluginFactory::SendHarvestingStatusEventL( TBool aStarted )
   439     {
   424     {
       
   425     WRITELOG( "CHarvesterPluginFactory::SendHarvestingStatusEventL" );
   440     const TInt pluginInfoCount = iHarvesterPluginInfoArray.Count();
   426     const TInt pluginInfoCount = iHarvesterPluginInfoArray.Count();
   441     TBool itemsLeft( EFalse );
   427     TBool itemsLeft( EFalse );
   442     TBool allPluginsOnIdle( ETrue );
   428     TBool allPluginsOnIdle( ETrue );
   443     for ( TInt i = pluginInfoCount; --i >= 0; )
   429     for ( TInt i = pluginInfoCount; --i >= 0; )
   444         {
   430         {
   458             }
   444             }
   459         }
   445         }
   460     
   446     
   461     if( !iHarvesting && itemsLeft && aStarted )
   447     if( !iHarvesting && itemsLeft && aStarted )
   462         {
   448         {
       
   449         WRITELOG( "CHarvesterPluginFactory::SendHarvestingStatusEventL - overall started" );
   463         iHarvesting = ETrue;
   450         iHarvesting = ETrue;
   464         iHarvesterEventManager->SendEventL( EHEObserverTypeOverall, EHEStateStarted );
   451         iHarvesterEventManager->SendEventL( EHEObserverTypeOverall, EHEStateStarted );
   465         // 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
   466         // after harvesting has already started
   453         // after harvesting has already started
   467         iHarvesterEventManager->IncreaseItemCount( EHEObserverTypeOverall, KCacheItemCountForEventCaching );
   454         iHarvesterEventManager->IncreaseItemCount( EHEObserverTypeOverall, KCacheItemCountForEventCaching );
   468         return;
   455         return;
   469         }
   456         }
   470     else if( iHarvesting && (!itemsLeft || allPluginsOnIdle) && !aStarted )
   457     else if( iHarvesting && (!itemsLeft || allPluginsOnIdle) && !aStarted )
   471         {
   458         {
       
   459         WRITELOG( "CHarvesterPluginFactory::SendHarvestingStatusEventL - overall finished" );
   472         iHarvesting = EFalse;                       
   460         iHarvesting = EFalse;                       
   473         iHarvesterEventManager->SendEventL( EHEObserverTypeOverall, EHEStateFinished );
   461         iHarvesterEventManager->SendEventL( EHEObserverTypeOverall, EHEStateFinished );
   474         iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeOverall, KCacheItemCountForEventCaching );
   462         iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeOverall, KCacheItemCountForEventCaching );
   475         }
   463         }
   476     }
   464     }
   480     const TInt count = iHarvesterPluginInfoArray.Count();
   468     const TInt count = iHarvesterPluginInfoArray.Count();
   481     for ( TInt i = count; --i >= 0; )
   469     for ( TInt i = count; --i >= 0; )
   482         {
   470         {
   483         if( iHarvesterPluginInfoArray[i]->iPlugin && aPaused )
   471         if( iHarvesterPluginInfoArray[i]->iPlugin && aPaused )
   484             {
   472             {
   485             iHarvesterPluginInfoArray[i]->iPlugin->Cancel();
   473             iHarvesterPluginInfoArray[i]->iPlugin->StopHarvest();
   486             }
   474             }
   487         else if( iHarvesterPluginInfoArray[i]->iPlugin )
   475         else if( iHarvesterPluginInfoArray[i]->iPlugin )
   488             {
   476             {
   489             iHarvesterPluginInfoArray[i]->iPlugin->StartHarvest();
   477             iHarvesterPluginInfoArray[i]->iPlugin->StartHarvest();
   490             }
   478             }
   491         }
   479         }
   492     }
   480     }
   493 
   481 
       
   482 EXPORT_C void CHarvesterPluginFactory::GetObjectDefL( CHarvesterData* aHD, TDes& aObjectDef )
       
   483     {
       
   484     TPtrC extPtr;
       
   485     if( MdsUtils::GetExt( aHD->Uri(), extPtr ) )
       
   486         {
       
   487         RPointerArray<CHarvesterPluginInfo> supportedPlugins;
       
   488         CleanupClosePushL( supportedPlugins );
       
   489         GetSupportedPluginsL( supportedPlugins, extPtr );
       
   490         
       
   491         const TInt sCount = supportedPlugins.Count();
       
   492         if( sCount == 1 )
       
   493             {
       
   494             CHarvesterPluginInfo* info = supportedPlugins[0];
       
   495             if( info->iObjectTypes.Count() == 1 )
       
   496                 {
       
   497                 aObjectDef.Copy( *(info->iObjectTypes[0]) );
       
   498                 aHD->SetHarvesterPluginInfo( info );
       
   499                 CleanupStack::PopAndDestroy( &supportedPlugins );
       
   500                 return;
       
   501                 }
       
   502             }
       
   503         for( TInt i = sCount - 1; i >=0; i-- )
       
   504             {
       
   505             CHarvesterPluginInfo* info = supportedPlugins[i];
       
   506             if ( !(info->iPlugin) )
       
   507                 {
       
   508                 info->iPlugin = CHarvesterPlugin::NewL( info->iPluginUid );
       
   509                 info->iPlugin->SetQueue( info->iQueue );
       
   510                 info->iPlugin->SetHarvesterPluginFactory( *this );  
       
   511                 info->iPlugin->SetBlacklist( *iBlacklist );
       
   512                 }
       
   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
       
   516             if( aHD && aObjectDef.Length() > 0 )
       
   517                 {
       
   518                 aHD->SetHarvesterPluginInfo( info );
       
   519                 break;
       
   520                 }
       
   521             else if( !aHD )
       
   522                 {
       
   523                 break;
       
   524                 }
       
   525             }
       
   526         CleanupStack::PopAndDestroy( &supportedPlugins );
       
   527         }
       
   528     else
       
   529         {
       
   530         aObjectDef.Zero();
       
   531         }
       
   532     }
       
   533 
       
   534