harvester/client/src/harvesterclientao.cpp
changeset 54 a3cc46f37772
parent 36 aa5a574040a4
--- a/harvester/client/src/harvesterclientao.cpp	Tue Jul 06 14:44:37 2010 +0300
+++ b/harvester/client/src/harvesterclientao.cpp	Fri Sep 17 16:54:49 2010 +0300
@@ -51,7 +51,7 @@
     OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_CHARVESTERCLIENTAO, "CHarvesterClientAO::~CHarvesterClientAO" );
     
     WRITELOG( "CHarvesterClientAO::~CHarvesterClientAO()" );
-    Cancel();
+    CancelRequest();
  	}
 
 // ---------------------------------------------------------------------------
@@ -60,9 +60,10 @@
 // ---------------------------------------------------------------------------
 //
 CHarvesterClientAO::CHarvesterClientAO( RHarvesterClient& aHarvesterClient )
-    : CActive( CActive::EPriorityStandard ), 
+    : CActive( CActive::EPriorityUserInput ), 
     iObserver( NULL ),
-    iHarvesterClient( aHarvesterClient )
+    iHarvesterClient( aHarvesterClient ),
+    iCancelled( EFalse )
   	{
     OstTrace0( TRACE_NORMAL, DUP1_CHARVESTERCLIENTAO_CHARVESTERCLIENTAO, "CHarvesterClientAO::CHarvesterClientAO" );
     
@@ -97,19 +98,17 @@
 // RemoveObserver
 // ---------------------------------------------------------------------------
 //	
-void CHarvesterClientAO::RemoveObserver( MHarvestObserver* aObserver )
+void CHarvesterClientAO::RemoveObserver( MHarvestObserver* /*aObserver*/ )
 	{
 	WRITELOG( "CHarvesterClientAO::RemoveObserver()" );
 	OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_REMOVEOBSERVER, "CHarvesterClientAO::RemoveObserver" );
-	
-	if ( aObserver == iObserver )
-		{
-		if ( iObserver )
-			{
-			WRITELOG( "CHarvesterClientAO::RemoveObserver() - deleting observer" );
-			iObserver = NULL;
-			}
-		}
+    if ( iObserver )
+        {
+        WRITELOG( "CHarvesterClientAO::RemoveObserver() - deleting observer" );
+        iObserver = NULL;
+        }
+    
+    CancelRequest();
 	}
 
 // ---------------------------------------------------------------------------
@@ -120,7 +119,8 @@
 	{
 	WRITELOG( "CHarvesterClientAO::DoCancel()" );
 	OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_DOCANCEL, "CHarvesterClientAO::DoCancel" );
-	
+	iHarvesterClient.UnregisterHarvestComplete();
+	WRITELOG( "CHarvesterClientAO::DoCancel() - end" );
 	}
 	
 // ---------------------------------------------------------------------------
@@ -129,9 +129,12 @@
 //
 void CHarvesterClientAO::Active()
 	{	
-	if (!IsActive())
+    WRITELOG( "CHarvesterClientAO::Active" );
+	if ( iObserver && !IsActive())
 		{
+	    WRITELOG( "CHarvesterClientAO::Active - calling RegisterHarvestComplete" );
 		iHarvesterClient.RegisterHarvestComplete(iURI, iStatus);
+		iCancelled = EFalse;
 		SetActive();
 		}
 	}
@@ -144,7 +147,6 @@
 	{
 	WRITELOG( "CHarvesterClientAO::RunL()" );
 	OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_RUNL, "CHarvesterClientAO::RunL" );
-	
 
 	const TInt status = iStatus.Int();
 	
@@ -161,10 +163,12 @@
 		}
 	
 	// if the request was not canceled or server is not terminated, Activating AO again
-	if ( status != KErrCancel && status != KErrServerTerminated )
+	if ( status != KErrCancel && status != KErrServerTerminated && iObserver && !iCancelled )
 		{
+	    WRITELOG( "CHarvesterClientAO::RunL() - not cancelled or terminated, calling Active" );
 		Active();
 		}
+	WRITELOG( "CHarvesterClientAO::RunL() - end" );
 	}
 	
 // ---------------------------------------------------------------------------
@@ -181,3 +185,24 @@
     
     return KErrNone;
     }
+
+// ---------------------------------------------------------------------------
+// Active
+// ---------------------------------------------------------------------------
+//
+void CHarvesterClientAO::CancelRequest()
+    {   
+    WRITELOG( "CHarvesterClientAO::CancelRequest" );
+    if( !iCancelled )
+        {
+        WRITELOG( "CHarvesterClientAO::CancelRequest - not cancelled, calling Cancel" );
+        iCancelled = ETrue;
+        Cancel();
+        }
+    if( !IsActive() )
+        {
+        WRITELOG( "CHarvesterClientAO::CancelRequest - setting priority to High" );
+        SetPriority( CActive::EPriorityHigh );
+        }
+    }
+