appfw/apparchitecture/apserv/apsnnappupdates.h
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // apsnnappupdates.h
       
    15 //
       
    16 
       
    17 #ifndef APSNNAPPUPDATES_H
       
    18 #define APSNNAPPUPDATES_H
       
    19 
       
    20 #include <e32base.h>
       
    21 #include <f32file.h>
       
    22 	
       
    23 
       
    24 
       
    25 // classes referenced
       
    26 class CApaAppData;
       
    27 class CApaAppArcServer;
       
    28 class RApsUpdateLog;
       
    29 class RWriteStream;
       
    30 
       
    31 /**
       
    32 This class keeps track of a resource file or icon file, 
       
    33 whether it is in its final location or a temporary directory.
       
    34 
       
    35 The NonNativeApps updates system makes heavy use of moving files
       
    36 between temporary and final locations, in an attempt to provide
       
    37 atomicity of update lists.
       
    38 
       
    39 @internalComponent
       
    40 */
       
    41 NONSHARABLE_CLASS(TFileDetails)
       
    42 	{
       
    43 public:
       
    44 	TFileDetails();
       
    45 	const TDesC& Path();
       
    46 	void SetPath(const TDesC& aPath);
       
    47 	TBool Exists() const;
       
    48 	void CloseHandle();
       
    49 	
       
    50 	void OpenL(RFs& aFs, const TFileName& aFileName);
       
    51 	void CreateTemporaryL(RFs& aFs, const TFileName& aDir);
       
    52 	void GetDuplicateHandleL(RFile& aFile);
       
    53 
       
    54 	void RenameToRealL(RFs& aFs);
       
    55 	void RenameToTemporaryL(RFs& aFs, const TFileName& aDir);
       
    56 	TInt Delete(RFs& aFs);
       
    57 	TInt DeleteTemporary(RFs& aFs);
       
    58 	TInt RestoreReal(RFs& aFs);
       
    59 
       
    60 	void ExternalizeL(RWriteStream& aStream);
       
    61 	void ExternalizeContinuationL(RWriteStream& aStream, TInt aTag);
       
    62 	TInt ExternalizeContinuation(RWriteStream& aStream, TInt aTag);
       
    63 	void InternalizeL(RReadStream& aStream, TInt& aPosition);
       
    64 	void PostInternalizeL(RFs& aFs);
       
    65 
       
    66 private:
       
    67 	TInt RenameToReal(RFs& aFs);
       
    68 
       
    69 private:
       
    70 	enum TState
       
    71 		{
       
    72 		EStateInvalid = 0,
       
    73 		EStateNull,
       
    74 		EStateTemporary,
       
    75 		EStateReal
       
    76 		};
       
    77 	TState iState;
       
    78 	TFileName iPath;
       
    79 	TFileName iTempPath;
       
    80 	RFile iHandle;
       
    81 	};
       
    82 
       
    83 /**
       
    84 Abstract base class for objects that represent updates to the non-native applications
       
    85 registry. Subclasses must implement the DoPerformUpdateL and DoRollbackUpdate methods.
       
    86 
       
    87 - DoPerformUpdateL will only ever be called once or not at all
       
    88 - DoPerformUpdateL will be called first, if at all
       
    89 - DoRollbackUpdate will not be called before DoPerformUpdateL
       
    90 - DoRollbackUpdate will be called if DoPerformUpdateL fails on this update or any subsequent one
       
    91 - DoRollbackUpdate will not be called twice
       
    92 - The object may be deleted at any time.
       
    93 
       
    94 If the device is turned off / crashes partway through performing updates, 
       
    95 the following will be called upon reboot:
       
    96 
       
    97 - The subclass' NewL, with dummy values instead of class-specific data (if any)
       
    98 - InternalizePerformLogL() will be called immediately afterwards
       
    99 - InternalizeRollbackLogL() iff a rollback action for this update is in the log
       
   100 - PostInternalizeL() will be called after the log has been read in entirely
       
   101 - DoRollbackUpdaetL() may then be called if, after replaying the log, the class' state is
       
   102                       EPerforming, EPerformed or ERollingBack
       
   103 
       
   104 @internalComponent
       
   105 */
       
   106 NONSHARABLE_CLASS(CApsNonNativeApplicationsUpdate) : public CBase
       
   107 	{
       
   108 public: // Types
       
   109 	enum TState
       
   110 		{
       
   111 		ENew,
       
   112 		ENeedsInternalizing,
       
   113 		EPerforming,
       
   114 		EPerformed,
       
   115 		ERollingBack,
       
   116 		ERolledBack
       
   117 		};
       
   118 	
       
   119 	enum TLogActionType
       
   120 		{
       
   121 		EInvalidAction = 0,
       
   122 		ENewUpdate,				// Indicates the record of an update's initial state
       
   123 		EPerformUpdate,			// Indicates the start of a Perform-update log
       
   124 		ERollbackUpdate,        // Indicates the start of a Rollback-update log
       
   125 		EContinuationOfUpdate,  // Specifies that the current update's log has not finished
       
   126 		EChangeOfUpdateState,   // Similar to EContinuationOfUpdate, but used by this superclass
       
   127 		EEndOfUpdate            // Specifies that the current update's log has finished
       
   128 		};
       
   129 
       
   130 	enum TLogUpdateType
       
   131 		{
       
   132 		EInvalidUpdate = 0,
       
   133 		ERegisterApplication,   // Indicates the start of a RegisterApplication update
       
   134 		EDeregisterApplication, // Indicates the start of a DeregisterApplication update
       
   135 #ifdef _DEBUG
       
   136 		EFail,                  // Indicates the start of a Forced-Fail update
       
   137 		EPanic,                 // Indicates the start of a Forced-Panic update
       
   138 		ERollbackPanic          // Indicates the start of a Forced-Panic-On-Rollback update
       
   139 #endif
       
   140 		};
       
   141 
       
   142 public:
       
   143 	~CApsNonNativeApplicationsUpdate();
       
   144 
       
   145 protected:
       
   146 	CApsNonNativeApplicationsUpdate(RFs& aFs, TUid aUid, TState aState, TLogUpdateType aType);
       
   147 
       
   148 public: 
       
   149 	CApsNonNativeApplicationsUpdate* Previous() const;
       
   150 	CApsNonNativeApplicationsUpdate* Next() const;
       
   151 	TUid Uid();
       
   152 	void PerformUpdateL(RApsUpdateLog& aUpdateLog);
       
   153 	void RollbackUpdateL(RApsUpdateLog& aUpdateLog);
       
   154 	void InternalizeStateChangeL(RReadStream& aStream, TInt& aPosition);
       
   155 
       
   156 	void InternalizeNewUpdateL(RReadStream& aStream, TInt& aPosition);
       
   157 	void InternalizePerformUpdateL(RReadStream& aStream, TInt& aPosition);
       
   158 	void InternalizeRollbackUpdateL(RReadStream& aStream, TInt& aPosition);
       
   159 
       
   160 protected:
       
   161 	TFileName TemporaryFilePathL(TDriveName& aDrive);
       
   162 	void StateChangeL(TState aState, RWriteStream& aStream);
       
   163 
       
   164 private:
       
   165 	void SharedInternalizeLoopL(RReadStream& aStream, TInt& aPosition);
       
   166 
       
   167 	virtual void DoPerformUpdateL(RApsUpdateLog& aUpdateLog) = 0;
       
   168 	virtual void DoRollbackUpdate(RApsUpdateLog& aUpdateLog) = 0;
       
   169 
       
   170 	virtual void ExternalizeL(RWriteStream& aStream);
       
   171 	virtual void InternalizeL(RReadStream& aStream, TInt& aPosition);
       
   172 	virtual void InternalizeUpdateContinuationL(RReadStream& aStream, TInt& aPosition);
       
   173 	virtual void PostInternalizeL();
       
   174 
       
   175 
       
   176 protected:
       
   177 	TState iState;
       
   178 	RFs& iFs;
       
   179 
       
   180 private:
       
   181 	friend class CApsNonNativeApplicationsUpdateList; // so it can link up iPrevious/iNext
       
   182 	const TLogUpdateType iType;
       
   183 	CApsNonNativeApplicationsUpdate* iPrevious;
       
   184 	CApsNonNativeApplicationsUpdate* iNext;
       
   185 	const TUid iUid;
       
   186 	};
       
   187 
       
   188 /**
       
   189 Implementation of CApsNonNativeApplicationsUpdate that performs the registration of a
       
   190 non-native application.
       
   191 
       
   192 The Write/Copy methods of this class should be used to prepare the update,
       
   193 they will write resource and icon files to a temporary directory.
       
   194 
       
   195 When this update is executed, the files will be moved to the locations set with the
       
   196 Set*FileTargetLocation functions.
       
   197 
       
   198 @internalComponent
       
   199 */
       
   200 NONSHARABLE_CLASS(CApsRegisterNonNativeApplication) : public CApsNonNativeApplicationsUpdate
       
   201 	{
       
   202 public:
       
   203 	static CApsRegisterNonNativeApplication* NewL(RFs& aFs, TUid aUid, const TDriveName& aDrive, TState aState = ENew);
       
   204 	~CApsRegisterNonNativeApplication();
       
   205 
       
   206 private:
       
   207 	CApsRegisterNonNativeApplication(RFs& aFs, TUid aUid, const TDriveName& aDrive, TState aState);
       
   208 
       
   209 public:
       
   210 	void SetResourceFileTargetLocation(const TDesC& aLocation);
       
   211 	void WriteResourceFileL(const TDesC8& aData, const TDesC8* aDataPrefix);
       
   212 
       
   213 	void SetLocalisableResourceFileTargetLocation(const TDesC& aLocation);
       
   214 	void WriteLocalisableResourceFileL( const TDesC8& aData, const TDesC8* aDataPrefix);
       
   215 
       
   216 	void SetIconFileTargetLocation(const TDesC& aLocation);
       
   217 	void CopyIconFileL(RFile& aSourceFile);
       
   218 
       
   219 private:	
       
   220 	void NewTemporaryFileL(TFileDetails& aFile);
       
   221 	void WriteResourceFileL(TFileDetails& aFile, const TDesC8& aData, const TDesC8* aDataPrefix);
       
   222 
       
   223 	// from CApsNonNativeApplicationsUpdate
       
   224 	void DoPerformUpdateL(RApsUpdateLog& aUpdateLog);
       
   225 	void DoRollbackUpdate(RApsUpdateLog& aUpdateLog);
       
   226 	void ExternalizeL(RWriteStream& aStream);
       
   227 	void InternalizeL(RReadStream& aStream, TInt& aPosition);
       
   228 	void InternalizeUpdateContinuationL(RReadStream& aStream, TInt& aPosition);
       
   229 	void PostInternalizeL();
       
   230 
       
   231 
       
   232 private:
       
   233 	enum TLogContinuationType 
       
   234 		{
       
   235 		EInvalidContinuation = 0,
       
   236 		EResourceFileUpdate,
       
   237 		ELocalisableResourceFileUpdate,
       
   238 		EIconFileUpdate
       
   239 		};
       
   240 	TDriveName iDrive;
       
   241 	TFileDetails iResourceFile;
       
   242 	TFileDetails iLocalisableResourceFile;
       
   243 	TFileDetails iIconFile;
       
   244 	};
       
   245 
       
   246 /**
       
   247 Implementation of CApsNonNativeApplicationsUpdate that performs the deregistration of a
       
   248 non-native application.
       
   249 
       
   250 @internalComponent
       
   251 */
       
   252 NONSHARABLE_CLASS(CApsDeregisterNonNativeApplication) : public CApsNonNativeApplicationsUpdate
       
   253 	{
       
   254 public:
       
   255 	static CApsDeregisterNonNativeApplication* NewL(RFs& aFs, CApaAppArcServer& aServ, TUid aUid, TState aState = ENew);
       
   256 	~CApsDeregisterNonNativeApplication();
       
   257 
       
   258 private:
       
   259 	CApsDeregisterNonNativeApplication(RFs& aFs, CApaAppArcServer& aServ, TUid aUid, TState aState);
       
   260 
       
   261 private:
       
   262 	void RenameToTemporaryL(TFileDetails& aFile, RApsUpdateLog& aUpdateLog);
       
   263 	CApaAppData* FindAppDataLC(RApsUpdateLog& aUpdateLog);
       
   264 
       
   265 	// from CApsNonNativeApplicationsUpdate
       
   266 	void DoPerformUpdateL(RApsUpdateLog& aUpdateLog);
       
   267 	void DoRollbackUpdate(RApsUpdateLog& aUpdateLog);
       
   268 	void ExternalizeL(RWriteStream& aStream);
       
   269 	void InternalizeL(RReadStream& aStream, TInt& aPosition);
       
   270 	void InternalizeUpdateContinuationL(RReadStream& aStream, TInt& aPosition);
       
   271 	void PostInternalizeL();
       
   272 
       
   273 private:
       
   274 	enum TLogContinuationType 
       
   275 		{
       
   276 		EInvalidContinuation = 0,
       
   277 		EResourceFileUpdate,
       
   278 		ELocalisableResourceFileUpdate,
       
   279 		EIconFileUpdate
       
   280 		};
       
   281 	CApaAppArcServer& iServ;
       
   282 	TFileDetails iResourceFile;
       
   283 	TFileDetails iLocalisableResourceFile;
       
   284 	TFileDetails iIconFile;
       
   285 	};
       
   286 
       
   287 
       
   288 #ifdef _DEBUG
       
   289 /**
       
   290 CApsAlwaysFailUpdate
       
   291 
       
   292 A dummy CNonNativeApplicationsUpdate for testing purpouses.
       
   293 Always fails with KErrGeneral when performed
       
   294 
       
   295 @internalComponent
       
   296 */
       
   297 NONSHARABLE_CLASS(CApsAlwaysFailUpdate) : public CApsNonNativeApplicationsUpdate
       
   298 	{
       
   299 public:
       
   300 	CApsAlwaysFailUpdate(RFs& aFs, TState aState = ENew);
       
   301 private:
       
   302 	// from CApsNonNativeApplicationsUpdate
       
   303 	void DoPerformUpdateL(RApsUpdateLog& aUpdateLog);
       
   304 	void DoRollbackUpdate(RApsUpdateLog&) {}
       
   305 	};
       
   306 
       
   307 
       
   308 /**
       
   309 CApsAlwaysPanicUpdate
       
   310 
       
   311 A dummy CNonNativeApplicationsUpdate for testing purpouses.
       
   312 Always panics when performed
       
   313 
       
   314 @internalComponent
       
   315 */
       
   316 NONSHARABLE_CLASS(CApsAlwaysPanicUpdate) : public CApsNonNativeApplicationsUpdate
       
   317 	{
       
   318 public:
       
   319 	CApsAlwaysPanicUpdate(RFs& aFs, TState aState = ENew);
       
   320 private:
       
   321 	// from CApsNonNativeApplicationsUpdate
       
   322 	void DoPerformUpdateL(RApsUpdateLog& aUpdateLog);
       
   323 	void DoRollbackUpdate(RApsUpdateLog&) {}
       
   324 	};
       
   325 
       
   326 
       
   327 /**
       
   328 CApsAlwaysPanicOnRollbackUpdate
       
   329 
       
   330 A dummy CNonNativeApplicationsUpdate for testing purpouses.
       
   331 Always panics upon rollback
       
   332 
       
   333 @internalComponent
       
   334 */
       
   335 NONSHARABLE_CLASS(CApsAlwaysPanicOnRollbackUpdate) : public CApsNonNativeApplicationsUpdate
       
   336 	{
       
   337 public:
       
   338 	CApsAlwaysPanicOnRollbackUpdate(RFs& aFs, TState aState = ENew);
       
   339 private:
       
   340 	// from CApsNonNativeApplicationsUpdate
       
   341 	void DoPerformUpdateL(RApsUpdateLog&) {}
       
   342 	void DoRollbackUpdate(RApsUpdateLog& aUpdateLog);
       
   343 	};
       
   344 #endif // _DEBUG
       
   345 
       
   346 
       
   347 #endif // APSNNAPPUPDATES_H
       
   348