filemanager/bkupengine/src/CMMCScBkupIndexJavaData.cpp
branchRCL_3
changeset 20 491b3ed49290
parent 19 95243422089a
child 21 65326cf895ed
equal deleted inserted replaced
19:95243422089a 20:491b3ed49290
     1 /*
       
     2 * Copyright (c) 2006 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: CMMCScBkupIndexJavaDataEntry implementation
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 #include "CMMCScBkupIndexJavaData.h"
       
    20 
       
    21 // User includes
       
    22 #include "MMMCScBkupArchiveDataInterface.h"
       
    23 #include "MMCScBkupLogger.h"
       
    24 
       
    25 
       
    26     /**
       
    27      * Registration Data
       
    28      * =================
       
    29      * 
       
    30      * 
       
    31      *  REG DATA for DO 0
       
    32      *  {
       
    33      *      RD for DO 0, 1st drive
       
    34      *      RD for DO 0, 2nd drive
       
    35      *      RD for DO 0, 'n'th drive
       
    36      *  },
       
    37      *  REG DATA for DO 1
       
    38      *  {
       
    39      *      RD for DO 0, 1st drive
       
    40      *      RD for DO 0, 2nd drive
       
    41      *      RD for DO 0, 'n'th drive
       
    42      *  },
       
    43      *  REG DATA for DO n
       
    44      *  {
       
    45      *      RD for DO 0, 1st drive
       
    46      *      RD for DO 0, 2nd drive
       
    47      *      RD for DO 0, 'n'th drive
       
    48      *  }
       
    49      * 
       
    50      * Registration Data Index
       
    51      * =======================
       
    52      * 
       
    53      * This is the format of the data written by this object.
       
    54      * The format allows the possibility of a future partial
       
    55      * restore (hopefully).
       
    56      * 
       
    57      * 
       
    58      *  4 bytes = count of registration data entries
       
    59      *
       
    60      *  FOR EACH DATA OWNER
       
    61      *  {
       
    62      *      4 bytes = secure id of data owner's process
       
    63      *      4 bytes = the number of different registration data files
       
    64      *                for this particular data owner (one for each drive that
       
    65      *                was backed up)
       
    66      *      ENTRY
       
    67      *      {
       
    68      *          1 byte = Associated TDriveNumber of the registration data 
       
    69      *          8 bytes = offset & length of actual registration data
       
    70      *      }
       
    71      *  }
       
    72      *
       
    73      **/
       
    74 
       
    75 
       
    76 
       
    77 
       
    78 
       
    79 
       
    80 
       
    81 
       
    82 // ========================= MEMBER FUNCTIONS ================================
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // CMMCScBkupIndexJavaDataEntry::CMMCScBkupIndexJavaDataEntry()
       
    86 // 
       
    87 // C++ constructor.
       
    88 // ---------------------------------------------------------------------------
       
    89 CMMCScBkupIndexJavaDataEntry::CMMCScBkupIndexJavaDataEntry()
       
    90     {
       
    91     }
       
    92 
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CMMCScBkupIndexJavaDataEntry::CMMCScBkupIndexJavaDataEntry()
       
    96 // 
       
    97 // C++ destructor.
       
    98 // ---------------------------------------------------------------------------
       
    99 CMMCScBkupIndexJavaDataEntry::~CMMCScBkupIndexJavaDataEntry()
       
   100     {
       
   101     delete iHash;
       
   102     }
       
   103 
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CMMCScBkupIndexJavaDataEntry::ConstructL()
       
   107 // 
       
   108 // 
       
   109 // ---------------------------------------------------------------------------
       
   110 void CMMCScBkupIndexJavaDataEntry::ConstructL()
       
   111     {
       
   112     iHash = KNullDesC().AllocL();
       
   113     }
       
   114 
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // CMMCScBkupIndexJavaDataEntry::NewLC()
       
   118 // 
       
   119 // 
       
   120 // ---------------------------------------------------------------------------
       
   121 CMMCScBkupIndexJavaDataEntry* CMMCScBkupIndexJavaDataEntry::NewLC()
       
   122     {
       
   123     CMMCScBkupIndexJavaDataEntry* self = new(ELeave) CMMCScBkupIndexJavaDataEntry();
       
   124     CleanupStack::PushL( self );
       
   125     self->ConstructL();
       
   126     return self;
       
   127     }
       
   128 
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // CMMCScBkupIndexJavaDataEntry::NewLC()
       
   132 // 
       
   133 // 
       
   134 // ---------------------------------------------------------------------------
       
   135 CMMCScBkupIndexJavaDataEntry* CMMCScBkupIndexJavaDataEntry::NewLC( RReadStream& aStream )
       
   136     {
       
   137     CMMCScBkupIndexJavaDataEntry* self = new(ELeave) CMMCScBkupIndexJavaDataEntry();
       
   138     CleanupStack::PushL( self );
       
   139     aStream >> *self;
       
   140     return self;
       
   141     }
       
   142 
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // CMMCScBkupIndexJavaDataEntry::SetHashL()
       
   146 // 
       
   147 // 
       
   148 // ---------------------------------------------------------------------------
       
   149 void CMMCScBkupIndexJavaDataEntry::SetHashL( const TDesC& aHash )
       
   150     {
       
   151     HBufC* hash  = aHash.AllocL();
       
   152     delete iHash;
       
   153     iHash = hash;
       
   154     }
       
   155 
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // CMMCScBkupIndexJavaDataEntry::InternalizeL()
       
   159 // 
       
   160 // 
       
   161 // ---------------------------------------------------------------------------
       
   162 void CMMCScBkupIndexJavaDataEntry::InternalizeL( RReadStream& aStream )
       
   163     {
       
   164     aStream.ReadInt32L(); // EStreamFormatVersion1 
       
   165     aStream.ReadInt32L(); // spare1
       
   166     aStream.ReadInt32L(); // spare2
       
   167     aStream.ReadInt32L(); // spare3
       
   168     //
       
   169     HBufC* hash = HBufC::NewL( aStream, KMaxTInt );
       
   170     delete iHash;
       
   171     iHash = hash;
       
   172     //
       
   173     aStream >> iMidletInfo;
       
   174     aStream >> iMidletDataInfo;
       
   175     iDrive = static_cast< TDriveNumber>( aStream.ReadInt8L() );
       
   176 	//
       
   177 	__LOG6("CMMCScBkupIndexJavaDataEntry::InternalizeL() - hash: %S, iDrive: %c:, MIDLET[offset: %8d, length: %8d], MIDLETDATA[offset: %8d, length: %8d]", iHash, iDrive + 'A', iMidletInfo.Offset(), iMidletInfo.Length(), iMidletDataInfo.Offset(), iMidletDataInfo.Length() );
       
   178     }
       
   179 
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // CMMCScBkupIndexJavaDataEntry::ExternalizeL()
       
   183 // 
       
   184 // 
       
   185 // ---------------------------------------------------------------------------
       
   186 void CMMCScBkupIndexJavaDataEntry::ExternalizeL( RWriteStream& aStream ) const
       
   187     {
       
   188     aStream.WriteInt32L( EStreamFormatVersion1 );
       
   189     aStream.WriteInt32L( 0 ); // spare1
       
   190     aStream.WriteInt32L( 0 ); // spare2
       
   191     aStream.WriteInt32L( 0 ); // spare3
       
   192     //
       
   193     aStream << Hash();
       
   194     aStream << iMidletInfo;
       
   195     aStream << iMidletDataInfo;
       
   196     aStream.WriteInt8L( iDrive );
       
   197 	//
       
   198 	__LOG6("CMMCScBkupIndexJavaDataEntry::ExternalizeL() - hash: %S, iDrive: %c:, MIDLET[offset: %8d, length: %8d], MIDLETDATA[offset: %8d, length: %8d]", iHash, iDrive + 'A', iMidletInfo.Offset(), iMidletInfo.Length(), iMidletDataInfo.Offset(), iMidletDataInfo.Length() );
       
   199 	}
       
   200 
       
   201 
       
   202 
       
   203 
       
   204 
       
   205 
       
   206 
       
   207 
       
   208 
       
   209 
       
   210 
       
   211 
       
   212 
       
   213 
       
   214 
       
   215 
       
   216 
       
   217 
       
   218 
       
   219 // ========================= MEMBER FUNCTIONS ================================
       
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // CMMCScBkupIndexJavaData::CMMCScBkupIndexJavaData()
       
   223 // 
       
   224 // C++ constructor.
       
   225 // ---------------------------------------------------------------------------
       
   226 CMMCScBkupIndexJavaData::CMMCScBkupIndexJavaData()
       
   227 :   CMMCScBkupIndexBase( EMMCScBkupOwnerDataTypeJavaData )
       
   228     {
       
   229     }
       
   230 
       
   231 // ---------------------------------------------------------------------------
       
   232 // CMMCScBkupIndexJavaData::~CMMCScBkupIndexJavaData()
       
   233 // 
       
   234 // C++ destructor.
       
   235 // ---------------------------------------------------------------------------
       
   236 CMMCScBkupIndexJavaData::~CMMCScBkupIndexJavaData()
       
   237     {
       
   238     iEntries.Close();
       
   239     }
       
   240 
       
   241 
       
   242 // ---------------------------------------------------------------------------
       
   243 // CMMCScBkupIndexJavaData::NewLC()
       
   244 // 
       
   245 // 
       
   246 // ---------------------------------------------------------------------------
       
   247 CMMCScBkupIndexJavaData* CMMCScBkupIndexJavaData::NewLC()
       
   248     {
       
   249     CMMCScBkupIndexJavaData* self = new(ELeave) CMMCScBkupIndexJavaData();
       
   250     CleanupStack::PushL( self );
       
   251     self->ConstructL();
       
   252     return self;
       
   253     }
       
   254 
       
   255 
       
   256 // ---------------------------------------------------------------------------
       
   257 // CMMCScBkupIndexJavaData::AddIndexRecordL()
       
   258 // 
       
   259 // 
       
   260 // ---------------------------------------------------------------------------
       
   261 void CMMCScBkupIndexJavaData::AddIndexRecordL( const TMMCScBkupArchiveVector& aInfo, const TDesC& aHash, TDriveNumber aDrive, TJavaTransferType aType )
       
   262     {
       
   263     // Check if we already have an entry for this item...
       
   264     CMMCScBkupIndexJavaDataEntry* entry = EntryByHash( aHash, aDrive );
       
   265     
       
   266     if  ( !entry )
       
   267         {
       
   268 		__LOG1("CMMCScBkupIndexJavaData::AddIndexRecordL() - making new entry for hash: %S", &aHash);
       
   269 		//
       
   270         entry = CMMCScBkupIndexJavaDataEntry::NewLC();
       
   271         //
       
   272         entry->SetHashL( aHash );
       
   273         entry->SetDrive( aDrive );
       
   274         iEntries.AppendL( entry );
       
   275         //
       
   276         CleanupStack::Pop( entry );
       
   277         }
       
   278 	else
       
   279 		{
       
   280 		__LOG1("CMMCScBkupIndexJavaData::AddIndexRecordL() - found existing entry for hash: %S", &aHash);
       
   281 		}
       
   282 
       
   283     if  ( aType == EJavaMIDlet )
       
   284         {
       
   285         entry->SetMidletInfo( aInfo );
       
   286         }
       
   287     else if ( aType == EJavaMIDletData )
       
   288         {
       
   289         entry->SetMidletDataInfo( aInfo );
       
   290         }
       
   291     }
       
   292 
       
   293 
       
   294 // ---------------------------------------------------------------------------
       
   295 // CMMCScBkupIndexJavaData::At()
       
   296 // 
       
   297 // 
       
   298 // ---------------------------------------------------------------------------
       
   299 const CMMCScBkupIndexJavaDataEntry& CMMCScBkupIndexJavaData::At( TInt aIndex ) const
       
   300     {
       
   301     const CMMCScBkupIndexJavaDataEntry* entry = iEntries[ aIndex ];
       
   302     return *entry;
       
   303     }
       
   304 
       
   305 
       
   306 // ---------------------------------------------------------------------------
       
   307 // CMMCScBkupIndexJavaData::StoreL()
       
   308 // 
       
   309 // 
       
   310 // ---------------------------------------------------------------------------
       
   311 void CMMCScBkupIndexJavaData::StoreL(MMMCScBkupDriver& aDriver)
       
   312     {
       
   313     MMMCScBkupArchiveDataInterface& archiveDataInterface = aDriver.DrvADI();
       
   314     RWriteStream stream(archiveDataInterface.ADIWriteStreamUncompressedLC());
       
   315     //    
       
   316     stream.WriteInt32L( EStreamFormatVersion1 );
       
   317     stream.WriteInt32L( 0 ); // spare1
       
   318     stream.WriteInt32L( 0 ); // spare2
       
   319     stream.WriteInt32L( 0 ); // spare3
       
   320     //
       
   321     const TInt count = iEntries.Count();
       
   322     stream.WriteInt32L(count);
       
   323     //
       
   324     for(TInt i=0; i<count; i++)
       
   325         {
       
   326         const CMMCScBkupIndexJavaDataEntry* entry = iEntries[i];
       
   327         stream << *entry;
       
   328         }
       
   329     //
       
   330     stream.CommitL();
       
   331     CleanupStack::PopAndDestroy(); // stream
       
   332 
       
   333     // Update our base class info with the offset to the index
       
   334     SetVector( archiveDataInterface.ADICurrentArchiveVectorInfo() );
       
   335     }
       
   336 
       
   337 
       
   338 // ---------------------------------------------------------------------------
       
   339 // CMMCScBkupIndexJavaData::RestoreL()
       
   340 // 
       
   341 // 
       
   342 // ---------------------------------------------------------------------------
       
   343 void CMMCScBkupIndexJavaData::RestoreL(MMMCScBkupDriver& aDriver)
       
   344     {
       
   345     MMMCScBkupArchiveDataInterface& archiveDataInterface = aDriver.DrvADI();
       
   346     RReadStream& stream = archiveDataInterface.ADIReadStreamUncompressedLC( Vector().Offset() );
       
   347     //
       
   348     stream.ReadInt32L(); // EStreamFormatVersion1 
       
   349     stream.ReadInt32L(); // spare1
       
   350     stream.ReadInt32L(); // spare2
       
   351     stream.ReadInt32L(); // spare3
       
   352     //
       
   353     const TInt count = stream.ReadInt32L();
       
   354     for(TInt i=0; i<count; i++)
       
   355         {
       
   356         CMMCScBkupIndexJavaDataEntry* entry = CMMCScBkupIndexJavaDataEntry::NewLC( stream );
       
   357         iEntries.AppendL( entry );
       
   358         CleanupStack::Pop( entry );
       
   359         }
       
   360     //
       
   361     CleanupStack::PopAndDestroy(); // stream
       
   362     //
       
   363     const TMMCScBkupArchiveVector& readInfo = archiveDataInterface.ADICurrentArchiveVectorInfo();
       
   364     if  ( readInfo.Length() > Vector().Length() )
       
   365         {
       
   366         // We've read too much!
       
   367         User::Leave( KErrCorrupt );
       
   368         }
       
   369     }
       
   370 
       
   371 
       
   372 // ---------------------------------------------------------------------------
       
   373 // CMMCScBkupIndexJavaData::EntryByHash()
       
   374 // 
       
   375 // 
       
   376 // ---------------------------------------------------------------------------
       
   377 CMMCScBkupIndexJavaDataEntry* CMMCScBkupIndexJavaData::EntryByHash( const TDesC& aHash, TDriveNumber aDrive ) const
       
   378     {
       
   379     CMMCScBkupIndexJavaDataEntry* ret = NULL;
       
   380     const TInt count = iEntries.Count();
       
   381     //
       
   382     for(TInt i=0; i<count; i++)
       
   383         {
       
   384         CMMCScBkupIndexJavaDataEntry* entry = iEntries[ i ];
       
   385         //
       
   386         if  ( entry->Hash() == aHash && entry->Drive() == aDrive )
       
   387             {
       
   388             ret = entry;
       
   389             break;
       
   390             }
       
   391         }
       
   392     //
       
   393     return ret;
       
   394     }
       
   395 
       
   396 
       
   397 
       
   398 
       
   399 
       
   400 
       
   401 
       
   402