javamanager/javabackup/midp2backup/src.s60/midp2backupplugin.h
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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:  Header file for CMidp2BackupPlugin class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef MIDP2BACKUPPLUGIN_H
       
    20 #define MIDP2BACKUPPLUGIN_H
       
    21 
       
    22 #include "backupplugin.h"
       
    23 #include <apadef.h>
       
    24 #include "logger.h"
       
    25 
       
    26 class RDesWriteStream;
       
    27 class RDesReadStream;
       
    28 
       
    29 namespace java
       
    30 {
       
    31 namespace backup
       
    32 {
       
    33 
       
    34 class CAppArcBackupUtil;
       
    35 class CJavaVersionBackupUtil;
       
    36 class CStorageBackupUtil;
       
    37 
       
    38 
       
    39 /**
       
    40  *  CMidp2BackupPlugin class is handling backup and restore operations
       
    41  *  for MIDlets
       
    42  *
       
    43  *  This class is instantiated when a BUR operation is starting.
       
    44  */
       
    45 class CMidp2BackupPlugin : public CBackupPlugin
       
    46 {
       
    47 
       
    48 public:
       
    49 
       
    50     /**
       
    51      * Instantiates an object of this type
       
    52      */
       
    53     static CMidp2BackupPlugin* NewL();
       
    54 
       
    55     ~CMidp2BackupPlugin();
       
    56 
       
    57 
       
    58     // from base class CBackupPlugin
       
    59 
       
    60     /**
       
    61      * This method is called when a backup or restore operation is
       
    62      * starting. Preparations can be done to prepare for BUR.
       
    63      *
       
    64      * @param aBackupStateValue the value of the current backup state
       
    65      */
       
    66     void PrepareForBURL(TInt aBackupStateValue);
       
    67 
       
    68     /**
       
    69      * This method receives all or part of a snapshot of data to allow
       
    70      * calculation of an incremental backup.  The snapshot is one that
       
    71      * was previously supplied by the data owner.  The snapshot data
       
    72      * should be read from the location supplied. The snapshot data may
       
    73      * be larger than the location supplied in which case the routine
       
    74      * will be called repeatedly until all data has been supplied.
       
    75      *
       
    76      * Snapshot data will also be supplied as part of a restore operation
       
    77      *
       
    78      * @param aDrive the drive being backed up
       
    79      * @param aBuffer a pointer to the base of the location from whence
       
    80      *        data can be copied.
       
    81      * @param aLastSection ETrue if this is the last section of snapshot
       
    82      *        data, else EFalse.
       
    83      */
       
    84     void ReceiveSnapshotDataL(TDriveNumber aDrive,
       
    85                               TDesC8& aBuffer,
       
    86                               TBool aLastSection);
       
    87 
       
    88     /**
       
    89      * This method returns the expected size of backup data that will be
       
    90      * supplied. If an incremental backup is underway then this method
       
    91      * will not be called until after ReceiveSnapshotDataL().
       
    92      * The size data will be used for the purpose of tracking progess
       
    93      * during a backup. If it is inaccurate then the user may see
       
    94      * irregular progress but the actual backup data will not be
       
    95      * affected so it is acceptable to return an estimated value.
       
    96      *
       
    97      * @param aDrive the drive being backed up.
       
    98      * @return the size of the data that will be returned
       
    99      */
       
   100     TUint GetExpectedDataSize(TDriveNumber aDrive);
       
   101 
       
   102     /**
       
   103      * This method returns a snapshot of data to accompany a backup. The
       
   104      * snapshot is expected to contain details on files / data being
       
   105      * backed up. The format of the snapshot is only meaningful to the
       
   106      * data owner. The snapshot will be supplied if the data owner is
       
   107      * asked for an incremental backup and for a restore operation. The
       
   108      * snapshot data should be copied to the location supplied.
       
   109      *
       
   110      * The snapshot data may be larger than the location supplied in
       
   111      * which case the routine will be called repeatedly until all data
       
   112      * has been retrieved.
       
   113      *
       
   114      * @param aDrive the drive being backed up
       
   115      * @param aBuffer a pointer to the base of the location where data
       
   116      *        can be copied.
       
   117      * @param aFinished on return ETrue if all data has been returned
       
   118      *        for this drive, else EFalse.
       
   119      */
       
   120     void GetSnapshotDataL(TDriveNumber aDrive,
       
   121                           TPtr8& aBuffer,
       
   122                           TBool& aFinished);
       
   123 
       
   124     /**
       
   125      * This method prepares the implementor to return backup data. It
       
   126      * will be followed by a sequence of calls to request the actual
       
   127      * data.
       
   128      *
       
   129      * @param aDrive the drive being backed up.
       
   130      */
       
   131     void InitialiseGetBackupDataL(TDriveNumber aDrive);
       
   132 
       
   133     /**
       
   134      * This method requests a section of backup data.
       
   135      * InitialiseGetBackupDataL() will have been called previously to
       
   136      * specify the drive concerned.  The data returned may be base or
       
   137      * incremental depending on the type of backup and the capability of
       
   138      * the data owner.
       
   139      *
       
   140      * @param aBuffer a pointer to the base of the location where data
       
   141      *        can be copied.
       
   142      * @param aFinished on return ETrue if all data has been returned
       
   143      *        for this drive, else EFalse.
       
   144      */
       
   145     void GetBackupDataSectionL(TPtr8& aBuffer,
       
   146                                TBool& aFinished);
       
   147 
       
   148     /**
       
   149      * This method prepares the implementor to receive base restore data
       
   150      * for a drive. It will be followed by a sequence of calls to supply
       
   151      * the actual data.
       
   152      *
       
   153      * @param aDrive the drive being restored.
       
   154      */
       
   155     void InitialiseRestoreBaseDataL(TDriveNumber aDrive);
       
   156 
       
   157     /**
       
   158      * This method receives a section of base restore data.
       
   159      * InitialiseRestoreBaseDataL() will have been called previously to
       
   160      * specify the drive concerned.
       
   161      *
       
   162      * @param aBuffer a pointer to the base of the location whence data
       
   163      *        can be read.
       
   164      * @param aFinished ETrue if all data has been returned for this
       
   165      *        drive, else EFalse.
       
   166      */
       
   167     void RestoreBaseDataSectionL(TDesC8& aBuffer,
       
   168                                  TBool aFinished);
       
   169 
       
   170     /**
       
   171      * This method prepares the implementor to receive incremental
       
   172      * restore data for a drive. It will be followed by a sequence
       
   173      * of calls to supply the actual data.  If multiple increments
       
   174      * are supplied then this methid will be called before each increment
       
   175      *
       
   176      * @param aDrive the drive being restored.
       
   177      */
       
   178     void InitialiseRestoreIncrementDataL(TDriveNumber aDrive);
       
   179 
       
   180     /**
       
   181      * This method receives a section of increment restore data.
       
   182      * InitialiseRestoreIncrementDataL() will have been called
       
   183      * previously to specify the drive concerned.
       
   184      *
       
   185      * @param aBuffer a pointer to the base of the location whence data
       
   186      *        can be read.
       
   187      * @param aFinished ETrue if all data has been returned for this
       
   188      *        increment, else EFalse.
       
   189      */
       
   190     void RestoreIncrementDataSectionL(TDesC8& aBuffer,
       
   191                                       TBool aFinished);
       
   192 
       
   193     /**
       
   194      * This method is called when all data to be restored has been
       
   195      * supplied.
       
   196      *
       
   197      * @param aDrive the drive being restored.
       
   198      */
       
   199     void RestoreComplete(TDriveNumber aDrive);
       
   200 
       
   201 private:
       
   202 
       
   203     CMidp2BackupPlugin();
       
   204 
       
   205     void ConstructL();
       
   206 
       
   207     /**
       
   208      * This method is called to get the unique Id of the current MMC
       
   209      *
       
   210      * @return The Id of the MMC, or 0, if no MMC is inserted
       
   211      */
       
   212     TUint MmcIdL();
       
   213 
       
   214     /**
       
   215      * This method is called to process the content of the buffer
       
   216      * provided in active phase of restore
       
   217      *
       
   218      * @param aBuffer the buffer to process
       
   219      */
       
   220     void ProcessBufferL(RDesReadStream& stream);
       
   221 
       
   222     /**
       
   223      * This method is called to restore the Java Registry entries
       
   224      * on the MMC, if needed
       
   225      */
       
   226     void RestoreMmcRegistryL();
       
   227 
       
   228     /**
       
   229      * This method creates the path for the Java Registry entries on
       
   230      * the specified MMC
       
   231      *
       
   232      * @param [out] aPathName path of the entries of the MMC
       
   233      * @param aDrive drive of the MMC
       
   234      * @param aUniqueId Unique Id of the MMC
       
   235      */
       
   236     void CreateMmcPath(TDes& aPathName,
       
   237                        TInt aDrive,
       
   238                        TUint aUniqueId);
       
   239 
       
   240     /**
       
   241      * This method gets the path for the next icon file to be backed up
       
   242      *
       
   243      * @param [out] aCurrentUid Uid of the next icon
       
   244      * @param [out] aFullFileName path of the next icon
       
   245      * @return EFalse if there are no more icons in the array, ETrue
       
   246      *         otherwise
       
   247      */
       
   248     TBool NextIcon(TUid& aCurrentUid, HBufC*& aFullFileName);
       
   249 
       
   250     /**
       
   251      * Process buffer when restore state is EFirstBuffer
       
   252      *
       
   253      * @param aStream readstream of buffer to process
       
   254      * @param aBufferSpaceLeft space left of buffer to be processed
       
   255      */
       
   256     void ProcessFirstBufferL(RDesReadStream& aStream, TInt& aBufferSpaceLeft);
       
   257 
       
   258     /**
       
   259      * Process buffer when restore state is EInIcon
       
   260      *
       
   261      * @param aStream readstream of buffer to process
       
   262      * @param aBufferSpaceLeft space left of buffer to be processed
       
   263      */
       
   264     void ProcessInIconL(RDesReadStream& aStream, TInt& aBufferSpaceLeft);
       
   265 
       
   266     /**
       
   267      * Process buffer when restore state is EInSize
       
   268      *
       
   269      * @param aStream readstream of buffer to process
       
   270      * @param aBufferSpaceLeft space left of buffer to be processed
       
   271      */
       
   272     void ProcessInSizeL(RDesReadStream& aStream, TInt& aBufferSpaceLeft);
       
   273 
       
   274     /**
       
   275      * Resets the array of icons to be backed up
       
   276      */
       
   277     void ResetIconArray();
       
   278 
       
   279 private: // data
       
   280 
       
   281     /**
       
   282      * File session
       
   283      * Own.
       
   284      */
       
   285     RFs iFs;
       
   286 
       
   287     /**
       
   288      * AppArcBackupUtil object for AppArc operations
       
   289      * Own.
       
   290      */
       
   291     CAppArcBackupUtil* iAppArcUtil;
       
   292 
       
   293     /**
       
   294      * StorageBackupUtil object for storage B&R
       
   295      * Own.
       
   296      */
       
   297     CStorageBackupUtil* iStorageBackupUtil;
       
   298 
       
   299     /**
       
   300      * The drive that is backed up or restored currently
       
   301      * Own.
       
   302      */
       
   303     TDriveNumber iDrive;
       
   304 
       
   305     /**
       
   306      * Id of backed up drive, gets its value from restored data
       
   307      * Own.
       
   308      */
       
   309     TInt32 iBackupDrive;
       
   310 
       
   311     /**
       
   312      * Id of backed up MMC, gets its value from restored data
       
   313      * Own.
       
   314      */
       
   315     TUint32 iBackupMmc;
       
   316 
       
   317     /**
       
   318      * State of streaming during restore
       
   319      * Own.
       
   320      */
       
   321     TInt iRestoreState;
       
   322 
       
   323     /**
       
   324      * Shows if it's the first call to GetBackupDataSectionL
       
   325      * Own.
       
   326      */
       
   327     TBool iFirstCallToGetBackupDataSection;
       
   328 
       
   329     /**
       
   330      * Shows if Backup of storage data is finished or not
       
   331      * Own.
       
   332      */
       
   333     TBool iStorageDataBackup;
       
   334 
       
   335     /**
       
   336      * Shows if Restore of storage data is finished or not
       
   337      * Own.
       
   338      */
       
   339     TBool iStorageDataRestore;
       
   340 
       
   341     /**
       
   342      * Shows if Java version information is already written or not
       
   343      * Own
       
   344      */
       
   345     TBool iJavaVersionInfoWritten;
       
   346 
       
   347     /**
       
   348      * Shows if its the first call to restore data or not.
       
   349      * Own.
       
   350      */
       
   351     TBool iFirstCallToRestoreBackupDataSection;
       
   352 
       
   353     /**
       
   354      * Stores the uids of the midlets whose icons are to be backed up.
       
   355      * Own.
       
   356      */
       
   357     RArray<TUid> iIconUidArray;
       
   358 
       
   359     /**
       
   360      * The current index in the icon file array
       
   361      * Own.
       
   362      */
       
   363     TInt iIconFilePointer;
       
   364 
       
   365     /**
       
   366      * Stores the current icon file for streaming
       
   367      * This descriptor will be streamed at subsequent calls of
       
   368      * GetBackupDataSectionL()
       
   369      * Own.
       
   370      */
       
   371     HBufC8* iIconDesc;
       
   372 
       
   373     /**
       
   374      * Stores the current icon file being restored
       
   375      * Own.
       
   376      */
       
   377     HBufC8* iRestoreIconDesc;
       
   378 
       
   379     /**
       
   380      * Size of the icon to be still read during restore
       
   381      * Own.
       
   382      */
       
   383     TInt32 iIconFileSizeLeft;
       
   384 
       
   385     /**
       
   386      * Current index of iIconDesc
       
   387      * Own.
       
   388      */
       
   389     TInt iIconDescIndex;
       
   390 
       
   391     /**
       
   392      * Holds the remaining bytes in the buffer
       
   393      * Own
       
   394      */
       
   395 
       
   396     TInt iBufferSpaceLeft;
       
   397 
       
   398     /**
       
   399      * Buffer for storing data size in restore
       
   400      * Own.
       
   401      */
       
   402     TBuf8<4> iSizeBuffer;
       
   403 };
       
   404 
       
   405 } //namespace backup
       
   406 } //namespace java
       
   407 
       
   408 #endif // MIDP2BACKUPPLUGIN_H