codhandler/codeng/src/CodProgress.cpp
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2004 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 the License "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: 
       
    15 *      Implementation of class TCodProgress.   
       
    16 *      
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include "CodProgress.h"
       
    24 #include "CodLoadObserver.h"
       
    25 #include "CodPanic.h"
       
    26 #include "CodLogger.h"
       
    27 #include "FileExt.h"
       
    28 
       
    29 // ================= MEMBER FUNCTIONS =======================
       
    30 
       
    31 // ---------------------------------------------------------
       
    32 // TCodProgress::NotifyObserverL()
       
    33 // ---------------------------------------------------------
       
    34 //
       
    35 void TCodProgress::NotifyObserverL()
       
    36     {
       
    37     CLOG(( ECodEng, 2, _L("TCodProgress::NotifyObserverL (0x%x) %d/%d"), \
       
    38         iObserver, CurrentValue(), FinalValue() ));
       
    39     if ( iObserver )
       
    40         {
       
    41         iObserver->ProgressL( FinalValue(), CurrentValue() );
       
    42         }
       
    43     }
       
    44 // ---------------------------------------------------------
       
    45 // TCodProgress::SetObserver()
       
    46 // ---------------------------------------------------------
       
    47 //
       
    48 void TCodProgress::SetObserver( MCodLoadObserver* aObserver )
       
    49     {
       
    50     CLOG(( ECodEng, 2, _L("TCodProgress::SetObserver(0x%x)"), aObserver ));
       
    51     __ASSERT_ALWAYS( !(aObserver && iObserver), \
       
    52         CodPanic( ECodObserverAlreadySet ) );
       
    53     iObserver = aObserver;
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------
       
    57 // TCodProgress::Setup()
       
    58 // ---------------------------------------------------------
       
    59 //
       
    60 void TCodProgress::Setup( TInt aLoad, TInt aNotify )
       
    61     {
       
    62     CLOG(( ECodEng, 2, \
       
    63         _L("TCodProgress::Setup load(%d) notify(%d)"), aLoad, aNotify ));
       
    64     iPhase = ELoad;
       
    65     iMax[ELoad] = aLoad;
       
    66     iMax[ENotify] = aNotify;
       
    67     iCur[ELoad] = 0;
       
    68     iCur[ENotify] = 0;
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------
       
    72 // TCodProgress::StartPhaseL()
       
    73 // ---------------------------------------------------------
       
    74 //
       
    75 void TCodProgress::StartPhaseL( TPhase aPhase )
       
    76     {
       
    77     CLOG(( ECodEng, 2, _L("TCodProgress::StartPhaseL(%d)"), aPhase ));
       
    78     iPhase = aPhase;
       
    79     NotifyObserverL();
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------
       
    83 // TCodProgress::IncrementL()
       
    84 // ---------------------------------------------------------
       
    85 //
       
    86 void TCodProgress::IncrementL( TInt aBytes )
       
    87     {
       
    88     CLOG(( ECodEng, 2, _L("TCodProgress::IncrementL (%d)"), aBytes ));
       
    89     if ( aBytes >= 0 )
       
    90         {
       
    91         iCur[iPhase] += aBytes;
       
    92         if ( iCur[iPhase] > iMax[iPhase] )
       
    93             {
       
    94             // Raise underestimated max. to match current.
       
    95             // Remaining unchanged, max. raised -> progress goes forward.
       
    96             iMax[iPhase] = iCur[iPhase];
       
    97             }
       
    98         }
       
    99         NotifyObserverL();
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------
       
   103 // TCodProgress::SetAmountL()
       
   104 // ---------------------------------------------------------
       
   105 //
       
   106 void TCodProgress::SetAmountL( TInt aBytes )
       
   107     {
       
   108     CLOG(( ECodEng, 2, _L("TCodProgress::SetAmountL (%d)"), aBytes ));
       
   109 
       
   110     iCur[iPhase] = aBytes;
       
   111     if ( iCur[iPhase] > iMax[iPhase] )
       
   112         {
       
   113         // Raise underestimated max. to match current.
       
   114         // Remaining unchanged, max. raised -> progress goes forward.
       
   115         iMax[iPhase] = iCur[iPhase];
       
   116         }
       
   117     NotifyObserverL();
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------
       
   121 // TCodProgress::DoneL()
       
   122 // ---------------------------------------------------------
       
   123 //
       
   124 void TCodProgress::DoneL()
       
   125     {
       
   126     CLOG(( ECodEng, 2, _L("TCodProgress::DoneL") ));
       
   127     NotifyObserverL();
       
   128     }