|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifndef SHREPOS_H |
|
17 #define SHREPOS_H |
|
18 |
|
19 #include <e32base.h> |
|
20 #include "obsrvr_noc.h" |
|
21 #include "srvres.h" |
|
22 #include "srvdefs.h" |
|
23 #include "setting.h" |
|
24 #include "clientrequest.h" |
|
25 #include "panic.h" |
|
26 #include "transstate.h" |
|
27 #include "inifile.h" |
|
28 #include "rstrepos.h" |
|
29 #include "datatype.h" |
|
30 #include "heaprepos.h" |
|
31 |
|
32 class CRepositoryTransactor; |
|
33 |
|
34 class CSharedRepository : public CBase |
|
35 { |
|
36 friend class CObservable; |
|
37 friend class CServerRepository; |
|
38 friend class TConvToolTester; |
|
39 |
|
40 public: |
|
41 static CSharedRepository* NewL(TUid aUid); |
|
42 ~CSharedRepository(); |
|
43 |
|
44 TUid Uid() const; |
|
45 |
|
46 TInt CommitChanges(TCentRepLocation aLocation = EPersists); |
|
47 void CommitChangesL(TCentRepLocation aLocation = EPersists) |
|
48 { |
|
49 User::LeaveIfError(CommitChanges(aLocation)); |
|
50 } |
|
51 |
|
52 void CreateL(TServerSetting& s, TSettingsAccessPolicy* &aPolicy, TBool aFirstLoad, TBool aSingleMetaFound=EFalse); |
|
53 |
|
54 void SetMetaDataOnRead(TServerSetting& aSetting, TBool aSingleMetaFound); |
|
55 |
|
56 void SetMetaDataOnCreate(TServerSetting& aNewSetting, TUint32* aMeta); |
|
57 |
|
58 TInt DeleteAndPersist(TUint32 aId); |
|
59 TInt DeleteNoPersist(TUint32 aId); |
|
60 |
|
61 TInt ResetNoPersistL(TServerSetting& aSetting); |
|
62 void ResetAndPersistL(TServerSetting& aSetting); |
|
63 TInt ResetAllNoPersistL(CSharedRepository& aRepository); |
|
64 |
|
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(); |
|
69 |
|
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(); |
|
74 |
|
75 TSettingsAccessPolicy* GetFallbackAccessPolicy(TUint32 aId |
|
76 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS |
|
77 ,TBool aSkipSingle=EFalse |
|
78 #endif |
|
79 ); |
|
80 |
|
81 TInt StartTransaction(CRepositoryTransactor& aTransactor, TInt aMode); |
|
82 TInt CommitTransaction(CRepositoryTransactor& aTransactor, TUint32& aKeyInfo); |
|
83 void CancelTransaction(CRepositoryTransactor& aTransactor); |
|
84 TInt FailTransaction(CRepositoryTransactor& aTransactor, TInt aError, TUint32 aErrorKey); |
|
85 void FailAllTransactions(const CRepositoryTransactor* aExcludeTransactor); |
|
86 TInt AttemptPromoteTransactionToReadWrite(CRepositoryTransactor& aTransactor); |
|
87 TBool IsTransactionActive(); |
|
88 |
|
89 void MergeL(CSharedRepository& aInstallRep, TMergeType aMergeType); |
|
90 #ifndef SYMBIAN_CENTREP_SUPPORT_MULTIROFS |
|
91 TInt FindLocationForFileL(TCentRepLocation& aLocation,TUid aUid,const TCentRepFileType aType) const; |
|
92 #endif |
|
93 |
|
94 void HandleUpdateMergeL(TTime aInstallFileTimeStamp, CSharedRepository& aInstallRep); |
|
95 void HandleDeleteMergeL(CSharedRepository& aRomRep); |
|
96 void SetInstallTime(TTime aInstallTime); |
|
97 |
|
98 inline TUid Owner() {return iSimRep->Owner(); } |
|
99 inline void WriteBackupStream(RWriteStream& aStream) const; |
|
100 inline void WriteDeletedSettingsStream(RWriteStream& aStream) const; |
|
101 inline void InternalizeL(RReadStream& aStream, CRestoredRepository& aRstRepos) ; |
|
102 void ExternalizeCre(RWriteStream& aStream) const; |
|
103 void InternalizeCreL(RReadStream& aStream) ; |
|
104 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS |
|
105 void InternalizeCreL(RReadStream& aStream,TUint8& aCreVersion); |
|
106 #endif |
|
107 TInt ReloadContentL(CIniFileIn& aIniFile, TBool aFirstLoad = EFalse); |
|
108 #ifdef CENTREP_CONV_TOOL |
|
109 void DoCommitChangesToIniFileL(const TDesC& aOutFileName |
|
110 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS |
|
111 ,TUint32 aCreVersion |
|
112 #endif |
|
113 ); |
|
114 #endif |
|
115 inline void SetSize(TInt aSize); |
|
116 inline TInt Size() const; |
|
117 |
|
118 private: |
|
119 |
|
120 void ResetContent(); |
|
121 void RestoreConsistencyL(); |
|
122 void DoRestoreConsistencyL(); |
|
123 TInt CreateRepositoryFromCreFileL(TCentRepLocation aLocation); |
|
124 TInt ReadSettingSavePolicyL(CIniFileIn& aFile,TServerSetting& aSetting, TSettingsAccessPolicy* &aPolicy, TBool& aSingleMetaFound); |
|
125 void ReleaseTransactionLock(CRepositoryTransactor& aTransactor); |
|
126 TInt DoCommitTransactionSettings(CRepositoryTransactor& aTransactor, TUint32& aKeyInfo); |
|
127 void Notify(TUint32 aVal) const; |
|
128 |
|
129 RSettingsArray& GetSettings(); |
|
130 CSharedRepository(); |
|
131 void ConstructL(TUid aUid); |
|
132 |
|
133 #ifdef FOTA_UNIT_TESTING |
|
134 public: |
|
135 void SetUid(TUid aUid) |
|
136 { |
|
137 iSimRep->SetUid(aUid); |
|
138 } |
|
139 #endif |
|
140 CHeapRepository* iSimRep; |
|
141 |
|
142 TInt32 iSize; //approximate size(in memory) of the repository after internalisation |
|
143 TBool iNotificationState;//Notification can be made if iNotificationState is non-zero, |
|
144 //otherwise the notification is disabled |
|
145 |
|
146 //iInconsistentData data flag will be set at the beginning of CommitChangesL() |
|
147 //and reset at the end of it. The flag is used to implement lazy-load approach for the |
|
148 //repository - if CommitChangesL() fails, the in-memory representation of the repository |
|
149 //won't match the updated by CommitChangesL() repository (ini) file. The repository |
|
150 //consistency has to be restored before any next call of CSharedRepository methods. |
|
151 TBool iInconsistentData; |
|
152 }; |
|
153 |
|
154 /** |
|
155 @internalTechnology |
|
156 Base class for CServerRepository and other objects that may be in transactions with the |
|
157 shared repository. Contains a double queue link so the shared repository can build a queue |
|
158 of them. In order to use transactions in the shared repository, the object needs to supply a |
|
159 CRepositoryTransactor - either itself or a member variable. This makes it possible to |
|
160 prevent one transactor from closing another's transaction. |
|
161 Stores transaction state and changes made during the transaction. |
|
162 Also stores RMessage2 while pending async start or commit, and handles its completion. |
|
163 */ |
|
164 class CRepositoryTransactor : public CBase |
|
165 { |
|
166 // shared repository may set private transaction state, but not derived classes |
|
167 friend class CSharedRepository; |
|
168 // for the _FOFF macro to work |
|
169 friend class CObservable::TSharedRepositoryInfo; |
|
170 friend class CObservable; |
|
171 public: |
|
172 |
|
173 inline TInt TransactionState() const |
|
174 { |
|
175 return iTransactionState; |
|
176 } |
|
177 inline TInt TransactionMode() const |
|
178 { |
|
179 return iTransactionState & EAllTransactionModeBits; |
|
180 } |
|
181 inline TBool IsInTransaction() const |
|
182 { |
|
183 return iTransactionState != ENoTransaction; |
|
184 } |
|
185 inline TBool IsInActiveTransaction() const |
|
186 { |
|
187 // transaction is active if no bits apart from the (non-zero) mode are set |
|
188 return (iTransactionState != ENoTransaction) && (TransactionMode() == iTransactionState); |
|
189 } |
|
190 inline TBool IsInActiveReadTransaction() const |
|
191 { |
|
192 return iTransactionState == EReadTransaction; |
|
193 } |
|
194 inline TBool IsInActiveConcurrentReadWriteTransaction() const |
|
195 { |
|
196 return (iTransactionState == EConcurrentReadWriteTransaction); |
|
197 } |
|
198 inline TBool IsInActiveExclusiveReadWriteTransaction() const |
|
199 { |
|
200 return (iTransactionState == EReadWriteTransaction); |
|
201 } |
|
202 inline TBool IsInActiveReadWriteTransaction() const |
|
203 { |
|
204 return (iTransactionState == EReadWriteTransaction) |
|
205 || (iTransactionState == EConcurrentReadWriteTransaction); |
|
206 } |
|
207 inline TBool IsInFailedTransaction() const |
|
208 { |
|
209 return (iTransactionState & EFailedBit) != 0; |
|
210 } |
|
211 |
|
212 protected: |
|
213 inline void ClearSettings() |
|
214 { |
|
215 iTransactionSettings.Reset(); |
|
216 } |
|
217 |
|
218 private: |
|
219 inline void SetFailed(TInt aError, TUint32 aErrorKey) |
|
220 { |
|
221 // don't want to fail more than once |
|
222 ASSERT(IsInActiveTransaction()); |
|
223 ASSERT(aError != KErrNone); // must fail for a reason |
|
224 iTransactionState |= EFailedBit; |
|
225 ClearSettings(); |
|
226 iTransactionResult = aError; |
|
227 iTransactionErrorKey = aErrorKey; |
|
228 } |
|
229 inline void PromoteToExclusiveReadWrite() |
|
230 { |
|
231 ASSERT(iTransactionState == EReadTransaction); |
|
232 iTransactionState = EReadWriteTransaction; |
|
233 ClearSettings(); |
|
234 } |
|
235 inline void AddToQueue(TSglQue<CRepositoryTransactor>& aTransactors, TInt aMode) |
|
236 { |
|
237 ASSERT(!IsInTransaction()); |
|
238 // if the following ASSERT fails, transactor is already in a queue |
|
239 ASSERT(iLink.iNext == NULL); |
|
240 aTransactors.AddLast(*this); |
|
241 iTransactionState = aMode; |
|
242 // check adding to queue in an active state |
|
243 ASSERT(IsInActiveTransaction()); |
|
244 ClearSettings(); |
|
245 // clear failure reasons |
|
246 iTransactionResult = KErrNone; |
|
247 iTransactionErrorKey = KUnspecifiedKey; |
|
248 } |
|
249 inline void Deque() |
|
250 { |
|
251 iTransactionState = ENoTransaction; |
|
252 ClearSettings(); |
|
253 delete iIniRep; |
|
254 iIniRep = NULL; |
|
255 } |
|
256 |
|
257 protected: |
|
258 // derived classes are free to change transaction settings. |
|
259 // these can be made persistent by committing write transaction |
|
260 RSettingsArray iTransactionSettings; |
|
261 |
|
262 // 'Create' needs to check the default (INI) file to see if the |
|
263 // key position has a setting defined. If that is the case, |
|
264 // the new setting uses meta defined for the original setting |
|
265 // in the INI file. |
|
266 // Store data read from INI here so that we only read the INI |
|
267 // once per transaction. |
|
268 CSharedRepository* iIniRep; |
|
269 |
|
270 private: |
|
271 // A queue link used by the CSharedRepository the CTransactor is working on |
|
272 TSglQueLink iLink; |
|
273 // integer encoding transaction state using definition of TTransactionState |
|
274 TInt iTransactionState; |
|
275 // result to be returned by commit if transaction failed earlier |
|
276 TInt iTransactionResult; |
|
277 // if transaction failed earlier, key or partial key involved in the original error, |
|
278 // or KUnspecifiedKey if could not be attributed to just one. |
|
279 TUint32 iTransactionErrorKey; |
|
280 }; |
|
281 |
|
282 #include "shrepos.inl" |
|
283 |
|
284 #endif // SHREPOS_H |