harvester/common/src/harvesterpluginfactory.cpp
branchRCL_3
changeset 8 6752808b2036
parent 0 c53acadfccc6
child 15 3cebc1a84278
equal deleted inserted replaced
3:b73a2e62868f 8:6752808b2036
    20 #include <e32std.h>
    20 #include <e32std.h>
    21 #include <apmrec.h>
    21 #include <apmrec.h>
    22 #include <harvesterplugin.h>
    22 #include <harvesterplugin.h>
    23 #include <mdeobject.h>
    23 #include <mdeobject.h>
    24 #include <harvesterdata.h>
    24 #include <harvesterdata.h>
    25 
    25 #include "harvestereventmanager.h"
    26 #include "harvesterpluginfactory.h"
    26 #include "harvesterpluginfactory.h"
    27 #include "harvesterplugininfo.h"
    27 #include "harvesterplugininfo.h"
    28 #include "mdsutils.h"
    28 #include "mdsutils.h"
    29 #include "harvesterlog.h"
    29 #include "harvesterlog.h"
    30 
    30 
       
    31 const TInt KCacheItemCountForEventCaching = 1;
       
    32 
    31 // ---------------------------------------------------------------------------
    33 // ---------------------------------------------------------------------------
    32 // Constructor
    34 // Constructor
    33 // ---------------------------------------------------------------------------
    35 // ---------------------------------------------------------------------------
    34 //
    36 //
    35 CHarvesterPluginFactory::CHarvesterPluginFactory() :
    37 CHarvesterPluginFactory::CHarvesterPluginFactory() :
    36     iBlacklist( NULL )
    38     iBlacklist( NULL ),
       
    39     iHarvesting( NULL ),
       
    40     iHarvesterEventManager( NULL )
    37 	{
    41 	{
    38 	WRITELOG( "CHarvesterPluginFactory::CHarvesterPluginFactory()" );
    42 	WRITELOG( "CHarvesterPluginFactory::CHarvesterPluginFactory()" );
    39 	}
    43 	}
    40 
    44 
    41 // ---------------------------------------------------------------------------
    45 // ---------------------------------------------------------------------------
    58 // ---------------------------------------------------------------------------
    62 // ---------------------------------------------------------------------------
    59 //
    63 //
    60 CHarvesterPluginFactory::~CHarvesterPluginFactory()
    64 CHarvesterPluginFactory::~CHarvesterPluginFactory()
    61 	{
    65 	{
    62 	WRITELOG( "CHarvesterPluginFactory::~CHarvesterPluginFactory()" );
    66 	WRITELOG( "CHarvesterPluginFactory::~CHarvesterPluginFactory()" );
       
    67 	
       
    68     if (iHarvesterEventManager)
       
    69         {
       
    70         iHarvesterEventManager->ReleaseInstance();
       
    71         }
       
    72 	
    63 	iHarvesterPluginInfoArray.ResetAndDestroy();
    73 	iHarvesterPluginInfoArray.ResetAndDestroy();
    64 	iHarvesterPluginInfoArray.Close();
    74 	iHarvesterPluginInfoArray.Close();
    65 	REComSession::FinalClose();
    75 	REComSession::FinalClose();
    66 	}
    76 	}
    67 
    77 
    70 // ---------------------------------------------------------------------------
    80 // ---------------------------------------------------------------------------
    71 //
    81 //
    72 void CHarvesterPluginFactory::ConstructL()
    82 void CHarvesterPluginFactory::ConstructL()
    73 	{
    83 	{
    74 	WRITELOG( "CHarvesterPluginFactory::ConstructL()" );
    84 	WRITELOG( "CHarvesterPluginFactory::ConstructL()" );
       
    85 	iHarvesterEventManager = CHarvesterEventManager::GetInstanceL();
    75 	SetupHarvesterPluginInfoL();
    86 	SetupHarvesterPluginInfoL();
    76 	}
    87 	}
    77 
    88 
    78 // ---------------------------------------------------------------------------
    89 // ---------------------------------------------------------------------------
    79 // GetObjectDef
    90 // GetObjectDef
   105 			CHarvesterPluginInfo* info = supportedPlugins[i];
   116 			CHarvesterPluginInfo* info = supportedPlugins[i];
   106 			if ( !(info->iPlugin) )
   117 			if ( !(info->iPlugin) )
   107 				{
   118 				{
   108 				info->iPlugin = CHarvesterPlugin::NewL( info->iPluginUid );
   119 				info->iPlugin = CHarvesterPlugin::NewL( info->iPluginUid );
   109 				info->iPlugin->SetQueue( info->iQueue );
   120 				info->iPlugin->SetQueue( info->iQueue );
       
   121 				info->iPlugin->SetHarvesterPluginFactory( *this );  
       
   122 				info->iPlugin->SetBlacklist( *iBlacklist );
   110 				}
   123 				}
   111 			info->iPlugin->GetObjectType( aHD.Uri(), aObjectDef );
   124 			info->iPlugin->GetObjectType( aHD.Uri(), aObjectDef );
   112 			if( aObjectDef.Length() > 0 )
   125 			if( aObjectDef.Length() > 0 )
   113 				{
   126 				{
   114 				aHD.SetHarvesterPluginInfo( info );
   127 				aHD.SetHarvesterPluginInfo( info );
   125 	
   138 	
   126 // ---------------------------------------------------------------------------
   139 // ---------------------------------------------------------------------------
   127 // GetMimeType
   140 // GetMimeType
   128 // ---------------------------------------------------------------------------
   141 // ---------------------------------------------------------------------------
   129 //
   142 //
   130 EXPORT_C void CHarvesterPluginFactory::GetMimeType(const TDesC& /*aUri*/, TDes& aMimeType)
   143 EXPORT_C void CHarvesterPluginFactory::GetMimeType(const TDesC& aUri, TDes& aMimeType)
   131 	{
   144 	{
   132 	_LIT( KJPGMimeType, "image/jpeg" );
   145     TPtrC extPtr;
   133 	aMimeType.Copy( KJPGMimeType );
   146     if( MdsUtils::GetExt( aUri, extPtr ) )
       
   147         {
       
   148         RPointerArray<CHarvesterPluginInfo> supportedPlugins;
       
   149         TRAP_IGNORE( GetSupportedPluginsL( supportedPlugins, extPtr ) );
       
   150         
       
   151         const TInt sCount = supportedPlugins.Count();
       
   152         for( TInt i = 0; i < sCount; i++ )
       
   153             {
       
   154             CHarvesterPluginInfo* info = supportedPlugins[i];
       
   155             if ( !(info->iPlugin) )
       
   156                 {
       
   157                 TRAPD( error, info->iPlugin = CHarvesterPlugin::NewL( info->iPluginUid ) );
       
   158                 if( error != KErrNone )
       
   159                     {
       
   160                     aMimeType.Zero();
       
   161                     return;
       
   162                     }
       
   163                 info->iPlugin->SetQueue( info->iQueue );
       
   164                 info->iPlugin->SetHarvesterPluginFactory( *this );  
       
   165                 info->iPlugin->SetBlacklist( *iBlacklist );
       
   166                 }
       
   167                 info->iPlugin->GetMimeType( aUri, aMimeType );
       
   168                 if( aMimeType.Length() > 0 )
       
   169                     {
       
   170                     break;
       
   171                     }
       
   172             }
       
   173         supportedPlugins.Close();
       
   174         }
       
   175     else
       
   176         {
       
   177         aMimeType.Zero();
       
   178         }
   134 	}
   179 	}
   135 
   180 
   136 // ---------------------------------------------------------------------------
   181 // ---------------------------------------------------------------------------
   137 // HarvestL
   182 // HarvestL
   138 // ---------------------------------------------------------------------------
   183 // ---------------------------------------------------------------------------
   141 	{
   186 	{
   142 #ifdef _DEBUG
   187 #ifdef _DEBUG
   143 	WRITELOG1("CHarvesterPluginFactory::HarvestL - aHD->Uri: %S", &aHD->Uri() );
   188 	WRITELOG1("CHarvesterPluginFactory::HarvestL - aHD->Uri: %S", &aHD->Uri() );
   144 #endif
   189 #endif
   145 	CHarvesterPluginInfo* hpi = aHD->HarvesterPluginInfo();
   190 	CHarvesterPluginInfo* hpi = aHD->HarvesterPluginInfo();
   146 		
   191 	
       
   192 	if( !hpi )
       
   193 	    {
       
   194 	    SetPluginInfo( aHD );
       
   195 	    hpi = aHD->HarvesterPluginInfo();
       
   196 	    }
       
   197 	
   147 	if ( hpi )
   198 	if ( hpi )
   148 		{
   199 		{
   149 		if ( ! hpi->iPlugin )
   200 		if ( ! hpi->iPlugin )
   150 	   		{
   201 	   		{
   151 	   		hpi->iPlugin = CHarvesterPlugin::NewL( hpi->iPluginUid );
   202 	   		hpi->iPlugin = CHarvesterPlugin::NewL( hpi->iPluginUid );
   152 	   		hpi->iPlugin->SetQueue( hpi->iQueue );
   203 	   		hpi->iPlugin->SetQueue( hpi->iQueue );
       
   204 	   		hpi->iPlugin->SetHarvesterPluginFactory( *this );  
   153 	   		hpi->iPlugin->SetBlacklist( *iBlacklist );
   205 	   		hpi->iPlugin->SetBlacklist( *iBlacklist );
   154 	   		}
   206 	   		}
   155 			
   207 			
   156 		if( aHD->ObjectType() == EFastHarvest || aHD->Origin() == MdeConstants::Object::ECamera )
   208 		if( aHD->ObjectType() == EFastHarvest || aHD->Origin() == MdeConstants::Object::ECamera )
   157 		   	{
   209 		   	{
   158 		   	hpi->iQueue.Insert( aHD, 0 );
   210 		   	hpi->iQueue.Insert( aHD, 0 );
   159 		    	}
   211 		   	if( !hpi->iPlugin->IsActive() )
       
   212 		   	    {
       
   213 	            hpi->iPlugin->SetPriority( KHarvesterPriorityHarvestingPlugin + 2 );
       
   214 		   	    }
       
   215 		    }
   160 	    else
   216 	    else
   161 			{
   217 			{
   162 			hpi->iQueue.AppendL( aHD );
   218 			hpi->iQueue.AppendL( aHD );
   163 			}
   219 			}
   164 		    
   220 		    
   268     
   324     
   269     pluginInfo->iPluginUid = aPluginUid;
   325     pluginInfo->iPluginUid = aPluginUid;
   270     
   326     
   271     // Load plugin
   327     // Load plugin
   272     pluginInfo->iPlugin = CHarvesterPlugin::NewL( pluginInfo->iPluginUid );
   328     pluginInfo->iPlugin = CHarvesterPlugin::NewL( pluginInfo->iPluginUid );
   273     pluginInfo->iPlugin->SetQueue( pluginInfo->iQueue );    
   329     pluginInfo->iPlugin->SetQueue( pluginInfo->iQueue );
       
   330     pluginInfo->iPlugin->SetHarvesterPluginFactory( *this );  
   274     
   331     
   275     iHarvesterPluginInfoArray.AppendL( pluginInfo );
   332     iHarvesterPluginInfoArray.AppendL( pluginInfo );
   276     CleanupStack::Pop( pluginInfo );
   333     CleanupStack::Pop( pluginInfo );
   277     }
   334     }
   278 
   335 
   279 void CHarvesterPluginFactory::GetSupportedPluginsL(
   336 void CHarvesterPluginFactory::GetSupportedPluginsL(
   280 		RPointerArray<CHarvesterPluginInfo>& aSupportedPlugins, const TDesC& aExt )
   337 		RPointerArray<CHarvesterPluginInfo>& aSupportedPlugins, const TDesC& aExt )
   281 	{
   338 	{
   282 	TInt pluginInfoCount = iHarvesterPluginInfoArray.Count();
   339 	const TInt pluginInfoCount = iHarvesterPluginInfoArray.Count();
   283 	TInt extCount = 0;
   340 	TInt extCount = 0;
   284 	for ( TInt i = pluginInfoCount; --i >= 0; )
   341 	for ( TInt i = pluginInfoCount; --i >= 0; )
   285         {
   342         {
   286         CHarvesterPluginInfo* info = iHarvesterPluginInfoArray[i];
   343         CHarvesterPluginInfo* info = iHarvesterPluginInfoArray[i];
   287         
   344         
   349 			}
   406 			}
   350 		CleanupStack::PopAndDestroy( &supportedPlugins );
   407 		CleanupStack::PopAndDestroy( &supportedPlugins );
   351 		}
   408 		}
   352 	return isContainerFile;
   409 	return isContainerFile;
   353 	}
   410 	}
       
   411 
       
   412 void CHarvesterPluginFactory::SetPluginInfo( CHarvesterData* aHD )
       
   413     {
       
   414     TPtrC extPtr;
       
   415     if( MdsUtils::GetExt( aHD->Uri(), extPtr ) )
       
   416         {
       
   417         RPointerArray<CHarvesterPluginInfo> supportedPlugins;
       
   418         TRAP_IGNORE( GetSupportedPluginsL( supportedPlugins, extPtr ) );
       
   419         
       
   420         if( supportedPlugins.Count() > 0 )
       
   421             {
       
   422             CHarvesterPluginInfo* info = supportedPlugins[0];
       
   423             aHD->SetHarvesterPluginInfo( info );
       
   424             }
       
   425 
       
   426         supportedPlugins.Close();
       
   427         }
       
   428     }
       
   429 
       
   430 EXPORT_C void CHarvesterPluginFactory::SendHarvestingStatusEventL( TBool aStarted )
       
   431     {
       
   432     const TInt pluginInfoCount = iHarvesterPluginInfoArray.Count();
       
   433     TBool itemsLeft( EFalse );
       
   434     for ( TInt i = pluginInfoCount; --i >= 0; )
       
   435         {
       
   436         CHarvesterPluginInfo* info = iHarvesterPluginInfoArray[i];
       
   437         if( info && info->iQueue.Count() )
       
   438             {
       
   439             itemsLeft = ETrue;
       
   440             break;
       
   441             }
       
   442         }
       
   443     
       
   444     if( !iHarvesting && itemsLeft && aStarted )
       
   445         {
       
   446         iHarvesting = ETrue;
       
   447         iHarvesterEventManager->SendEventL( EHEObserverTypeOverall, EHEStateStarted );
       
   448         // This next line is for caching the harvester started event for observers registering
       
   449         // after harvesting has already started
       
   450         iHarvesterEventManager->IncreaseItemCount( EHEObserverTypeOverall, KCacheItemCountForEventCaching );
       
   451         return;
       
   452         }
       
   453     else if( iHarvesting && !itemsLeft && !aStarted )
       
   454         {
       
   455         iHarvesting = EFalse;                       
       
   456         iHarvesterEventManager->SendEventL( EHEObserverTypeOverall, EHEStateFinished );
       
   457         iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeOverall, KCacheItemCountForEventCaching );
       
   458         }
       
   459     }
       
   460