filemanager/bkupengine/src/CMMCScBkupDriveDataSizeManager.cpp
branchRCL_3
changeset 38 491b3ed49290
parent 36 95243422089a
child 39 65326cf895ed
equal deleted inserted replaced
36:95243422089a 38: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: CMMCScBkupDriveSizer implementation
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 #include "CMMCScBkupDriveDataSizeManager.h"
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 // ========================= MEMBER FUNCTIONS ================================
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // CMMCScBkupDriveSizer::CMMCScBkupDriveSizer()
       
    28 // 
       
    29 // C++ constructor.
       
    30 // ---------------------------------------------------------------------------
       
    31 CMMCScBkupDriveSizer::CMMCScBkupDriveSizer( TMMCScBkupOwnerDataType aType )
       
    32 :   iDataType( aType )
       
    33     {
       
    34     }
       
    35 
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // CMMCScBkupDriveSizer::~CMMCScBkupDriveSizer()
       
    39 // 
       
    40 // Destructor.
       
    41 // ---------------------------------------------------------------------------
       
    42 CMMCScBkupDriveSizer::~CMMCScBkupDriveSizer()
       
    43     {
       
    44     iEntries.Close();
       
    45     }
       
    46 
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // CMMCScBkupDriveSizer::ConstructL()
       
    50 // 
       
    51 // 
       
    52 // ---------------------------------------------------------------------------
       
    53 void CMMCScBkupDriveSizer::ConstructL()
       
    54     {
       
    55     }
       
    56 
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // CMMCScBkupDriveSizer::NewLC()
       
    60 // 
       
    61 // 
       
    62 // ---------------------------------------------------------------------------
       
    63 CMMCScBkupDriveSizer* CMMCScBkupDriveSizer::NewLC( TMMCScBkupOwnerDataType aType )
       
    64     {
       
    65     CMMCScBkupDriveSizer* self = new(ELeave) CMMCScBkupDriveSizer( aType );
       
    66     CleanupStack::PushL(self);
       
    67     self->ConstructL();
       
    68     return self;
       
    69     }
       
    70 
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CMMCScBkupDriveSizer::NewLC()
       
    74 // 
       
    75 // 
       
    76 // ---------------------------------------------------------------------------
       
    77 CMMCScBkupDriveSizer* CMMCScBkupDriveSizer::NewLC( RReadStream& aStream )
       
    78     {
       
    79     CMMCScBkupDriveSizer* self = new(ELeave) CMMCScBkupDriveSizer( EMMCScBkupOwnerDataTypeAny );
       
    80     CleanupStack::PushL(self);
       
    81     aStream >> *self;
       
    82     return self;
       
    83     }
       
    84 
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // CMMCScBkupDriveSizer::AddToSizeL()
       
    88 // 
       
    89 // 
       
    90 // ---------------------------------------------------------------------------
       
    91 void CMMCScBkupDriveSizer::AddToSizeL( TInt64 aAmount, TDriveNumber aDrive )
       
    92     {
       
    93     TMMCScBkupDriveAndSize* entry = EntryByDrive( aDrive );
       
    94     //
       
    95     if  ( entry == NULL )
       
    96         {
       
    97         if  ( aAmount > 0 )
       
    98             {
       
    99             TMMCScBkupDriveAndSize newEntry( aDrive, aAmount );
       
   100             iEntries.AppendL( newEntry );
       
   101             }
       
   102         }
       
   103     else
       
   104         {
       
   105         entry->AddToSize( aAmount );
       
   106         }
       
   107     }
       
   108 
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CMMCScBkupDriveSizer::Reset()
       
   112 // 
       
   113 // 
       
   114 // ---------------------------------------------------------------------------
       
   115 void CMMCScBkupDriveSizer::Reset()
       
   116     {
       
   117     const TInt count = iEntries.Count();
       
   118     for( TInt i=0; i<count; i++ )
       
   119         {
       
   120         TMMCScBkupDriveAndSize& entry = iEntries[ i ];
       
   121         entry.SetSize( 0 );
       
   122         }
       
   123     }
       
   124 
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CMMCScBkupDriveSizer::Reset()
       
   128 // 
       
   129 // 
       
   130 // ---------------------------------------------------------------------------
       
   131 void CMMCScBkupDriveSizer::Reset( TDriveNumber aDrive )
       
   132     {
       
   133     TMMCScBkupDriveAndSize* entry = EntryByDrive( aDrive );
       
   134     //
       
   135     if  ( entry != NULL )
       
   136         {
       
   137         entry->SetSize( 0 );
       
   138         }
       
   139     }
       
   140 
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CMMCScBkupDriveSizer::Size()
       
   144 // 
       
   145 // 
       
   146 // ---------------------------------------------------------------------------
       
   147 TInt64 CMMCScBkupDriveSizer::Size() const
       
   148     {
       
   149     TInt64 size = 0;
       
   150     //
       
   151     const TInt count = iEntries.Count();
       
   152     for( TInt i=0; i<count; i++ )
       
   153         {
       
   154         const TMMCScBkupDriveAndSize& entry = iEntries[ i ];
       
   155         size += entry.Size();
       
   156         }
       
   157     //
       
   158     return size;
       
   159     }
       
   160 
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // CMMCScBkupDriveSizer::Size()
       
   164 // 
       
   165 // 
       
   166 // ---------------------------------------------------------------------------
       
   167 TInt64 CMMCScBkupDriveSizer::Size( TDriveNumber aDrive ) const
       
   168     {
       
   169     TInt64 size = 0;
       
   170     TMMCScBkupDriveAndSize* entry = const_cast< CMMCScBkupDriveSizer* >( this )->EntryByDrive( aDrive );
       
   171     //
       
   172     if  ( entry != NULL )
       
   173         {
       
   174         size = entry->Size();
       
   175         }
       
   176     //
       
   177     return size;
       
   178     }
       
   179 
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // CMMCScBkupDriveSizer::InternalizeL()
       
   183 // 
       
   184 // 
       
   185 // ---------------------------------------------------------------------------
       
   186 void CMMCScBkupDriveSizer::InternalizeL(RReadStream& aStream)
       
   187     {
       
   188     aStream.ReadInt32L(); // EStreamFormatVersion1 
       
   189     aStream.ReadInt32L(); // spare1
       
   190     aStream.ReadInt32L(); // spare2
       
   191     //
       
   192     iDataType = static_cast< TMMCScBkupOwnerDataType >( aStream.ReadInt8L() );
       
   193     const TInt count = aStream.ReadInt8L();
       
   194     for( TInt i=0; i<count; i++ )
       
   195         {
       
   196         TMMCScBkupDriveAndSize entry;
       
   197         aStream >> entry;
       
   198         iEntries.AppendL( entry );
       
   199         }
       
   200     }
       
   201 
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // CMMCScBkupDriveSizer::ExternalizeL()
       
   205 // 
       
   206 // 
       
   207 // ---------------------------------------------------------------------------
       
   208 void CMMCScBkupDriveSizer::ExternalizeL(RWriteStream& aStream) const
       
   209     {
       
   210     aStream.WriteInt32L( EStreamFormatVersion1 );
       
   211     aStream.WriteInt32L( 0 ); // spare1
       
   212     aStream.WriteInt32L( 0 ); // spare2
       
   213     //
       
   214     aStream.WriteInt8L( iDataType );
       
   215 
       
   216     // Work out how many non-zero entries we need to write.
       
   217     TInt i = 0;
       
   218     const TInt count = iEntries.Count();
       
   219     TInt numberOfExternalisedEntries = 0;
       
   220     //    
       
   221     for( i=0; i<count; i++ )
       
   222         {
       
   223         const TMMCScBkupDriveAndSize& entry = iEntries[ i ];
       
   224         if  ( entry.Size() > 0 )
       
   225             {
       
   226             ++numberOfExternalisedEntries;
       
   227             }
       
   228         }
       
   229     
       
   230     // Now really write the entries...
       
   231     aStream.WriteInt8L( numberOfExternalisedEntries );
       
   232     if  ( numberOfExternalisedEntries > 0 )
       
   233         {
       
   234         for( i=0; i<count; i++ )
       
   235             {
       
   236             const TMMCScBkupDriveAndSize& entry = iEntries[ i ];
       
   237             if  ( entry.Size() > 0 )
       
   238                 {
       
   239                 aStream << entry;
       
   240                 }
       
   241             }
       
   242         }
       
   243     }
       
   244 
       
   245 
       
   246 // ---------------------------------------------------------------------------
       
   247 // CMMCScBkupDriveSizer::EntryByDrive()
       
   248 // 
       
   249 // 
       
   250 // ---------------------------------------------------------------------------
       
   251 TMMCScBkupDriveAndSize* CMMCScBkupDriveSizer::EntryByDrive( TDriveNumber aDrive )
       
   252     {
       
   253     TMMCScBkupDriveAndSize* ret = NULL;
       
   254     //
       
   255     const TInt count = iEntries.Count();
       
   256     for( TInt i=0; i<count; i++ )
       
   257         {
       
   258         TMMCScBkupDriveAndSize& entry = iEntries[ i ];
       
   259         //
       
   260         if  ( entry.Drive() == aDrive )
       
   261             {
       
   262             ret = &entry;
       
   263             break;
       
   264             }
       
   265         }
       
   266     //
       
   267     return ret;
       
   268     }
       
   269 
       
   270 
       
   271 
       
   272 
       
   273 
       
   274 
       
   275 
       
   276 
       
   277 
       
   278 
       
   279 
       
   280 
       
   281 
       
   282 
       
   283 
       
   284 
       
   285 
       
   286 
       
   287 
       
   288 
       
   289 
       
   290 
       
   291 
       
   292 
       
   293 
       
   294 
       
   295 
       
   296 
       
   297 
       
   298 
       
   299 
       
   300 
       
   301 
       
   302 
       
   303 
       
   304 
       
   305 
       
   306 
       
   307 
       
   308 
       
   309 
       
   310 
       
   311 // ========================= MEMBER FUNCTIONS ================================
       
   312 
       
   313 // ---------------------------------------------------------------------------
       
   314 // CMMCScBkupDataTypeSizer::CMMCScBkupDataTypeSizer()
       
   315 // 
       
   316 // C++ constructor.
       
   317 // ---------------------------------------------------------------------------
       
   318 CMMCScBkupDataTypeSizer::CMMCScBkupDataTypeSizer()
       
   319     {
       
   320     }
       
   321 
       
   322 
       
   323 // ---------------------------------------------------------------------------
       
   324 // CMMCScBkupDataTypeSizer::~CMMCScBkupDataTypeSizer()
       
   325 // 
       
   326 // Destructor.
       
   327 // ---------------------------------------------------------------------------
       
   328 CMMCScBkupDataTypeSizer::~CMMCScBkupDataTypeSizer()
       
   329     {
       
   330     iSizers.Close();
       
   331     }
       
   332 
       
   333 
       
   334 // ---------------------------------------------------------------------------
       
   335 // CMMCScBkupDataTypeSizer::ConstructL()
       
   336 // 
       
   337 // 
       
   338 // ---------------------------------------------------------------------------
       
   339 void CMMCScBkupDataTypeSizer::ConstructL()
       
   340     {
       
   341     iSizers.AppendL( CMMCScBkupDriveSizer::NewLC( EMMCScBkupOwnerDataTypeDataOwner ) );
       
   342     CleanupStack::Pop(); // sizer
       
   343     iSizers.AppendL( CMMCScBkupDriveSizer::NewLC( EMMCScBkupOwnerDataTypeJavaData ) );
       
   344     CleanupStack::Pop(); // sizer
       
   345     iSizers.AppendL( CMMCScBkupDriveSizer::NewLC( EMMCScBkupOwnerDataTypePublicData ) );
       
   346     CleanupStack::Pop(); // sizer
       
   347     iSizers.AppendL( CMMCScBkupDriveSizer::NewLC( EMMCScBkupOwnerDataTypeSystemData ) );
       
   348     CleanupStack::Pop(); // sizer
       
   349     iSizers.AppendL( CMMCScBkupDriveSizer::NewLC( EMMCScBkupOwnerDataTypeActiveData ) );
       
   350     CleanupStack::Pop(); // sizer
       
   351     iSizers.AppendL( CMMCScBkupDriveSizer::NewLC( EMMCScBkupOwnerDataTypePassiveData ) );
       
   352     CleanupStack::Pop(); // sizer
       
   353     }
       
   354 
       
   355 
       
   356 // ---------------------------------------------------------------------------
       
   357 // CMMCScBkupDataTypeSizer::NewL()
       
   358 // 
       
   359 // 
       
   360 // ---------------------------------------------------------------------------
       
   361 CMMCScBkupDataTypeSizer* CMMCScBkupDataTypeSizer::NewL()
       
   362     {
       
   363     CMMCScBkupDataTypeSizer* self = new(ELeave) CMMCScBkupDataTypeSizer();
       
   364     CleanupStack::PushL(self);
       
   365     self->ConstructL();
       
   366     CleanupStack::Pop( self );
       
   367     return self;
       
   368     }
       
   369 
       
   370 
       
   371 // ---------------------------------------------------------------------------
       
   372 // CMMCScBkupDataTypeSizer::NewLC()
       
   373 // 
       
   374 // 
       
   375 // ---------------------------------------------------------------------------
       
   376 CMMCScBkupDataTypeSizer* CMMCScBkupDataTypeSizer::NewLC( RReadStream& aStream )
       
   377     {
       
   378     CMMCScBkupDataTypeSizer* self = new(ELeave) CMMCScBkupDataTypeSizer();
       
   379     CleanupStack::PushL(self);
       
   380     aStream >> *self;
       
   381     return self;
       
   382     }
       
   383 
       
   384 
       
   385 // ---------------------------------------------------------------------------
       
   386 // CMMCScBkupDataTypeSizer::AddToSizeL()
       
   387 // 
       
   388 // 
       
   389 // ---------------------------------------------------------------------------
       
   390 void CMMCScBkupDataTypeSizer::AddToSizeL( TMMCScBkupOwnerDataType aDataType, TInt64 aAmount, TDriveNumber aDrive )
       
   391     {
       
   392     CMMCScBkupDriveSizer* sizer = SizerByDataType( aDataType );
       
   393     ASSERT( sizer != NULL );
       
   394     sizer->AddToSizeL( aAmount, aDrive );
       
   395     }
       
   396 
       
   397 
       
   398 // ---------------------------------------------------------------------------
       
   399 // CMMCScBkupDataTypeSizer::Reset()
       
   400 // 
       
   401 // 
       
   402 // ---------------------------------------------------------------------------
       
   403 void CMMCScBkupDataTypeSizer::Reset( TMMCScBkupOwnerDataType aDataType )
       
   404     {
       
   405     CMMCScBkupDriveSizer* sizer = SizerByDataType( aDataType );
       
   406     ASSERT( sizer != NULL );
       
   407     sizer->Reset();
       
   408     }
       
   409 
       
   410 
       
   411 // ---------------------------------------------------------------------------
       
   412 // CMMCScBkupDataTypeSizer::Reset()
       
   413 // 
       
   414 // 
       
   415 // ---------------------------------------------------------------------------
       
   416 void CMMCScBkupDataTypeSizer::Reset( TMMCScBkupOwnerDataType aDataType, TDriveNumber aDrive )
       
   417     {
       
   418     CMMCScBkupDriveSizer* sizer = SizerByDataType( aDataType );
       
   419     ASSERT( sizer != NULL );
       
   420     sizer->Reset( aDrive );
       
   421     }
       
   422 
       
   423 
       
   424 // ---------------------------------------------------------------------------
       
   425 // CMMCScBkupDataTypeSizer::Size()
       
   426 // 
       
   427 // 
       
   428 // ---------------------------------------------------------------------------
       
   429 TInt64 CMMCScBkupDataTypeSizer::Size( TMMCScBkupOwnerDataType aDataType ) const
       
   430     {
       
   431     CMMCScBkupDriveSizer* sizer = const_cast< CMMCScBkupDataTypeSizer* >( this )->SizerByDataType( aDataType );
       
   432     ASSERT( sizer != NULL );
       
   433     const TInt64 size = sizer->Size();
       
   434     return size;
       
   435     }
       
   436 
       
   437 
       
   438 // ---------------------------------------------------------------------------
       
   439 // CMMCScBkupDataTypeSizer::Size()
       
   440 // 
       
   441 // 
       
   442 // ---------------------------------------------------------------------------
       
   443 TInt64 CMMCScBkupDataTypeSizer::Size( TMMCScBkupOwnerDataType aDataType, TDriveNumber aDrive ) const
       
   444     {
       
   445     CMMCScBkupDriveSizer* sizer = const_cast< CMMCScBkupDataTypeSizer* >( this )->SizerByDataType( aDataType );
       
   446     ASSERT( sizer != NULL );
       
   447     const TInt64 size = sizer->Size( aDrive );
       
   448     return size;
       
   449     }
       
   450 
       
   451 
       
   452 // ---------------------------------------------------------------------------
       
   453 // CMMCScBkupDataTypeSizer::GetSizesL()
       
   454 // 
       
   455 // 
       
   456 // ---------------------------------------------------------------------------
       
   457 void CMMCScBkupDataTypeSizer::GetSizesL( RArray<TMMCScBkupDriveAndSize>& aSizes ) const
       
   458     {
       
   459     CleanupClosePushL( aSizes );
       
   460     aSizes.Reset();
       
   461     //
       
   462     for( TInt d = EDriveA; d<=EDriveZ; d++ )
       
   463         {
       
   464         // Get the size of each data type for this drive.
       
   465         const TDriveNumber drive = static_cast< TDriveNumber >( d );
       
   466         TMMCScBkupDriveAndSize driveAndSize( drive, 0 );
       
   467 
       
   468         const TInt count = iSizers.Count();
       
   469         for( TInt i=0; i<count; i++ )
       
   470             {
       
   471             const CMMCScBkupDriveSizer* sizer = iSizers[ i ];
       
   472             const TInt sizeOfDataForDrive = sizer->Size( drive );
       
   473             //
       
   474             driveAndSize.AddToSize( sizeOfDataForDrive );
       
   475             }
       
   476 
       
   477         // Add the entry if the size is more than 0
       
   478         if  ( driveAndSize.Size() > 0 )
       
   479             {
       
   480             aSizes.AppendL( driveAndSize );
       
   481             }
       
   482         }
       
   483     CleanupStack::Pop( &aSizes );
       
   484     }
       
   485 
       
   486 
       
   487 // ---------------------------------------------------------------------------
       
   488 // CMMCScBkupDataTypeSizer::CombinedSize()
       
   489 // 
       
   490 // 
       
   491 // ---------------------------------------------------------------------------
       
   492 TInt64 CMMCScBkupDataTypeSizer::CombinedSize( TDriveNumber aDrive ) const
       
   493     {
       
   494     TInt64 size = 0;
       
   495     //
       
   496     const TInt count = iSizers.Count();
       
   497     for( TInt i=0; i<count; i++ )
       
   498         {
       
   499         const CMMCScBkupDriveSizer* sizer = iSizers[ i ];
       
   500         size += sizer->Size( aDrive );
       
   501         }
       
   502     //
       
   503     return size;
       
   504     }
       
   505 
       
   506 
       
   507 // ---------------------------------------------------------------------------
       
   508 // CMMCScBkupDataTypeSizer::InternalizeL()
       
   509 // 
       
   510 // 
       
   511 // ---------------------------------------------------------------------------
       
   512 void CMMCScBkupDataTypeSizer::InternalizeL(RReadStream& aStream)
       
   513     {
       
   514     aStream.ReadInt32L(); // EStreamFormatVersion1 
       
   515     aStream.ReadInt32L(); // spare1
       
   516     aStream.ReadInt32L(); // spare2
       
   517     //
       
   518     const TInt count = aStream.ReadInt8L();
       
   519     for( TInt i=0; i<count; i++ )
       
   520         {
       
   521         CMMCScBkupDriveSizer* sizer = CMMCScBkupDriveSizer::NewLC( aStream );
       
   522         iSizers.AppendL( sizer );
       
   523         CleanupStack::Pop( sizer );
       
   524         }
       
   525     }
       
   526 
       
   527 
       
   528 // ---------------------------------------------------------------------------
       
   529 // CMMCScBkupDataTypeSizer::ExternalizeL()
       
   530 // 
       
   531 // 
       
   532 // ---------------------------------------------------------------------------
       
   533 void CMMCScBkupDataTypeSizer::ExternalizeL(RWriteStream& aStream) const
       
   534     {
       
   535     aStream.WriteInt32L( EStreamFormatVersion1 );
       
   536     aStream.WriteInt32L( 0 ); // spare1
       
   537     aStream.WriteInt32L( 0 ); // spare2
       
   538     //
       
   539     const TInt count = iSizers.Count();
       
   540     aStream.WriteInt8L( count );
       
   541     //
       
   542     for( TInt i=0; i<count; i++ )
       
   543         {
       
   544         CMMCScBkupDriveSizer* sizer = iSizers[ i ];
       
   545         aStream << *sizer;
       
   546         }
       
   547     }
       
   548 
       
   549 
       
   550 // ---------------------------------------------------------------------------
       
   551 // CMMCScBkupDataTypeSizer::SizerByDataType()
       
   552 // 
       
   553 // 
       
   554 // ---------------------------------------------------------------------------
       
   555 CMMCScBkupDriveSizer* CMMCScBkupDataTypeSizer::SizerByDataType( TMMCScBkupOwnerDataType aDataType )
       
   556     {
       
   557     CMMCScBkupDriveSizer* ret = NULL;
       
   558     //
       
   559     const TInt count = iSizers.Count();
       
   560     for( TInt i=0; i<count; i++ )
       
   561         {
       
   562         CMMCScBkupDriveSizer* sizer = iSizers[ i ];
       
   563         //
       
   564         if  ( sizer->DataType() == aDataType )
       
   565             {
       
   566             ret = sizer;
       
   567             break;
       
   568             }
       
   569         }
       
   570     //
       
   571     return ret;
       
   572     }
       
   573