iaupdate/IAD/engine/controller/src/iaupdatecachecleaner.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     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:   ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <ncdprovider.h>
       
    22 
       
    23 #include "iaupdatecachecleaner.h"
       
    24 #include "iaupdatedebug.h"
       
    25 
       
    26 
       
    27 CIAUpdateCacheCleaner* CIAUpdateCacheCleaner::NewL( MNcdProvider& aProvider )
       
    28     {
       
    29     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateCacheCleaner::NewL begin");
       
    30     CIAUpdateCacheCleaner* self(
       
    31         CIAUpdateCacheCleaner::NewLC( aProvider ) );
       
    32     CleanupStack::Pop( self );
       
    33     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateCacheCleaner::NewL end");
       
    34     return self;
       
    35     }
       
    36     
       
    37     
       
    38 CIAUpdateCacheCleaner* CIAUpdateCacheCleaner::NewLC( MNcdProvider& aProvider )
       
    39     {
       
    40     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateCacheCleaner::NewLC begin");
       
    41     CIAUpdateCacheCleaner* self(
       
    42         new( ELeave ) CIAUpdateCacheCleaner( aProvider ) );
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateCacheCleaner::NewLC end");
       
    46     return self;
       
    47     }
       
    48 
       
    49 
       
    50 CIAUpdateCacheCleaner::CIAUpdateCacheCleaner( MNcdProvider& aProvider )
       
    51 : CActive( CActive::EPriorityStandard ),
       
    52   iProvider( aProvider )
       
    53     {
       
    54     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateCacheCleaner::CIAUpdateCacheCleaner begin");    
       
    55 
       
    56     CActiveScheduler::Add( this );
       
    57 
       
    58     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateCacheCleaner::CIAUpdateCacheCleaner end");
       
    59     }
       
    60 
       
    61 
       
    62 void CIAUpdateCacheCleaner::ConstructL()
       
    63     {
       
    64     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateCacheCleaner::ConstructL");
       
    65     }
       
    66     
       
    67     
       
    68 CIAUpdateCacheCleaner::~CIAUpdateCacheCleaner()
       
    69     {
       
    70     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateCacheCleaner::~CIAUpdateCacheCleaner begin");    
       
    71     
       
    72     // Wait until the ongoing operation is finished.
       
    73     // Cancel handles this.
       
    74     Cancel();
       
    75 
       
    76     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateCacheCleaner::~CIAUpdateCacheCleaner end");
       
    77     }
       
    78 
       
    79 
       
    80 void CIAUpdateCacheCleaner::ClearL( TRequestStatus& aStatus )
       
    81     {
       
    82     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateCacheCleaner::ClearL begin");    
       
    83     
       
    84     if ( IsActive()
       
    85          || iRequestStatus )
       
    86         {
       
    87         IAUPDATE_TRACE("[IAUPDATE] ERROR: ClearL already started");
       
    88         User::Leave( KErrInUse );
       
    89         }
       
    90 
       
    91     // Use provider to clear the cache.
       
    92     // This will asynchronously finish the operation
       
    93     // and update the status when operation finishes.
       
    94     // Start to wait the completion in this active object.
       
    95     iProvider.ClearCacheL( iStatus );
       
    96     SetActive();
       
    97 
       
    98     // Set the pending value for the request.
       
    99     // Notice, iRequestStatus is just a reference to the
       
   100     // actual status object of the user of this object.
       
   101     // The user will be informed when the operation finishes
       
   102     // by completing the request.
       
   103     aStatus = KRequestPending;
       
   104     iRequestStatus = &aStatus;
       
   105 
       
   106     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateCacheCleaner::ClearL begin");    
       
   107     }
       
   108 
       
   109 
       
   110 void CIAUpdateCacheCleaner::DoCancel()
       
   111     {
       
   112     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateCacheCleaner::DoCancel begin");    
       
   113     
       
   114     // Because we do not have any means to cancel the actual
       
   115     // operation. We need to use CActiveSchedulerWait::Start
       
   116     // here. This way this function will not proceed directly
       
   117     // to the User::WaitForRequest in Cancel after DoCancel. 
       
   118     // That would block the thread and the iStatus
       
   119     // would not be updated by the cache clear operation. 
       
   120     // Then, Cancel would be stuck forever. iWaiter->AsyncStop
       
   121     // is called in RunL that is in turn called when the actual 
       
   122     // operation finishes. Then, this will continue and the 
       
   123     // RunL has set the iStatus and Cancel can continue also.
       
   124     TRAP_IGNORE( iWaiter = new( ELeave ) CActiveSchedulerWait() );
       
   125 	if ( iWaiter  )
       
   126 	    {
       
   127         iWaiter->Start();
       
   128         }
       
   129     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateCacheCleaner::DoCancel begin");    
       
   130     }
       
   131     
       
   132     
       
   133 void CIAUpdateCacheCleaner::RunL()
       
   134     {
       
   135     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateCacheCleaner::RunL begin");    
       
   136     
       
   137     TInt errorCode( iStatus.Int() );
       
   138     IAUPDATE_TRACE_1("[IAUPDATE] Error code: %d", errorCode);
       
   139     
       
   140     if ( iWaiter )
       
   141         {
       
   142         IAUPDATE_TRACE("[IAUPDATE] Waiter exists. Cancel should be going on.");
       
   143         
       
   144         // Notice, that we come here only when the Cancel is
       
   145         // called for this operation and there was an cache
       
   146         // clear operation going on.
       
   147 
       
   148         // Stop the waiter. 
       
   149         // So, DoCancel may continue after this.
       
   150         iWaiter->AsyncStop();    
       
   151         delete iWaiter;
       
   152         iWaiter = NULL;
       
   153 
       
   154         // Update the request status.
       
   155         // So, Cancel can continue after DoCancel.
       
   156         TRequestStatus* status( &iStatus );
       
   157         User::RequestComplete( status, errorCode );
       
   158         }
       
   159     else
       
   160         {
       
   161         IAUPDATE_TRACE("[IAUPDATE] Cache clear operation done.");
       
   162         
       
   163         // Complete the original operation because it
       
   164         // has completed normally.
       
   165         User::RequestComplete( iRequestStatus, errorCode );
       
   166         }
       
   167 
       
   168     // Because the operation is finished now,
       
   169     // set the request status pointer to NULL.
       
   170     iRequestStatus = NULL;
       
   171 
       
   172     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateCacheCleaner::RunL end");
       
   173     }
       
   174 
       
   175 
       
   176 TInt CIAUpdateCacheCleaner::RunError( TInt aError )
       
   177     {
       
   178     IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateCacheCleaner::RunError: %d", aError);
       
   179     
       
   180     // Because the operation is finished now,
       
   181     // set the request status pointer to NULL.
       
   182     iRequestStatus = NULL;    
       
   183     
       
   184     // Notice, that if the return value is not KErrNone,
       
   185     // the code will panic.
       
   186     return aError;
       
   187     }