harvester/client/src/harvesterrequestactive.cpp
changeset 0 c53acadfccc6
child 1 acef663c1218
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2009 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:  Active object for an asynchronous harvesrt request
       
    15  *
       
    16 */
       
    17 
       
    18 #include <e32base.h>
       
    19 
       
    20 #include "harvesterrequestactive.h"
       
    21 #include "harvesterrequestqueue.h"
       
    22 
       
    23 // ======== MEMBER FUNCTIONS ========
       
    24 
       
    25 // ---------------------------------------------------------------------------
       
    26 // CHarvesterRequestActive::~CHarvesterRequestActive()
       
    27 // Destructor.
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 CHarvesterRequestActive::~CHarvesterRequestActive()
       
    31     {
       
    32     if( IsActive() )
       
    33         {
       
    34         Cancel();
       
    35         if( iObserver )
       
    36             {
       
    37             iObserver->HarvestingComplete( iUri, KErrCancel );
       
    38             }    
       
    39         iRequestCompleted = ETrue;
       
    40         }
       
    41     
       
    42     delete iAlbumIds;
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CHarvesterRequestActive::NewL
       
    47 // Two-phased constructor.
       
    48 // --------------------------------------------------------------------------- 
       
    49 //
       
    50 CHarvesterRequestActive* CHarvesterRequestActive::NewL(
       
    51         RHarvesterClient& aClient, MHarvestObserver* aObserver,
       
    52         TInt aService, const TDesC& aUri, 
       
    53         HBufC8* aAlbumIds, TBool& aAddLocation,
       
    54         CHarvesterRequestQueue* aQueue )
       
    55     {
       
    56     CHarvesterRequestActive* self = new( ELeave )CHarvesterRequestActive( aClient, aObserver,
       
    57             aService, aUri, aAlbumIds, aAddLocation, aQueue );
       
    58     return self;
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CHarvesterRequestActive::CHarvesterRequestActive()
       
    63 // C++ default constructor can NOT contain any code, that might leave.
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 CHarvesterRequestActive::CHarvesterRequestActive( RHarvesterClient& aClient,
       
    67     MHarvestObserver* aObserver, TInt aService, const TDesC& aUri, 
       
    68     HBufC8* aAlbumIds, TBool& aAddLocation, CHarvesterRequestQueue* aQueue )
       
    69     : CActive( CActive::EPriorityStandard ), iClient( aClient ), iObserver( aObserver ), 
       
    70     iService( aService ), iUri( aUri ), iAlbumIds( aAlbumIds ), iAddLocation( aAddLocation ),
       
    71     iRequestQueue( aQueue ), iLocation( EFalse )
       
    72     {
       
    73     CActiveScheduler::Add( this );
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CHarvesterRequestActive::RunL()
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 void CHarvesterRequestActive::RunL()
       
    81     {
       
    82     if( iStatus.Int() && iObserver )
       
    83         {
       
    84         iObserver->HarvestingComplete( iUri, iStatus.Int() );
       
    85         }       
       
    86     iRequestCompleted = ETrue;
       
    87     if( iRequestQueue )
       
    88         {
       
    89         iRequestQueue->RequestComplete();
       
    90         }
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // CHarvesterRequestActive::RunError()
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 TInt CHarvesterRequestActive::RunError( TInt aError )
       
    98     {
       
    99     if( aError == KErrCancel )
       
   100         {
       
   101         return KErrNone;
       
   102         }
       
   103     
       
   104     if( iObserver )
       
   105         {
       
   106         iObserver->HarvestingComplete( iUri, aError );
       
   107         }    
       
   108     iRequestCompleted = ETrue;
       
   109     return KErrNone;
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // CHarvesterRequestActive::DoCancel()
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 void CHarvesterRequestActive::DoCancel()
       
   117     {
       
   118     // Nothing to do here
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // CHarvesterRequestActive::Start()
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 void CHarvesterRequestActive::Start()
       
   126     {
       
   127     TPckg<TBool> location( iAddLocation );
       
   128     iLocation.Set( location );
       
   129     
       
   130     TIpcArgs ipcArgs( &iUri, iAlbumIds, &iLocation );
       
   131     iPersistentArgs = ipcArgs;
       
   132     
       
   133     iClient.HarvestFile( iService, iPersistentArgs, iStatus );
       
   134     SetActive();
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // CHarvesterRequestActive::ForceHarvest()
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 void CHarvesterRequestActive::ForceHarvest()
       
   142     {
       
   143     iObserver = NULL;
       
   144     
       
   145     TPckg<TBool> location( iAddLocation );
       
   146     iLocation.Set( location );
       
   147     
       
   148     TIpcArgs ipcArgs( &iUri, iAlbumIds, &iLocation );
       
   149     iPersistentArgs = ipcArgs;
       
   150     
       
   151     iClient.ForceHarvestFile( iService, iPersistentArgs );
       
   152     }
       
   153 
       
   154 // End of file