harvesterplugins/file/src/cfileharvester.cpp
changeset 2 208a4ba3894c
parent 0 ccd0fd43f247
child 26 367228f82b66
equal deleted inserted replaced
0:ccd0fd43f247 2:208a4ba3894c
    22 #include <bautils.h>
    22 #include <bautils.h>
    23 
    23 
    24 // For Logging
    24 // For Logging
    25 #include "harvesterserverlogger.h"
    25 #include "harvesterserverlogger.h"
    26 #include "cfileharvester.h"
    26 #include "cfileharvester.h"
       
    27 #include "OstTraceDefinitions.h"
       
    28 #ifdef OST_TRACE_COMPILER_IN_USE
       
    29 #include "cfileharvesterTraces.h"
       
    30 #endif
       
    31 
    27 
    32 
    28 // CONSTANTS
    33 // CONSTANTS
    29 _LIT( KFileMask, "*.*" );
    34 _LIT( KFileMask, "*.*" );
    30 const TInt KItemsPerRun = 1;
    35 const TInt KItemsPerRun = 1;
    31 
    36 
    65 CFileHarvester::CFileHarvester( CFilePlugin& aFilePlugin, RFs& aFs )
    70 CFileHarvester::CFileHarvester( CFilePlugin& aFilePlugin, RFs& aFs )
    66   : CActive( CActive::EPriorityIdle ),
    71   : CActive( CActive::EPriorityIdle ),
    67     iFilePlugin( aFilePlugin ),
    72     iFilePlugin( aFilePlugin ),
    68     iFs( aFs )
    73     iFs( aFs )
    69     {
    74     {
       
    75     OstTraceFunctionEntry0( CFILEHARVESTER_CFILEHARVESTER_ENTRY );
    70     CPIXLOGSTRING("ENTER CFileHarvester::CFileHarvester");
    76     CPIXLOGSTRING("ENTER CFileHarvester::CFileHarvester");
    71     CActiveScheduler::Add( this );
    77     CActiveScheduler::Add( this );
    72     CPIXLOGSTRING("END CFileHarvester::CFileHarvester");
    78     CPIXLOGSTRING("END CFileHarvester::CFileHarvester");
       
    79     OstTraceFunctionExit0( CFILEHARVESTER_CFILEHARVESTER_EXIT );
    73     }
    80     }
    74 
    81 
    75 
    82 
    76 // ---------------------------------------------------------------------------
    83 // ---------------------------------------------------------------------------
    77 // CFileHarvester::ConstructL
    84 // CFileHarvester::ConstructL
    87 // CFileHarvester::StartL
    94 // CFileHarvester::StartL
    88 // ---------------------------------------------------------------------------
    95 // ---------------------------------------------------------------------------
    89 //
    96 //
    90 void CFileHarvester::StartL( const TDriveNumber aDriveNumber )
    97 void CFileHarvester::StartL( const TDriveNumber aDriveNumber )
    91     {
    98     {
       
    99     OstTraceFunctionEntry0( CFILEHARVESTER_STARTL_ENTRY );
    92     CPIXLOGSTRING("ENTER CFileHarvester::Start");
   100     CPIXLOGSTRING("ENTER CFileHarvester::Start");
    93 
   101 
    94     TFileName rootPath;
   102     TFileName rootPath;
    95     User::LeaveIfError( PathInfo::GetRootPath( rootPath, aDriveNumber ) );
   103     User::LeaveIfError( PathInfo::GetRootPath( rootPath, aDriveNumber ) );
    96 
   104 
    98 				ESortNone, // No need to sort data
   106 				ESortNone, // No need to sort data
    99 				CDirScan::EScanDownTree );
   107 				CDirScan::EScanDownTree );
   100 	iCurrentHarvestDrive = aDriveNumber;
   108 	iCurrentHarvestDrive = aDriveNumber;
   101 	SetNextRequest( EHarvesterStartHarvest );
   109 	SetNextRequest( EHarvesterStartHarvest );
   102     CPIXLOGSTRING("END CFileHarvester::Start");
   110     CPIXLOGSTRING("END CFileHarvester::Start");
       
   111     OstTraceFunctionExit0( CFILEHARVESTER_STARTL_EXIT );
   103     }
   112     }
   104 
   113 
   105 
   114 
   106 // -----------------------------------------------------------------------------
   115 // -----------------------------------------------------------------------------
   107 // CFileHarvester::AddIgnorePathsL
   116 // CFileHarvester::AddIgnorePathsL
   114     User::LeaveIfError( RFs::DriveToChar( aDriveNumber, chr ) );
   123     User::LeaveIfError( RFs::DriveToChar( aDriveNumber, chr ) );
   115 
   124 
   116     ignorePath.Append( chr );
   125     ignorePath.Append( chr );
   117     ignorePath.Append( KExcludePathSystem );
   126     ignorePath.Append( KExcludePathSystem );
   118     AddIgnorePathL( ignorePath );
   127     AddIgnorePathL( ignorePath );
       
   128     OstTraceExt1( TRACE_NORMAL, CFILEHARVESTER_ADDIGNOREPATHSL, "CFileHarvester::AddIgnorePathsL;AddIgnorePath=%S", ignorePath );
   119     CPIXLOGSTRING2("CFileHarvester::AddIgnorePathsL - AddIgnorePath: %S", &ignorePath );
   129     CPIXLOGSTRING2("CFileHarvester::AddIgnorePathsL - AddIgnorePath: %S", &ignorePath );
   120 
   130 
   121     ignorePath.Zero();
   131     ignorePath.Zero();
   122 
   132 
   123     // As index databases are located under \\Private\\ path,
   133     // As index databases are located under \\Private\\ path,
   124     // this ignore path will mean index databases are also ignored.
   134     // this ignore path will mean index databases are also ignored.
   125     ignorePath.Append( chr );
   135     ignorePath.Append( chr );
   126     ignorePath.Append( KExcludePathPrivate );
   136     ignorePath.Append( KExcludePathPrivate );
   127     AddIgnorePathL( ignorePath );
   137     AddIgnorePathL( ignorePath );
       
   138     OstTraceExt1( TRACE_NORMAL, DUP1_CFILEHARVESTER_ADDIGNOREPATHSL, "CFileHarvester::AddIgnorePathsL;AddIgnorePath=%S", ignorePath );
   128     CPIXLOGSTRING2("CFileHarvester::AddIgnorePathsL - AddIgnorePath: %S", &ignorePath );
   139     CPIXLOGSTRING2("CFileHarvester::AddIgnorePathsL - AddIgnorePath: %S", &ignorePath );
   129 
   140 
   130     ignorePath.Zero();
   141     ignorePath.Zero();
   131 
   142 
   132     // Maps data must not be indexed
   143     // Maps data must not be indexed
   133     ignorePath.Append( chr );
   144     ignorePath.Append( chr );
   134     ignorePath.Append( KExcludePathMapsCities );
   145     ignorePath.Append( KExcludePathMapsCities );
   135     AddIgnorePathL( ignorePath );
   146     AddIgnorePathL( ignorePath );
       
   147     OstTraceExt1( TRACE_NORMAL, DUP2_CFILEHARVESTER_ADDIGNOREPATHSL, "CFileHarvester::AddIgnorePathsL;AddIgnorePath=%S", ignorePath );
   136     CPIXLOGSTRING2("CFileHarvester::AddIgnorePathsL - AddIgnorePath: %S", &ignorePath );
   148     CPIXLOGSTRING2("CFileHarvester::AddIgnorePathsL - AddIgnorePath: %S", &ignorePath );
   137     }
   149     }
   138 
   150 
   139 
   151 
   140 // -----------------------------------------------------------------------------
   152 // -----------------------------------------------------------------------------
   148     RFs::DriveToChar( aDriveNumber, chr );
   160     RFs::DriveToChar( aDriveNumber, chr );
   149 
   161 
   150     ignorePath.Append( chr );
   162     ignorePath.Append( chr );
   151     ignorePath.Append( KExcludePathSystem );
   163     ignorePath.Append( KExcludePathSystem );
   152     RemoveIgnorePath( ignorePath );
   164     RemoveIgnorePath( ignorePath );
       
   165     OstTraceExt1( TRACE_NORMAL, CFILEHARVESTER_REMOVEIGNOREPATHS, "CFileHarvester::RemoveIgnorePaths;RemoveIgnorePath=%S", ignorePath );
   153     CPIXLOGSTRING2("CFileHarvester::RemoveIgnorePaths - RemoveIgnorePath: %S", &ignorePath );
   166     CPIXLOGSTRING2("CFileHarvester::RemoveIgnorePaths - RemoveIgnorePath: %S", &ignorePath );
   154 
   167 
   155     ignorePath.Zero();
   168     ignorePath.Zero();
   156 
   169 
   157     // As index databases are located under \\Private\\ path,
   170     // As index databases are located under \\Private\\ path,
   158     // this ignore path will mean index databases are also ignored.
   171     // this ignore path will mean index databases are also ignored.
   159     ignorePath.Append( chr );
   172     ignorePath.Append( chr );
   160     ignorePath.Append( KExcludePathPrivate );
   173     ignorePath.Append( KExcludePathPrivate );
   161     RemoveIgnorePath( ignorePath );
   174     RemoveIgnorePath( ignorePath );
       
   175     OstTraceExt1( TRACE_NORMAL, DUP1_CFILEHARVESTER_REMOVEIGNOREPATHS, "CFileHarvester::RemoveIgnorePaths;RemoveIgnorePath=%S", ignorePath );
   162     CPIXLOGSTRING2("CFileHarvester::RemoveIgnorePaths - RemoveIgnorePath: %S", &ignorePath );
   176     CPIXLOGSTRING2("CFileHarvester::RemoveIgnorePaths - RemoveIgnorePath: %S", &ignorePath );
   163 
   177 
   164     ignorePath.Zero();
   178     ignorePath.Zero();
   165 
   179 
   166     // Maps
   180     // Maps
   167     ignorePath.Append( chr );
   181     ignorePath.Append( chr );
   168     ignorePath.Append( KExcludePathMapsCities );
   182     ignorePath.Append( KExcludePathMapsCities );
   169     RemoveIgnorePath( ignorePath );
   183     RemoveIgnorePath( ignorePath );
       
   184     OstTraceExt1( TRACE_NORMAL, DUP2_CFILEHARVESTER_REMOVEIGNOREPATHS, "CFileHarvester::RemoveIgnorePaths;RemoveIgnorePath=%S", ignorePath );
   170     CPIXLOGSTRING2("CFileHarvester::RemoveIgnorePaths - RemoveIgnorePath: %S", &ignorePath );
   185     CPIXLOGSTRING2("CFileHarvester::RemoveIgnorePaths - RemoveIgnorePath: %S", &ignorePath );
   171     }
   186     }
   172 
   187 
   173 
   188 
   174 // -----------------------------------------------------------------------------
   189 // -----------------------------------------------------------------------------
   230             for ( TInt i = 0; i < iIgnorePaths.Count(); i++ )
   245             for ( TInt i = 0; i < iIgnorePaths.Count(); i++ )
   231                 {
   246                 {
   232                 TFileName* tf = iIgnorePaths[i];
   247                 TFileName* tf = iIgnorePaths[i];
   233                 if ( tf->Compare(aIgnorePath) == 0 )
   248                 if ( tf->Compare(aIgnorePath) == 0 )
   234                     {
   249                     {
       
   250                     OstTraceExt1( TRACE_NORMAL, CFILEHARVESTER_REMOVEIGNOREPATH, "CFileHarvester::RemoveIgnorePath;remove path=%S", aIgnorePath );
   235                     CPIXLOGSTRING2( "CFileHarvester::RemoveIgnorePath() - remove path: %S", &aIgnorePath );
   251                     CPIXLOGSTRING2( "CFileHarvester::RemoveIgnorePath() - remove path: %S", &aIgnorePath );
   236                     delete tf;
   252                     delete tf;
   237                     tf = NULL;
   253                     tf = NULL;
   238                     iIgnorePaths.Remove( i );
   254                     iIgnorePaths.Remove( i );
   239                     }
   255                     }
   267 			TFileName tempFileName;
   283 			TFileName tempFileName;
   268 			tempFileName.Copy( aFileName );
   284 			tempFileName.Copy( aFileName );
   269 			tempFileName.LowerCase();
   285 			tempFileName.LowerCase();
   270 			if ( tempFileName.Find(*pathName) != KErrNotFound )
   286 			if ( tempFileName.Find(*pathName) != KErrNotFound )
   271 				{
   287 				{
       
   288 				OstTrace0( TRACE_NORMAL, CFILEHARVESTER_CHECKPATH, "CFileHarvester::CheckPath() - is ignore path" );
   272 				CPIXLOGSTRING( "CFileHarvester::CheckPath() - is ignore path" );
   289 				CPIXLOGSTRING( "CFileHarvester::CheckPath() - is ignore path" );
   273 				return EFalse;
   290 				return EFalse;
   274 				}
   291 				}
   275 			}
   292 			}
   276 		}
   293 		}
   282 // CFileHarvester::GetNextFolderL
   299 // CFileHarvester::GetNextFolderL
   283 // ---------------------------------------------------------------------------
   300 // ---------------------------------------------------------------------------
   284 //		
   301 //		
   285 void CFileHarvester::GetNextFolderL()
   302 void CFileHarvester::GetNextFolderL()
   286     {
   303     {
       
   304     OstTraceFunctionEntry0( CFILEHARVESTER_GETNEXTFOLDERL_ENTRY );
   287     CPIXLOGSTRING("ENTER CFileHarvester::GetNextFolderL");
   305     CPIXLOGSTRING("ENTER CFileHarvester::GetNextFolderL");
   288 
   306 
   289     delete iDir;
   307     delete iDir;
   290     iDir = NULL;
   308     iDir = NULL;
   291     // Documentation: CDirScan::NextL() The caller of this function 
   309     // Documentation: CDirScan::NextL() The caller of this function 
   295     if ( iDir )
   313     if ( iDir )
   296     	{
   314     	{
   297         // if folder is in ignore path then skip it
   315         // if folder is in ignore path then skip it
   298         if ( !CheckPath( iDirscan->FullPath() ) )
   316         if ( !CheckPath( iDirscan->FullPath() ) )
   299         	{
   317         	{
       
   318 			OstTrace0( TRACE_NORMAL, CFILEHARVESTER_GETNEXTFOLDERL, "CFileHarvester::GetNextFolderL - IF EHarvesterStartHarvest" );
   300 			CPIXLOGSTRING("CFileHarvester::GetNextFolderL - IF EHarvesterStartHarvest");
   319 			CPIXLOGSTRING("CFileHarvester::GetNextFolderL - IF EHarvesterStartHarvest");
   301         	SetNextRequest( EHarvesterStartHarvest );
   320         	SetNextRequest( EHarvesterStartHarvest );
   302         	}
   321         	}
   303         else
   322         else
   304 			{
   323 			{
       
   324 			OstTrace0( TRACE_NORMAL, DUP1_CFILEHARVESTER_GETNEXTFOLDERL, "CFileHarvester::GetNextFolderL - IF EHarvesterGetFileId" );
   305 			CPIXLOGSTRING("CFileHarvester::GetNextFolderL - IF EHarvesterGetFileId");
   325 			CPIXLOGSTRING("CFileHarvester::GetNextFolderL - IF EHarvesterGetFileId");
   306 			SetNextRequest( EHarvesterGetFileId );
   326 			SetNextRequest( EHarvesterGetFileId );
   307 			}
   327 			}
   308     	}
   328     	}
   309     else
   329     else
   310         {
   330         {
       
   331         OstTrace0( TRACE_NORMAL, DUP2_CFILEHARVESTER_GETNEXTFOLDERL, "CFileHarvester::GetNextFolderL - IF EHarvesterIdle" );
   311         CPIXLOGSTRING("CFileHarvester::GetNextFolderL - IF EHarvesterIdle");
   332         CPIXLOGSTRING("CFileHarvester::GetNextFolderL - IF EHarvesterIdle");
   312         SetNextRequest( EHarvesterIdleState );
   333         SetNextRequest( EHarvesterIdleState );
   313         }
   334         }
   314     CPIXLOGSTRING("END CFileHarvester::GetNextFolderL");
   335     CPIXLOGSTRING("END CFileHarvester::GetNextFolderL");
       
   336     OstTraceFunctionExit0( CFILEHARVESTER_GETNEXTFOLDERL_EXIT );
   315     }
   337     }
   316 
   338 
   317 
   339 
   318 // ---------------------------------------------------------------------------
   340 // ---------------------------------------------------------------------------
   319 // CFileHarvester::GetFileIdL
   341 // CFileHarvester::GetFileIdL
   320 // 
   342 // 
   321 // ---------------------------------------------------------------------------
   343 // ---------------------------------------------------------------------------
   322 //
   344 //
   323 void CFileHarvester::GetFileIdL()
   345 void CFileHarvester::GetFileIdL()
   324     {
   346     {
       
   347     OstTraceFunctionEntry0( CFILEHARVESTER_GETFILEIDL_ENTRY );
   325     CPIXLOGSTRING("ENTER CFileHarvester::GetFileId");
   348     CPIXLOGSTRING("ENTER CFileHarvester::GetFileId");
   326 
   349 
   327     if( iCurrentIndex == 0 )
   350     if( iCurrentIndex == 0 )
   328         {
   351         {
   329         TParse parse;
   352         TParse parse;
   344         while( ( iCurrentIndex < count ) && ( iStepNumber < KItemsPerRun ) )
   367         while( ( iCurrentIndex < count ) && ( iStepNumber < KItemsPerRun ) )
   345             {
   368             {
   346             TEntry aEntry = (*iDir)[iCurrentIndex];
   369             TEntry aEntry = (*iDir)[iCurrentIndex];
   347             // Check if entry is a hidden or system file
   370             // Check if entry is a hidden or system file
   348             // if true -> continue until find something to index or have checked whole directory
   371             // if true -> continue until find something to index or have checked whole directory
   349             if( !aEntry.IsHidden() && !aEntry.IsSystem() && !aEntry.IsDir() )
   372             // if the entry is a file, index both its filename and contents, for folder index the 
       
   373             // folder name
       
   374             if( !aEntry.IsHidden() && !aEntry.IsSystem())
   350                 {
   375                 {
   351                 TParse fileParser;
   376                 TParse fileParser;
   352                 fileParser.Set( iDirscan->FullPath(), &(*iDir)[iCurrentIndex].iName, NULL );
   377                 fileParser.Set( iDirscan->FullPath(), &(*iDir)[iCurrentIndex].iName, NULL );
   353                 iFilePlugin.CreateFileIndexItemL(fileParser.FullName(), ECPixAddAction);
   378                 if(aEntry.IsDir())
       
   379                     {                    
       
   380                     iFilePlugin.CreateFolderFileIndexItemL(fileParser.FullName(), ECPixAddAction);
       
   381                     }
       
   382                 else
       
   383                     {
       
   384                     iFilePlugin.CreateContentIndexItemL(fileParser.FullName(), ECPixAddAction);
       
   385                     iFilePlugin.CreateFolderFileIndexItemL(fileParser.FullName(), ECPixAddAction, false);
       
   386                     }
   354                 // TODO: If this is not TRAPPED, state machine breaks 
   387                 // TODO: If this is not TRAPPED, state machine breaks 
   355                 iStepNumber++;
   388                 iStepNumber++;
   356                 }
   389                 }
   357             iCurrentIndex++;
   390             iCurrentIndex++;
   358             }
   391             }
   372     else
   405     else
   373         {
   406         {
   374         SetNextRequest( EHarvesterStartHarvest );
   407         SetNextRequest( EHarvesterStartHarvest );
   375         }
   408         }
   376     CPIXLOGSTRING("END CFileHarvester::GetFileId");
   409     CPIXLOGSTRING("END CFileHarvester::GetFileId");
       
   410     OstTraceFunctionExit0( CFILEHARVESTER_GETFILEIDL_EXIT );
   377     }
   411     }
   378 
   412 
   379 
   413 
   380 // -----------------------------------------------------------------------------
   414 // -----------------------------------------------------------------------------
   381 // CFileHarvester::DoCancel
   415 // CFileHarvester::DoCancel
   382 // -----------------------------------------------------------------------------
   416 // -----------------------------------------------------------------------------
   383 //   
   417 //   
   384 void CFileHarvester::DoCancel()
   418 void CFileHarvester::DoCancel()
   385 	{
   419 	{
       
   420     OstTrace0( TRACE_NORMAL, CFILEHARVESTER_DOCANCEL, "CFileHarvester::DoCancel" );
   386     CPIXLOGSTRING("CFileHarvester::DoCancel");
   421     CPIXLOGSTRING("CFileHarvester::DoCancel");
   387 	}
   422 	}
   388 
   423 
   389 
   424 
   390 // -----------------------------------------------------------------------------
   425 // -----------------------------------------------------------------------------
   391 // CFileHarvester::RunL
   426 // CFileHarvester::RunL
   392 // -----------------------------------------------------------------------------
   427 // -----------------------------------------------------------------------------
   393 //   
   428 //   
   394 void CFileHarvester::RunL()
   429 void CFileHarvester::RunL()
   395     {
   430     {
       
   431     OstTraceFunctionEntry0( CFILEHARVESTER_RUNL_ENTRY );
   396     CPIXLOGSTRING("ENTER CFileHarvester::RunL");
   432     CPIXLOGSTRING("ENTER CFileHarvester::RunL");
   397     // Simple Round-Robin scheduling.
   433     // Simple Round-Robin scheduling.
   398     Deque();
   434     Deque();
   399     CActiveScheduler::Add( this );
   435     CActiveScheduler::Add( this );
   400 
   436 
   420 
   456 
   421 		default:
   457 		default:
   422 			break;
   458 			break;
   423 		}
   459 		}
   424 	CPIXLOGSTRING("END CFileHarvester::RunL");
   460 	CPIXLOGSTRING("END CFileHarvester::RunL");
       
   461 	OstTraceFunctionExit0( CFILEHARVESTER_RUNL_EXIT );
   425 	}
   462 	}
   426 
   463 
   427 
   464 
   428 // -----------------------------------------------------------------------------
   465 // -----------------------------------------------------------------------------
   429 // CFileHarvester::RunError
   466 // CFileHarvester::RunError
   430 // -----------------------------------------------------------------------------
   467 // -----------------------------------------------------------------------------
   431 //   
   468 //   
   432 TInt CFileHarvester::RunError(TInt aError)
   469 TInt CFileHarvester::RunError(TInt aError)
   433 	{
   470 	{
       
   471     OstTrace1( TRACE_NORMAL, CFILEHARVESTER_RUNERROR, "CFileHarvester::RunError;aError=%d", aError );
   434     CPIXLOGSTRING2("CFileHarvester::RunError - aError: %d", aError );
   472     CPIXLOGSTRING2("CFileHarvester::RunError - aError: %d", aError );
   435 	iHarvestState = EHarvesterIdleState;
   473 	iHarvestState = EHarvesterIdleState;
   436     iFilePlugin.HarvestingCompleted(iCurrentHarvestDrive, aError);
   474     iFilePlugin.HarvestingCompleted(iCurrentHarvestDrive, aError);
   437 	return KErrNone;
   475 	return KErrNone;
   438 	}
   476 	}
   442 // SetNextRequest
   480 // SetNextRequest
   443 // ---------------------------------------------------------------------------
   481 // ---------------------------------------------------------------------------
   444 //
   482 //
   445 void CFileHarvester::SetNextRequest( TFileHarvesterState aState )
   483 void CFileHarvester::SetNextRequest( TFileHarvesterState aState )
   446     {
   484     {
       
   485     OstTrace0( TRACE_NORMAL, CFILEHARVESTER_SETNEXTREQUEST, "CFileHarvester::SetNextRequest" );
   447     CPIXLOGSTRING("CFileHarvester::SetNextRequest");
   486     CPIXLOGSTRING("CFileHarvester::SetNextRequest");
   448     if ( !IsActive() )
   487     if ( !IsActive() )
   449         {
   488         {
   450         iHarvestState = aState;
   489         iHarvestState = aState;
   451         SetActive();
   490         SetActive();