harvester/harvesterserver/src/cindexingmanager.cpp
branchGCC_SURGE
changeset 12 e3bafe42f98a
parent 9 d575fd691cf9
child 19 e3c09e9691e0
equal deleted inserted replaced
6:8b3b4d191198 12:e3bafe42f98a
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <f32file.h>
    18 #include <f32file.h>
    19 #include <s32file.h>
    19 #include <s32file.h>
       
    20 #include <centralrepository.h>
    20 #include "CIndexingManager.h"
    21 #include "CIndexingManager.h"
    21 #include "HarvesterServerLogger.h"
    22 #include "HarvesterServerLogger.h"
    22 #include "CBlacklistMgr.h"
    23 #include "CBlacklistMgr.h"
    23 #include "contentinfomgr.h"
    24 #include "contentinfomgr.h"
    24 #include "ccontentinfo.h"
    25 #include "ccontentinfo.h"
    46 // default difference in RunL calls with additional buffer.
    47 // default difference in RunL calls with additional buffer.
    47 const TInt KMaxTimeDifference = 1 + KDefaultWaitTimeInMinutes;
    48 const TInt KMaxTimeDifference = 1 + KDefaultWaitTimeInMinutes;
    48 //constants for enable and disable status
    49 //constants for enable and disable status
    49 const TInt KEnable = 1;
    50 const TInt KEnable = 1;
    50 const TInt KDisable = 0;
    51 const TInt KDisable = 0;
       
    52 //Uid of Harvester server cetral repository database
       
    53 const TUid KCPIXHSrepoUidMenu = {0x2001f6fb};
       
    54 
       
    55 //Length of uid string in cenrep
       
    56 const TInt KCenrepUidLength = 8;
    51 // -----------------------------------------------------------------------------
    57 // -----------------------------------------------------------------------------
    52 // CHarvesterServer::NewL()
    58 // CHarvesterServer::NewL()
    53 // -----------------------------------------------------------------------------
    59 // -----------------------------------------------------------------------------
    54 //
    60 //
    55 CIndexingManager* CIndexingManager::NewL()
    61 CIndexingManager* CIndexingManager::NewL()
   132 	
   138 	
   133 	//instantiate blacklist database
   139 	//instantiate blacklist database
   134 	iBlacklistMgr = CBlacklistMgr::NewL();
   140 	iBlacklistMgr = CBlacklistMgr::NewL();
   135 	//Instantiate Contentinfo manager
   141 	//Instantiate Contentinfo manager
   136 	iContentInfoMgr = CContentInfoMgr::NewL();
   142 	iContentInfoMgr = CContentInfoMgr::NewL();
       
   143 	
       
   144 	UpdateDontloadListL();
   137 
   145 
   138 	// Load plugins
   146 	// Load plugins
   139 	LoadPluginsL();
   147 	LoadPluginsL();
   140 	
   148 	
   141 	//release the Blacklist manager as the blacklist functionality is done
   149 	//release the Blacklist manager as the blacklist functionality is done
   298 // CIndexingManager::LoadPluginsL()
   306 // CIndexingManager::LoadPluginsL()
   299 // -----------------------------------------------------------------------------
   307 // -----------------------------------------------------------------------------
   300 //
   308 //
   301 void CIndexingManager::LoadPluginsL()
   309 void CIndexingManager::LoadPluginsL()
   302 	{
   310 	{
       
   311     OstTraceFunctionEntry0( CINDEXINGMANAGER_LOADPLUGINSL_ENTRY );
   303     RImplInfoPtrArray infoArray;    
   312     RImplInfoPtrArray infoArray;    
   304     TCleanupItem cleanupItem( CPixSearchECom::CleanupEComArray, &infoArray );
   313     TCleanupItem cleanupItem( CPixSearchECom::CleanupEComArray, &infoArray );
   305     CleanupStack::PushL( cleanupItem );
   314     CleanupStack::PushL( cleanupItem );
   306     
   315     
   307     CIndexingPlugin::ListImplementationsL( infoArray );
   316     CIndexingPlugin::ListImplementationsL( infoArray );
   308     TInt count( 0 );
   317     TInt count( 0 );
   309     count = infoArray.Count();
   318     count = infoArray.Count();
   310     
       
   311     //FFLOGSTRING2( "CFastFindHarvesterPluginControl:: PLUGINS COUNT %d", count );
       
   312     CIndexingPlugin* plugin = NULL;
       
   313     
   319     
   314     TInt contentcount(iContentInfoMgr->GetContentCountL() );
   320     TInt contentcount(iContentInfoMgr->GetContentCountL() );
   315     // If the content count in the content info DB is not equal to the plugin count, reset the content info DB
   321     // If the content count in the content info DB is not equal to the plugin count, reset the content info DB
   316     if ( contentcount != count)
   322     if ( contentcount != count)
   317         iContentInfoMgr->ResetL();
   323         iContentInfoMgr->ResetL();
   318     
   324     
       
   325     CContentInfo* contentinfo = CContentInfo::NewL();
       
   326     
   319     for ( TInt i = 0; i < count; i++ )
   327     for ( TInt i = 0; i < count; i++ )
   320         {
   328         {
   321         TUid uid = infoArray[i]->ImplementationUid();    // Create the plug-ins
   329         TUid uid = infoArray[i]->ImplementationUid();    // Create the plug-ins
   322         TInt version = infoArray[i]->Version();
   330         TInt version = infoArray[i]->Version();
   323         //FFLOGSTRING2( "CFastFindHarvesterPluginControl:: PLUGINS UID %x", uid );
   331         //Update the details of the plugin in Contentinfo DB
   324         plugin = NULL;
   332         UpdateContentInfoDbL( infoArray[i]->DisplayName(), contentinfo );
   325         TBool pluginblacklisted = EFalse;
   333         //Get the load status of the plugin.
       
   334         TBool pluginloadstatus = GetPluginLoadStatusL ( uid, version, infoArray[i]->DisplayName() );        
   326         
   335         
   327         pluginblacklisted = iBlacklistMgr->FindL( uid , version );
   336         if ( pluginloadstatus )
   328         
       
   329         TBool iscontentfound = iContentInfoMgr->FindL( infoArray[i]->DisplayName() );
       
   330         
       
   331         if( !iscontentfound )
       
   332             {
   337             {
   333             //Add the content details to database
   338             LoadHarvesterpluginL (uid, version, infoArray[i]->DisplayName() );//Load the harvester plugin
   334             CContentInfo* contentinfo = CContentInfo::NewL();
       
   335             contentinfo->SetNameL( infoArray[i]->DisplayName() );
       
   336             contentinfo->SetBlacklistStatus( KEnable );
       
   337             contentinfo->SetIndexStatus( KEnable );
       
   338             iContentInfoMgr->AddL( contentinfo );
       
   339             delete contentinfo;
       
   340             }
   339             }
   341         else
   340         }
   342             {
   341     delete contentinfo;
   343             iContentInfoMgr->UpdateBlacklistStatusL( infoArray[i]->DisplayName() , KEnable );
   342     CleanupStack::PopAndDestroy( &infoArray ); // infoArray, results in a call to CleanupEComArray    
   344             }
   343 	OstTraceFunctionExit0( CINDEXINGMANAGER_LOADPLUGINSL_EXIT );
   345         
       
   346         if ( !pluginblacklisted )
       
   347             {
       
   348             // Plugin is not black listed. Add it to database and try to load the plugin
       
   349             iBlacklistMgr->AddL( uid , version );
       
   350             OstTrace1( TRACE_NORMAL, CINDEXINGMANAGER_LOADPLUGINSL, "CIndexingManager::LoadPluginsL;Plugin with uid=%x is added to DB", uid.iUid );
       
   351             CPIXLOGSTRING2("CIndexingManager::LoadPluginsL(): Plugin with uid = %x is added to database", uid.iUid);
       
   352             TRAPD( err, plugin = CIndexingPlugin::NewL( uid ) );
       
   353             //FFLOGSTRING2( "CFastFindHarvesterPluginControl:: ERROR %d", err );
       
   354             if ( err == KErrNone )
       
   355                 {
       
   356                 // Plugin loaded succesfully. Remove it from the database
       
   357                 iBlacklistMgr->Remove(uid);
       
   358                 OstTrace1( TRACE_NORMAL, DUP1_CINDEXINGMANAGER_LOADPLUGINSL, "CIndexingManager::LoadPluginsL;Plugin with uid=%x is removed from DB", uid.iUid );
       
   359                 CPIXLOGSTRING2("CIndexingManager::LoadPluginsL(): Plugin with uid = %x is removed from database", uid.iUid);
       
   360                 iContentInfoMgr->UpdateBlacklistStatusL( infoArray[i]->DisplayName() , KDisable );
       
   361                 CleanupStack::PushL( plugin );
       
   362                 plugin->SetObserver( *this );
       
   363                 plugin->SetSearchSession( iSearchSession );
       
   364                 iPluginArray.AppendL( plugin ); // and add them to array
       
   365                 CleanupStack::Pop( plugin );
       
   366                 OstTrace1( TRACE_NORMAL, DUP2_CINDEXINGMANAGER_LOADPLUGINSL, "CIndexingManager::LoadPluginsL;Plugin with uid=%x is loaded successfully", uid.iUid );
       
   367                 CPIXLOGSTRING2("CIndexingManager::LoadPluginsL(): Plugin with uid = %x is loaded succesfully", uid.iUid);
       
   368                 }
       
   369             }
       
   370         }    
       
   371     CleanupStack::PopAndDestroy( &infoArray ); // infoArray, results in a call to CleanupEComArray
       
   372     //FFLOGSTRING( "CFastFindHarvesterPluginControl::LoadPluginsL() plugin!" );    
       
   373     
       
   374 	}
   344 	}
   375 
   345 
   376 // -----------------------------------------------------------------------------
   346 // -----------------------------------------------------------------------------
   377 // CIndexingManager::StartPlugins()
   347 // CIndexingManager::StartPlugins()
   378 // -----------------------------------------------------------------------------
   348 // -----------------------------------------------------------------------------
   612 	// Commit and cleanup
   582 	// Commit and cleanup
   613 	wr.CommitL();
   583 	wr.CommitL();
   614 	CleanupStack::PopAndDestroy(2, &file);
   584 	CleanupStack::PopAndDestroy(2, &file);
   615 }
   585 }
   616 
   586 
       
   587 // -----------------------------------------------------------------------------
       
   588 // CIndexingManager::UpdateContentInfoDbL()
       
   589 // -----------------------------------------------------------------------------
       
   590 //
       
   591 void CIndexingManager::UpdateContentInfoDbL( const TDesC& aPluginName, CContentInfo* aContentinfo)
       
   592 {
       
   593     OstTraceFunctionEntry0( CINDEXINGMANAGER_UPDATECONTENTINFODBL_ENTRY );
       
   594     TBool iscontentfound = iContentInfoMgr->FindL( aPluginName );
       
   595             
       
   596     if( !iscontentfound )
       
   597         {
       
   598         //Add the content details to database
       
   599         aContentinfo->SetNameL( aPluginName );
       
   600         aContentinfo->SetBlacklistStatus( KEnable );
       
   601         aContentinfo->SetIndexStatus( KEnable );
       
   602         iContentInfoMgr->AddL( aContentinfo );
       
   603         
       
   604         }
       
   605     else
       
   606         {
       
   607         iContentInfoMgr->UpdateBlacklistStatusL( aPluginName , KEnable );
       
   608         }
       
   609     OstTraceFunctionExit0( CINDEXINGMANAGER_UPDATECONTENTINFODBL_EXIT );
       
   610 }
       
   611 
       
   612 // -----------------------------------------------------------------------------
       
   613 // CIndexingManager::UpdateDontloadListL()
       
   614 // -----------------------------------------------------------------------------
       
   615 //
       
   616 void CIndexingManager::UpdateDontloadListL()
       
   617     {
       
   618     OstTraceFunctionEntry0( CINDEXINGMANAGER_UPDATEDONTLOADLISTL_ENTRY );
       
   619     CPIXLOGSTRING("CIndexingManager::UpdateDontloadList : Start");
       
   620     //Read the list of Uid's from the cenrep and update blacklist database
       
   621     //Open the unload list common repository
       
   622     CRepository* unloadrepo = NULL;
       
   623     TRAPD( cerror , unloadrepo = CRepository::NewL( KCPIXHSrepoUidMenu ));
       
   624     if ( cerror != KErrNone)
       
   625         return;
       
   626     RArray<TUint32> uidlist;    
       
   627     //Read all the key list
       
   628     //Matches occur whenever (key & mask) == (partialKey & mask). 
       
   629     //The partial key is guaranteed to be masked before use
       
   630     // To fetch all the keys we have done masking with '0'
       
   631     TInt error = unloadrepo->FindL( 0, 0, uidlist);
       
   632     if ( error == KErrNone )
       
   633         {
       
   634         TBuf<KCenrepUidLength> temp;
       
   635         //get the Uid of each and every plugin and add it to blacklist database
       
   636         TInt count = uidlist.Count();
       
   637         for (int i = 0; i < count; i++ )
       
   638             {
       
   639             TUid uid;
       
   640             TInt64 value;
       
   641             unloadrepo->Get( uidlist[i], temp );
       
   642             TLex uidvalue(temp);
       
   643             TInt xerr = uidvalue.Val( value,EHex );
       
   644             uid.iUid = value;
       
   645             (void)iBlacklistMgr->AddtoDontloadListL( uid );            
       
   646             }
       
   647         }
       
   648     CPIXLOGSTRING("CIndexingManager::UpdateDontloadList : End");
       
   649     OstTraceFunctionExit0( CINDEXINGMANAGER_UPDATEDONTLOADLISTL_EXIT );
       
   650     }
       
   651 
       
   652 // -----------------------------------------------------------------------------
       
   653 // CIndexingManager::GetPluginLoadStatus()
       
   654 // -----------------------------------------------------------------------------
       
   655 //
       
   656 TBool CIndexingManager::GetPluginLoadStatusL (TUid aPluginUid, TInt aVersion, const TDesC& aPluginName)
       
   657     {
       
   658     OstTraceFunctionEntry0( DUP1_CINDEXINGMANAGER_GETPLUGINLOADSTATUSL_ENTRY );
       
   659     //status of plugin in blacklist table
       
   660     TBool pluginblacklisted = iBlacklistMgr->FindL( aPluginUid, aVersion);
       
   661     //status of plugin in unload table
       
   662     TBool loadstatus =  iBlacklistMgr->FindInDontloadListL( aPluginUid );  
       
   663     //Check the Uid in both the tables of the blacklist db 
       
   664 //    if ( loadstatus || pluginblacklisted )
       
   665 //        loadplugin = EFalse;
       
   666     
       
   667     if ( loadstatus )
       
   668         {
       
   669         //Found in unload list.Update the indexing and blacklist status in contentinfo DB
       
   670         iContentInfoMgr->UpdatePluginIndexStatusL( aPluginName , KDisable );
       
   671         iContentInfoMgr->UpdateBlacklistStatusL( aPluginName , KDisable );
       
   672         }
       
   673     if ( pluginblacklisted )
       
   674         //Update the blacklist status in content info db
       
   675         iContentInfoMgr->UpdateBlacklistStatusL( aPluginName , KEnable );
       
   676     
       
   677     return (! (loadstatus | pluginblacklisted));
       
   678     }
       
   679 
       
   680 // -----------------------------------------------------------------------------
       
   681 // CIndexingManager::GetPluginLoadStatus()
       
   682 // -----------------------------------------------------------------------------
       
   683 //
       
   684 void CIndexingManager::LoadHarvesterpluginL (TUid aPluginUid, TInt aVersion, const TDesC& aPluginName)
       
   685     {
       
   686     OstTraceFunctionEntry0( CINDEXINGMANAGER_LOADHARVESTERPLUGINL_ENTRY );
       
   687     CIndexingPlugin* plugin = NULL;
       
   688     // Plugin is not black listed. Add it to blacklist database
       
   689     iBlacklistMgr->AddL( aPluginUid , aVersion );
       
   690     OstTrace1( TRACE_NORMAL, DUP1_CINDEXINGMANAGER_LOADHARVESTERPLUGINL, "CIndexingManager::LoadPluginsL;Plugin with uid=%x is added to DB", aPluginUid.iUid );
       
   691     CPIXLOGSTRING2("CIndexingManager::LoadHarvesterpluginL(): Plugin with uid = %x is added to database", aPluginUid.iUid);
       
   692     //try to load the plugin
       
   693     TRAPD( err, plugin = CIndexingPlugin::NewL( aPluginUid ) );
       
   694     if ( err == KErrNone )
       
   695         {
       
   696         // Plugin loaded succesfully. Remove it from the blacklist database
       
   697         iBlacklistMgr->Remove(aPluginUid);
       
   698         OstTrace1( TRACE_NORMAL, CINDEXINGMANAGER_LOADHARVESTERPLUGINL, "CIndexingManager::LoadPluginsL;Plugin with uid=%x is removed from DB", aPluginUid.iUid );
       
   699         CPIXLOGSTRING2("CIndexingManager::LoadHarvesterpluginL(): Plugin with uid = %x is removed from database", aPluginUid.iUid);
       
   700         iContentInfoMgr->UpdateBlacklistStatusL( aPluginName , KDisable );
       
   701         CleanupStack::PushL( plugin );
       
   702         plugin->SetObserver( *this );
       
   703         plugin->SetSearchSession( iSearchSession );
       
   704         iPluginArray.AppendL( plugin ); // and add them to array
       
   705         CleanupStack::Pop( plugin );
       
   706         OstTrace1( TRACE_NORMAL, DUP2_CINDEXINGMANAGER_LOADHARVESTERPLUGINL, "CIndexingManager::LoadPluginsL;Plugin with uid=%x is loaded successfully", aPluginUid.iUid );
       
   707         CPIXLOGSTRING2("CIndexingManager::LoadHarvesterpluginL(): Plugin with uid = %x is loaded succesfully", aPluginUid.iUid);
       
   708         }
       
   709     OstTraceFunctionExit0( CINDEXINGMANAGER_LOADHARVESTERPLUGINL_EXIT );
       
   710     }