installationservices/swtransactionservices/inc_private/integrityservices.h
branchRCL_3
changeset 66 8b7f4e561641
parent 65 7333d7932ef7
child 70 e8965914fac7
equal deleted inserted replaced
65:7333d7932ef7 66:8b7f4e561641
     1 /*
       
     2 * Copyright (c) 2008-2010 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 the License "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: 
       
    15 * Definition of CIntegrityServices
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file 
       
    22  @released
       
    23  @internalTechnology 
       
    24 */
       
    25 
       
    26 #ifndef __INTEGRITYSERVICES_H__
       
    27 #define __INTEGRITYSERVICES_H__
       
    28 
       
    29 #include <e32base.h>
       
    30 #include <f32file.h>
       
    31 #include <e32ldr_private.h>
       
    32 #include <usif/sts/stsdefs.h>
       
    33 #include "integrityservicesevent.h"
       
    34 
       
    35 
       
    36 class RFs;
       
    37 
       
    38 namespace Usif
       
    39 {
       
    40 class CJournal;
       
    41 class CIntegrityTreeNode;
       
    42 /**
       
    43  * This class maintains the integrity of installed software by ensuring that
       
    44  * the device is always left in a consistent state. If a software modification
       
    45  * process (install, upgrade or uninstall) is interrupted then that process is
       
    46  * reverted, returning the device to its original state with no orphaned or
       
    47  * missing files.
       
    48  *
       
    49  * @released
       
    50  * @internalTechnology 
       
    51  */
       
    52 class CIntegrityServices : public CBase
       
    53 	{
       
    54 	public:
       
    55 
       
    56 		/**
       
    57 		 * Constructs a new CIntegrityServices object specifying a path for
       
    58 		 * the journal files
       
    59 		 *
       
    60 		 * @code
       
    61 		 *
       
    62 		 *	TTime currentTime;
       
    63 		 *	currentTime.UniversalTime();
       
    64 		 *	_LIT(KIntegrityServicesPath, "\\private\\SID\\");
       
    65 		 *	iIntegrityServices = CIntegrityServices::NewL(currentTime.Int64(), 
       
    66 		 *											KIntegrityServicesPath);
       
    67 		 *
       
    68 		 * @endcode
       
    69 		 *
       
    70 		 * @param aTransactionID A unique ID provided by the client to
       
    71 		 *						 identify this transaction. It is suggested
       
    72 		 *						 that the client use the current time as the
       
    73 		 *						 unique ID. This value can then be shared
       
    74 		 *						 between different processes so that they use
       
    75 		 *						 the same journal.
       
    76 		 */
       
    77 		 static CIntegrityServices* NewL(TStsTransactionId aTransactionID);
       
    78 		
       
    79 		/**
       
    80 		 * Constructs a new CIntegrityServices object specifying a path for
       
    81 		 * the journal files and puts it on the cleanup stack
       
    82 		 * @param aTransactionID A unique ID provided by the client to
       
    83 		 *						 identify this transaction. It is suggested
       
    84 		 *						 that the client use the current time as the
       
    85 		 *						 unique ID. This value can then be shared
       
    86 		 *						 between different processes so that they use
       
    87 		 *						 the same journal.
       
    88 		 */
       
    89 		 static CIntegrityServices* NewLC(TStsTransactionId aTransactionID);
       
    90 		
       
    91 		 ~CIntegrityServices();
       
    92 		
       
    93 		/**
       
    94 		 * Notifies Integrity Services that a file or directory is being added
       
    95 		 * so that it can be removed if a rollback occurs. A record is created
       
    96 		 * in the journal file on the appropriate drive.
       
    97 		 *
       
    98 		 * @param aFileName - Name of file or directory including path
       
    99 		 */
       
   100 		 void RegisterNewL(const TDesC& aFileName);
       
   101 
       
   102 		/**
       
   103 		 * Instructs Integrity Services to create a new file. 
       
   104 		 * It is removed if a rollback occurs. A record is created
       
   105 		 * in the journal file on the appropriate drive.
       
   106 		 *
       
   107 		 * @param aFileName - Name of file or directory including path
       
   108 		 * @param newFile - Reference of a file handle that is set to the newly created file
       
   109 		 * @param aFileMode - File creation mode of the new file (see TFileMode documentation
       
   110 		 *                    for the possible mode or combination of modes)
       
   111 		 */
       
   112 		 void CreateNewL(const TDesC& aFileName, RFile &newFile, TUint aFileMode);
       
   113 		
       
   114 		/**
       
   115 		 * Removes the specified file or directory, first backing it up before
       
   116 		 * deleting it. A record is created in the journal file on the
       
   117 		 * appropriate drive.
       
   118 		 *
       
   119 		 * @param aFileName - Name of file or directory including path
       
   120 		 */
       
   121 		 void RemoveL(const TDesC& aFileName);
       
   122 		
       
   123 		/**
       
   124 		 * Notifies Integrity Services that a file or directory is being added
       
   125 		 * that must later be removed. A record is created in the journal file
       
   126 		 * on the appropriate drive.
       
   127 		 *
       
   128 		 * @param aFileName - Name of file including path
       
   129 		 */
       
   130 		 void RegisterTemporaryL(const TDesC& aFileName);
       
   131 
       
   132 		/**
       
   133 		 * Instructs Integrity Services to create a new temporary file. 
       
   134 		 * It is removed if a rollback occurs. A record is created
       
   135 		 * in the journal file on the appropriate drive.
       
   136 		 *
       
   137 		 * @param aFileName - Name of file including path
       
   138 		 * @param newFile - Reference of a file handle that is set to the newly created file
       
   139 		 * @param aFileMode - File creation mode of the new file (see TFileMode documentation
       
   140 		 *                    for the possible mode or combination of modes)
       
   141 		 */
       
   142 		 void CreateTemporaryL(const TDesC& aFileName, RFile &newFile, TUint aFileMode);
       
   143 
       
   144 		/**
       
   145 		 * Instructs Integrity Services to create a new file.
       
   146 		 * If the file already exists it's removed to a backup location first before the new file is created. 
       
   147 		 * The newly created file is removed if a rollback occurs and the old one is restored. 
       
   148 		 * A record is created in the journal file on the appropriate drive.
       
   149 		 * @param aFileName - Name of file or directory including path
       
   150 		 * @param newFile - Reference of a file handle that is set to the newly created file
       
   151 		 * @param aFileMode - File creation mode of the new file (see TFileMode documentation
       
   152 		 *                    for the possible mode or combination of modes)
       
   153 		 */
       
   154 		 void OverwriteL(const TDesC& aFileName, RFile &newFile, TUint aFileMode);
       
   155 
       
   156 		/**
       
   157 		 * Commits the current transaction by deleting backup, temporary and
       
   158 		 * journal files. The journal files are first refreshed so that
       
   159 		 * operations shared between processes and spread across multiple
       
   160 		 * drives are committed at the same time. If any journal file from this
       
   161 		 * transaction is not present or has already been rolledback the
       
   162 		 * commit will fail.
       
   163 		 */
       
   164 		 void CommitL();
       
   165 		
       
   166 		/**
       
   167 		 * Starts the recovery process for all drives.
       
   168 		 * Drive are rolled back independantly since removable media may be at
       
   169 		 * a different state to internal drives (which may have already been 
       
   170 		 * rolled back).
       
   171 		 *
       
   172 		 * @param aRecordAllRollbackEvents- This parameter specifies whether we should record events during the rollback.
       
   173 		 *  This allows continuing the rollback in case it has been interrupted. In most cases, this flag should be "on", however
       
   174 		 *   if we failed a previous roll back due to low space or low memory, it can prevent any roll back due to lack of resources for recording
       
   175 		 *   the rollback events. In these cases, it should be set to "off".
       
   176 		 *
       
   177 		 */
       
   178 		 void RollBackL(TBool aRecordAllRollbackEvents = ETrue);
       
   179 
       
   180 		/**
       
   181 		 * Returns the TransactionID
       
   182 		 *
       
   183 		 * @return a TStsTransactionId representing the transaction
       
   184 		 */
       
   185 		inline TStsTransactionId TransactionId() const;
       
   186 
       
   187 		/**
       
   188 		 * Scans through the transaction path and returns a list if transaction ids that have been found.
       
   189 		 *  
       
   190 		 * @param idArray - an array of TStsTransactionId in which the found ids are returned to the caller
       
   191 		 */
       
   192 		static void GetListOfTransactionsL(RArray<TStsTransactionId>& aIdArray);
       
   193 
       
   194 		/**
       
   195 		 * Roll back all transactions that it can find in the transaction path in the filesystem
       
   196 		 * Important note: The function tries the best effort to roll back all transactions found. 
       
   197 		 *                 Failing to roll back one transaction doesn't influence the roll back of others,
       
   198 		 *                 however if any of the transactions fail to roll back properly the function finally
       
   199 		 *                 will leave with the latest error encountered. (After it has tried to roll back all!)    
       
   200 		 */
       
   201 		static void RollbackAllL();
       
   202 
       
   203 		/**
       
   204 		 * Failure types - indicate when to simulate power failure during
       
   205 		 * testing
       
   206 		 */
       
   207 		enum TFailType
       
   208 			{
       
   209 			EFailNone,
       
   210 			EFailAddingNewFile,
       
   211 			EFailRemovingFile,
       
   212 			EFailAddingTempFile,
       
   213 			EFailRestoringFile,
       
   214 			EFailDeletingFile,
       
   215 			EFailInstallComplete,
       
   216 			EFailNewFilesRemoved,
       
   217 			EFailOldFilesRestored,
       
   218 			EFailTempFilesRemoved,
       
   219 			EFailBackupFilesRemoved,
       
   220 			};
       
   221 		
       
   222 		/**
       
   223 		 * Failure position - indicate when to simulate power failure during
       
   224 		 * testing
       
   225 		 */	
       
   226 		enum TFailPosition
       
   227 			{
       
   228 			EBeforeJournal,
       
   229 			EAfterJournal,
       
   230 			EBeforeAction,
       
   231 			EAfterAction
       
   232 			};
       
   233 			
       
   234 	private:
       
   235 		/**
       
   236 		 * Constructor for CIntegrityServices
       
   237 		 *
       
   238 		 * @param aTransactionID A unique ID provided by the client to
       
   239 		 *						 identify this transaction. It is suggested
       
   240 		 *						 that the client use the current time as the
       
   241 		 *						 unique ID. This value can then be shared
       
   242 		 *						 between different processes so that they use
       
   243 		 *						 the same journal.
       
   244 		 */
       
   245 		 CIntegrityServices(TStsTransactionId aTransactionID);
       
   246 		
       
   247 		/**
       
   248 		 * Second phase constructor for CIntegrityServices
       
   249 		 *
       
   250 		 */
       
   251 		 void ConstructL();
       
   252 						
       
   253 		/**
       
   254 		 * Removes a trailing slash from directory name, if needed.
       
   255 		 * 
       
   256 		 * @param aFileName the filename to modify. If the filename does not represent a directory, it is not modified
       
   257 		 */
       
   258 		static void NormalizeDirectoryName(TDes& aFileName);
       
   259 
       
   260 	private:
       
   261 	
       
   262 	    /**
       
   263 		 * Pointer to the journal - uses log file(s) for persistant storage
       
   264 		 * A log file is created on each drive involved so that they can be
       
   265 		 * recovered independantly.
       
   266 		 */
       
   267 		CJournal* iJournal;
       
   268 		
       
   269 		/**
       
   270 		 * Provided by the client to identify this transaction.
       
   271 		 */
       
   272 		TStsTransactionId iTransactionID;
       
   273 		
       
   274 		/**
       
   275 		 * The supplied path in which to read and write journal files.
       
   276 		 */
       
   277 		TPath iJournalPath;
       
   278 
       
   279 		 /**
       
   280 		 The drive number for the system drive.
       
   281 		 */
       
   282 		 TDriveNumber iSystemDrive;
       
   283 		 
       
   284 	private:
       
   285 	
       
   286 		RFs iFs;
       
   287 		
       
   288 		RLoader iLoader;
       
   289 	
       
   290 	public:
       
   291 	    /** 
       
   292 		 * Failure type (used only by test code)
       
   293 		 */
       
   294 		static TFailType iFailType;
       
   295 		
       
   296 		/** 
       
   297 		 * Failure position (used only by test code)
       
   298 		 */
       
   299 		static TFailPosition iFailPosition;
       
   300 		
       
   301 		/** 
       
   302 		 * Specify the name of the file to fail on (used only in test code)
       
   303 		 */
       
   304 		static TFileName iFailFileName;
       
   305 		static TBool iIsFailureTestingEnabled;
       
   306 		
       
   307 		/**
       
   308 		 * Test utility function
       
   309 		 *
       
   310 		 * @param aFailType		 The operation on which to fail
       
   311 		 * @param aFailPosition	 The position at which to fail
       
   312 		 * @param aFailFileName	 The filename on which to fail
       
   313 		 */
       
   314 		static void SimulatePowerFailureL(TFailType aFailType, TFailPosition aPosition, const TDesC& aFailFileName);
       
   315 	};
       
   316 
       
   317 inline TStsTransactionId CIntegrityServices::TransactionId() const
       
   318 	{
       
   319 	return iTransactionID;
       
   320 	}
       
   321 
       
   322 } //namespace
       
   323 #endif