harvester/common/src/harvesterplugin.cpp
changeset 1 acef663c1218
parent 0 c53acadfccc6
child 8 6752808b2036
child 20 6dfc5f825351
--- a/harvester/common/src/harvesterplugin.cpp	Mon Jan 18 20:34:07 2010 +0200
+++ b/harvester/common/src/harvesterplugin.cpp	Tue Jan 26 12:13:20 2010 +0200
@@ -24,8 +24,11 @@
 #include "harvesterlog.h"
 #include "harvestercommon.h"
 #include "harvesterblacklist.h"
+#include "harvestereventmanager.h"
 #include "mdsutils.h"
 
+const TInt KCacheItemCountForEventCaching = 1;
+
 // ---------------------------------------------------------------------------
 // NewL
 // ---------------------------------------------------------------------------
@@ -49,6 +52,7 @@
 	{
 	User::LeaveIfError( iFs.Connect() );
 	iState = EHarvesterIdle;
+	iHarvesterEventManager = CHarvesterEventManager::GetInstanceL();
 	CActiveScheduler::Add( this );
 	}
 
@@ -86,6 +90,11 @@
 EXPORT_C CHarvesterPlugin::~CHarvesterPlugin() // destruct - virtual
 	{
 	Cancel();
+
+    if (iHarvesterEventManager)
+        {
+        iHarvesterEventManager->ReleaseInstance();
+        }
 	
 	iFs.Close();
 	REComSession::DestroyedImplementation( iDtor_ID_Key );
@@ -139,10 +148,22 @@
             if( iQueue->Count() == 0 )
                 {
                 SetNextRequest( EHarvesterIdle );
+                iHarvesting = EFalse;                       
+                iHarvesterEventManager->SendEventL( EHEObserverTypeOverall, EHEStateFinished );
+                iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeOverall, KCacheItemCountForEventCaching );
                 iQueue->Compress();
                 }
             else
             	{
+                if ( !iHarvesting )
+                    {
+                    iHarvesting = ETrue;
+                    iHarvesterEventManager->SendEventL( EHEObserverTypeOverall, EHEStateStarted );
+                    // This next line is for caching the harvester started event for observers registering
+                    // after harvesting has already started
+                    iHarvesterEventManager->IncreaseItemCount( EHEObserverTypeOverall, KCacheItemCountForEventCaching );
+                    }
+            
             	CHarvesterData* hd = (*iQueue)[0];
             	iQueue->Remove( 0 );
             	const TDesC& uri = hd->Uri();