Update contrib.
1 // Copyright (c) 2004-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
20 #include "obsrvr_noc.h"
24 #include "clientrequest.h"
26 #include "transstate.h"
30 #include "heaprepos.h"
32 class CRepositoryTransactor;
34 class CSharedRepository : public CBase
36 friend class CObservable;
37 friend class CServerRepository;
38 friend class TConvToolTester;
41 static CSharedRepository* NewL(TUid aUid);
46 TInt CommitChanges(TCentRepLocation aLocation = EPersists);
47 void CommitChangesL(TCentRepLocation aLocation = EPersists)
49 User::LeaveIfError(CommitChanges(aLocation));
52 void CreateL(TServerSetting& s, TSettingsAccessPolicy* &aPolicy, TBool aFirstLoad, TBool aSingleMetaFound=EFalse);
54 void SetMetaDataOnRead(TServerSetting& aSetting, TBool aSingleMetaFound);
56 void SetMetaDataOnCreate(TServerSetting& aNewSetting, TUint32* aMeta);
58 TInt DeleteAndPersist(TUint32 aId);
59 TInt DeleteNoPersist(TUint32 aId);
61 TInt ResetNoPersistL(TServerSetting& aSetting);
62 void ResetAndPersistL(TServerSetting& aSetting);
63 TInt ResetAllNoPersistL(CSharedRepository& aRepository);
65 const TSecurityPolicy& GetFallbackReadAccessPolicy(TUint32 aId);
66 inline const TSecurityPolicy& GetReadAccessPolicy(const TServerSetting& aSetting);
67 inline const TSecurityPolicy& GetReadAccessPolicy(TUint32 aId);
68 inline const TSecurityPolicy& GetDefaultReadAccessPolicy();
70 const TSecurityPolicy& GetFallbackWriteAccessPolicy(TUint32 aId);
71 inline const TSecurityPolicy& GetWriteAccessPolicy(const TServerSetting& aSetting);
72 inline const TSecurityPolicy& GetWriteAccessPolicy(TUint32 aId);
73 inline const TSecurityPolicy& GetDefaultWriteAccessPolicy();
75 TSettingsAccessPolicy* GetFallbackAccessPolicy(TUint32 aId
76 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
77 ,TBool aSkipSingle=EFalse
81 TInt StartTransaction(CRepositoryTransactor& aTransactor, TInt aMode);
82 TInt CommitTransaction(CRepositoryTransactor& aTransactor, TUint32& aKeyInfo);
83 TInt FailTransaction(CRepositoryTransactor& aTransactor, TInt aError, TUint32 aErrorKey);
84 void FailAllTransactions(const CRepositoryTransactor* aExcludeTransactor);
85 TInt AttemptPromoteTransactionToReadWrite(CRepositoryTransactor& aTransactor);
86 TBool IsTransactionActive();
88 void MergeL(CSharedRepository& aInstallRep, TMergeType aMergeType);
89 #ifndef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
90 TInt FindLocationForFileL(TCentRepLocation& aLocation,TUid aUid,const TCentRepFileType aType) const;
93 void HandleUpdateMergeL(TTime aInstallFileTimeStamp, CSharedRepository& aInstallRep);
94 void HandleDeleteMergeL(CSharedRepository& aRomRep);
95 void SetInstallTime(TTime aInstallTime);
97 inline TUid Owner() {return iSimRep->Owner(); }
98 inline void WriteBackupStream(RWriteStream& aStream) const;
99 inline void WriteDeletedSettingsStream(RWriteStream& aStream) const;
100 inline void InternalizeL(RReadStream& aStream, CRestoredRepository& aRstRepos) ;
101 void ExternalizeCre(RWriteStream& aStream) const;
102 void InternalizeCreL(RReadStream& aStream) ;
103 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
104 void InternalizeCreL(RReadStream& aStream,TUint8& aCreVersion);
106 TInt ReloadContentL(CIniFileIn& aIniFile, TBool aFirstLoad = EFalse);
107 #ifdef CENTREP_CONV_TOOL
108 void DoCommitChangesToIniFileL(const TDesC& aOutFileName
109 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
114 inline void SetSize(TInt aSize);
115 inline TInt Size() const;
120 void RestoreConsistencyL();
121 void DoRestoreConsistencyL();
122 TInt CreateRepositoryFromCreFileL(TCentRepLocation aLocation);
123 TInt ReadSettingSavePolicyL(CIniFileIn& aFile,TServerSetting& aSetting, TSettingsAccessPolicy* &aPolicy, TBool& aSingleMetaFound);
124 TInt DoCommitTransactionSettings(CRepositoryTransactor& aTransactor, TUint32& aKeyInfo);
125 void Notify(TUint32 aVal) const;
127 RSettingsArray& GetSettings();
129 void ConstructL(TUid aUid);
131 #ifdef FOTA_UNIT_TESTING
133 void SetUid(TUid aUid)
135 iSimRep->SetUid(aUid);
138 CHeapRepository* iSimRep;
140 TInt32 iSize; //approximate size(in memory) of the repository after internalisation
141 TBool iNotificationState;//Notification can be made if iNotificationState is non-zero,
142 //otherwise the notification is disabled
144 //iInconsistentData data flag will be set at the beginning of CommitChangesL()
145 //and reset at the end of it. The flag is used to implement lazy-load approach for the
146 //repository - if CommitChangesL() fails, the in-memory representation of the repository
147 //won't match the updated by CommitChangesL() repository (ini) file. The repository
148 //consistency has to be restored before any next call of CSharedRepository methods.
149 TBool iInconsistentData;
154 Base class for CServerRepository and other objects that may be in transactions with the
155 shared repository. Contains a double queue link so the shared repository can build a queue
156 of them. In order to use transactions in the shared repository, the object needs to supply a
157 CRepositoryTransactor - either itself or a member variable. This makes it possible to
158 prevent one transactor from closing another's transaction.
159 Stores transaction state and changes made during the transaction.
160 Also stores RMessage2 while pending async start or commit, and handles its completion.
162 class CRepositoryTransactor : public CBase
164 // shared repository may set private transaction state, but not derived classes
165 friend class CSharedRepository;
166 // for the _FOFF macro to work
167 friend class CObservable::TSharedRepositoryInfo;
168 friend class CObservable;
171 inline TInt TransactionState() const
173 return iTransactionState;
175 inline TInt TransactionMode() const
177 return iTransactionState & EAllTransactionModeBits;
179 inline TBool IsInTransaction() const
181 return iTransactionState != ENoTransaction;
183 inline TBool IsInActiveTransaction() const
185 // transaction is active if no bits apart from the (non-zero) mode are set
186 return (iTransactionState != ENoTransaction) && (TransactionMode() == iTransactionState);
188 inline TBool IsInActiveReadTransaction() const
190 return iTransactionState == EReadTransaction;
192 inline TBool IsInActiveConcurrentReadWriteTransaction() const
194 return (iTransactionState == EConcurrentReadWriteTransaction);
196 inline TBool IsInActiveExclusiveReadWriteTransaction() const
198 return (iTransactionState == EReadWriteTransaction);
200 inline TBool IsInActiveReadWriteTransaction() const
202 return (iTransactionState == EReadWriteTransaction)
203 || (iTransactionState == EConcurrentReadWriteTransaction);
205 inline TBool IsInFailedTransaction() const
207 return (iTransactionState & EFailedBit) != 0;
211 inline void ClearSettings()
213 iTransactionSettings.Reset();
217 inline void SetFailed(TInt aError, TUint32 aErrorKey)
219 // don't want to fail more than once
220 ASSERT(IsInActiveTransaction());
221 ASSERT(aError != KErrNone); // must fail for a reason
222 iTransactionState |= EFailedBit;
224 iTransactionResult = aError;
225 iTransactionErrorKey = aErrorKey;
227 inline void PromoteToExclusiveReadWrite()
229 ASSERT(iTransactionState == EReadTransaction);
230 iTransactionState = EReadWriteTransaction;
233 inline void AddToQueue(TSglQue<CRepositoryTransactor>& aTransactors, TInt aMode)
235 ASSERT(!IsInTransaction());
236 // if the following ASSERT fails, transactor is already in a queue
237 ASSERT(iLink.iNext == NULL);
238 aTransactors.AddLast(*this);
239 iTransactionState = aMode;
240 // check adding to queue in an active state
241 ASSERT(IsInActiveTransaction());
243 // clear failure reasons
244 iTransactionResult = KErrNone;
245 iTransactionErrorKey = KUnspecifiedKey;
249 iTransactionState = ENoTransaction;
256 // derived classes are free to change transaction settings.
257 // these can be made persistent by committing write transaction
258 RSettingsArray iTransactionSettings;
260 // 'Create' needs to check the default (INI) file to see if the
261 // key position has a setting defined. If that is the case,
262 // the new setting uses meta defined for the original setting
264 // Store data read from INI here so that we only read the INI
265 // once per transaction.
266 CSharedRepository* iIniRep;
269 // A queue link used by the CSharedRepository the CTransactor is working on
271 // integer encoding transaction state using definition of TTransactionState
272 TInt iTransactionState;
273 // result to be returned by commit if transaction failed earlier
274 TInt iTransactionResult;
275 // if transaction failed earlier, key or partial key involved in the original error,
276 // or KUnspecifiedKey if could not be attributed to just one.
277 TUint32 iTransactionErrorKey;
280 #include "shrepos.inl"