harvesterplugins/messaging/smsmms/src/cmessageplugin.cpp
changeset 2 208a4ba3894c
child 9 4a2987baf8f7
equal deleted inserted replaced
0:ccd0fd43f247 2:208a4ba3894c
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h> 
       
    20 #include <msvids.h>
       
    21 #include <msvuids.h>
       
    22 #include <mmsconst.h>
       
    23 #include <mmsclient.h>
       
    24 #include <smsclnt.h>
       
    25 #include <txtrich.h>
       
    26 #include <smuthdr.h>
       
    27 #include <smut.h>
       
    28 #include <miutset.h>
       
    29 #include <SendUiConsts.h>
       
    30 #include <mtclreg.h>
       
    31 #include <gsmuelem.h>
       
    32 #include <msventry.h>
       
    33 #include <ccpixindexer.h>
       
    34 
       
    35 #include "cmessageplugin.h"
       
    36 #include "cmessagemonitor.h"
       
    37 #include "cmessageharvester.h"
       
    38 #include "cmessagedatahandler.h"
       
    39 #include "harvesterserverlogger.h"
       
    40 #include "OstTraceDefinitions.h"
       
    41 #ifdef OST_TRACE_COMPILER_IN_USE
       
    42 #include "cmessagepluginTraces.h"
       
    43 #endif
       
    44 
       
    45 
       
    46 // maximum length that the fully qualified msg Plugin base app class descriptor can be
       
    47 // e.g. "@c:root msg"
       
    48 const TInt KMsgPluginBaseAppClassMaxLen = 64;
       
    49 
       
    50 
       
    51 // local declarations and functions
       
    52 namespace {
       
    53 
       
    54 _LIT(KCPixSearchServerPrivateDirectory, "\\Private\\2001f6f7\\");
       
    55 _LIT(KPathIndexDbPath, CPIX_INDEVICE_INDEXDB);
       
    56 
       
    57 _LIT(KPathTrailer, "\\root\\msg\\smsmms");
       
    58 _LIT(KMsgBaseAppClassGeneric, ":root msg smsmms");
       
    59 _LIT(KAtSign, "@");
       
    60 _LIT(KColon, ":");
       
    61 
       
    62 /**
       
    63 * MapFileToDrive - gets the TDriveNumber associated with the aBaseAppClass.
       
    64 * @aBaseAppClass e.g. "@c:root file"
       
    65 * @aDrive returns the TDriveNumber for the aBaseAppClass
       
    66 * returns KErrNone on success or a standard error code
       
    67 */
       
    68 TInt MapBaseAppClassToDrive(const TDesC& aBaseAppClass, TDriveNumber& aDrive)
       
    69     {
       
    70     if (KErrNone != aBaseAppClass.Left(1).Compare(KAtSign))
       
    71         {
       
    72         return KErrGeneral;
       
    73         }
       
    74 
       
    75     TPtrC drvChar = aBaseAppClass.Left(2).Right(1);
       
    76     TChar d(drvChar[0]);
       
    77     TInt drive;
       
    78     const TInt ret = RFs::CharToDrive(d, drive);
       
    79     if (!ret)
       
    80         {
       
    81         aDrive = TDriveNumber(drive);
       
    82         }
       
    83 
       
    84     return ret;
       
    85     }
       
    86 
       
    87 }// anonymous namespace
       
    88 
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // CMessagePlugin::NewL
       
    92 // ---------------------------------------------------------------------------
       
    93 //  
       
    94 CMessagePlugin* CMessagePlugin::NewL()
       
    95 {
       
    96 	CMessagePlugin* instance = CMessagePlugin::NewLC();
       
    97     CleanupStack::Pop(instance);
       
    98     return instance;
       
    99 }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // CMessagePlugin::NewLC
       
   103 // ---------------------------------------------------------------------------
       
   104 //  
       
   105 CMessagePlugin* CMessagePlugin::NewLC()
       
   106 {
       
   107 	CMessagePlugin* instance = new (ELeave)CMessagePlugin();
       
   108     CleanupStack::PushL(instance);
       
   109     instance->ConstructL();
       
   110     return instance;
       
   111 }
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // CMessagePlugin::CMessagePlugin
       
   115 // ---------------------------------------------------------------------------
       
   116 //  
       
   117 CMessagePlugin::CMessagePlugin()
       
   118 {
       
   119 	iMessageDataHandler = NULL;
       
   120 	iMessageHarvester = NULL;
       
   121 	iMessageMonitor = NULL;
       
   122 	iMsvSession = NULL;
       
   123 }
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // CMessagePlugin::~CMessagePlugin
       
   127 // ---------------------------------------------------------------------------
       
   128 //  
       
   129 CMessagePlugin::~CMessagePlugin()
       
   130 {
       
   131     // remove notification paths before destroying iMonitor
       
   132     for (TInt i=EDriveA; i<=EDriveZ; i++)
       
   133         UnMount(TDriveNumber(i), EFalse);
       
   134 	delete iMessageDataHandler;
       
   135 	delete iMessageHarvester;	
       
   136 	delete iMessageMonitor;	
       
   137 	delete iMsvSession;
       
   138 	iFs.Close();
       
   139 }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // CMessagePlugin::ConstructL
       
   143 // ---------------------------------------------------------------------------
       
   144 //  
       
   145 void CMessagePlugin::ConstructL()
       
   146 {
       
   147     TInt err = iFs.Connect();
       
   148     OstTrace1( TRACE_NORMAL, CMESSAGEPLUGIN_CONSTRUCTL, "CMessagePlugin::ConstructL;iFs Connect Error=%d", err );
       
   149     CPIXLOGSTRING2("CMessagePlugin::ConstructL, iFs.Connect: %i", err);
       
   150     User::LeaveIfError(err);
       
   151     iCurrentDrive = EDriveC; //Default drive is C drive
       
   152     iMsvSession = CMsvSession::OpenSyncL(*this);
       
   153     iMessageMonitor = CMessageMonitor::NewL( *this, *iMsvSession );    
       
   154     iMessageHarvester = CMessageHarvester::NewL( *this, *iMsvSession );    
       
   155     iMessageDataHandler = CMessageDataHandler::NewL( *this, *iMsvSession );    
       
   156     for (TInt i=EDriveA; i<=EDriveZ; i++)
       
   157         {
       
   158         iIndexer[i] = NULL; //Initialize to NULL
       
   159         }
       
   160 }
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // CMessagePlugin::StartPluginL
       
   164 // ---------------------------------------------------------------------------
       
   165 //  
       
   166 void CMessagePlugin::StartPluginL()
       
   167 	{
       
   168 	//Get the current Drive for storage
       
   169 	iCurrentDrive = iMsvSession->CurrentDriveL();
       
   170 	OstTrace1( TRACE_NORMAL, CMESSAGEPLUGIN_STARTPLUGINL, "CMessagePlugin::StartPluginL;Current Drive for Messaging =%d", iCurrentDrive );
       
   171 	CPIXLOGSTRING2("currentDrive from messaging app : %d", iCurrentDrive );
       
   172 	MountL(TDriveNumber(iCurrentDrive)); //Mount current drive
       
   173 	// Define this base application class, use default location
       
   174 	}
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // CMessagePlugin::StartHarvestingL
       
   178 // ---------------------------------------------------------------------------
       
   179 //  
       
   180 void CMessagePlugin::StartHarvestingL(const TDesC& aQualifiedBaseAppClass)
       
   181 	{
       
   182 	OstTraceFunctionEntry0( CMESSAGEPLUGIN_STARTHARVESTINGL_ENTRY );
       
   183 	CPIXLOGSTRING("START CMessagePlugin::StartHarvestingL");
       
   184 	// Map base app class to a drive number
       
   185 	TDriveNumber drive ( EDriveA );//Initialize to silence compiler warnings.
       
   186 	if (KErrNone != MapBaseAppClassToDrive(aQualifiedBaseAppClass, drive))
       
   187 	   User::Leave(KErrGeneral);
       
   188 
       
   189     // Leave if no indexer for this drive
       
   190 	if (!iIndexer[drive])
       
   191 	   User::Leave(KErrGeneral);
       
   192 	        
       
   193     // Reset the database
       
   194 	iIndexer[drive]->ResetL();
       
   195 #ifdef __PERFORMANCE_DATA
       
   196     iStartTime.UniversalTime();
       
   197 #endif
       
   198     iMessageHarvester->StartHarvestingL();
       
   199 	OstTraceFunctionExit0( CMESSAGEPLUGIN_STARTHARVESTINGL_EXIT );
       
   200 	}
       
   201 
       
   202 // ---------------------------------------------------------------------------
       
   203 // CMessagePlugin::MountL
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 void CMessagePlugin::MountL(TDriveNumber aMedia,TBool aForceReharvesting)
       
   207     {
       
   208     OstTraceFunctionEntry0( CMESSAGEPLUGIN_MOUNTL_ENTRY );
       
   209     CPIXLOGSTRING("START CMessagePlugin::MountL");
       
   210     // Check if already exists
       
   211     if (iIndexer[aMedia])
       
   212         return;
       
   213     
       
   214     // Form the baseappclass for this media
       
   215     TBuf<KMsgPluginBaseAppClassMaxLen> baseAppClass;
       
   216     FormBaseAppClass(aMedia, baseAppClass);
       
   217 
       
   218     // Define this volume
       
   219     HBufC* path = DatabasePathLC(aMedia);
       
   220     User::LeaveIfError(iSearchSession.DefineVolume(baseAppClass, *path));
       
   221     CleanupStack::PopAndDestroy(path);
       
   222     
       
   223     // construct and open the database
       
   224     TRAPD(err,iIndexer[aMedia] = CCPixIndexer::NewL(iSearchSession));
       
   225     OstTrace1( TRACE_NORMAL, CMESSAGEPLUGIN_MOUNTL, "CMessagePlugin::MountL;Indexer NewL return error=%d", err );
       
   226     CPIXLOGSTRING2("CCPixIndexer::NewL returned : %d", err );
       
   227     TRAP(err,iIndexer[aMedia]->OpenDatabaseL(baseAppClass));
       
   228 
       
   229     // Add to harvesting queue
       
   230     iObserver->AddHarvestingQueue(this, baseAppClass,aForceReharvesting);  
       
   231     CPIXLOGSTRING("END CMessagePlugin::MountL");
       
   232     OstTraceFunctionExit0( CMESSAGEPLUGIN_MOUNTL_EXIT );
       
   233     }
       
   234 
       
   235 // ---------------------------------------------------------------------------
       
   236 // CMessagePlugin::UnMount
       
   237 // ---------------------------------------------------------------------------
       
   238 //
       
   239 void CMessagePlugin::UnMount(TDriveNumber aMedia, TBool aUndefineAsWell)
       
   240     {
       
   241     OstTraceFunctionEntry0( CMESSAGEPLUGIN_UNMOUNT_ENTRY );
       
   242     CPIXLOGSTRING("START CMessagePlugin::UnMount");
       
   243     // Check if already exists
       
   244     if (!iIndexer[aMedia])
       
   245         return;
       
   246     
       
   247     // Form the baseappclass for this media
       
   248     TBuf<KMsgPluginBaseAppClassMaxLen> baseAppClass;
       
   249     FormBaseAppClass(aMedia, baseAppClass);             
       
   250         
       
   251     // Remove from harvesting queue
       
   252     iObserver->RemoveHarvestingQueue(this, baseAppClass);   
       
   253     
       
   254     // Delete the index object
       
   255     if (iIndexer[aMedia])
       
   256         {
       
   257         delete iIndexer[aMedia];
       
   258         iIndexer[aMedia] = NULL;
       
   259         }
       
   260     
       
   261     // if the aActionType is EFFMmcDismount, then the
       
   262     // parameter aFilename is the baseAppClass of the Index database
       
   263     // to be dropped.
       
   264     if (aUndefineAsWell)
       
   265         iSearchSession.UnDefineVolume(baseAppClass);
       
   266     OstTraceFunctionExit0( CMESSAGEPLUGIN_UNMOUNT_EXIT );
       
   267     }
       
   268 
       
   269 
       
   270 // ---------------------------------------------------------------------------
       
   271 // CMessagePlugin::FormBaseAppClass
       
   272 // ---------------------------------------------------------------------------
       
   273 //  
       
   274 TInt CMessagePlugin::FormBaseAppClass(TDriveNumber aMedia, TDes& aBaseAppClass)
       
   275     {
       
   276     TChar chr;
       
   277     const TInt ret = RFs::DriveToChar(aMedia, chr);
       
   278     if (KErrNone == ret)
       
   279         {
       
   280         aBaseAppClass.Copy(KAtSign);
       
   281         aBaseAppClass.Append(chr);
       
   282         aBaseAppClass.LowerCase();
       
   283         aBaseAppClass.Append(KMsgBaseAppClassGeneric);
       
   284         }
       
   285 
       
   286     return ret;
       
   287     }
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // CMessagePlugin::DatabasePathLC
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 HBufC* CMessagePlugin::DatabasePathLC(TDriveNumber aMedia)
       
   294     {
       
   295     OstTraceFunctionEntry0( CMESSAGEPLUGIN_DATABASEPATHLC_ENTRY );
       
   296     CPIXLOGSTRING("START CMessagePlugin::DatabasePathLC");
       
   297     // Allocate extra space for root path e.g. "C:\\Private\\2001f6f7\\"
       
   298     const TInt KRootPathMaxLength = 30;
       
   299     HBufC* indexDbPath = HBufC::NewLC(KRootPathMaxLength + KPathIndexDbPath().Length() + KPathTrailer().Length());
       
   300     TPtr indexDbPathPtr = indexDbPath->Des();
       
   301 
       
   302 #if 1 // Data caging implementation
       
   303     iFs.CreatePrivatePath(aMedia);
       
   304 
       
   305     TChar chr;
       
   306     RFs::DriveToChar(aMedia, chr);
       
   307     indexDbPathPtr.Append(chr);
       
   308     indexDbPathPtr.Append(KColon);
       
   309 
       
   310     TFileName pathWithoutDrive;
       
   311     iFs.PrivatePath(pathWithoutDrive);
       
   312     indexDbPathPtr.Append(KCPixSearchServerPrivateDirectory);
       
   313 #else // here is the way to calculate the path if data caging is not being used.
       
   314     TFileName rootPath;
       
   315     PathInfo::GetRootPath(rootPath, aMedia);
       
   316     indexDbPathPtr.Append(rootPath);
       
   317 #endif 
       
   318 
       
   319     indexDbPathPtr.Append(KPathIndexDbPath);
       
   320     indexDbPathPtr.Append(KPathTrailer);
       
   321 
       
   322     OstTraceFunctionExit0( CMESSAGEPLUGIN_DATABASEPATHLC_EXIT );
       
   323     return indexDbPath;
       
   324     }
       
   325 
       
   326 // ---------------------------------------------------------------------------
       
   327 // CMessagePlugin::GetIndexer
       
   328 // ---------------------------------------------------------------------------
       
   329 //
       
   330 CCPixIndexer* CMessagePlugin::GetIndexer()
       
   331     {
       
   332     return iIndexer[iCurrentDrive];
       
   333     }
       
   334 
       
   335 // ---------------------------------------------------------------------------
       
   336 // CMessagePlugin::IsMediaRemovableL
       
   337 // ---------------------------------------------------------------------------
       
   338 // 
       
   339 TBool CMessagePlugin::IsMediaRemovableL(TDriveNumber& aDrive)
       
   340     {
       
   341     TDriveInfo driveInfo; 
       
   342     User::LeaveIfError(iFs.Drive(driveInfo,aDrive));
       
   343     TBool mediaRemovable(EFalse);
       
   344     driveInfo.iDriveAtt & KDriveAttRemovable ? mediaRemovable = ETrue : mediaRemovable = EFalse;
       
   345     return mediaRemovable;
       
   346     }
       
   347 // ---------------------------------------------------------------------------
       
   348 // CMessagePlugin::HandleSessionEventL
       
   349 // ---------------------------------------------------------------------------
       
   350 //  
       
   351 void CMessagePlugin::HandleSessionEventL( TMsvSessionEvent aEvent, 
       
   352 										  		 TAny* aArg1, 
       
   353 										  		 TAny* aArg2, 
       
   354 										  		 TAny* aArg3 )
       
   355 	{		
       
   356 	OstTraceFunctionEntry0( CMESSAGEPLUGIN_HANDLESESSIONEVENTL_ENTRY );
       
   357 	CPIXLOGSTRING("ENTER CMessagePlugin::HandleSessionEventL");
       
   358 	OstTrace1( TRACE_NORMAL, CMESSAGEPLUGIN_HANDLESESSIONEVENTL, "CMessagePlugin::HandleSessionEventL;aEvent=%d", aEvent );
       
   359 	CPIXLOGSTRING2("TMsvSessionEvent aEvent: %d", aEvent );			
       
   360 		
       
   361 	switch( aEvent )
       
   362 		{
       
   363 		case EMsvEntriesCreated:
       
   364 		case EMsvEntriesChanged:
       
   365 			{
       
   366 			// Handle changed / created event
       
   367             CMsvEntrySelection* selection = reinterpret_cast<CMsvEntrySelection*>(aArg1);
       
   368             TMsvId folderId = *( reinterpret_cast<TMsvId*>(aArg2));
       
   369 #ifdef __PERFORMANCE_DATA
       
   370             iStartTime.UniversalTime();
       
   371 		    iMessageMonitor->HandleMsgCreatedChangedL(*selection, folderId, aEvent);
       
   372 		    UpdatePerformaceDataL(EMsvEntriesChanged);
       
   373 #else
       
   374 		    iMessageMonitor->HandleMsgCreatedChangedL(*selection, folderId, aEvent);
       
   375 #endif		    
       
   376 			break;
       
   377 			}		
       
   378 		case EMsvEntriesDeleted:
       
   379 			{
       
   380 			// Handle deletion event
       
   381 		    CMsvEntrySelection* selection = reinterpret_cast<CMsvEntrySelection*> ( aArg1 );
       
   382 #ifdef __PERFORMANCE_DATA
       
   383             iStartTime.UniversalTime();
       
   384 		    iMessageMonitor->HandleMsgDeletedL( *selection );
       
   385 		    UpdatePerformaceDataL(EMsvEntriesDeleted);
       
   386 #else
       
   387 		    iMessageMonitor->HandleMsgDeletedL( *selection );
       
   388 #endif
       
   389 			break;
       
   390 			}
       
   391 		case EMsvEntriesMoved:
       
   392 			{
       
   393 			// track move operations
       
   394 			// or sent folder
       
   395 			// ... extract the useful parameters
       
   396             if( aArg1 && aArg2 && aArg3 )
       
   397                 {
       
   398                 CMsvEntrySelection* selection = reinterpret_cast<CMsvEntrySelection*> ( aArg1 );
       
   399                 // aArg2 is the TMsvId of the new parent. aArg3 is the TMsvId of 
       
   400                 // the old parent entry.
       
   401                 TMsvId newFolderId = *(reinterpret_cast<TMsvId*>(aArg2));
       
   402                 TMsvId oldFolderId = *(reinterpret_cast<TMsvId*>(aArg3));
       
   403 #ifdef __PERFORMANCE_DATA
       
   404                 iStartTime.UniversalTime();
       
   405                 iMessageMonitor->HandleMsgMovedL(newFolderId, oldFolderId, *selection);
       
   406                 UpdatePerformaceDataL(EMsvEntriesMoved);
       
   407 #else
       
   408                 iMessageMonitor->HandleMsgMovedL(newFolderId, oldFolderId, *selection);
       
   409 #endif
       
   410                 }
       
   411 			break;
       
   412 			}			
       
   413 		case EMsvMediaChanged:
       
   414 		    {
       
   415 		    //Unmount old media drive
       
   416 		    OstTrace0( TRACE_NORMAL, DUP1_CMESSAGEPLUGIN_HANDLESESSIONEVENTL, "ENTER CMessagePlugin::HandleSessionEventL EMsvMediaChanged" );
       
   417 		    CPIXLOGSTRING("ENTER CMessagePlugin::HandleSessionEventL EMsvMediaChanged");
       
   418 		    TDriveNumber drive = *(reinterpret_cast<TDriveNumber*>(aArg1));
       
   419 		    UnMount(drive);
       
   420 		    drive = *(reinterpret_cast<TDriveNumber*>(aArg2));
       
   421 		    //Check if Media is removable then force reharvesting else keep indexes same
       
   422 		    MountL(drive,IsMediaRemovableL(drive)); //Mount new media drive for harvesting
       
   423 		    iCurrentDrive = drive;//Index of current drive
       
   424 		    }
       
   425 		    break;
       
   426 		case EMsvMediaUnavailable:
       
   427 		    {
       
   428 		    //No need to handle as when drive will be removed EMsvMediaChanged event
       
   429 		    //will be received for default media drive can be handled there
       
   430 		    //Unmount old media drive
       
   431 		    OstTrace0( TRACE_NORMAL, DUP2_CMESSAGEPLUGIN_HANDLESESSIONEVENTL, "ENTER CMessagePlugin::HandleSessionEventL EMsvMediaUnavailable" );
       
   432 		    CPIXLOGSTRING("ENTER CMessagePlugin::HandleSessionEventL EMsvMediaUnavailable");
       
   433 		    TDriveNumber drive = *(reinterpret_cast<TDriveNumber*>(aArg1));
       
   434 		    UnMount(drive);
       
   435 		    }
       
   436 		    break;
       
   437 		case EMsvMediaAvailable:
       
   438 			{
       
   439 			OstTrace0( TRACE_NORMAL, DUP3_CMESSAGEPLUGIN_HANDLESESSIONEVENTL, "ENTER CMessagePlugin::HandleSessionEventL EMsvMediaAvailable" );
       
   440 			CPIXLOGSTRING("ENTER CMessagePlugin::HandleSessionEventL EMsvMediaAvailable");
       
   441 			//Removed media drive available again mount media drive and unmount default
       
   442 			UnMount(TDriveNumber(iCurrentDrive)); //Unmount current drive
       
   443 			TDriveNumber drive = *(reinterpret_cast<TDriveNumber*>(aArg1));
       
   444 			MountL(drive,IsMediaRemovableL(drive)); //Mount avilable media drive for harvesting
       
   445 			}
       
   446 			break;
       
   447 		case EMsvServerFailedToStart:			
       
   448 		case EMsvCloseSession:
       
   449 		case EMsvServerTerminated:
       
   450 			{
       
   451 			User::Panic(_L("CMessagePlugin PANIC"), KErrServerTerminated);
       
   452 			break;				
       
   453 			}			
       
   454 		case EMsvMtmGroupInstalled:
       
   455 		case EMsvMtmGroupDeInstalled:
       
   456 		case EMsvGeneralError: // not used after v5
       
   457 		case EMsvServerReady:
       
   458 		case EMsvCorruptedIndexRebuilt:
       
   459 		case EMsvMediaIncorrect:
       
   460 		case EMsvCorruptedIndexRebuilding:
       
   461 		default:
       
   462 			{
       
   463 			break;
       
   464 			}							
       
   465 		}	
       
   466 	CPIXLOGSTRING("END CMessagePlugin::HandleSessionEventL");	
       
   467 		
       
   468 	OstTraceFunctionExit0( CMESSAGEPLUGIN_HANDLESESSIONEVENTL_EXIT );
       
   469 	}	
       
   470 
       
   471 // ---------------------------------------------------------------------------
       
   472 // CMessageDataHandler::CalculateMessageType
       
   473 // ---------------------------------------------------------------------------
       
   474 //	    
       
   475 TMsgType CMessagePlugin::CalculateMessageType (const TMsvEntry& aEntry )
       
   476 {
       
   477     OstTraceFunctionEntry0( CMESSAGEPLUGIN_CALCULATEMESSAGETYPE_ENTRY );
       
   478     CPIXLOGSTRING("ENTER CMessagePlugin::CalculateMessageType");
       
   479 	TMsgType ret = EMsgTypeInvalid;
       
   480 	OstTrace1( TRACE_NORMAL, CMESSAGEPLUGIN_CALCULATEMESSAGETYPE, "CMessagePlugin::CalculateMessageType;uid=%x", aEntry.iMtm.iUid );
       
   481 	CPIXLOGSTRING2("CMessagePlugin::CalculateMessageType uid: %x", aEntry.iMtm.iUid );
       
   482     if( aEntry.iMtm.iUid  == KUidMsgTypeMultimedia.iUid ) 
       
   483         {
       
   484         OstTrace0( TRACE_NORMAL, DUP1_CMESSAGEPLUGIN_CALCULATEMESSAGETYPE, "CMessagePlugin:CalculateMessageType  ###  Mms Message ###" );
       
   485         CPIXLOGSTRING("CMessagePlugin:CalculateMessageType  ###  Mms Message ###");
       
   486         ret = EMsgTypeMms;
       
   487         }
       
   488     else if( aEntry.iMtm.iUid  == KUidMsgTypeSMTP.iUid )
       
   489 		{
       
   490 		OstTrace0( TRACE_NORMAL, DUP2_CMESSAGEPLUGIN_CALCULATEMESSAGETYPE, "CMessagePlugin:CalculateMessageType  ### ESmtpEmail ###" );
       
   491 		CPIXLOGSTRING("CMessagePlugin:CalculateMessageType  ### ESmtpEmail ###");
       
   492         ret = EMsgTypeEmailSmtp;
       
   493 		}
       
   494 	else if( aEntry.iMtm.iUid  == KUidMsgTypePOP3.iUid )
       
   495 		{
       
   496 		OstTrace0( TRACE_NORMAL, DUP3_CMESSAGEPLUGIN_CALCULATEMESSAGETYPE, "CMessagePlugin:CalculateMessageType  ### EPop3Email ###" );
       
   497 		CPIXLOGSTRING("CMessagePlugin:CalculateMessageType  ### EPop3Email ###");
       
   498         ret = EMsgTypeEmailPop3;
       
   499 		}
       
   500 	else if( aEntry.iMtm.iUid  == KUidMsgTypeIMAP4.iUid )
       
   501 		{
       
   502 		OstTrace0( TRACE_NORMAL, DUP4_CMESSAGEPLUGIN_CALCULATEMESSAGETYPE, "CMessagePlugin:CalculateMessageType  ### EImap4Email ###" );
       
   503 		CPIXLOGSTRING("CMessagePlugin:CalculateMessageType  ### EImap4Email ###");
       
   504         ret = EMsgTypeEmailImap4;
       
   505 		}
       
   506 	// Add J.J	
       
   507 #ifndef __SERIES60_30__ // Not supported before S60 3d FP1
       
   508    	else if ( aEntry.iMtm.iUid == KSenduiMtmUniMessageUid.iUid )
       
   509 	    {
       
   510 	    OstTrace0( TRACE_NORMAL, DUP5_CMESSAGEPLUGIN_CALCULATEMESSAGETYPE, "CMessagePlugin:CalculateMessageType  ### EDraftMessage ###" );
       
   511 	    CPIXLOGSTRING("CMessagePlugin:CalculateMessageType  ### EDraftMessage ###");
       
   512         ret = EMsgTypeDraft;
       
   513 	    }
       
   514 #endif
       
   515     // else if we have a normal text based SMS it is valid    
       
   516  	else if ( aEntry.iMtm.iUid == KUidMsgTypeSMS.iUid )
       
   517  		{
       
   518  		OstTrace0( TRACE_NORMAL, DUP6_CMESSAGEPLUGIN_CALCULATEMESSAGETYPE, "CMessagePlugin:CalculateMessageType  ###  SMS Message ###" );
       
   519  		CPIXLOGSTRING("CMessagePlugin:CalculateMessageType  ###  SMS Message ###");
       
   520         ret = EMsgTypeSms;
       
   521  		}
       
   522    	else if ( aEntry.iMtm.iUid == KSenduiMtmSmsUid.iUid )
       
   523 		{
       
   524 		OstTrace0( TRACE_NORMAL, DUP7_CMESSAGEPLUGIN_CALCULATEMESSAGETYPE, "CMessagePlugin:CalculateMessageType  ### Sms Message ###" );
       
   525 		CPIXLOGSTRING("CMessagePlugin:CalculateMessageType  ### Sms Message ###");
       
   526         ret = EMsgTypeSms;
       
   527 		}
       
   528     CPIXLOGSTRING("END CMessagePlugin::CalculateMessageType");
       
   529 	OstTraceFunctionExit0( CMESSAGEPLUGIN_CALCULATEMESSAGETYPE_EXIT );
       
   530 	return ret;
       
   531 }
       
   532 
       
   533 // ---------------------------------------------------------------------------
       
   534 // CMessagePlugin::MessageItemL
       
   535 // ---------------------------------------------------------------------------
       
   536 //  
       
   537 void CMessagePlugin::MessageItemL( TMsvId aMsgId, TCPixActionType aActionType, TMsvId aFolderId  )	
       
   538     {
       
   539     //New item found gather data from that.
       
   540      iMessageDataHandler->GatherDataL( aMsgId, aActionType, aFolderId ); 
       
   541     }
       
   542 
       
   543 // ---------------------------------------------------------------------------
       
   544 // CMessagePlugin::HarvestingCompleted
       
   545 // ---------------------------------------------------------------------------
       
   546 //  
       
   547 void CMessagePlugin::HarvestingCompleted(TInt aError)
       
   548 {
       
   549 	// Notifies the indexing manager of completed harvesting, called by CMessageHarvester
       
   550     Flush( *GetIndexer() );
       
   551     TBuf<KMsgPluginBaseAppClassMaxLen> baseAppClass;
       
   552     FormBaseAppClass(TDriveNumber(iCurrentDrive), baseAppClass);
       
   553 #ifdef __PERFORMANCE_DATA
       
   554     TRAP_IGNORE( UpdatePerformaceDataL() );
       
   555 #endif
       
   556     iObserver->HarvestingCompleted(this, baseAppClass, aError);
       
   557 }
       
   558 
       
   559 // ---------------------------------------------------------------------------
       
   560 // CMessagePlugin::UpdatePerformaceDataL
       
   561 // ---------------------------------------------------------------------------
       
   562 //
       
   563 #ifdef __PERFORMANCE_DATA
       
   564 void CMessagePlugin::UpdatePerformaceDataL()
       
   565     {
       
   566     TTime now;
       
   567    
       
   568     
       
   569     iCompleteTime.UniversalTime();
       
   570     TTimeIntervalMicroSeconds timeDiff = iCompleteTime.MicroSecondsFrom(iStartTime);
       
   571     
       
   572     RFs fileSession;
       
   573     RFile perfFile;
       
   574     User::LeaveIfError( fileSession.Connect () );
       
   575     
       
   576     
       
   577     /* Open file if it exists, otherwise create it and write content in it */
       
   578     
       
   579         if(perfFile.Open(fileSession, _L("c:\\data\\MessagePerf.txt"), EFileWrite))
       
   580                    User::LeaveIfError(perfFile.Create (fileSession, _L("c:\\data\\MessagePerf.txt"), EFileWrite));
       
   581     
       
   582     HBufC8 *heap = HBufC8::NewL(100);
       
   583     TPtr8 ptr = heap->Des();
       
   584     now.HomeTime();
       
   585     TBuf<50> timeString;             
       
   586                 
       
   587     _LIT(KOwnTimeFormat,"%:0%H%:1%T%:2%S");
       
   588     now.FormatL(timeString,KOwnTimeFormat);
       
   589     ptr.AppendNum(now.DateTime().Day());
       
   590     ptr.Append(_L("/"));
       
   591     ptr.AppendNum(now.DateTime().Month());
       
   592     ptr.Append(_L("/"));
       
   593     ptr.AppendNum(now.DateTime().Year());
       
   594     ptr.Append(_L(":"));
       
   595     ptr.Append(timeString);
       
   596     ptr.Append( _L("Time taken for Harvesting Message is : "));
       
   597     ptr.AppendNum(timeDiff.Int64()/1000) ;
       
   598     ptr.Append(_L(" MilliSeonds \n"));
       
   599     TInt myInt = 0;
       
   600     perfFile.Seek(ESeekEnd,myInt);
       
   601     perfFile.Write (ptr);
       
   602     perfFile.Close ();
       
   603     fileSession.Close ();
       
   604     delete heap;
       
   605     }
       
   606 
       
   607 // ---------------------------------------------------------------------------
       
   608 // CMessagePlugin::UpdatePerformaceDataL
       
   609 // ---------------------------------------------------------------------------
       
   610 //
       
   611 void CMessagePlugin::UpdatePerformaceDataL(TMsvSessionEvent action) {
       
   612     
       
   613         iCompleteTime.UniversalTime();
       
   614         TTimeIntervalMicroSeconds timeDiff = iCompleteTime.MicroSecondsFrom(iStartTime);
       
   615         
       
   616         RFs fileSession;
       
   617         RFile perfFile;
       
   618         User::LeaveIfError( fileSession.Connect () );
       
   619         
       
   620         
       
   621         /* Open file if it exists, otherwise create it and write content in it */
       
   622         
       
   623             if(perfFile.Open(fileSession, _L("c:\\data\\MessagePerf.txt"), EFileWrite))
       
   624                        User::LeaveIfError(perfFile.Create (fileSession, _L("c:\\data\\MessagePerf.txt"), EFileWrite));
       
   625         
       
   626         HBufC8 *heap = HBufC8::NewL(100);
       
   627         TPtr8 ptr = heap->Des();
       
   628 
       
   629         switch (action) {
       
   630             case EMsvEntriesDeleted: ptr.Append( _L("del "));break;
       
   631             case EMsvEntriesChanged: ptr.Append( _L("upd "));break;
       
   632             case EMsvEntriesMoved: ptr.Append( _L("mov "));break;
       
   633         }
       
   634         ptr.AppendNum(timeDiff.Int64()/1000) ;
       
   635         ptr.Append(_L("\n"));
       
   636         TInt myInt = 0;
       
   637         perfFile.Seek(ESeekEnd,myInt);
       
   638         perfFile.Write (ptr);
       
   639         perfFile.Close ();
       
   640         fileSession.Close ();
       
   641         delete heap;
       
   642     }
       
   643 
       
   644 #endif