harvester/client/src/harvesterrequestactive.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 11 Jun 2010 14:04:21 +0300
changeset 31 81125601ee77
parent 20 6dfc5f825351
child 40 910a23996aa0
child 45 a93990e5815e
child 47 b73252188534
permissions -rw-r--r--
Revision: 201021 Kit: 2010123

/*
* 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 ), iCancelled( 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()
    {
    iCancelled = ETrue;
    }

// ---------------------------------------------------------------------------
// CHarvesterRequestActive::Start()
// ---------------------------------------------------------------------------
//
void CHarvesterRequestActive::Start()
    {
    TPckg<TBool> location( iAddLocation );
    iLocation.Set( location );
    
    TIpcArgs ipcArgs( &iUri, iAlbumIds, &iLocation );
    iPersistentArgs = ipcArgs;
    
    if( !iCancelled )
        {
        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