harvester/client/src/harvesterrequestactive.cpp
changeset 0 c53acadfccc6
child 1 acef663c1218
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/harvester/client/src/harvesterrequestactive.cpp	Mon Jan 18 20:34:07 2010 +0200
@@ -0,0 +1,154 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  Active object for an asynchronous harvesrt request
+ *
+*/
+
+#include <e32base.h>
+
+#include "harvesterrequestactive.h"
+#include "harvesterrequestqueue.h"
+
+// ======== MEMBER FUNCTIONS ========
+
+// ---------------------------------------------------------------------------
+// CHarvesterRequestActive::~CHarvesterRequestActive()
+// Destructor.
+// ---------------------------------------------------------------------------
+//
+CHarvesterRequestActive::~CHarvesterRequestActive()
+    {
+    if( IsActive() )
+        {
+        Cancel();
+        if( iObserver )
+            {
+            iObserver->HarvestingComplete( iUri, KErrCancel );
+            }    
+        iRequestCompleted = ETrue;
+        }
+    
+    delete iAlbumIds;
+    }
+
+// ---------------------------------------------------------------------------
+// CHarvesterRequestActive::NewL
+// Two-phased constructor.
+// --------------------------------------------------------------------------- 
+//
+CHarvesterRequestActive* CHarvesterRequestActive::NewL(
+        RHarvesterClient& aClient, MHarvestObserver* aObserver,
+        TInt aService, const TDesC& aUri, 
+        HBufC8* aAlbumIds, TBool& aAddLocation,
+        CHarvesterRequestQueue* aQueue )
+    {
+    CHarvesterRequestActive* self = new( ELeave )CHarvesterRequestActive( aClient, aObserver,
+            aService, aUri, aAlbumIds, aAddLocation, aQueue );
+    return self;
+    }
+
+// ---------------------------------------------------------------------------
+// CHarvesterRequestActive::CHarvesterRequestActive()
+// C++ default constructor can NOT contain any code, that might leave.
+// ---------------------------------------------------------------------------
+//
+CHarvesterRequestActive::CHarvesterRequestActive( RHarvesterClient& aClient,
+    MHarvestObserver* aObserver, TInt aService, const TDesC& aUri, 
+    HBufC8* aAlbumIds, TBool& aAddLocation, CHarvesterRequestQueue* aQueue )
+    : CActive( CActive::EPriorityStandard ), iClient( aClient ), iObserver( aObserver ), 
+    iService( aService ), iUri( aUri ), iAlbumIds( aAlbumIds ), iAddLocation( aAddLocation ),
+    iRequestQueue( aQueue ), iLocation( EFalse )
+    {
+    CActiveScheduler::Add( this );
+    }
+
+// ---------------------------------------------------------------------------
+// CHarvesterRequestActive::RunL()
+// ---------------------------------------------------------------------------
+//
+void CHarvesterRequestActive::RunL()
+    {
+    if( iStatus.Int() && iObserver )
+        {
+        iObserver->HarvestingComplete( iUri, iStatus.Int() );
+        }       
+    iRequestCompleted = ETrue;
+    if( iRequestQueue )
+        {
+        iRequestQueue->RequestComplete();
+        }
+    }
+
+// ---------------------------------------------------------------------------
+// CHarvesterRequestActive::RunError()
+// ---------------------------------------------------------------------------
+//
+TInt CHarvesterRequestActive::RunError( TInt aError )
+    {
+    if( aError == KErrCancel )
+        {
+        return KErrNone;
+        }
+    
+    if( iObserver )
+        {
+        iObserver->HarvestingComplete( iUri, aError );
+        }    
+    iRequestCompleted = ETrue;
+    return KErrNone;
+    }
+
+// ---------------------------------------------------------------------------
+// CHarvesterRequestActive::DoCancel()
+// ---------------------------------------------------------------------------
+//
+void CHarvesterRequestActive::DoCancel()
+    {
+    // Nothing to do here
+    }
+
+// ---------------------------------------------------------------------------
+// CHarvesterRequestActive::Start()
+// ---------------------------------------------------------------------------
+//
+void CHarvesterRequestActive::Start()
+    {
+    TPckg<TBool> location( iAddLocation );
+    iLocation.Set( location );
+    
+    TIpcArgs ipcArgs( &iUri, iAlbumIds, &iLocation );
+    iPersistentArgs = ipcArgs;
+    
+    iClient.HarvestFile( iService, iPersistentArgs, iStatus );
+    SetActive();
+    }
+
+// ---------------------------------------------------------------------------
+// CHarvesterRequestActive::ForceHarvest()
+// ---------------------------------------------------------------------------
+//
+void CHarvesterRequestActive::ForceHarvest()
+    {
+    iObserver = NULL;
+    
+    TPckg<TBool> location( iAddLocation );
+    iLocation.Set( location );
+    
+    TIpcArgs ipcArgs( &iUri, iAlbumIds, &iLocation );
+    iPersistentArgs = ipcArgs;
+    
+    iClient.ForceHarvestFile( iService, iPersistentArgs );
+    }
+
+// End of file