|
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 #include "srvres.h" |
|
17 #include "cachemgr.h" |
|
18 #include "obsrvr_noc.h" |
|
19 #include <bautils.h> // BaflUtils::GetSystemDrive |
|
20 #ifdef SYMBIAN_BAFL_SYSUTIL |
|
21 #include <bafl/sysutil.h> |
|
22 #endif |
|
23 RFs TServerResources::iFs; |
|
24 |
|
25 HBufC* TServerResources::iRomDirectory; |
|
26 HBufC* TServerResources::iDataDirectory; |
|
27 HBufC* TServerResources::iInstallDirectory; |
|
28 HBufC* TServerResources::iBURDirectory; |
|
29 |
|
30 |
|
31 HBufC* TServerResources::iIniExt; |
|
32 HBufC* TServerResources::iCreExt; |
|
33 HBufC* TServerResources::iTrnsExt; |
|
34 |
|
35 TUint8 TServerResources::iPersistsVersion; |
|
36 |
|
37 RArray<TOwnerIdMapping> TServerResources::iOwnerIdLookUpTable; |
|
38 |
|
39 CRepositoryCacheManager* TServerResources::iCacheManager; |
|
40 CObservable* TServerResources::iObserver; |
|
41 |
|
42 |
|
43 #ifdef __CENTREP_SERVER_PERFTEST__ |
|
44 TCentRepPerfTest TServerResources::iPerfTestMgr; |
|
45 #endif |
|
46 #ifdef __CENTREP_SERVER_MEMTEST__ |
|
47 TInt32 TServerResources::iMemTestData[KMemBufMaxEntry]; |
|
48 TInt32 TServerResources::iMemTestDataCount = 0; |
|
49 #endif //__CENTREP_SERVER_MEMTEST__ |
|
50 |
|
51 TTime TServerResources::CentrepFileTimeStampL(TUid aUid, TCentRepLocation aLocation) |
|
52 { |
|
53 TEntry entry; |
|
54 HBufC* fileName(NULL); |
|
55 TServerResources::CreateRepositoryFileNameLC(fileName,aUid,aLocation,ECre); |
|
56 TInt err=TServerResources::iFs.Entry(fileName->Des(), entry); |
|
57 CleanupStack::PopAndDestroy(fileName); |
|
58 |
|
59 if(err==KErrNone) |
|
60 { |
|
61 return entry.iModified; |
|
62 } |
|
63 |
|
64 TServerResources::CreateRepositoryFileNameLC(fileName,aUid,aLocation,EIni); |
|
65 User::LeaveIfError(TServerResources::iFs.Entry(fileName->Des(), entry)); |
|
66 CleanupStack::PopAndDestroy(fileName); |
|
67 |
|
68 return entry.iModified; |
|
69 } |
|
70 |
|
71 TBool TServerResources::CentrepFileExistsL(TUid aUid, TCentRepLocation aLocation, TCentRepFileType aType) |
|
72 { |
|
73 HBufC* fileName(NULL); |
|
74 TServerResources::CreateRepositoryFileNameLC(fileName,aUid,aLocation,aType); |
|
75 TEntry entry; |
|
76 TInt err=TServerResources::iFs.Entry(fileName->Des(), entry); |
|
77 CleanupStack::PopAndDestroy(fileName); |
|
78 |
|
79 TBool r=EFalse; |
|
80 |
|
81 if(err==KErrNone) |
|
82 { |
|
83 r=ETrue; |
|
84 } |
|
85 else if(err==KErrNotFound) |
|
86 { |
|
87 r=EFalse; |
|
88 } |
|
89 // Looking for a file on a composite file system may return KErrPathNotFound when |
|
90 // the ROM file doesn't exist, so check for this return code as well. |
|
91 else if((aLocation==ERom) && (err== KErrPathNotFound)) |
|
92 { |
|
93 r=EFalse; |
|
94 } |
|
95 else |
|
96 { |
|
97 User::Leave(err); |
|
98 } |
|
99 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS |
|
100 //only for ROM we still have to consider for multiple ROFS presence |
|
101 if (aLocation==ERom && r==EFalse) |
|
102 { |
|
103 //if not still have to check for multi rofs, it might be the case that first file is already mangled |
|
104 TMultiRofsList find(aUid); |
|
105 TLinearOrder<TMultiRofsList> sort_order(CObservable::CompareUid); |
|
106 |
|
107 TInt index=iObserver->GetMultiRofsList().FindInOrder(find,sort_order); |
|
108 if (index!=KErrNotFound) |
|
109 r=ETrue; |
|
110 } |
|
111 #endif |
|
112 return r; |
|
113 } |
|
114 |
|
115 TBool TServerResources::CentrepFileExistsL(TUid aUid, TCentRepLocation aLocation) |
|
116 { |
|
117 return( CentrepFileExistsL( aUid, aLocation, EIni) || CentrepFileExistsL( aUid, aLocation, ECre)); |
|
118 } |
|
119 |
|
120 TBool TServerResources::InstallFileExistsL(TUid aUid) |
|
121 { |
|
122 return CentrepFileExistsL(aUid, EInstall); |
|
123 } |
|
124 |
|
125 TBool TServerResources::RomFileExistsL(TUid aUid) |
|
126 { |
|
127 return CentrepFileExistsL(aUid, ERom); |
|
128 } |
|
129 |
|
130 TBool TServerResources::PersistsFileExistsL(TUid aUid) |
|
131 { |
|
132 return CentrepFileExistsL(aUid, EPersists); |
|
133 } |
|
134 |
|
135 #ifdef SYMBIAN_BAFL_SYSUTIL |
|
136 TInt TServerResources::GetTextFromFile( const TDesC& aFilename, TDes8& aValue) |
|
137 { |
|
138 |
|
139 TInt err = KErrNone; |
|
140 RFile file; |
|
141 err = file.Open( iFs, aFilename, |
|
142 EFileRead | EFileStreamText | EFileShareReadersOnly ); |
|
143 if (err != KErrNone) |
|
144 { |
|
145 return err; |
|
146 } |
|
147 |
|
148 err = file.Read(aValue); |
|
149 |
|
150 file.Close(); |
|
151 |
|
152 return err; |
|
153 } |
|
154 #endif |
|
155 void TServerResources::DeleteCentrepFileL(TUid aUid, TCentRepLocation aLocation, TCentRepFileType aType) |
|
156 { |
|
157 HBufC* fileName(NULL); |
|
158 TServerResources::CreateRepositoryFileNameLC(fileName,aUid,aLocation,aType); |
|
159 if(CentrepFileExistsL( aUid, aLocation, aType)) |
|
160 { |
|
161 User::LeaveIfError(TServerResources::iFs.Delete(fileName->Des())); |
|
162 } |
|
163 CleanupStack::PopAndDestroy(fileName); |
|
164 } |
|
165 |
|
166 void TServerResources::CreateRepositoryFileNameLC(HBufC*& aFullFileName, |
|
167 TUid aUid, |
|
168 TCentRepLocation aLocation, |
|
169 TCentRepFileType aFileType) |
|
170 { |
|
171 TServerResources::CreateRepositoryFileNameL(aFullFileName,aUid,aLocation,aFileType); |
|
172 CleanupStack::PushL(aFullFileName); |
|
173 } |
|
174 /** |
|
175 Generic routine for creating a full repository file name. |
|
176 aFullFileName is created on the heap and it is caller responsibility |
|
177 to delete it. |
|
178 */ |
|
179 void TServerResources::CreateRepositoryFileNameL(HBufC*& aFullFileName, |
|
180 TUid aUid, |
|
181 TCentRepLocation aLocation, |
|
182 TCentRepFileType aFileType) |
|
183 { |
|
184 const TInt KExtLen = 4; |
|
185 const TInt KDirLen = 40; |
|
186 const TInt KUidLen = 8; |
|
187 |
|
188 TBuf<KDirLen> directory; |
|
189 TBuf<KExtLen> ext; |
|
190 |
|
191 //path |
|
192 switch (aLocation) |
|
193 { |
|
194 case EPersists: |
|
195 { |
|
196 directory.Copy(iDataDirectory->Des()); |
|
197 } |
|
198 break; |
|
199 case EInstall: |
|
200 { |
|
201 directory.Copy(iInstallDirectory->Des()); |
|
202 } |
|
203 break; |
|
204 case ERom: |
|
205 { |
|
206 if (iRomDirectory) |
|
207 { |
|
208 directory.Copy(iRomDirectory->Des()); |
|
209 } |
|
210 else |
|
211 { |
|
212 User::Leave(KErrNotFound); //CentRep ROM directory is empty or doesn't exist at all |
|
213 } |
|
214 } |
|
215 break; |
|
216 default: |
|
217 User::Leave(KErrNotFound); //should never get here |
|
218 } |
|
219 |
|
220 //file name |
|
221 TBuf<KUidLen> name; |
|
222 name.NumFixedWidth(aUid.iUid, EHex, KUidLen); |
|
223 |
|
224 //extension |
|
225 switch (aFileType) |
|
226 { |
|
227 case ECre: |
|
228 { |
|
229 ext.Copy(iCreExt->Des()); |
|
230 } |
|
231 break; |
|
232 case EIni: |
|
233 { |
|
234 ext.Copy(iIniExt->Des()); |
|
235 } |
|
236 break; |
|
237 case ETmp: |
|
238 { |
|
239 ext.Copy(iTrnsExt->Des()); |
|
240 } |
|
241 break; |
|
242 default: |
|
243 User::Leave(KErrNotFound); //should never get here |
|
244 } |
|
245 |
|
246 TBuf<KMaxFileName> fullFileName; |
|
247 fullFileName.Append(directory); |
|
248 fullFileName.Append(name); |
|
249 fullFileName.Append(ext); |
|
250 //allocates memory on the heap. It is caller's resposibility to delete aFullFileName |
|
251 aFullFileName = fullFileName.AllocL(); |
|
252 } |
|
253 |
|
254 void TServerResources::InitialiseL() |
|
255 { |
|
256 #ifndef SYMBIAN_CENTREP_SUPPORT_MULTIROFS |
|
257 iPersistsVersion = KPersistFormatVersion; // Version 0 of persists |
|
258 #else |
|
259 iPersistsVersion = KPersistFormatSupportsIndMetaIndicator; |
|
260 #endif |
|
261 User::LeaveIfError(iFs.Connect()); |
|
262 |
|
263 // get system drive |
|
264 _LIT(KDriveMask, "_:"); |
|
265 TDriveName systemDrive(KDriveMask); |
|
266 systemDrive[0] = 'A' + static_cast<TInt>(RFs::GetSystemDrive()); |
|
267 |
|
268 _LIT(KRomDrive, "z:"); // This may not always be z: |
|
269 _LIT(KPersistsDir, "persists\\"); |
|
270 _LIT(KBURDir, "bur\\"); |
|
271 |
|
272 |
|
273 // File extensions |
|
274 |
|
275 _LIT(KIniFileExtension, ".txt"); |
|
276 _LIT(KExternalizedPersistsFileExt, ".cre"); |
|
277 _LIT(KTransactFileExt, ".tmp"); |
|
278 |
|
279 const TInt KMaxExtLength=4; |
|
280 |
|
281 iIniExt=HBufC::NewL(KMaxExtLength); |
|
282 iCreExt=HBufC::NewL(KMaxExtLength); |
|
283 iTrnsExt=HBufC::NewL(KMaxExtLength); |
|
284 |
|
285 iIniExt->Des().Copy(KIniFileExtension); |
|
286 iCreExt->Des().Copy(KExternalizedPersistsFileExt); |
|
287 iTrnsExt->Des().Copy(KTransactFileExt); |
|
288 |
|
289 TBuf<KMaxFileName> path; |
|
290 User::LeaveIfError(iFs.PrivatePath(path)); |
|
291 |
|
292 const TInt pathLen = path.Length(); |
|
293 |
|
294 // |
|
295 // ROM-drive cenrep directory |
|
296 // |
|
297 iRomDirectory = HBufC::NewL(KRomDrive().Length()+pathLen); |
|
298 TPtr ptr(iRomDirectory->Des()); |
|
299 ptr.Append(KRomDrive); |
|
300 ptr.Append(path); |
|
301 // If the ROM directory does not exist (very unlikely) we set iRomDirectory to zero. |
|
302 TEntry fsEntry; |
|
303 if(iFs.Entry(*iRomDirectory, fsEntry)!=KErrNone || !fsEntry.IsDir()) |
|
304 { |
|
305 delete iRomDirectory; |
|
306 iRomDirectory = NULL; |
|
307 } |
|
308 |
|
309 // |
|
310 // Cenrep install directory |
|
311 // |
|
312 iInstallDirectory = HBufC::NewL(systemDrive.Length()+pathLen); |
|
313 ptr.Set(iInstallDirectory->Des()); |
|
314 ptr.Append(systemDrive); |
|
315 ptr.Append(path); |
|
316 TInt r = iFs.MkDirAll(*iInstallDirectory); |
|
317 if(r!=KErrNone && r!=KErrAlreadyExists) |
|
318 { |
|
319 User::Leave(r); |
|
320 } |
|
321 // |
|
322 // Writeable-drive data directory |
|
323 // |
|
324 |
|
325 iDataDirectory = HBufC::NewL(systemDrive.Length()+pathLen+KPersistsDir().Length()); |
|
326 ptr.Set(iDataDirectory->Des()); |
|
327 ptr.Append(systemDrive); |
|
328 ptr.Append(path); |
|
329 ptr.Append(KPersistsDir); |
|
330 |
|
331 r = iFs.MkDirAll(*iDataDirectory); |
|
332 if(r!=KErrNone && r!=KErrAlreadyExists) |
|
333 User::Leave(r); |
|
334 |
|
335 // |
|
336 // Writeable-drive backup/restore directory |
|
337 // |
|
338 iBURDirectory = HBufC::NewL(systemDrive.Length()+pathLen+KBURDir().Length()); |
|
339 ptr.Set(iBURDirectory->Des()); |
|
340 ptr.Append(systemDrive); |
|
341 ptr.Append(path); |
|
342 ptr.Append(KBURDir); |
|
343 |
|
344 r = iFs.MkDirAll(*iBURDirectory); |
|
345 if(r!=KErrNone && r!=KErrAlreadyExists) |
|
346 User::Leave(r); |
|
347 |
|
348 #ifdef SYMBIAN_BAFL_SYSUTIL |
|
349 // |
|
350 // romversion directory |
|
351 // |
|
352 _LIT(KRomCache,"romversion\\"); |
|
353 HBufC* romVersionDir = HBufC::NewLC(systemDrive.Length()+pathLen+KRomCache().Length()); |
|
354 |
|
355 ptr.Set(romVersionDir->Des()); |
|
356 ptr.Append(systemDrive); |
|
357 ptr.Append(path); |
|
358 ptr.Append(KRomCache); |
|
359 |
|
360 r = iFs.MkDirAll(*romVersionDir); |
|
361 if(r!=KErrNone && r!=KErrAlreadyExists) |
|
362 User::Leave(r); |
|
363 CleanupStack::PopAndDestroy();//romVersionDir |
|
364 #endif |
|
365 // |
|
366 // Cache Manager |
|
367 // |
|
368 iCacheManager = CRepositoryCacheManager::NewLC(iFs); |
|
369 CleanupStack::Pop(); |
|
370 |
|
371 // Observer |
|
372 iObserver = CObservable::NewLC(); |
|
373 CleanupStack::Pop(); |
|
374 |
|
375 iOwnerIdLookUpTable.Reset(); |
|
376 |
|
377 } |
|
378 |
|
379 void TServerResources::Close() |
|
380 { |
|
381 delete iObserver; |
|
382 delete iCacheManager; |
|
383 delete iInstallDirectory; |
|
384 delete iDataDirectory; |
|
385 delete iRomDirectory; |
|
386 delete iBURDirectory; |
|
387 delete iIniExt; |
|
388 delete iCreExt; |
|
389 delete iTrnsExt; |
|
390 iFs.Close(); |
|
391 |
|
392 iCacheManager=NULL; |
|
393 iInstallDirectory=NULL; |
|
394 iDataDirectory=NULL; |
|
395 iRomDirectory=NULL; |
|
396 iBURDirectory=NULL; |
|
397 iIniExt=NULL; |
|
398 iCreExt=NULL; |
|
399 iTrnsExt=NULL; |
|
400 |
|
401 iOwnerIdLookUpTable.Close() ; |
|
402 } |
|
403 |
|
404 TInt TServerResources::GetUid(TEntry& aEntry, TUid& aUid) |
|
405 { |
|
406 const TInt KUidLen = 8; |
|
407 TPtrC uidPtr = aEntry.iName.Des().LeftTPtr(KUidLen); |
|
408 TLex lex=uidPtr; |
|
409 TUint32 uidValue; |
|
410 |
|
411 if (lex.Val(uidValue, EHex) == KErrNone) |
|
412 { |
|
413 aUid = TUid::Uid(uidValue); |
|
414 } |
|
415 else |
|
416 { |
|
417 return KErrNotFound; |
|
418 } |
|
419 |
|
420 return KErrNone; |
|
421 } |
|
422 |
|
423 TInt TOwnerIdMapping::CompareUids (const TOwnerIdMapping& aOwnerIdMapping1, const TOwnerIdMapping& aOwnerIdMapping2) |
|
424 { |
|
425 if (aOwnerIdMapping1.iRepUid < aOwnerIdMapping2.iRepUid) |
|
426 return -1 ; |
|
427 else if (aOwnerIdMapping1.iRepUid > aOwnerIdMapping2.iRepUid) |
|
428 return 1 ; |
|
429 else |
|
430 return 0 ; |
|
431 } |
|
432 |
|
433 |
|
434 #ifdef __CENTREP_SERVER_MEMTEST__ |
|
435 |
|
436 void TServerResources::StopRecordTimerResult() |
|
437 { |
|
438 iMemTestDataCount = KMemBufMaxEntry; |
|
439 } |
|
440 |
|
441 //aLocation: location where the memory reading is done (a method specifier) |
|
442 //aIdentifier: identifier of the memory reading (e.g. repository id, 10th reading etc) |
|
443 void TServerResources::RecordTimerResult(TMemTestLocationIdentifier aLocation, TInt32 aIdentifier) |
|
444 { |
|
445 if(iMemTestDataCount+6 > KMemBufMaxEntry) |
|
446 { |
|
447 if(iMemTestDataCount+3 <= KMemBufMaxEntry) |
|
448 { |
|
449 iMemTestData[iMemTestDataCount++] = static_cast<TInt32>(KMagicMemTestOutOfBounds); |
|
450 iMemTestData[iMemTestDataCount++] = static_cast<TInt32>(KMagicMemTestOutOfBounds); |
|
451 iMemTestData[iMemTestDataCount++] = static_cast<TInt32>(KMagicMemTestOutOfBounds); |
|
452 } |
|
453 } |
|
454 else |
|
455 { |
|
456 RHeap& heap = User::Heap(); |
|
457 TInt biggestBlock; |
|
458 |
|
459 iMemTestData[iMemTestDataCount++] = aLocation; |
|
460 iMemTestData[iMemTestDataCount++] = aIdentifier; |
|
461 iMemTestData[iMemTestDataCount++] = static_cast<TInt32>(heap.Size() - heap.Available(biggestBlock)); |
|
462 } |
|
463 } |
|
464 |
|
465 void TServerResources::StartRecordTimerResult() |
|
466 { |
|
467 iMemTestDataCount = 0; |
|
468 } |
|
469 |
|
470 #endif //__CENTREP_SERVER_MEMTEST__ |