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