filemanager/src/fmbkupengine/inc/CMMCScBkupIndexWithIdentifier.h
branchRCL_3
changeset 38 491b3ed49290
equal deleted inserted replaced
36:95243422089a 38:491b3ed49290
       
     1 /*
       
     2 * Copyright (c) 2005 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: Declaration for CMMCScBkupIndexWithIdentifier
       
    15 *     
       
    16 *
       
    17 */
       
    18 
       
    19 #ifndef __CMMCSCBKUPINDEXWITHIDENTIFIER_H__
       
    20 #define __CMMCSCBKUPINDEXWITHIDENTIFIER_H__
       
    21 
       
    22 // User includes
       
    23 #include "CMMCScBkupIndexBase.h"
       
    24 #include "TMMCScBkupOwnerDataType.h"
       
    25 #include "TMMCScBkupArchiveVector.h"
       
    26 #include "MMMCScBkupArchiveDataInterface.h"
       
    27 
       
    28 
       
    29 
       
    30 /**
       
    31 *
       
    32 *
       
    33 * @since 3.0
       
    34 */
       
    35 template < class TIdentifier >
       
    36 class CMMCScBkupIndexEntry : public CBase
       
    37     {
       
    38     public:
       
    39         inline static CMMCScBkupIndexEntry* NewLC( const TIdentifier& aIdentifier )
       
    40             {
       
    41             CMMCScBkupIndexEntry* self = new(ELeave) CMMCScBkupIndexEntry( aIdentifier );
       
    42             CleanupStack::PushL( self );
       
    43             return self;
       
    44             }
       
    45 
       
    46         inline static CMMCScBkupIndexEntry* NewLC( RReadStream& aStream )
       
    47             {
       
    48             CMMCScBkupIndexEntry* self = new(ELeave) CMMCScBkupIndexEntry();
       
    49             CleanupStack::PushL( self );
       
    50             aStream >> *self;
       
    51             return self;
       
    52             }
       
    53 
       
    54        inline ~CMMCScBkupIndexEntry()
       
    55             {
       
    56             iAssociatedData.Close();
       
    57             }
       
    58 
       
    59     private:
       
    60 
       
    61         inline CMMCScBkupIndexEntry()
       
    62             {
       
    63             }
       
    64 
       
    65         inline CMMCScBkupIndexEntry( const TIdentifier& aIdentifier )
       
    66             : iIdentifier( aIdentifier )
       
    67             {
       
    68             }
       
    69 
       
    70     private: // Internal enumerations
       
    71         enum
       
    72             {
       
    73             EStreamFormatVersion1 = 1
       
    74             };
       
    75 
       
    76     public:// Store & Restore
       
    77 
       
    78         inline void InternalizeL( RReadStream& aStream )
       
    79             {
       
    80             aStream.ReadInt32L(); // EStreamFormatVersion1
       
    81             aStream.ReadInt32L(); // spare1
       
    82             aStream.ReadInt32L(); // spare2
       
    83             aStream.ReadInt32L(); // spare3
       
    84             //
       
    85             iIdentifier = aStream.ReadInt32L();
       
    86             //
       
    87             const TInt count = aStream.ReadInt32L();
       
    88             for(TInt i=0; i<count; i++)
       
    89                 {
       
    90                 TMMCScBkupArchiveDriveAndVector entry;
       
    91                 aStream >> entry;
       
    92                 //
       
    93                 iAssociatedData.AppendL( entry );
       
    94                 }
       
    95             }
       
    96 
       
    97         inline void ExternalizeL( RWriteStream& aStream ) const
       
    98             {
       
    99             aStream.WriteInt32L( EStreamFormatVersion1 );
       
   100             aStream.WriteInt32L( 0 ); // spare1
       
   101             aStream.WriteInt32L( 0 ); // spare2
       
   102             aStream.WriteInt32L( 0 ); // spare3
       
   103             //
       
   104             aStream.WriteInt32L( iIdentifier );
       
   105             //
       
   106             const TInt count = iAssociatedData.Count();
       
   107             aStream.WriteInt32L(count);
       
   108             //
       
   109             for(TInt i=0; i<count; i++)
       
   110                 {
       
   111                 const TMMCScBkupArchiveDriveAndVector& entry = iAssociatedData[i];
       
   112                 aStream << entry;
       
   113                 }
       
   114             }
       
   115 
       
   116     public: // General access
       
   117         
       
   118         inline const TIdentifier& Identifier() const
       
   119             { return iIdentifier; }
       
   120 
       
   121         inline void AddEntryL( const TMMCScBkupArchiveDriveAndVector& aEntry )
       
   122             { iAssociatedData.AppendL(aEntry); }
       
   123 
       
   124         inline TInt Count() const
       
   125             { return iAssociatedData.Count(); }
       
   126 
       
   127         inline const TMMCScBkupArchiveDriveAndVector& Entry(TInt aIndex) const
       
   128             { return iAssociatedData[ aIndex ]; }
       
   129 
       
   130         inline const RArray<TMMCScBkupArchiveDriveAndVector>& Entries() const
       
   131             { return iAssociatedData; }
       
   132 
       
   133     private:
       
   134 
       
   135         /**
       
   136         *
       
   137         */
       
   138         TIdentifier iIdentifier;
       
   139 
       
   140         /**
       
   141         *
       
   142         */
       
   143         RArray<TMMCScBkupArchiveDriveAndVector> iAssociatedData;
       
   144    };
       
   145 
       
   146 
       
   147 
       
   148 
       
   149 
       
   150 
       
   151 /**
       
   152 *
       
   153 *
       
   154 * @since 3.0
       
   155 */
       
   156 template < class TIdentifier >
       
   157 class CMMCScBkupIndexWithIdentifier : public CMMCScBkupIndexBase
       
   158     {
       
   159 
       
   160     public:
       
   161 
       
   162         /**
       
   163         * C++ destructor
       
   164         */
       
   165         inline ~CMMCScBkupIndexWithIdentifier()
       
   166             {
       
   167             iEntries.Close();
       
   168             }
       
   169 
       
   170     protected:
       
   171 
       
   172         /**
       
   173         * C++ default constructor
       
   174         */
       
   175         inline CMMCScBkupIndexWithIdentifier( TMMCScBkupOwnerDataType aType )
       
   176             : CMMCScBkupIndexBase( aType )
       
   177             {
       
   178             }
       
   179 
       
   180     private: // Internal enumerations
       
   181         enum
       
   182             {
       
   183             EStreamFormatVersion1 = 1
       
   184             };
       
   185 
       
   186     public: // API
       
   187 
       
   188         /**
       
   189         *
       
   190         */
       
   191         inline void AddIndexRecordL( const TMMCScBkupArchiveVector& aInfo, TDriveNumber aDrive, const TIdentifier& aIdentifier )
       
   192             {
       
   193             // Locate the parent
       
   194             CMMCScBkupIndexEntry< TIdentifier >& entry = EntryByIdentifierL( aIdentifier );
       
   195 
       
   196             // Create new sub-entry
       
   197             TMMCScBkupArchiveDriveAndVector subItem;
       
   198             subItem.iDrive = aDrive;
       
   199             subItem.iVector = aInfo;
       
   200 
       
   201             // Add it to our index
       
   202             entry.AddEntryL( subItem );
       
   203             }
       
   204 
       
   205         /**
       
   206         *
       
   207         */
       
   208         inline TInt Count() const
       
   209             { return iEntries.Count(); }
       
   210 
       
   211         /**
       
   212         *
       
   213         */
       
   214         inline const CMMCScBkupIndexEntry< TIdentifier >& At( TInt aIndex ) const
       
   215             { return *iEntries[ aIndex ]; }
       
   216 
       
   217         /**
       
   218         *
       
   219         */
       
   220         inline void StoreL(MMMCScBkupDriver& aDriver)
       
   221             {
       
   222             MMMCScBkupArchiveDataInterface& archiveDataInterface = aDriver.DrvADI();
       
   223             RWriteStream stream( archiveDataInterface.ADIWriteStreamUncompressedLC() );
       
   224             //    
       
   225             stream.WriteInt32L( EStreamFormatVersion1 );
       
   226             stream.WriteInt32L( 0 ); // spare1
       
   227             stream.WriteInt32L( 0 ); // spare2
       
   228             stream.WriteInt32L( 0 ); // spare3
       
   229 
       
   230             const TInt count = iEntries.Count();
       
   231             stream.WriteInt32L( count );
       
   232             //
       
   233             for(TInt i=0; i<count; i++)
       
   234                 {
       
   235                 const CMMCScBkupIndexEntry< TIdentifier > & entry = *iEntries[ i ];
       
   236                 stream << entry;
       
   237                 }
       
   238             //
       
   239             stream.CommitL();
       
   240             CleanupStack::PopAndDestroy(); // stream
       
   241 
       
   242             // Update our base class info with the offset to the index
       
   243             SetVector( archiveDataInterface.ADICurrentArchiveVectorInfo() );
       
   244             }
       
   245 
       
   246         /**
       
   247         *
       
   248         */
       
   249         inline void RestoreL(MMMCScBkupDriver& aDriver)
       
   250             {
       
   251             MMMCScBkupArchiveDataInterface& archiveDataInterface = aDriver.DrvADI();
       
   252             RReadStream stream( archiveDataInterface.ADIReadStreamUncompressedLC( Vector().Offset() ) );
       
   253             //    
       
   254             stream.ReadInt32L(); // EStreamFormatVersion1 
       
   255             stream.ReadInt32L(); // spare1
       
   256             stream.ReadInt32L(); // spare2
       
   257             stream.ReadInt32L(); // spare3
       
   258             //    
       
   259             const TInt count = stream.ReadInt32L();
       
   260             for(TInt i=0; i<count; i++)
       
   261                 {
       
   262                 CMMCScBkupIndexEntry< TIdentifier >* entry = CMMCScBkupIndexEntry< TIdentifier >::NewLC( stream );
       
   263                 iEntries.AppendL( entry );
       
   264                 CleanupStack::Pop( entry );
       
   265                 }
       
   266             //
       
   267             CleanupStack::PopAndDestroy(); // stream
       
   268             //
       
   269             if  ( archiveDataInterface.ADICurrentArchiveVectorInfo().Length() > Vector().Length() )
       
   270                 {
       
   271                 // We've read too much!
       
   272                 User::Leave( KErrCorrupt );
       
   273                 }
       
   274             }
       
   275 
       
   276     private: // Internal methods
       
   277 
       
   278         /**
       
   279         *
       
   280         */
       
   281         inline CMMCScBkupIndexEntry< TIdentifier >* EntryByIdentifier( const TIdentifier& aIdentifier )
       
   282             {
       
   283             CMMCScBkupIndexEntry< TIdentifier >* ret = NULL;
       
   284             //
       
   285             const TInt count = iEntries.Count();
       
   286             for( TInt i=count-1; i>=0; i-- )
       
   287                 {
       
   288                 CMMCScBkupIndexEntry< TIdentifier >* entry = iEntries[ i ];
       
   289                 if  ( entry->Identifier() == aIdentifier )
       
   290                     {
       
   291                     ret = entry;
       
   292                     break;
       
   293                     }
       
   294                 }
       
   295             //
       
   296             return ret;
       
   297             }
       
   298 
       
   299         /**
       
   300         *
       
   301         */
       
   302         inline CMMCScBkupIndexEntry< TIdentifier >& EntryByIdentifierL( const TIdentifier& aIdentifier )
       
   303             {
       
   304             CMMCScBkupIndexEntry< TIdentifier >* ret = EntryByIdentifier( aIdentifier );
       
   305             if  ( !ret )
       
   306                 {
       
   307                 // Need to make a new entry
       
   308                 ret = CMMCScBkupIndexEntry< TIdentifier >::NewLC( aIdentifier );
       
   309                 iEntries.AppendL( ret );
       
   310                 CleanupStack::Pop( ret );
       
   311                 }
       
   312             //
       
   313             return *ret;
       
   314             }
       
   315 
       
   316     private: // Member Data
       
   317 
       
   318         //
       
   319         RMMCScBkupPointerArray< CMMCScBkupIndexEntry< TIdentifier > > iEntries;
       
   320     };
       
   321 
       
   322 
       
   323 
       
   324 
       
   325 
       
   326 
       
   327 #endif // __CMMCSCBKUPINDEXWITHIDENTIFIER_H__
       
   328 
       
   329 //End of File