filemanager/src/fmbkupengine/src/RMMCScBkupProgressSizer.cpp
branchRCL_3
changeset 20 491b3ed49290
equal deleted inserted replaced
19:95243422089a 20:491b3ed49290
       
     1 /*
       
     2 * Copyright (c) 2005-2008 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: RMMCScBkupProgressSizer implementation
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 #include "RMMCScBkupProgressSizer.h"
       
    20 
       
    21 // User includes
       
    22 #include "MMCScBkupLogger.h"
       
    23 #include "MMCScBkupSBEUtils.h"
       
    24 #include "CMMCScBkupDataOwnerInfo.h"
       
    25 #include "MMMCScBkupProgressObserver.h"
       
    26 #include "CMMCScBkupDriveAndOperationTypeManager.h"
       
    27 
       
    28 // Constants
       
    29 const TInt KMMCScBkupWeightingFactor = 10000;
       
    30 
       
    31 
       
    32 
       
    33 // ========================= MEMBER FUNCTIONS ================================
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // RMMCScBkupProgressSizer::RMMCScBkupProgressSizer()
       
    37 // 
       
    38 // C++ constructor.
       
    39 // ---------------------------------------------------------------------------
       
    40 RMMCScBkupProgressSizer::RMMCScBkupProgressSizer( const CMMCScBkupDriveAndOperationTypeManager& aDriveAndOperationTypes )
       
    41 :   iDriveAndOperationTypes( aDriveAndOperationTypes ), iDriveFilter( aDriveAndOperationTypes.DriveList() )
       
    42     {
       
    43     }
       
    44 
       
    45    
       
    46 // ---------------------------------------------------------------------------
       
    47 // RMMCScBkupProgressSizer::BackupTotalProgressValueL()
       
    48 // 
       
    49 // Calculate the total amount of progress steps that a particular data owner 
       
    50 // requires. This method can only be called after all of the sizing info
       
    51 // has been obtained from the SBE
       
    52 // ---------------------------------------------------------------------------
       
    53 TInt64 RMMCScBkupProgressSizer::BackupTotalProgressValueL( const CMMCScBkupDataOwnerInfo& aDataOwner )
       
    54     {
       
    55     __LOG(" ");
       
    56     __LOG1("RMMCScBkupProgressSizer::BackupTotalProgressValueL() - START - DO: 0x%08x", aDataOwner.SecureId().iId);
       
    57     TInt64 totalStepCount = 0;
       
    58 
       
    59     //////////////////////////////////////////////////////////////////////
       
    60     // THESE ELEMENTS HAVE PSEUDO-PROGRESS - that is, the report a fixed
       
    61     // number of progress nibbles per operation. For example:
       
    62     // 
       
    63     // TYPE     DRIVE        PROGRESS
       
    64     // =======================================
       
    65     // ACTIVE   (C:)          1 x 2000
       
    66     // PASSIVE  (C:)          1 x 2000
       
    67     // SYSTEM   (C:, E:)      2 x 2000
       
    68     // JAVA     (C:)          1 x 2000
       
    69     // PUBLIC   (C: = 12k)   12 x 1024
       
    70     // ----------------------------------------
       
    71     // total                 10000 + (12 x 1024)
       
    72     //
       
    73     //////////////////////////////////////////////////////////////////////
       
    74 
       
    75     const CDataOwnerInfo& sbeDataOwner = aDataOwner.Owner();
       
    76     
       
    77     // Passive data
       
    78     if  ( MMCScBkupSBEUtils::HasPassiveDataL( sbeDataOwner ) )
       
    79         {
       
    80         const TInt opsCount = NumberOfDriveOpsRequiredL( aDataOwner, EMMCScBkupOwnerDataTypePassiveData );
       
    81         __LOG2("RMMCScBkupProgressSizer::BackupTotalProgressValueL() - passive - %d of progress (%d ops)", opsCount * KMMCScBkupWeightingFactor, opsCount);
       
    82         totalStepCount += ( opsCount * KMMCScBkupWeightingFactor );
       
    83         }
       
    84 
       
    85     // Active data
       
    86     if  ( MMCScBkupSBEUtils::HasActiveDataL( sbeDataOwner ) )
       
    87         {
       
    88         const TInt opsCount = NumberOfDriveOpsRequiredL( aDataOwner, EMMCScBkupOwnerDataTypeActiveData );
       
    89         __LOG2("RMMCScBkupProgressSizer::BackupTotalProgressValueL() - active  - %d of progress (%d ops)", opsCount * KMMCScBkupWeightingFactor, opsCount);
       
    90         totalStepCount += ( opsCount * KMMCScBkupWeightingFactor );
       
    91         }
       
    92 
       
    93     // System data
       
    94     if  ( MMCScBkupSBEUtils::HasSystemDataL( sbeDataOwner ) )
       
    95         {
       
    96         const TInt opsCount = NumberOfDriveOpsRequiredL( aDataOwner, EMMCScBkupOwnerDataTypeSystemData );
       
    97         __LOG2("RMMCScBkupProgressSizer::BackupTotalProgressValueL() - system  - %d of progress (%d ops)", opsCount * KMMCScBkupWeightingFactor, opsCount);
       
    98         totalStepCount += ( opsCount * KMMCScBkupWeightingFactor );
       
    99         }
       
   100 
       
   101     // Java data
       
   102     if  ( MMCScBkupSBEUtils::HasJavaDataL( sbeDataOwner ) )
       
   103         {
       
   104         const TInt opsCount = NumberOfDriveOpsRequiredL( aDataOwner, EMMCScBkupOwnerDataTypeJavaData );
       
   105         __LOG2("RMMCScBkupProgressSizer::BackupTotalProgressValueL() - java    - %d of progress (%d ops)", opsCount * KMMCScBkupWeightingFactor, opsCount);
       
   106         totalStepCount += ( opsCount * KMMCScBkupWeightingFactor );
       
   107         }
       
   108 
       
   109 
       
   110     ///////////////////////////////////
       
   111     // PUBLIC REPORTS ACTUAL SIZING
       
   112     ///////////////////////////////////
       
   113 
       
   114     // Public data
       
   115     if  ( MMCScBkupSBEUtils::HasPublicDataL( sbeDataOwner ) )
       
   116         {
       
   117         const TInt64 size = AmountOfPublicDataToBeRestoredL( aDataOwner );
       
   118         __LOG1("RMMCScBkupProgressSizer::BackupTotalProgressValueL() - public  - %Ld of progress", size);
       
   119         totalStepCount += size;
       
   120         }
       
   121 
       
   122     //
       
   123     __LOG2("RMMCScBkupProgressSizer::BackupTotalProgressValueL() - END - DO: 0x%08x, totalStepCount: %8Ld", aDataOwner.SecureId().iId, totalStepCount);
       
   124     return totalStepCount;
       
   125     }
       
   126 
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // RMMCScBkupProgressSizer::BackupReportFixedProgressForOpL()
       
   130 // 
       
   131 // 
       
   132 // ---------------------------------------------------------------------------
       
   133 void RMMCScBkupProgressSizer::BackupReportFixedProgressForOpL( MMMCScBkupProgressObserver& aProgressManager, TMMCScBkupOwnerDataType aType )
       
   134     {
       
   135     switch( aType )
       
   136         {
       
   137     case EMMCScBkupOwnerDataTypeSystemData:
       
   138     case EMMCScBkupOwnerDataTypeActiveData:
       
   139     case EMMCScBkupOwnerDataTypePassiveData:
       
   140     case EMMCScBkupOwnerDataTypeJavaData:
       
   141         __LOG2("RMMCScBkupProgressSizer::BackupReportFixedProgressForOpL() - aType: %d, amount: %d ", aType, KMMCScBkupWeightingFactor );
       
   142         aProgressManager.MMCScBkupHandleProgress( KMMCScBkupWeightingFactor );
       
   143         break;
       
   144     default:
       
   145     case EMMCScBkupOwnerDataTypeDataOwner:
       
   146     case EMMCScBkupOwnerDataTypePublicData:
       
   147         ASSERT( EFalse );
       
   148         break;
       
   149         }
       
   150     }
       
   151 
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // RMMCScBkupProgressSizer::RestoreCombinedDataSizeL()
       
   155 // 
       
   156 // 
       
   157 // ---------------------------------------------------------------------------
       
   158 TInt64 RMMCScBkupProgressSizer::RestoreCombinedDataSizeL( const CMMCScBkupDataOwnerInfo& aOwner )
       
   159     {
       
   160     TInt64 size = 0;
       
   161     //
       
   162     iDriveFilter.Reset();
       
   163     iDriveFilter.SetSecondaryDriveFilter( aOwner.Owner().DriveList() );
       
   164     //
       
   165     TDriveNumber drive = EDriveA;
       
   166     while ( iDriveFilter.NextValidDrive( drive ) )
       
   167         {
       
   168         for( TInt i=0; i<EMMCScBkupOwnerDataTypeCount; i++ )
       
   169             {
       
   170             const TMMCScBkupOwnerDataType dataType = static_cast< TMMCScBkupOwnerDataType > ( i );
       
   171             const TBool allowedForDrive = iDriveAndOperationTypes.IsDataTypeAllowedToAccessDrive( drive, dataType );
       
   172             //
       
   173             if  ( allowedForDrive )
       
   174                 {
       
   175                 // Get the amount of data for this drive
       
   176                 size += aOwner.OperationalSize( dataType, drive );
       
   177                 }
       
   178             }
       
   179         }
       
   180     //
       
   181     return size;
       
   182     }
       
   183 
       
   184 
       
   185 
       
   186 
       
   187 
       
   188 
       
   189 
       
   190 
       
   191 
       
   192 
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // RMMCScBkupProgressSizer::NumberOfDriveOpsRequiredL()
       
   196 // 
       
   197 // 
       
   198 // ---------------------------------------------------------------------------
       
   199 TInt RMMCScBkupProgressSizer::NumberOfDriveOpsRequiredL( const CMMCScBkupDataOwnerInfo& aOwner, TMMCScBkupOwnerDataType aType )
       
   200     {
       
   201     TInt count = 0;
       
   202     //
       
   203     iDriveFilter.Reset();
       
   204     iDriveFilter.SetSecondaryDriveFilter( aOwner.Owner().DriveList() );
       
   205     //
       
   206     TDriveNumber drive = EDriveA;
       
   207     while ( iDriveFilter.NextValidDrive( drive ) )
       
   208         {
       
   209         const TBool allowedForDrive = iDriveAndOperationTypes.IsDataTypeAllowedToAccessDrive( drive, aType );
       
   210         //
       
   211         if  ( allowedForDrive )
       
   212             {
       
   213             ++count;
       
   214             }
       
   215         }
       
   216     //
       
   217     return count;
       
   218     }
       
   219 
       
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // RMMCScBkupProgressSizer::AmountOfPublicDataToBeRestoredL()
       
   223 // 
       
   224 // 
       
   225 // ---------------------------------------------------------------------------
       
   226 TInt64 RMMCScBkupProgressSizer::AmountOfPublicDataToBeRestoredL( const CMMCScBkupDataOwnerInfo& aOwner )
       
   227     {
       
   228     TInt64 size = 0;
       
   229     //
       
   230     iDriveFilter.Reset();
       
   231     iDriveFilter.SetSecondaryDriveFilter( aOwner.Owner().DriveList() );
       
   232     //
       
   233     TDriveNumber drive = EDriveA;
       
   234     while ( iDriveFilter.NextValidDrive( drive ) )
       
   235         {
       
   236         const TBool allowedForDrive = iDriveAndOperationTypes.IsDataTypeAllowedToAccessDrive( drive, EMMCScBkupOwnerDataTypePublicData );
       
   237         //
       
   238         if  ( allowedForDrive )
       
   239             {
       
   240             // Get the amount of data for this drive
       
   241             size += aOwner.OperationalSize( EMMCScBkupOwnerDataTypePublicData, drive );
       
   242             }
       
   243         }
       
   244     //
       
   245     return size;
       
   246     }
       
   247 
       
   248 
       
   249 
       
   250