|
1 // Copyright (c) 2008-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 "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 // Hardware Configuration Respoitory Platform Independent Layer (PIL) |
|
15 // |
|
16 |
|
17 |
|
18 // -- INCLUDES ---------------------------------------------------------------- |
|
19 |
|
20 |
|
21 #include "hcr_debug.h" |
|
22 |
|
23 #include <e32def.h> |
|
24 #include <e32err.h> |
|
25 #include <e32des8.h> |
|
26 #include <e32cmn.h> |
|
27 |
|
28 #include <nkern/nkern.h> |
|
29 #include <kernel/kernel.h> |
|
30 |
|
31 #include <e32rom.h> |
|
32 #include <plat_priv.h> |
|
33 |
|
34 #include <kernel/kernboot.h> |
|
35 |
|
36 |
|
37 #include "hcr_hai.h" |
|
38 #include "hcr_pil.h" |
|
39 |
|
40 // -- GLOBALS ----------------------------------------------------------------- |
|
41 |
|
42 GLDEF_C HCR::HCRInternal gHCR; |
|
43 |
|
44 #ifdef HCR_TRACE |
|
45 GLDEF_C TBuf<81> gTraceBuffer; |
|
46 #endif |
|
47 |
|
48 |
|
49 // -- Local functions prototypes |
|
50 /** |
|
51 Retrive Repository file address stored in the iHcrFileAddress field of ROM Image header. |
|
52 If this filed is zero or it is equal with a special value then it keeps the original vaule of |
|
53 aRepos parameter and signals it with the retun value. |
|
54 |
|
55 |
|
56 @param aRepos The reference to a repository variable |
|
57 @return KErrNone if successful, the aRepos parameter references to the file in ROM Image. |
|
58 KErrNotFound if the ROM Image header contains zero or a special value as the repository file address |
|
59 |
|
60 |
|
61 */ |
|
62 LOCAL_C TInt LocateCoreImgRepository(HCR::TRepository*& aRepos); |
|
63 |
|
64 /** |
|
65 This method transfer the value of aFileName to ROM Image conform file name string. |
|
66 Retrive the variant dependent ROM Root directory address. |
|
67 Search the file in \sys\bin directory and if it doesn't exists there it try to find it in \sys\Data. |
|
68 |
|
69 |
|
70 @param aRepos The reference to a repository variable. |
|
71 aFileName The name of the new repository file without path. '\0' terminated c-style string. |
|
72 |
|
73 @return KErrNone if successful |
|
74 KErrNotFound if file not found in \sys\bin or \sys\Data |
|
75 |
|
76 |
|
77 */ |
|
78 LOCAL_C TInt SearchCoreImgRepository(HCR::TRepository* & aRepos, const TText * aFileName); |
|
79 |
|
80 /** |
|
81 Scanning a given directory for the given entry name. The entry name can be sub-directory or file. |
|
82 |
|
83 @param aActDir Pointer to curretn directory in the ROM Image directory tree |
|
84 aFileName File to be search |
|
85 aEntry If the file found this referenced to proper directory entry |
|
86 |
|
87 @return KErrNone if the entry found |
|
88 KErrNotFound if the entry not found |
|
89 */ |
|
90 |
|
91 LOCAL_C TInt SearchEntryInTRomDir(const TRomDir* aActDir, const TPtrC aFileName, TRomEntry* &aEntry); |
|
92 |
|
93 |
|
94 // -- WINS Specific ---------------------------------------------------------- |
|
95 |
|
96 #ifdef __WINS__ |
|
97 |
|
98 // Set to ensure Rom Hdr dependency does not break compilation in |
|
99 // LocateCoreImgRepository() at the end of this file. |
|
100 // Undef incase it is set in MMP file, avoids compiler warning. |
|
101 // |
|
102 #undef HCRTEST_COREIMG_DONTUSE_ROMHDR |
|
103 #define HCRTEST_COREIMG_DONTUSE_ROMHDR |
|
104 |
|
105 #endif |
|
106 |
|
107 // -- FUNCTIONS --------------------------------------------------------------- |
|
108 |
|
109 /** |
|
110 Returns 1 when a1 > a2 |
|
111 Returns -1 when a1 < a2 |
|
112 Returns 0 when identical. |
|
113 */ |
|
114 TInt CompareSSettingIds(const HCR::TSettingId& a1, const HCR::SSettingId& a2) |
|
115 { |
|
116 // HCR_FUNC("CompareSSettingIds"); |
|
117 if (a1.iCat > a2.iCat) |
|
118 return (1); // HCR_TRACE_RETURN(1); |
|
119 if (a1.iCat < a2.iCat) |
|
120 return (-1); // HCR_TRACE_RETURN(-1); |
|
121 |
|
122 // Categories are the same at this point, check keys. |
|
123 if (a1.iKey > a2.iKey) |
|
124 return (1); // HCR_TRACE_RETURN(1); |
|
125 if (a1.iKey < a2.iKey) |
|
126 return (-1); // HCR_TRACE_RETURN(-1); |
|
127 |
|
128 // Both Categories and jeys are the same here. |
|
129 return (0); // HCR_TRACE_RETURN(0); |
|
130 } |
|
131 |
|
132 #ifdef __EPOC32__ |
|
133 TBool ROMAddressIsInUnpagedSection(const TLinAddr address) |
|
134 { |
|
135 HCR_FUNC("ROMAddressIsInUnpagedSection"); |
|
136 |
|
137 const TRomHeader& romHdr = Epoc::RomHeader(); |
|
138 TLinAddr romBase = romHdr.iRomBase; |
|
139 |
|
140 HCR_TRACE1("--- address to check if in unpaged ROM section = 0x%8x", address); |
|
141 HCR_TRACE2("--- iRomSize (0x%8x), iPageableRomStart (0x%8x), ", romHdr.iRomSize, romHdr.iPageableRomStart); |
|
142 |
|
143 if ((address < romBase) || (romBase > romBase+romHdr.iRomSize)) |
|
144 return EFalse; |
|
145 if (romHdr.iPageableRomStart == 0) |
|
146 return ETrue; |
|
147 if (address < romBase+romHdr.iPageableRomStart) |
|
148 return ETrue; |
|
149 return EFalse; |
|
150 } |
|
151 #endif |
|
152 |
|
153 |
|
154 TInt CompareByCategory(const HCR::TCategoryUid aCatId, const HCR::SSettingId& aSetId) |
|
155 { |
|
156 //HCR_FUNC("CompareByCategory"); |
|
157 if (aCatId > aSetId.iCat) |
|
158 return (1); // HCR_TRACE_RETURN(1); |
|
159 if (aCatId < aSetId.iCat) |
|
160 return (-1); // HCR_TRACE_RETURN(-1); |
|
161 |
|
162 // Both Categories and jeys are the same here. |
|
163 return (0); |
|
164 } |
|
165 |
|
166 /* |
|
167 * SafeArray TSa class object destructor. It delets the allocated in the heap |
|
168 * memory and set the instance pointer to NULL. See also TSa class definition |
|
169 * in hcr_pil.h. |
|
170 */ |
|
171 template<typename T> |
|
172 HCR::TSa<T>::~TSa() |
|
173 { |
|
174 delete[] iSa; |
|
175 iSa = NULL; |
|
176 } |
|
177 |
|
178 /** |
|
179 * operator=() changes the memory ownership by |
|
180 * reinitiazing SafeArray class object with the address to |
|
181 * already allocated array. |
|
182 */ |
|
183 template<typename T> |
|
184 HCR::TSa<T>& HCR::TSa<T>::operator=(T* aP) |
|
185 { |
|
186 delete[] iSa; |
|
187 iSa = aP; |
|
188 return (*this); |
|
189 } |
|
190 |
|
191 |
|
192 // -- METHODS ----------------------------------------------------------------- |
|
193 // |
|
194 // HCRInternal |
|
195 |
|
196 HCR::HCRInternal::HCRInternal() |
|
197 : iStatus(EStatConstructed), iVariant(0), iVariantStore(0), iCoreImgStore(0), iOverrideStore(0) |
|
198 { |
|
199 HCR_FUNC("HCRInternal(Defualt)"); |
|
200 } |
|
201 |
|
202 HCR::HCRInternal::HCRInternal(HCR::MVariant* aVar) |
|
203 : iVariant(aVar), iVariantStore(0), iCoreImgStore(0), iOverrideStore(0) |
|
204 { |
|
205 HCR_FUNC("HCRInternal"); |
|
206 } |
|
207 |
|
208 HCR::HCRInternal::~HCRInternal() |
|
209 { |
|
210 HCR_FUNC("~HCRInternal"); |
|
211 } |
|
212 |
|
213 TUint32 HCR::HCRInternal::GetStatus() |
|
214 { |
|
215 HCR_FUNC("GetStatus"); |
|
216 return iStatus; |
|
217 } |
|
218 |
|
219 |
|
220 TInt HCR::HCRInternal::Initialise() |
|
221 { |
|
222 HCR_FUNC("HCRInternal::Initialise"); |
|
223 |
|
224 TAny* store = 0; |
|
225 TInt err = 0; |
|
226 |
|
227 // Variant PSL object must exist before PIL initalised. |
|
228 if (iVariant == 0) { |
|
229 err = KErrGeneral; goto failed; } |
|
230 |
|
231 // Inform the PSL that we are initialising, give them an opportunity to do |
|
232 // initialisation work too. |
|
233 err = iVariant->Initialise(); |
|
234 if (err != KErrNone) |
|
235 goto failed; |
|
236 |
|
237 iStatus = EStatVariantInitialised; |
|
238 |
|
239 // Ask the PSL for the address of the SRepositoryCompiled object. PSL |
|
240 // can return KErrNotSupported & NULL if compiled repository not |
|
241 // used/support by PSL. |
|
242 err = iVariant->GetCompiledRepositoryAddress(store); |
|
243 if (err == KErrNone) |
|
244 { |
|
245 if (store == 0) { // Programming error in PSL, ptr/rc mismatch |
|
246 err = KErrArgument; goto failed; } |
|
247 |
|
248 iVariantStore = TRepositoryCompiled::New(reinterpret_cast<const HCR::SRepositoryCompiled *>(store)); |
|
249 if (iVariantStore == 0) { |
|
250 err = KErrNoMemory; goto failed; } |
|
251 |
|
252 } |
|
253 else if (err != KErrNotSupported) |
|
254 goto failed; |
|
255 |
|
256 |
|
257 // Ask the PSL if it wants the PIL not to search for the Core Image |
|
258 // SRepositoryFile settings. |
|
259 iCoreImgStore = 0; |
|
260 if (!iVariant->IgnoreCoreImgRepository()) |
|
261 { |
|
262 err = LocateCoreImgRepository(iCoreImgStore); |
|
263 if (err == KErrNone) |
|
264 { |
|
265 if (iCoreImgStore == 0) { |
|
266 err = KErrNoMemory; goto failed; } |
|
267 } |
|
268 else if (err != KErrNotFound) |
|
269 goto failed; |
|
270 } |
|
271 |
|
272 |
|
273 // Ask the PSL for the address of the SRepositoryFile object. PSL |
|
274 // can return KErrNotSupported & NULL if a local media based file |
|
275 // repository is not used/support by PSL. |
|
276 store = 0; |
|
277 err = iVariant->GetOverrideRepositoryAddress(store); |
|
278 if (err == KErrNone) |
|
279 { |
|
280 if (store == 0) { // Programming error in PSL, ptr/rc mismatch |
|
281 err = KErrArgument; goto failed; } |
|
282 |
|
283 iOverrideStore = TRepositoryFile::New(reinterpret_cast<const HCR::SRepositoryFile *>(store)); |
|
284 if (iOverrideStore == 0) { |
|
285 err = KErrNoMemory; goto failed; } |
|
286 |
|
287 } |
|
288 else if (err != KErrNotSupported) |
|
289 goto failed; |
|
290 |
|
291 iStatus = EStatInitialised; |
|
292 |
|
293 // Sanity check here to ensure we have atleast one repository to use and run |
|
294 // sanity check on their contents to look for ordering issues and duplicates. |
|
295 HCR_TRACE3("=== HCR Ready: compiled:%x, coreimg:%x, override:%x", iVariantStore, iCoreImgStore, iOverrideStore); |
|
296 if ((iVariantStore == 0) && (iCoreImgStore == 0) && (iOverrideStore == 0)) { |
|
297 err = KErrArgument; goto failed; } |
|
298 |
|
299 |
|
300 #ifdef _DEBUG |
|
301 err = CheckIntegrity(); |
|
302 if (err != KErrNone) |
|
303 goto failed; |
|
304 #endif |
|
305 |
|
306 iStatus = EStatReady; |
|
307 return KErrNone; |
|
308 |
|
309 failed: |
|
310 iStatus = (iStatus & EStatMinorMask) | EStatFailed; |
|
311 HCR_TRACE_RETURN(err); |
|
312 } |
|
313 |
|
314 |
|
315 TInt HCR::HCRInternal::SwitchRepository(const TText * aFileName, const TReposId aId) |
|
316 { |
|
317 HCR_FUNC("HCRInternal::SwitchRepository"); |
|
318 |
|
319 TInt retVal = KErrNone; |
|
320 TRepository* store = NULL; |
|
321 |
|
322 if( aFileName != NULL) |
|
323 { |
|
324 retVal = SearchCoreImgRepository(store, aFileName); |
|
325 HCR_TRACE2("--- SearchCoreImgRepository()->%d (0x%08x)", retVal, retVal); |
|
326 } |
|
327 |
|
328 if( retVal == KErrNone ) |
|
329 { |
|
330 switch(aId) |
|
331 { |
|
332 case ECoreRepos: |
|
333 HCR_TRACE0("--- ECoreRepos"); |
|
334 if( iCoreImgStore ) |
|
335 { |
|
336 NKern::ThreadEnterCS(); |
|
337 delete iCoreImgStore; |
|
338 NKern::ThreadLeaveCS(); |
|
339 } |
|
340 iCoreImgStore = store; |
|
341 break; |
|
342 |
|
343 case EOverrideRepos: |
|
344 HCR_TRACE0("--- EOverrideRepos"); |
|
345 if( iOverrideStore ) |
|
346 { |
|
347 NKern::ThreadEnterCS(); |
|
348 delete iOverrideStore; |
|
349 NKern::ThreadLeaveCS(); |
|
350 } |
|
351 iOverrideStore = store; |
|
352 break; |
|
353 |
|
354 default: |
|
355 HCR_TRACE0("--- default:"); |
|
356 retVal = KErrNotSupported; |
|
357 break; |
|
358 } |
|
359 } |
|
360 |
|
361 HCR_TRACE_RETURN(retVal); |
|
362 } |
|
363 |
|
364 TInt HCR::HCRInternal::CheckIntegrity() |
|
365 { |
|
366 HCR_FUNC("HCRInternal::CheckIntegrity"); |
|
367 |
|
368 TInt err = KErrNone; |
|
369 if (iVariantStore) |
|
370 { |
|
371 err = iVariantStore->CheckIntegrity(); |
|
372 if (err != KErrNone) |
|
373 HCR_TRACEMSG_RETURN("HCR iVariantStore failed integrity check", err); |
|
374 } |
|
375 |
|
376 if (iCoreImgStore) |
|
377 { |
|
378 err = iCoreImgStore->CheckIntegrity(); |
|
379 if (err != KErrNone) |
|
380 HCR_TRACEMSG_RETURN("HCR iCoreImgStore failed integrity check", err); |
|
381 } |
|
382 |
|
383 if (iOverrideStore) |
|
384 { |
|
385 err = iOverrideStore->CheckIntegrity(); |
|
386 if (err != KErrNone) |
|
387 HCR_TRACEMSG_RETURN("HCR iOverrideStore failed integrity check", err); |
|
388 } |
|
389 |
|
390 HCR_TRACE0("=== HCR Repository integrity checks PASSED!"); |
|
391 return KErrNone; |
|
392 } |
|
393 |
|
394 |
|
395 TInt HCR::HCRInternal::FindSetting(const TSettingId& aId, TSettingType aType, |
|
396 TSettingRef& aSetting) |
|
397 { |
|
398 HCR_FUNC("HCRInternal::FindSetting"); |
|
399 TInt err = 0; |
|
400 TBool found = EFalse; |
|
401 |
|
402 HCR_TRACE3("--- Repository state: %x, %x, %x", iOverrideStore, iCoreImgStore, iVariantStore); |
|
403 |
|
404 if (iOverrideStore && |
|
405 ((err = iOverrideStore->FindSetting(aId, aSetting)) == KErrNone)) |
|
406 found = ETrue; |
|
407 if ((err != KErrNone) && (err != KErrNotFound)) |
|
408 HCR_TRACE_RETURN(err); |
|
409 |
|
410 if (!found && |
|
411 iCoreImgStore && |
|
412 ((err = iCoreImgStore->FindSetting(aId, aSetting)) == KErrNone)) |
|
413 found = ETrue; |
|
414 if ((err != KErrNone) && (err != KErrNotFound)) |
|
415 HCR_TRACE_RETURN(err); |
|
416 |
|
417 if (!found && |
|
418 iVariantStore && |
|
419 ((err = iVariantStore->FindSetting(aId, aSetting)) == KErrNone)) |
|
420 found = ETrue; |
|
421 |
|
422 if ((err != KErrNone) && (err != KErrNotFound)) |
|
423 HCR_TRACE_RETURN(err); |
|
424 |
|
425 HCR_TRACE3("--- Search results: %d, %d, %x", found, err, aSetting.iSet); |
|
426 |
|
427 if (!found || (aSetting.iSet == 0)) |
|
428 HCR_TRACE_RETURN(KErrNotFound); |
|
429 |
|
430 // Setting found at this point in the function |
|
431 // |
|
432 |
|
433 TSettingType type=static_cast<TSettingType>(aSetting.iRep->GetType(aSetting)); |
|
434 if (type & ~aType) |
|
435 HCR_TRACE_RETURN(KErrArgument); // Wrong setting type |
|
436 |
|
437 HCR_TRACE3("--- Setting found! ID: (%d,%d) Type: %d", aId.iCat, aId.iKey, type); |
|
438 |
|
439 return KErrNone; |
|
440 } |
|
441 |
|
442 |
|
443 TInt HCR::HCRInternal::FindSettingWithType(const TSettingId& aId, TSettingType& aType, |
|
444 TSettingRef& aSetting) |
|
445 { |
|
446 HCR_FUNC("HCRInternal::FindSettingWithType"); |
|
447 TInt err = 0; |
|
448 TBool found = EFalse; |
|
449 |
|
450 HCR_TRACE3("--- Repository state: %x, %x, %x", iOverrideStore, iCoreImgStore, iVariantStore); |
|
451 |
|
452 if (iOverrideStore && |
|
453 ((err = iOverrideStore->FindSetting(aId, aSetting)) == KErrNone)) |
|
454 found = ETrue; |
|
455 if ((err != KErrNone) && (err != KErrNotFound)) |
|
456 HCR_TRACE_RETURN(err); |
|
457 |
|
458 if (!found && |
|
459 iCoreImgStore && |
|
460 ((err = iCoreImgStore->FindSetting(aId, aSetting)) == KErrNone)) |
|
461 found = ETrue; |
|
462 if ((err != KErrNone) && (err != KErrNotFound)) |
|
463 HCR_TRACE_RETURN(err); |
|
464 |
|
465 if (!found && |
|
466 iVariantStore && |
|
467 ((err = iVariantStore->FindSetting(aId, aSetting)) == KErrNone)) |
|
468 found = ETrue; |
|
469 |
|
470 if ((err != KErrNone) && (err != KErrNotFound)) |
|
471 HCR_TRACE_RETURN(err); |
|
472 |
|
473 HCR_TRACE3("--- Search results: %d, %d, %x", found, err, aSetting.iSet); |
|
474 |
|
475 if (!found || (aSetting.iSet == 0)) |
|
476 { |
|
477 aType = ETypeUndefined; |
|
478 HCR_TRACE_RETURN(KErrNotFound); |
|
479 } |
|
480 |
|
481 // Setting found at this point in the function |
|
482 // |
|
483 |
|
484 aType=static_cast<TSettingType>(aSetting.iRep->GetType(aSetting)); |
|
485 |
|
486 HCR_TRACE3("--- Setting found! ID: (%d,%d) Type: %d", aId.iCat, aId.iKey, aType); |
|
487 |
|
488 return KErrNone; |
|
489 } |
|
490 |
|
491 |
|
492 TInt HCR::HCRInternal::GetWordSettings(TInt aNum, const SSettingId aIds[], |
|
493 TInt32 aValues[], TSettingType aTypes[], TInt aErrors[]) |
|
494 { |
|
495 HCR_FUNC("++ HCRInternal::GetWordSettings"); |
|
496 HCR_TRACE3("--- Repository state: %x, %x, %x", iOverrideStore, iCoreImgStore, iVariantStore); |
|
497 |
|
498 if(aNum <= 0 || aIds == NULL || aErrors == NULL) |
|
499 HCR_TRACE_RETURN(KErrArgument); |
|
500 |
|
501 TInt err = 0; |
|
502 //If the user only supplies a single setting then there is no reasons to |
|
503 //continue with multiple searach and it should be limited by internal |
|
504 //invocation of FindSettingWithType. |
|
505 if(aNum == 1) |
|
506 { |
|
507 TSettingRef sref(0,0); |
|
508 TSettingType* pTypes; |
|
509 |
|
510 //aTypes array is optional and user may not provided it for us. So we |
|
511 //need to be sure it's not a null pointer |
|
512 if(aTypes == NULL) |
|
513 { |
|
514 //If this is a null pointer then just create our own element and |
|
515 //assign it to the pTypes pointer |
|
516 TSettingType types[1]; |
|
517 pTypes = types; |
|
518 } |
|
519 else |
|
520 { |
|
521 //else we use the user supplied array |
|
522 pTypes = aTypes; |
|
523 } |
|
524 |
|
525 //Let's find this setting |
|
526 err = HCRSingleton->FindSettingWithType(aIds[0], *pTypes, sref); |
|
527 |
|
528 //and analyse the result of operation |
|
529 |
|
530 //If setting is not found or it's larger than 4 bytes then store this |
|
531 //error cause in the user error array |
|
532 if(err == KErrNotFound || err == KErrArgument) |
|
533 { |
|
534 //Indicate the error for the element and set the value to 0 |
|
535 aErrors[0] = err; |
|
536 aValues[0] = 0; |
|
537 return 0; |
|
538 } |
|
539 //fatal error here, nothing to do, just exit and return the error code |
|
540 else if(err == KErrNotReady || err != KErrNone) |
|
541 { |
|
542 HCR_TRACE_RETURN(err); |
|
543 } |
|
544 else //err == KErrNone |
|
545 { |
|
546 //Get the value of the setting |
|
547 err = sref.iRep->GetValue(sref, reinterpret_cast<UValueWord&>(aValues[0])); |
|
548 |
|
549 //The GetValue can only return either KErrArgument or KErrNone |
|
550 if(err == KErrArgument) |
|
551 { |
|
552 aErrors[0] = KErrArgument; |
|
553 aValues[0] = 0; |
|
554 return 0; |
|
555 } |
|
556 else //err == KErrNone |
|
557 { |
|
558 aErrors[0] = KErrNone; |
|
559 } |
|
560 |
|
561 } |
|
562 |
|
563 //This single setting was found so indicate it to the user |
|
564 return (1); |
|
565 } |
|
566 |
|
567 |
|
568 //Introducing a SafeArray of pointers to the settings, which is passed to ver- |
|
569 //sion of GetWordSettings() method declared in TRepository, and implemented |
|
570 //in TRepositoryCompiled and TRepositoryFile |
|
571 TSa<SSettingId*> ids; |
|
572 |
|
573 //SafeArray of pointers to the aValues user array elements |
|
574 TSa<TInt32*> values; |
|
575 |
|
576 //SafeArray of pointers to the aErrors user array elements |
|
577 TSa<TInt*> errors; |
|
578 |
|
579 //SafeArray of pointers to the aTypes user array elements |
|
580 TSa<TSettingType*> types; |
|
581 |
|
582 |
|
583 //Local replacement for the aTypes[] array if it's not provided by user |
|
584 TSa<TSettingType> typesHolder; |
|
585 |
|
586 //Allocate the arrays of pointers in the heap |
|
587 ids = new SSettingId*[aNum]; |
|
588 values = new TInt32*[aNum]; |
|
589 errors = new TInt*[aNum]; |
|
590 types = new TSettingType*[aNum]; |
|
591 |
|
592 |
|
593 //Check all arrays allocations |
|
594 if(!ids() || !values() || !errors() || !types()) |
|
595 { |
|
596 //One of the allocation was unsuccessful |
|
597 HCR_TRACE_RETURN(KErrNoMemory); |
|
598 } |
|
599 |
|
600 //If the user did not supply the aTypes array for us we need to create one |
|
601 //for ourself |
|
602 if(aTypes == NULL) |
|
603 { |
|
604 typesHolder = new TSettingType[aNum]; |
|
605 if(!typesHolder()) |
|
606 HCR_TRACE_RETURN(KErrNoMemory); |
|
607 } |
|
608 |
|
609 |
|
610 //Ininialize newly created array of pointers to the user supplied settings |
|
611 for (TInt index = 0; index < aNum; index++) |
|
612 { |
|
613 ids[index] = const_cast<SSettingId*>(&aIds[index]); |
|
614 values[index] = const_cast<TInt32*>(&aValues[index]); |
|
615 errors[index] = &aErrors[index]; |
|
616 |
|
617 if(aTypes == NULL) |
|
618 types[index] = &typesHolder[index]; |
|
619 else |
|
620 types[index] = &aTypes[index]; |
|
621 } |
|
622 |
|
623 |
|
624 //nfCount represents a total number of settings which were not found in all |
|
625 //repositories |
|
626 TInt nfCount = aNum; |
|
627 |
|
628 //nfReposCount represents a number of settings "not found - nf" in the searched |
|
629 //repository |
|
630 TInt nfReposCount = 0; |
|
631 |
|
632 //It represents a number of setting found in the repository |
|
633 TInt reposCount = 0; |
|
634 |
|
635 |
|
636 //First step through the Override store and gather all settings we need. |
|
637 //In the end of this procedure we'll have number of settings not found here |
|
638 //and found settings data are copied to the user arrays. |
|
639 if (iOverrideStore) |
|
640 { |
|
641 |
|
642 //Call the sibling method from the TRepositoryFile object |
|
643 err = iOverrideStore->GetWordSettings(aNum, ids(), |
|
644 values(), types(), errors()); |
|
645 |
|
646 //Analyse the err we've got |
|
647 if(err != KErrNone && err != KErrNotFound) |
|
648 { |
|
649 HCR_TRACE_RETURN(err); |
|
650 } |
|
651 else if(err == KErrNone) |
|
652 { |
|
653 //Search for number of not found parameters |
|
654 for(TInt index = 0; index < aNum; index ++) |
|
655 { |
|
656 switch(*(errors[index])) |
|
657 { |
|
658 //The setting was found or it's found but the type is larger |
|
659 //than 4 bytes then we just increase a counter of the found |
|
660 //settings in the repository |
|
661 case KErrNone: |
|
662 case KErrArgument: |
|
663 reposCount ++; |
|
664 break; |
|
665 |
|
666 |
|
667 //The setting was not found, then re-initialize all the |
|
668 //arrays of pointers with the pointer to this element. |
|
669 //nfReposCount depict the counter of not found element and |
|
670 //index shows the intial element position. |
|
671 //As nfReposCount is always less or equal to index then we |
|
672 //can easily make reassignment as nfReposCoun element was |
|
673 //already analysed. In the end the nfReposCount is increased. |
|
674 case KErrNotFound: |
|
675 ids[nfReposCount] = ids[index]; |
|
676 values[nfReposCount] = values[index]; |
|
677 types[nfReposCount] = types[index]; |
|
678 errors[nfReposCount] = errors[index]; |
|
679 nfReposCount ++; |
|
680 break; |
|
681 |
|
682 |
|
683 default: |
|
684 //No any action is needed |
|
685 break; |
|
686 } |
|
687 } |
|
688 |
|
689 } |
|
690 else //err == KErrNotFound |
|
691 { |
|
692 //No settings were found in the repository |
|
693 //reposCount is zero intialized, so nothing to do here |
|
694 } |
|
695 |
|
696 //Update the global counter only if there are some settings were found, |
|
697 //otherwise it can be situation when we overwrite the nfCount with zero |
|
698 //when either no any setting presents or no settings were found in the |
|
699 //repository |
|
700 if(reposCount > 0) |
|
701 nfCount = nfReposCount; |
|
702 } |
|
703 |
|
704 //Go through core image and search for the rest of settings |
|
705 nfReposCount = 0; |
|
706 reposCount = 0; |
|
707 |
|
708 if (iCoreImgStore && nfCount > 0) |
|
709 { |
|
710 |
|
711 err = iCoreImgStore->GetWordSettings(nfCount, ids(), |
|
712 values(), types(), errors()); |
|
713 |
|
714 if (err != KErrNone && err != KErrNotFound) |
|
715 { |
|
716 HCR_TRACE_RETURN(err); |
|
717 } |
|
718 else if(err == KErrNone) |
|
719 { |
|
720 //Search for number of errors |
|
721 for(TInt index = 0; index < nfCount; index ++) |
|
722 { |
|
723 switch(*(errors[index])) |
|
724 { |
|
725 //The setting was found or it's found but the type is larger |
|
726 //than 4 bytes then we just increase a counter of the found |
|
727 //settings in the repository |
|
728 case KErrNone: |
|
729 case KErrArgument: |
|
730 reposCount ++; |
|
731 break; |
|
732 |
|
733 //The setting was not found, then re-initialize all the |
|
734 //arrays of pointers with the pointer to this element. |
|
735 //nfReposCount depict the counter of not found element and |
|
736 //index shows the intial element position. |
|
737 //As nfReposCount is always less or equal to index then we |
|
738 //can easily make reassignment as nfReposCoun element was |
|
739 //already analysed. In the end the nfReposCount is increased. |
|
740 case KErrNotFound: |
|
741 ids[nfReposCount] = ids[index]; |
|
742 values[nfReposCount] = values[index]; |
|
743 types[nfReposCount] = types[index]; |
|
744 errors[nfReposCount] = errors[index]; |
|
745 nfReposCount ++; |
|
746 break; |
|
747 |
|
748 |
|
749 default: |
|
750 //No any action is needed |
|
751 break; |
|
752 |
|
753 } |
|
754 |
|
755 } |
|
756 |
|
757 } |
|
758 else //err == KErrNotFound |
|
759 { |
|
760 //No settings were found in the repository |
|
761 //reposCount is zero intialized, so nothing to do here |
|
762 } |
|
763 |
|
764 |
|
765 //Update the global counter only if there are some settings were found, |
|
766 //otherwise it can be situation when we overwrite the nfCount with zero |
|
767 //when either no any setting presents or no settings were found in the |
|
768 //repository |
|
769 if(reposCount > 0) |
|
770 nfCount = nfReposCount; |
|
771 } |
|
772 |
|
773 //let's go through the last Variant store |
|
774 nfReposCount = 0; |
|
775 reposCount = 0; |
|
776 if(iVariantStore && nfCount > 0) |
|
777 { |
|
778 err = iVariantStore->GetWordSettings(nfCount, ids(), values(), |
|
779 types(), errors()); |
|
780 |
|
781 if (err != KErrNone && err != KErrNotFound) |
|
782 { |
|
783 HCR_TRACE_RETURN(err); |
|
784 } |
|
785 else if(err == KErrNone) |
|
786 { |
|
787 //Search for number of errors |
|
788 for(TInt index = 0; index < nfCount; index ++) |
|
789 { |
|
790 switch(*(errors[index])) |
|
791 { |
|
792 //The setting was found or it's found but the type is larger |
|
793 //than 4 bytes then we just increase a counter of the found |
|
794 //settings in the repository |
|
795 case KErrNone: |
|
796 case KErrArgument: |
|
797 reposCount ++; |
|
798 break; |
|
799 |
|
800 //The setting was not found, then re-initialize all the |
|
801 //arrays of pointers with the pointer to this element. |
|
802 //nfReposCount depict the counter of not found element and |
|
803 //index shows the intial element position. |
|
804 //As nfReposCount is always less or equal to index then we |
|
805 //can easily make reassignment as nfReposCoun element was |
|
806 //already analysed. In the end the nfReposCount is increased. |
|
807 case KErrNotFound: |
|
808 *values[nfReposCount] = 0; |
|
809 *types[nfReposCount] = ETypeUndefined; |
|
810 *errors[nfReposCount] = KErrNotFound; |
|
811 nfReposCount ++; |
|
812 break; |
|
813 |
|
814 |
|
815 default: |
|
816 //No any action is needed |
|
817 break; |
|
818 |
|
819 } |
|
820 } |
|
821 |
|
822 } |
|
823 else //err == KErrNotFound |
|
824 { |
|
825 //No settings were found in the repository |
|
826 //reposCount is zero intialized, so nothing to do here |
|
827 } |
|
828 |
|
829 //Update the global counter only if there are some settings were found, |
|
830 //otherwise it can be situation when we overwrite the nfCount with zero |
|
831 //when either no any setting presents or no settings were found in the |
|
832 //repository |
|
833 if(reposCount > 0) |
|
834 nfCount = nfReposCount; |
|
835 } |
|
836 //Return the number of found elements |
|
837 return (aNum - nfCount); |
|
838 } |
|
839 |
|
840 |
|
841 |
|
842 |
|
843 |
|
844 TInt HCR::HCRInternal::FindNumSettingsInCategory (TCategoryUid aCatUid) |
|
845 { |
|
846 HCR_FUNC("++ HCRInternal::FindNumSettingsInCategory"); |
|
847 TInt err = 0; |
|
848 |
|
849 HCR_TRACE3("--- Repository state: %x, %x, %x", iOverrideStore, iCoreImgStore, iVariantStore); |
|
850 |
|
851 //First and last element index within category in the Override store |
|
852 TInt32 oLowIndex = 0; |
|
853 TInt32 oHighIndex = 0; |
|
854 TInt oCount = 0; |
|
855 |
|
856 //Find numOverride number of settings within the category in the OverrideStore |
|
857 //repository |
|
858 if(iOverrideStore) |
|
859 { |
|
860 err = iOverrideStore->FindNumSettingsInCategory(aCatUid, |
|
861 oLowIndex, oHighIndex); |
|
862 |
|
863 if(err == KErrNotFound) |
|
864 oCount = 0; |
|
865 else |
|
866 oCount = oHighIndex - oLowIndex + 1; |
|
867 |
|
868 //If CoreImg and Variant store are not activated so just return the |
|
869 //number of elements found in the Override store |
|
870 if(!iCoreImgStore && !iVariantStore) |
|
871 return oCount; |
|
872 } |
|
873 |
|
874 |
|
875 //First and last element index within category in the CoreImg store |
|
876 TInt32 cLowIndex = 0; |
|
877 TInt32 cHighIndex = 0; |
|
878 TInt32 cLength = 0; |
|
879 TInt cCount = 0; |
|
880 |
|
881 |
|
882 |
|
883 //Temproary holder for the found element position |
|
884 TInt32 elementPos; |
|
885 //Temproary holder for the low index, which is used to decrease the scope |
|
886 //of search |
|
887 TInt32 lowIndex = oLowIndex; |
|
888 |
|
889 //Setting data holders |
|
890 SSettingId setId; |
|
891 TSettingRef setRef; |
|
892 |
|
893 if(iCoreImgStore) |
|
894 { |
|
895 //Find numCoreImg number of settings within the category in the CoreImg re- |
|
896 //pository |
|
897 err = iCoreImgStore->FindNumSettingsInCategory(aCatUid, |
|
898 cLowIndex, cHighIndex); |
|
899 |
|
900 if(err == KErrNotFound) |
|
901 cLength = 0; |
|
902 else |
|
903 //Calculate the number of elements within category, in CoreImg store |
|
904 cLength = cHighIndex - cLowIndex + 1; |
|
905 |
|
906 if(oCount > 0) |
|
907 { |
|
908 //Find all elemnts from CoreImg store which are not redefined in the |
|
909 //Override store. When element is not found in the Override store |
|
910 //then cCount is increased. |
|
911 for(TInt element = 0; element < cLength; element ++) |
|
912 { |
|
913 //Find element in the repository by its index |
|
914 iCoreImgStore->GetSettingRef(cLowIndex + element, setRef); |
|
915 //and get its id |
|
916 iCoreImgStore->GetId(setRef, setId); |
|
917 |
|
918 //Check either this element is already redefined in the Override |
|
919 //store |
|
920 err = iOverrideStore->FindSetting( setId, setRef, |
|
921 elementPos, lowIndex, oHighIndex); |
|
922 |
|
923 if(err == KErrNone) |
|
924 { |
|
925 //if the element is found in the Override store, then store the posi- |
|
926 //tion of this element in lowIndex, to narrow next search procedure |
|
927 lowIndex = elementPos; |
|
928 } |
|
929 else if(err == KErrNotFound) |
|
930 { |
|
931 //if element is not found then it means it's not redefined in the |
|
932 //Override store and this element must be counted in the total number |
|
933 //of elemnts in all stores |
|
934 cCount ++; |
|
935 } |
|
936 else |
|
937 { |
|
938 return err; |
|
939 } |
|
940 } |
|
941 } |
|
942 else |
|
943 { |
|
944 cCount = cLength; |
|
945 } |
|
946 |
|
947 |
|
948 |
|
949 //Check if the Variant store is present if it's not then just return the |
|
950 //result |
|
951 if(!iVariantStore) |
|
952 return (oCount + cCount); |
|
953 |
|
954 } |
|
955 |
|
956 //First and last element index within giving category in the Variant store |
|
957 TInt32 vLowIndex = 0; |
|
958 TInt32 vHighIndex = 0; |
|
959 TInt32 vLength = 0; |
|
960 TInt vCount = 0; |
|
961 |
|
962 if(iVariantStore) |
|
963 { |
|
964 //Find numVariant number of settings within the category in the VariantStore |
|
965 //repository |
|
966 err = iVariantStore->FindNumSettingsInCategory(aCatUid, vLowIndex, |
|
967 vHighIndex); |
|
968 |
|
969 //Analyze returned error code |
|
970 |
|
971 if(err == KErrNotFound) |
|
972 vLength = 0; |
|
973 else |
|
974 //Calculate the number of elements within category, in CoreImg store |
|
975 vLength = vHighIndex - vLowIndex + 1; |
|
976 |
|
977 if(oCount == 0 && cCount == 0) |
|
978 { |
|
979 return vLength; |
|
980 } |
|
981 |
|
982 if(oCount > 0 || cCount >0) |
|
983 { |
|
984 //Find all elemnts from Variant store which are not redefined either in the |
|
985 //Override or CoreImg store. These elements are added to the total |
|
986 //count. |
|
987 |
|
988 // Some additional containers. They are needed because we |
|
989 // must check two stores Override and Variant in this iteration. Making a |
|
990 // decision of uniqueness of the element is made from the analyse of both |
|
991 // result. The element is only unique defined in the Variant store if it's |
|
992 // not redefined either in the Override or Variant store |
|
993 TSettingRef tmpRef; |
|
994 //Temproary holder for the found element position |
|
995 TInt32 elementPos2 = 0; |
|
996 //Temproary holder for the low index, which is used to decrease the scope |
|
997 //of search |
|
998 TInt32 lowIndex2 = cLowIndex; |
|
999 // This index contains Override low index and will be changed by the position |
|
1000 // of a new found element |
|
1001 lowIndex= oLowIndex; |
|
1002 |
|
1003 TBool isRedefined = EFalse; |
|
1004 |
|
1005 for(TInt element = 0; element < vLength; element ++) |
|
1006 { |
|
1007 //Find the setting in the repository by its index and |
|
1008 iVariantStore->GetSettingRef(vLowIndex + element, setRef); |
|
1009 //get its id |
|
1010 iVariantStore->GetId(setRef, setId); |
|
1011 |
|
1012 if(oCount > 0) |
|
1013 { |
|
1014 //Check either this element is already redefined in the Override store |
|
1015 err = iOverrideStore->FindSetting(setId, tmpRef, |
|
1016 elementPos, lowIndex, oHighIndex); |
|
1017 |
|
1018 if(err == KErrNone) |
|
1019 { |
|
1020 //if the element is found in the Override store, then store the posi- |
|
1021 //tion of this element in lowIndex, to narrow next search procedure |
|
1022 lowIndex = elementPos; |
|
1023 isRedefined = ETrue; |
|
1024 } |
|
1025 else if(err == KErrNotFound) |
|
1026 { |
|
1027 //the element is not presented in the Override store |
|
1028 //nothing to do here |
|
1029 } |
|
1030 else |
|
1031 { |
|
1032 return err; |
|
1033 } |
|
1034 |
|
1035 } |
|
1036 |
|
1037 |
|
1038 if(cCount > 0 && !isRedefined) |
|
1039 { |
|
1040 //Check either this element is already redefined in the CoreImg store |
|
1041 err = iCoreImgStore->FindSetting(setId, tmpRef, |
|
1042 elementPos2, lowIndex2, cHighIndex); |
|
1043 |
|
1044 |
|
1045 if(err == KErrNone) |
|
1046 { |
|
1047 //if the element is found in the Override store, then store the posi- |
|
1048 //tion of this element in lowIndex, to narrow next search procedure |
|
1049 lowIndex2 = elementPos2; |
|
1050 isRedefined = ETrue; |
|
1051 } |
|
1052 else if(err == KErrNotFound) |
|
1053 { |
|
1054 //the element is not presented in the Override store |
|
1055 //nothing to do here |
|
1056 } |
|
1057 else |
|
1058 { |
|
1059 return err; |
|
1060 } |
|
1061 } |
|
1062 |
|
1063 |
|
1064 if(!isRedefined) |
|
1065 vCount ++; |
|
1066 else |
|
1067 isRedefined = EFalse; |
|
1068 |
|
1069 }//for(TInt element = 0; element < vLength; element ++) |
|
1070 |
|
1071 } |
|
1072 else |
|
1073 { |
|
1074 vCount = vLength; |
|
1075 } |
|
1076 } |
|
1077 |
|
1078 //Return the total number of elements found in the category |
|
1079 return (oCount + cCount + vCount); |
|
1080 } |
|
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 TInt HCR::HCRInternal::FindSettings(TCategoryUid aCatUid, |
|
1086 TInt aMaxNum, TElementId aIds[], |
|
1087 TSettingType aTypes[], TUint16 aLens[]) |
|
1088 { |
|
1089 HCR_FUNC("++ HCRInternal::FindSettings w/o patterns"); |
|
1090 |
|
1091 HCR_TRACE3("--- Repository state: %x, %x, %x", iOverrideStore, |
|
1092 iCoreImgStore, iVariantStore); |
|
1093 |
|
1094 //Error container |
|
1095 TInt err = KErrNone; |
|
1096 |
|
1097 //Total number of found elements |
|
1098 TInt numFound = 0; |
|
1099 //Number of found elements in the Override store |
|
1100 TInt oNumFound = 0; |
|
1101 |
|
1102 //Low and High indexes in the Override store |
|
1103 TInt32 oLoIndex = 0; |
|
1104 TInt32 oHiIndex = 0; |
|
1105 |
|
1106 //Temproary holder for the found element position |
|
1107 TInt32 elementPos = 0; |
|
1108 TInt32 lowIndex = 0; |
|
1109 |
|
1110 |
|
1111 //Tempoary type and length value holders if the |
|
1112 //user does not provide these arrays for us |
|
1113 TSettingType tmpType; |
|
1114 TUint16 tmpLen; |
|
1115 |
|
1116 |
|
1117 //Setting datat holders |
|
1118 TSettingRef setRef; |
|
1119 TSettingId setId; |
|
1120 |
|
1121 |
|
1122 //Find number of elements, low and hingh index in the Override store |
|
1123 if(iOverrideStore) |
|
1124 { |
|
1125 err = iOverrideStore->FindNumSettingsInCategory(aCatUid, oLoIndex, |
|
1126 oHiIndex); |
|
1127 if(err == KErrNone) |
|
1128 { |
|
1129 //If number of elements in the Override Store is larger than aMaxNum or |
|
1130 //CoreImage/Variant stores are not present then write all found |
|
1131 //settings into the user array, return the number of found elements and |
|
1132 //exit |
|
1133 oNumFound = (oHiIndex - oLoIndex + 1); |
|
1134 lowIndex = oLoIndex; |
|
1135 |
|
1136 if(oNumFound < aMaxNum) |
|
1137 { |
|
1138 for(TInt index = 0; index < oNumFound; index ++) |
|
1139 { |
|
1140 //Get setting reference data from the repository |
|
1141 iOverrideStore->GetSettingRef(oLoIndex + index, setRef); |
|
1142 |
|
1143 //Copy the settings data into the user arrays |
|
1144 iOverrideStore->GetSettingInfo(setRef, |
|
1145 aIds[index], |
|
1146 aTypes ? aTypes[index]:tmpType, |
|
1147 aLens ? aLens[index]:tmpLen); |
|
1148 |
|
1149 |
|
1150 } |
|
1151 } |
|
1152 else //oNumFound >= aMaxNum |
|
1153 { |
|
1154 //Copy data to the user array |
|
1155 for(TInt index = 0; index < aMaxNum; index++) |
|
1156 { |
|
1157 //Get setting reference data from the repository |
|
1158 iOverrideStore->GetSettingRef(oLoIndex + index, setRef); |
|
1159 //Copy the settings data into the user arrays |
|
1160 iOverrideStore->GetSettingInfo(setRef, |
|
1161 aIds[index], |
|
1162 aTypes ? aTypes[index]:tmpType, |
|
1163 aLens ? aLens[index]:tmpLen); |
|
1164 |
|
1165 } |
|
1166 return oNumFound; |
|
1167 } |
|
1168 } |
|
1169 else if(err == KErrNotFound) |
|
1170 { |
|
1171 //Nothing to do here, oNumFound is set to zero already |
|
1172 } |
|
1173 else |
|
1174 { |
|
1175 return err; |
|
1176 } |
|
1177 } |
|
1178 |
|
1179 |
|
1180 //Low/High index in the CoreImg |
|
1181 TInt32 cLoIndex = 0; |
|
1182 TInt32 cHiIndex = 0; |
|
1183 TInt cNumFound = 0; |
|
1184 |
|
1185 //Temproary setting reference holder |
|
1186 TSettingRef tmpRef; |
|
1187 |
|
1188 //Temproary holder for the found element position |
|
1189 elementPos = 0; |
|
1190 lowIndex = oLoIndex; |
|
1191 |
|
1192 //Redefined status flag, it's used to flag that the element is found in the |
|
1193 //upper stores |
|
1194 TBool isRedefined = EFalse; |
|
1195 |
|
1196 //User array index |
|
1197 TInt usrArrIndx = 0; |
|
1198 |
|
1199 //If the count is still less than aMaxNum then continue with searching |
|
1200 //settings in the CoreImage store |
|
1201 if(iCoreImgStore) |
|
1202 { |
|
1203 |
|
1204 //Find number of elements and low/high indexes |
|
1205 err = iCoreImgStore->FindNumSettingsInCategory(aCatUid, cLoIndex, |
|
1206 cHiIndex); |
|
1207 |
|
1208 if(err == KErrNone) |
|
1209 { |
|
1210 for(TInt index = 0; index < (cHiIndex - cLoIndex + 1); index ++) |
|
1211 { |
|
1212 //Get the setting data by its index in the repository |
|
1213 iCoreImgStore->GetSettingRef(cLoIndex + index, setRef); |
|
1214 //get setting id |
|
1215 iCoreImgStore->GetId(setRef, setId); |
|
1216 |
|
1217 if(oNumFound > 0) |
|
1218 { |
|
1219 //Check either this element is already redefined in the |
|
1220 err = iOverrideStore->FindSetting(setId, tmpRef, |
|
1221 elementPos, lowIndex, oHiIndex); |
|
1222 |
|
1223 |
|
1224 if(err == KErrNone) |
|
1225 { |
|
1226 lowIndex = elementPos + 1; |
|
1227 isRedefined = ETrue; |
|
1228 } |
|
1229 else if (err == KErrNotFound) |
|
1230 { |
|
1231 //Nothing to do hear, isRedefined flag is EFalse |
|
1232 //all analysis is done later in the code |
|
1233 } |
|
1234 else |
|
1235 { |
|
1236 return err; |
|
1237 } |
|
1238 } |
|
1239 |
|
1240 //Examine the redefined status flag |
|
1241 if(!isRedefined) |
|
1242 { |
|
1243 // If the element was not found then we need to copy to |
|
1244 // the pA array and increase the counter of setting data |
|
1245 // only if we did not reach the aMaxNum of found elements |
|
1246 |
|
1247 usrArrIndx = oNumFound + cNumFound; |
|
1248 if(usrArrIndx < aMaxNum) |
|
1249 { |
|
1250 //Copy the settings data into the user arrays |
|
1251 iCoreImgStore->GetSettingInfo(setRef, |
|
1252 aIds[usrArrIndx], |
|
1253 aTypes ? aTypes[usrArrIndx]:tmpType, |
|
1254 aLens ? aLens[usrArrIndx]:tmpLen); |
|
1255 cNumFound ++; |
|
1256 } |
|
1257 else |
|
1258 { |
|
1259 //All required elements were found! |
|
1260 //As vNumFound was used an index so it's value it runs |
|
1261 //from 0 to X-1, where X - number of found elements. To |
|
1262 //get number of elements found we need increase the last |
|
1263 //counter value by 1. |
|
1264 if(cNumFound != 0) |
|
1265 cNumFound ++; |
|
1266 //It reaches the goal, all required elements are found |
|
1267 //stop here and return the result |
|
1268 break; |
|
1269 } |
|
1270 } |
|
1271 else |
|
1272 //Element is found in other repositories, just reset a flag |
|
1273 isRedefined = EFalse; |
|
1274 } |
|
1275 } |
|
1276 else if (err == KErrNotFound) |
|
1277 { |
|
1278 //cNumFound is already set to zero during the initialization |
|
1279 //Nothing to do here |
|
1280 } |
|
1281 else //any other errors |
|
1282 { |
|
1283 return err; |
|
1284 } |
|
1285 } |
|
1286 |
|
1287 |
|
1288 //Low/High index in the CoreImg |
|
1289 TInt32 vLoIndex = 0; |
|
1290 TInt32 vHiIndex = 0; |
|
1291 TInt vNumFound = 0; |
|
1292 |
|
1293 //Temproary holder for the found element position |
|
1294 TInt32 elementPos2 = 0; |
|
1295 |
|
1296 TInt32 lowIndex2 = cLoIndex; |
|
1297 lowIndex = oLoIndex; |
|
1298 |
|
1299 isRedefined = EFalse; |
|
1300 |
|
1301 |
|
1302 //If the count is still less than aMaxNum then continue with searching |
|
1303 //settings in the CoreImage store |
|
1304 if(iVariantStore) |
|
1305 { |
|
1306 |
|
1307 //Find number of elements and low/high indexes |
|
1308 err = iVariantStore->FindNumSettingsInCategory(aCatUid, vLoIndex, |
|
1309 vHiIndex); |
|
1310 if(err == KErrNone) |
|
1311 { |
|
1312 |
|
1313 for(TInt index = 0; index < (vHiIndex - vLoIndex + 1); index ++) |
|
1314 { |
|
1315 //Get setting reference data by its index in the repository |
|
1316 iVariantStore->GetSettingRef(vLoIndex + index, setRef); |
|
1317 |
|
1318 //and get setting id |
|
1319 iVariantStore->GetId(setRef, setId); |
|
1320 |
|
1321 if(oNumFound > 0) |
|
1322 { |
|
1323 //Check either this element is already redefined in the |
|
1324 err = iOverrideStore->FindSetting(setId, tmpRef, elementPos, |
|
1325 lowIndex, oHiIndex); |
|
1326 |
|
1327 |
|
1328 //Also suppress the error checking due the reason described |
|
1329 //above |
|
1330 if(err == KErrNone) |
|
1331 { |
|
1332 lowIndex = elementPos + 1; |
|
1333 isRedefined = ETrue; |
|
1334 } |
|
1335 else if (err == KErrNotFound) |
|
1336 { |
|
1337 //Element is not found, nothing to proceed here |
|
1338 } |
|
1339 else |
|
1340 { |
|
1341 return err; |
|
1342 } |
|
1343 } |
|
1344 |
|
1345 if(cNumFound > 0 && !isRedefined) |
|
1346 { |
|
1347 //Check either this element is already redefined in the |
|
1348 err = iCoreImgStore->FindSetting(setId, tmpRef, elementPos2, |
|
1349 lowIndex2, cHiIndex); |
|
1350 |
|
1351 if(err == KErrNone) |
|
1352 { |
|
1353 lowIndex2 = elementPos2 + 1; |
|
1354 isRedefined = ETrue; |
|
1355 } |
|
1356 else if (err == KErrNotFound) |
|
1357 { |
|
1358 //Element is not found, nothing to proceed here |
|
1359 } |
|
1360 else |
|
1361 { |
|
1362 return err; |
|
1363 } |
|
1364 } |
|
1365 |
|
1366 if(!isRedefined) |
|
1367 { |
|
1368 usrArrIndx = oNumFound + cNumFound + vNumFound; |
|
1369 if(usrArrIndx < aMaxNum) |
|
1370 { |
|
1371 //Copy the settings data into the user arrays |
|
1372 iVariantStore->GetSettingInfo(setRef, |
|
1373 aIds[usrArrIndx], |
|
1374 aTypes ? aTypes[usrArrIndx]:tmpType, |
|
1375 aLens ? aLens[usrArrIndx]:tmpLen); |
|
1376 |
|
1377 vNumFound ++; |
|
1378 } |
|
1379 else |
|
1380 { |
|
1381 //All required elements were found! |
|
1382 //As vNumFound was used an index so it's value it runs |
|
1383 //from 0 to X-1, where X - number of found elements. To |
|
1384 //get number of elements found we need increase the last |
|
1385 //counter value by 1. |
|
1386 if(vNumFound != 0) |
|
1387 vNumFound ++; |
|
1388 //It reaches the goal, all required elements are found |
|
1389 //stop here and return the result |
|
1390 break; |
|
1391 } |
|
1392 } |
|
1393 else |
|
1394 { |
|
1395 isRedefined = EFalse; |
|
1396 } |
|
1397 } |
|
1398 } |
|
1399 else if (err == KErrNotFound) |
|
1400 { |
|
1401 //oNumFound is already set to zero during the initialization |
|
1402 //Nothing to do here |
|
1403 } |
|
1404 else |
|
1405 { |
|
1406 return err; |
|
1407 } |
|
1408 |
|
1409 } |
|
1410 |
|
1411 //Let's prepare the final data |
|
1412 numFound = oNumFound + cNumFound + vNumFound; |
|
1413 |
|
1414 //Return result to the user |
|
1415 return numFound; |
|
1416 } |
|
1417 |
|
1418 |
|
1419 |
|
1420 |
|
1421 |
|
1422 |
|
1423 |
|
1424 TInt HCR::HCRInternal::FindSettings(TCategoryUid aCat, TInt aMaxNum, |
|
1425 TUint32 aMask, TUint32 aPattern, |
|
1426 TElementId aIds[], TSettingType aTypes[], TUint16 aLens[]) |
|
1427 { |
|
1428 //Holder for errors and number of elements |
|
1429 TInt r = KErrNone; |
|
1430 //Total number of elements within the given category |
|
1431 TInt allInCatFound = 0; |
|
1432 //Number of elements which corresponds to the aMask and aPattern |
|
1433 TInt numFound = 0; |
|
1434 |
|
1435 //Find the number of elements within the category |
|
1436 r = FindNumSettingsInCategory(aCat); |
|
1437 |
|
1438 //Analyse the returned error |
|
1439 //if r < 0 - this is an error return to the user |
|
1440 //if r > 0 - number of found settings |
|
1441 if(r < 0) |
|
1442 { |
|
1443 HCR_TRACE_RETURN(r); |
|
1444 } |
|
1445 else if (r == 0) |
|
1446 //No any elements found for this category |
|
1447 return 0; |
|
1448 else |
|
1449 allInCatFound = r; |
|
1450 |
|
1451 //Result data array holder |
|
1452 TSa<TElementId> pIds; |
|
1453 TSa<TSettingType> pTypes; |
|
1454 TSa<TUint16> pLens; |
|
1455 |
|
1456 pIds = new TElementId[allInCatFound]; |
|
1457 pTypes = new TSettingType[allInCatFound]; |
|
1458 pLens = new TUint16[allInCatFound]; |
|
1459 |
|
1460 if(pIds() == NULL || pTypes() == NULL || pLens() == NULL) |
|
1461 //One of the allocation was unsuccessful |
|
1462 HCR_TRACE_RETURN(KErrNoMemory); |
|
1463 |
|
1464 r = FindSettings(aCat, allInCatFound, pIds(), pTypes(), pLens()); |
|
1465 |
|
1466 //Exit if we've got negative result just report error |
|
1467 if(r < 0) |
|
1468 HCR_TRACE_RETURN(r); |
|
1469 |
|
1470 //Somehow we'got less elements than it must be!!! |
|
1471 __NK_ASSERT_DEBUG(r == allInCatFound); |
|
1472 if(r < allInCatFound) |
|
1473 HCR_TRACE_RETURN(KErrGeneral); |
|
1474 |
|
1475 |
|
1476 //Choose the elements which satisfy this condition |
|
1477 //((elementID & aElementMask) == (aPattern & aElementMask)). The total num- |
|
1478 //ber of returned elements should not exceed the aMaxNum |
|
1479 for(TInt index = 0; index < allInCatFound; index++) |
|
1480 { |
|
1481 if(((pIds[index] & aMask) == (aPattern & aMask))) |
|
1482 { |
|
1483 aIds[numFound] = pIds[index]; |
|
1484 |
|
1485 if(aTypes) |
|
1486 aTypes[numFound] = pTypes[index]; |
|
1487 |
|
1488 if(aLens) |
|
1489 aLens[numFound] = pLens[index]; |
|
1490 |
|
1491 numFound ++; |
|
1492 } |
|
1493 else |
|
1494 continue; |
|
1495 |
|
1496 //Check either we already found or not enough elements |
|
1497 //If we did then break the loop |
|
1498 if(numFound == aMaxNum) |
|
1499 break; |
|
1500 } |
|
1501 |
|
1502 return numFound; |
|
1503 } |
|
1504 |
|
1505 |
|
1506 // -- METHODS ----------------------------------------------------------------- |
|
1507 // |
|
1508 // TRepository |
|
1509 |
|
1510 HCR::TRepository::~TRepository() |
|
1511 { |
|
1512 HCR_FUNC("~TRepository"); |
|
1513 } |
|
1514 |
|
1515 TBool HCR::TRepository::IsWordValue(const TSettingRef& aRef) |
|
1516 { |
|
1517 HCR_FUNC("TRepository::IsWordValue"); |
|
1518 return ((aRef.iSet->iType & KMaskWordTypes) != 0); |
|
1519 } |
|
1520 |
|
1521 TBool HCR::TRepository::IsLargeValue(const TSettingRef& aRef) |
|
1522 { |
|
1523 HCR_FUNC("TRepository::IsLargeValue"); |
|
1524 return ((aRef.iSet->iType & KMaskLargeTypes) != 0); |
|
1525 } |
|
1526 |
|
1527 void HCR::TRepository::GetId(const TSettingRef& aRef, TCategoryUid& aCat, TElementId& aKey) |
|
1528 { |
|
1529 HCR_FUNC("TRepository::GetId1"); |
|
1530 aCat = aRef.iSet->iId.iCat; |
|
1531 aKey = aRef.iSet->iId.iKey; |
|
1532 } |
|
1533 |
|
1534 void HCR::TRepository::GetId(const TSettingRef& aRef, SSettingId& aId) |
|
1535 { |
|
1536 HCR_FUNC("TRepository::GetId2"); |
|
1537 aId = aRef.iSet->iId; |
|
1538 } |
|
1539 |
|
1540 TInt32 HCR::TRepository::GetType(const TSettingRef& aRef) |
|
1541 { |
|
1542 HCR_FUNC("TRepository::GetType"); |
|
1543 return (aRef.iSet->iType); |
|
1544 } |
|
1545 |
|
1546 TUint16 HCR::TRepository::GetLength(const TSettingRef& aRef) |
|
1547 { |
|
1548 HCR_FUNC("TRepository::GetLength"); |
|
1549 |
|
1550 // Assume large value, will be caught when value retreived if not correct. |
|
1551 // Saves some CPU cycles... |
|
1552 // if (IsLargeValue(aRef)) |
|
1553 return (aRef.iSet->iLen); |
|
1554 } |
|
1555 |
|
1556 void HCR::TRepository::GetSettingInfo(const HCR::TSettingRef& aSetRef, |
|
1557 HCR::TElementId& aId, HCR::TSettingType& aType, TUint16& aLen) |
|
1558 { |
|
1559 HCR_FUNC("TRepository::GetSettingInfo"); |
|
1560 |
|
1561 aId = aSetRef.iSet->iId.iKey; |
|
1562 |
|
1563 aType = static_cast<TSettingType>(aSetRef.iSet->iType); |
|
1564 |
|
1565 aLen = aSetRef.iSet->iLen; |
|
1566 } |
|
1567 |
|
1568 // -- METHODS ----------------------------------------------------------------- |
|
1569 // |
|
1570 // TRepositoryCompiled |
|
1571 |
|
1572 |
|
1573 HCR::TRepository* HCR::TRepositoryCompiled::New(const SRepositoryCompiled* aRepos) |
|
1574 { |
|
1575 HCR_FUNC("TRepositoryCompiled::New"); |
|
1576 |
|
1577 __NK_ASSERT_ALWAYS(aRepos != 0); |
|
1578 return new TRepositoryCompiled(aRepos); |
|
1579 } |
|
1580 |
|
1581 HCR::TRepositoryCompiled::TRepositoryCompiled(const SRepositoryCompiled* aRepos) |
|
1582 : iRepos(aRepos) |
|
1583 { |
|
1584 HCR_FUNC("TRepositoryCompiled"); |
|
1585 } |
|
1586 |
|
1587 HCR::TRepositoryCompiled::~TRepositoryCompiled() |
|
1588 { |
|
1589 HCR_FUNC("~TRepositoryCompiled"); |
|
1590 } |
|
1591 |
|
1592 TInt HCR::TRepositoryCompiled::CheckIntegrity() |
|
1593 { |
|
1594 HCR_FUNC("TRepositoryCompiled::CheckIntegrity"); |
|
1595 |
|
1596 __NK_ASSERT_ALWAYS(this != 0); |
|
1597 __NK_ASSERT_ALWAYS(iRepos != 0); |
|
1598 |
|
1599 if (iRepos->iOrderedSettingList == 0) |
|
1600 HCR_TRACEMSG_RETURN("Compiled Repository header missing setting array list", KErrNotFound); |
|
1601 |
|
1602 HCR_TRACE2("Compiled repository 0x%x contains %05d entries", iRepos, iRepos->iHdr->iNumSettings); |
|
1603 |
|
1604 SSettingC* arr = iRepos->iOrderedSettingList; |
|
1605 TSettingId prev(0,0); |
|
1606 TInt rc=0; |
|
1607 for (int i=0; i < iRepos->iHdr->iNumSettings; i++, arr++) |
|
1608 { |
|
1609 __NK_ASSERT_ALWAYS(arr != 0); |
|
1610 HCR_TRACE3("Checking entry %05d - (0x%x,0x%x)", i, arr->iName.iId.iCat, arr->iName.iId.iKey); |
|
1611 rc = CompareSSettingIds(prev, arr->iName.iId); |
|
1612 // Check for duplicates that reside next to each other |
|
1613 if ((i > 0) && (rc == 0)) |
|
1614 HCR_TRACE_RETURN (KErrAlreadyExists); |
|
1615 // Check that the entries are in ascending order |
|
1616 if (rc != -1) |
|
1617 HCR_TRACE_RETURN (KErrCorrupt); |
|
1618 prev = arr->iName.iId; |
|
1619 } |
|
1620 return KErrNone; |
|
1621 } |
|
1622 |
|
1623 TInt HCR::TRepositoryCompiled::FindSetting(const TSettingId& aId, TSettingRef& aSetting) |
|
1624 { |
|
1625 HCR_FUNC("TRepositoryCompiled::FindSetting"); |
|
1626 |
|
1627 __NK_ASSERT_DEBUG(iRepos != 0); |
|
1628 __NK_ASSERT_DEBUG(iRepos->iHdr != 0); |
|
1629 |
|
1630 if ((iRepos->iHdr->iNumSettings == 0) || |
|
1631 (iRepos->iOrderedSettingList == 0)) |
|
1632 HCR_TRACE_RETURN(KErrNotFound); |
|
1633 |
|
1634 SSettingC* arr = iRepos->iOrderedSettingList; |
|
1635 int low = 0; |
|
1636 int high = iRepos->iHdr->iNumSettings-1; |
|
1637 int mid; |
|
1638 int com; |
|
1639 |
|
1640 while (low<=high) |
|
1641 { |
|
1642 mid = (low+high) >> 1; |
|
1643 com = CompareSSettingIds(aId, arr[mid].iName.iId); |
|
1644 if (com < 0) |
|
1645 high = mid-1; |
|
1646 else if (com > 0) |
|
1647 low = mid+1; |
|
1648 else |
|
1649 { |
|
1650 aSetting.iRep = this; |
|
1651 aSetting.iSet = &((arr[mid]).iName); |
|
1652 return KErrNone; |
|
1653 } |
|
1654 } |
|
1655 |
|
1656 aSetting.iRep = 0; |
|
1657 aSetting.iSet = 0; |
|
1658 return KErrNotFound; |
|
1659 } |
|
1660 |
|
1661 |
|
1662 |
|
1663 |
|
1664 TInt HCR::TRepositoryCompiled::FindSetting(const TSettingId& aId, |
|
1665 TSettingRef& aSetting, TInt32& aPosition, TInt32 aLow, TInt32 aHigh) |
|
1666 { |
|
1667 HCR_FUNC("TRepositoryCompiled::FindSetting within the given range"); |
|
1668 |
|
1669 |
|
1670 __NK_ASSERT_DEBUG(iRepos != 0); |
|
1671 __NK_ASSERT_DEBUG(iRepos->iHdr != 0); |
|
1672 |
|
1673 if ((iRepos->iHdr->iNumSettings == 0) || |
|
1674 (iRepos->iOrderedSettingList == 0)) |
|
1675 HCR_TRACE_RETURN(KErrNotFound); |
|
1676 |
|
1677 SSettingC* arr = iRepos->iOrderedSettingList; |
|
1678 TInt32 low = aLow; |
|
1679 TInt32 high = aHigh; |
|
1680 TInt32 mid; |
|
1681 TInt32 com; |
|
1682 |
|
1683 while (low<=high) |
|
1684 { |
|
1685 mid = (low+high) >> 1; |
|
1686 com = CompareSSettingIds(aId, arr[mid].iName.iId); |
|
1687 if (com < 0) |
|
1688 high = mid-1; |
|
1689 else if (com > 0) |
|
1690 low = mid+1; |
|
1691 else |
|
1692 { |
|
1693 aSetting.iRep = this; |
|
1694 aSetting.iSet = &((arr[mid]).iName); |
|
1695 aPosition = mid; |
|
1696 return KErrNone; |
|
1697 } |
|
1698 } |
|
1699 |
|
1700 aSetting.iRep = 0; |
|
1701 aSetting.iSet = 0; |
|
1702 aPosition = 0; |
|
1703 return KErrNotFound; |
|
1704 } |
|
1705 |
|
1706 |
|
1707 |
|
1708 TInt HCR::TRepositoryCompiled::GetWordSettings(TInt aNum, |
|
1709 SSettingId* aIds[], TInt32* aValues[], TSettingType* aTypes[], |
|
1710 TInt* aErrors[]) |
|
1711 { |
|
1712 HCR_FUNC("TRepositoryCompiled::GetWordSettings"); |
|
1713 |
|
1714 __NK_ASSERT_DEBUG(iRepos != 0); |
|
1715 __NK_ASSERT_DEBUG(iRepos->iHdr != 0); |
|
1716 |
|
1717 if ((iRepos->iHdr->iNumSettings == 0) || |
|
1718 (iRepos->iOrderedSettingList == 0)) |
|
1719 HCR_TRACE_RETURN(KErrNotFound); |
|
1720 |
|
1721 TInt err = KErrNone; |
|
1722 |
|
1723 TInt32 rMaxIndex = 0; |
|
1724 TInt32 rMinIndex = 0; |
|
1725 TInt32 uFirstIndex = 0; |
|
1726 TInt32 uLastIndex = 0; |
|
1727 TInt32 rIndex = 0; |
|
1728 TInt32 uIndex = 0; |
|
1729 |
|
1730 TSettingRef settingRef(NULL, NULL); |
|
1731 SSettingC* pSetting = NULL; |
|
1732 |
|
1733 |
|
1734 //Find position index within the repository for the first and last setting |
|
1735 //from user supplied array aIds[] |
|
1736 uIndex = 0; |
|
1737 TBool isRedefined = EFalse; |
|
1738 err = KErrNotFound; |
|
1739 uFirstIndex = 0; |
|
1740 while(!isRedefined && uIndex < aNum) |
|
1741 { |
|
1742 //Find first setting from user array. The importance here is that we |
|
1743 //should get value of first setting index in the repository in rMinIndex. |
|
1744 //This time the scope of search is whole repository. |
|
1745 err = this->FindSetting(*aIds[uIndex],settingRef, rMinIndex, |
|
1746 0, iRepos->iHdr->iNumSettings); |
|
1747 if(err == KErrNotFound) |
|
1748 { |
|
1749 *aErrors[uIndex] = err; |
|
1750 *aValues[uIndex] = 0; |
|
1751 //Copy type only if user provided aTypes array |
|
1752 if(aTypes) |
|
1753 *aTypes[uIndex] = ETypeUndefined; |
|
1754 |
|
1755 //As FindSetting did not find the element, let's challenge with |
|
1756 //the next one from aIds[] array |
|
1757 uIndex ++; |
|
1758 continue; |
|
1759 } |
|
1760 //fatal error here, nothing to do, just exit and return the error code |
|
1761 else if(err == KErrNotReady || err != KErrNone) |
|
1762 { |
|
1763 return err; |
|
1764 } |
|
1765 else // err == KErrNone |
|
1766 { |
|
1767 //Get the value and type |
|
1768 pSetting = (SSettingC*) settingRef.iSet; |
|
1769 //again copy the type value into the user array if it's provided |
|
1770 if(aTypes) |
|
1771 *aTypes[uIndex] = static_cast<TSettingType>(settingRef.iSet->iType); |
|
1772 |
|
1773 //Check for the found type is this word size? If it's not then |
|
1774 //indicate error for this setting |
|
1775 if(*aTypes[uIndex] > ETypeLinAddr) |
|
1776 { |
|
1777 *aErrors[uIndex] = KErrArgument; |
|
1778 *aValues[uIndex] = 0; |
|
1779 } |
|
1780 else |
|
1781 { |
|
1782 *aErrors[uIndex] = KErrNone; |
|
1783 *aValues[uIndex] = pSetting->iValue.iLit.iInt32; |
|
1784 } |
|
1785 |
|
1786 //Break the loop by setting the redefined status |
|
1787 isRedefined = ETrue; |
|
1788 } |
|
1789 } |
|
1790 |
|
1791 //At this point we should find at least one element from the user array, |
|
1792 //store this index in the local variable, it is used later in the code. |
|
1793 //Please be noticed we've also got rMinIndex - first setting index in the |
|
1794 //repository. |
|
1795 if(err == KErrNone) |
|
1796 uFirstIndex = uIndex; |
|
1797 //if we did not find any elements at all just return KErrNotFound |
|
1798 else |
|
1799 return KErrNotFound; |
|
1800 |
|
1801 |
|
1802 |
|
1803 //Now lets find the last setting |
|
1804 uIndex = aNum - 1; |
|
1805 isRedefined = EFalse; |
|
1806 err = KErrNotFound; |
|
1807 while(!isRedefined && uIndex > uFirstIndex) |
|
1808 { |
|
1809 //Find the last setting from user array. The importance here is that we |
|
1810 //should get value of first setting index in the repository in |
|
1811 //rMinIndex. This time the scope of search is whole repository. |
|
1812 err = this->FindSetting(*aIds[uIndex],settingRef, rMaxIndex, |
|
1813 rMinIndex, iRepos->iHdr->iNumSettings); |
|
1814 if(err == KErrNotFound) |
|
1815 { |
|
1816 *aErrors[uIndex] = err; |
|
1817 *aValues[uIndex] = 0; |
|
1818 if(aTypes) |
|
1819 *aTypes[uIndex] = ETypeUndefined; |
|
1820 |
|
1821 //As FindSetting did not find the element, let's challenge with |
|
1822 //previous one, as we are moving in reverse direction |
|
1823 uIndex --; |
|
1824 continue; |
|
1825 } |
|
1826 //fatal error here, nothing to do, just exit and return the error code |
|
1827 else if(err == KErrNotReady || err != KErrNone) |
|
1828 { |
|
1829 return err; |
|
1830 } |
|
1831 else //err == KErrNone |
|
1832 { |
|
1833 pSetting = (SSettingC*) settingRef.iSet; |
|
1834 if(aTypes) |
|
1835 *aTypes[uIndex] = static_cast<TSettingType>(settingRef.iSet->iType); |
|
1836 |
|
1837 //Check for the found type is this word size? If it's not then indicate |
|
1838 //error for this setting |
|
1839 if(*aTypes[uIndex] > ETypeLinAddr) |
|
1840 { |
|
1841 *aErrors[uIndex] = KErrArgument; |
|
1842 *aValues[uIndex] = 0; |
|
1843 } |
|
1844 else |
|
1845 { |
|
1846 *aErrors[uIndex] = KErrNone; |
|
1847 *aValues[uIndex] = pSetting->iValue.iLit.iInt32; |
|
1848 } |
|
1849 |
|
1850 isRedefined = ETrue; |
|
1851 } |
|
1852 } |
|
1853 |
|
1854 //At this point we found the last setting, store it's user array index in |
|
1855 //the local variable, it is used later in the code. Please be noticed |
|
1856 //we've also got rMaxIndex - last setting index in the repository. |
|
1857 if(err == KErrNone) |
|
1858 uLastIndex = uIndex; |
|
1859 else |
|
1860 //if we are here we did not find any other elements than was found |
|
1861 //in previous iteration then just stop here |
|
1862 return KErrNotFound; |
|
1863 |
|
1864 //The scope of user array settings in the repository is found. |
|
1865 //Let's find all other settings from user array. Bare in mind the low |
|
1866 //bound for the repository index is increased each iteration to optimize the |
|
1867 //search time. |
|
1868 for(uIndex = uFirstIndex + 1; uIndex < uLastIndex; uIndex ++) |
|
1869 { |
|
1870 err = this->FindSetting(*aIds[uIndex],settingRef, rIndex, |
|
1871 rMinIndex, rMaxIndex); |
|
1872 if(err == KErrNotFound) |
|
1873 { |
|
1874 *aErrors[uIndex] = err; |
|
1875 *aValues[uIndex] = 0; |
|
1876 if(aTypes) |
|
1877 *aTypes[uIndex] = ETypeUndefined; |
|
1878 |
|
1879 //As FindSetting did not find the element, let's challenge with |
|
1880 //another one |
|
1881 continue; |
|
1882 } |
|
1883 else if(err == KErrNotReady || err != KErrNone) |
|
1884 { |
|
1885 return err; |
|
1886 } |
|
1887 else //err == KErrNone |
|
1888 { |
|
1889 |
|
1890 pSetting = (SSettingC*) settingRef.iSet; |
|
1891 if(aTypes) |
|
1892 *aTypes[uIndex] = static_cast<TSettingType>(settingRef.iSet->iType); |
|
1893 |
|
1894 //Check for the found type is this word size? If it's not then indicate |
|
1895 //error for this setting |
|
1896 if(*aTypes[uIndex] > ETypeLinAddr) |
|
1897 { |
|
1898 *aErrors[uIndex] = KErrArgument; |
|
1899 *aValues[uIndex] = 0; |
|
1900 } |
|
1901 else |
|
1902 { |
|
1903 *aErrors[uIndex] = KErrNone; |
|
1904 *aValues[uIndex] = pSetting->iValue.iLit.iInt32; |
|
1905 } |
|
1906 |
|
1907 rMinIndex = rIndex + 1; |
|
1908 |
|
1909 } |
|
1910 |
|
1911 } |
|
1912 |
|
1913 return KErrNone; |
|
1914 } |
|
1915 |
|
1916 |
|
1917 |
|
1918 |
|
1919 |
|
1920 TInt HCR::TRepositoryCompiled::FindNumSettingsInCategory(TCategoryUid aCatUid, |
|
1921 TInt32& aFirst, TInt32& aLast) |
|
1922 { |
|
1923 HCR_FUNC("TRepositoryCompiled::FindNumSettingsInCategory"); |
|
1924 |
|
1925 __NK_ASSERT_DEBUG(iRepos != 0); |
|
1926 __NK_ASSERT_DEBUG(iRepos->iHdr != 0); |
|
1927 |
|
1928 if ((iRepos->iHdr->iNumSettings == 0) || (iRepos->iOrderedSettingList == 0)) |
|
1929 HCR_TRACE_RETURN(KErrNotFound); |
|
1930 |
|
1931 SSettingC* arr = iRepos->iOrderedSettingList; |
|
1932 int low = 0; |
|
1933 int high = iRepos->iHdr->iNumSettings-1; |
|
1934 int mid = 0; |
|
1935 int com = 0; |
|
1936 |
|
1937 //Let's find any setting within the category, mid will store the setting |
|
1938 //index in the repository |
|
1939 while (low<=high) |
|
1940 { |
|
1941 mid = (low+high) >> 1; |
|
1942 com = CompareByCategory(aCatUid, arr[mid].iName.iId); |
|
1943 if (com < 0) |
|
1944 high = mid-1; |
|
1945 else if (com > 0) |
|
1946 low = mid+1; |
|
1947 else |
|
1948 { |
|
1949 break; |
|
1950 } |
|
1951 } |
|
1952 |
|
1953 // If no one setting with the given category was found the return error |
|
1954 // to the user |
|
1955 if(low > high) |
|
1956 { |
|
1957 aFirst = 0; |
|
1958 aLast = 0; |
|
1959 return KErrNotFound; |
|
1960 } |
|
1961 |
|
1962 //Search the first element within the category |
|
1963 low = mid; |
|
1964 while(low > 0 && arr[low].iName.iId.iCat == aCatUid) |
|
1965 { |
|
1966 low --; |
|
1967 } |
|
1968 //Check the boundary conditions, there are two cases when we exit the loop |
|
1969 //either we found an element which category is not one we are looking for or |
|
1970 //we reach the beggining of the repository. If we reach the beggining of the |
|
1971 //repository we don't really know is it because this is last elment or it |
|
1972 //has required aCatUid, so we check these two conditions below |
|
1973 if(low == 0 && arr[low].iName.iId.iCat == aCatUid) |
|
1974 aFirst = low; |
|
1975 //We finish the loop either reaching the setting which category id is not |
|
1976 //what we need or this is first setting in the repository again with another |
|
1977 //category, so in both case we throw this element from the account. |
|
1978 else |
|
1979 aFirst = low + 1; |
|
1980 |
|
1981 //Search the last element within the category |
|
1982 high = mid; |
|
1983 while(high < iRepos->iHdr->iNumSettings && arr[high].iName.iId.iCat == aCatUid) |
|
1984 { |
|
1985 high ++; |
|
1986 } |
|
1987 |
|
1988 //Same situation as above, boundary conditions |
|
1989 if(high == (iRepos->iHdr->iNumSettings -1) && arr[high].iName.iId.iCat == aCatUid) |
|
1990 aLast = high; |
|
1991 else |
|
1992 aLast = high -1; |
|
1993 |
|
1994 |
|
1995 return KErrNone; |
|
1996 } |
|
1997 |
|
1998 |
|
1999 |
|
2000 void HCR::TRepositoryCompiled::GetSettingRef(TInt32 aIndex, |
|
2001 HCR::TSettingRef& aRef) |
|
2002 { |
|
2003 __NK_ASSERT_DEBUG(iRepos != 0); |
|
2004 __NK_ASSERT_DEBUG(iRepos->iHdr != 0); |
|
2005 __NK_ASSERT_DEBUG(aIndex >=0 && aIndex < iRepos->iHdr->iNumSettings); |
|
2006 |
|
2007 if ((iRepos->iHdr->iNumSettings == 0) || (iRepos->iOrderedSettingList == 0)) |
|
2008 { |
|
2009 aRef.iRep = NULL; |
|
2010 aRef.iSet = NULL; |
|
2011 } |
|
2012 |
|
2013 //Get the pointer to the repository data |
|
2014 SSettingC* arr = iRepos->iOrderedSettingList; |
|
2015 |
|
2016 aRef.iRep = this; |
|
2017 aRef.iSet = &(arr[aIndex].iName); |
|
2018 } |
|
2019 |
|
2020 |
|
2021 TInt HCR::TRepositoryCompiled::GetValue(const TSettingRef& aRef, UValueWord& aValue) |
|
2022 { |
|
2023 HCR_FUNC("TRepositoryCompiled::GetValue"); |
|
2024 if (!IsWordValue(aRef)) |
|
2025 HCR_TRACE_RETURN(KErrArgument); |
|
2026 |
|
2027 SSettingC* sptr = (SSettingC*)(aRef.iSet); |
|
2028 aValue = sptr->iValue.iLit; |
|
2029 return KErrNone; |
|
2030 } |
|
2031 |
|
2032 TInt HCR::TRepositoryCompiled::GetLargeValue(const TSettingRef& aRef, UValueLarge& aValue) |
|
2033 { |
|
2034 HCR_FUNC("TRepositoryCompiled::GetLargeValue"); |
|
2035 if (!IsLargeValue(aRef)) |
|
2036 HCR_TRACE_RETURN(KErrArgument); |
|
2037 |
|
2038 SSettingC* sptr = (SSettingC*)(aRef.iSet); |
|
2039 aValue = sptr->iValue.iPtr; |
|
2040 return KErrNone; |
|
2041 } |
|
2042 |
|
2043 |
|
2044 // -- METHODS ----------------------------------------------------------------- |
|
2045 // |
|
2046 // TRepositoryFile |
|
2047 |
|
2048 |
|
2049 HCR::TRepository* HCR::TRepositoryFile::New(const SRepositoryFile* aRepos) |
|
2050 { |
|
2051 HCR_FUNC("TRepositoryFile::New"); |
|
2052 |
|
2053 __NK_ASSERT_ALWAYS(aRepos != 0); |
|
2054 return new TRepositoryFile(aRepos); |
|
2055 } |
|
2056 |
|
2057 HCR::TRepositoryFile::TRepositoryFile(const SRepositoryFile* aRepos) |
|
2058 : iRepos(aRepos) |
|
2059 { |
|
2060 HCR_FUNC("TRepositoryFile"); |
|
2061 } |
|
2062 |
|
2063 HCR::TRepositoryFile::~TRepositoryFile() |
|
2064 { |
|
2065 HCR_FUNC("~TRepositoryFile"); |
|
2066 |
|
2067 #ifdef __WINS__ |
|
2068 // On target hardware the iRepos pointer always points to a file in the Core |
|
2069 // rom image and hence is not memory allocated on kernel heap. Hence it does |
|
2070 // not need to be freeded. |
|
2071 // When running under the emulator the file repositories are loaded into |
|
2072 // allocated memory which needs to be freed here. |
|
2073 |
|
2074 delete const_cast<SRepositoryFile*>(iRepos); |
|
2075 iRepos = 0; |
|
2076 #endif // __WINS__ |
|
2077 |
|
2078 } |
|
2079 |
|
2080 TInt HCR::TRepositoryFile::CheckIntegrity() |
|
2081 { |
|
2082 HCR_FUNC("TRepositoryFile::CheckIntegrity"); |
|
2083 |
|
2084 __NK_ASSERT_ALWAYS(this != 0); |
|
2085 __NK_ASSERT_ALWAYS(iRepos != 0); |
|
2086 |
|
2087 if ((*((TUint32*)&(iRepos->iHdr)) != 0x66524348) || |
|
2088 (iRepos->iHdr.iFormatVersion != 0x0001)) |
|
2089 HCR_TRACEMSG_RETURN("File Repository header describes an unsupported repository type", KErrCorrupt); |
|
2090 |
|
2091 HCR_TRACE2("File repository 0x%x contains %05d entries", iRepos, iRepos->iHdr.iNumSettings); |
|
2092 |
|
2093 SSettingF* arr = (SSettingF*) (iRepos+1); |
|
2094 TSettingId prev(0,0); |
|
2095 TInt rc=0; |
|
2096 for (int i=0; i < iRepos->iHdr.iNumSettings; i++, arr++) |
|
2097 { |
|
2098 __NK_ASSERT_ALWAYS(arr != 0); |
|
2099 HCR_TRACE3("Checking entry %05d - (0x%x,0x%x)", i, arr->iName.iId.iCat, arr->iName.iId.iKey); |
|
2100 rc = CompareSSettingIds(prev, arr->iName.iId); |
|
2101 // Check for duplicates that reside next to each other |
|
2102 if ((i > 0) && (rc == 0)) |
|
2103 HCR_TRACE_RETURN (KErrAlreadyExists); |
|
2104 // Check that the entries are in ascending order |
|
2105 if (rc != -1) |
|
2106 HCR_TRACE_RETURN (KErrCorrupt); |
|
2107 prev = arr->iName.iId; |
|
2108 } |
|
2109 return KErrNone; |
|
2110 } |
|
2111 |
|
2112 TInt HCR::TRepositoryFile::FindSetting(const TSettingId& aId, TSettingRef& aSetting) |
|
2113 { |
|
2114 HCR_FUNC("TRepositoryFile::FindSetting"); |
|
2115 |
|
2116 __NK_ASSERT_DEBUG(iRepos != 0); |
|
2117 |
|
2118 if (iRepos->iHdr.iNumSettings == 0) |
|
2119 HCR_TRACE_RETURN(KErrNotFound); |
|
2120 |
|
2121 SSettingF* arr = (SSettingF*) (iRepos+1); |
|
2122 int low = 0; |
|
2123 int high = iRepos->iHdr.iNumSettings-1; |
|
2124 int mid; |
|
2125 int com; |
|
2126 |
|
2127 while (low<=high) |
|
2128 { |
|
2129 mid = (low+high) >> 1; |
|
2130 com = CompareSSettingIds(aId, arr[mid].iName.iId); |
|
2131 if (com < 0) |
|
2132 high = mid-1; |
|
2133 else if (com > 0) |
|
2134 low = mid+1; |
|
2135 else |
|
2136 { |
|
2137 aSetting.iRep = this; |
|
2138 aSetting.iSet = &((arr[mid]).iName); |
|
2139 return KErrNone; |
|
2140 } |
|
2141 } |
|
2142 |
|
2143 aSetting.iRep = 0; |
|
2144 aSetting.iSet = 0; |
|
2145 return KErrNotFound; |
|
2146 } |
|
2147 |
|
2148 |
|
2149 TInt HCR::TRepositoryFile::FindSetting (const TSettingId& aId, |
|
2150 TSettingRef& aSetting, TInt32& aPosition, TInt32 aLow, TInt32 aHigh) |
|
2151 { |
|
2152 HCR_FUNC("TRepositoryFile::FindSetting within the given range"); |
|
2153 |
|
2154 |
|
2155 __NK_ASSERT_DEBUG(iRepos != 0); |
|
2156 |
|
2157 if (iRepos->iHdr.iNumSettings == 0) |
|
2158 HCR_TRACE_RETURN(KErrNotFound); |
|
2159 |
|
2160 SSettingF* arr = (SSettingF*) (iRepos+1); |
|
2161 TInt32 low = aLow; |
|
2162 TInt32 high = aHigh; |
|
2163 TInt32 mid; |
|
2164 TInt32 com; |
|
2165 |
|
2166 while (low<=high) |
|
2167 { |
|
2168 mid = (low+high) >> 1; |
|
2169 com = CompareSSettingIds(aId, arr[mid].iName.iId); |
|
2170 if (com < 0) |
|
2171 high = mid-1; |
|
2172 else if (com > 0) |
|
2173 low = mid+1; |
|
2174 else |
|
2175 { |
|
2176 aSetting.iRep = this; |
|
2177 aSetting.iSet = &((arr[mid]).iName); |
|
2178 aPosition = mid; |
|
2179 return KErrNone; |
|
2180 } |
|
2181 } |
|
2182 |
|
2183 aSetting.iRep = 0; |
|
2184 aSetting.iSet = 0; |
|
2185 aPosition = 0; |
|
2186 return KErrNotFound; |
|
2187 } |
|
2188 |
|
2189 |
|
2190 |
|
2191 |
|
2192 TInt HCR::TRepositoryFile::GetWordSettings(TInt aNum, |
|
2193 SSettingId* aIds[], TInt32* aValues[], TSettingType* aTypes[], |
|
2194 TInt* aErrors[]) |
|
2195 { |
|
2196 HCR_FUNC("TRepositoryFile::GetWordSettings"); |
|
2197 |
|
2198 |
|
2199 __NK_ASSERT_DEBUG(iRepos != 0); |
|
2200 |
|
2201 if (iRepos->iHdr.iNumSettings == 0) |
|
2202 return KErrNotFound; |
|
2203 |
|
2204 TInt err = KErrNone; |
|
2205 |
|
2206 TInt32 rMaxIndex = 0; |
|
2207 TInt32 rMinIndex = 0; |
|
2208 TInt32 uFirstIndex = 0; |
|
2209 TInt32 uLastIndex = 0; |
|
2210 TInt32 rIndex = 0; |
|
2211 TInt32 uIndex = 0; |
|
2212 |
|
2213 TSettingRef settingRef(NULL, NULL); |
|
2214 SSettingF* pSetting = NULL; |
|
2215 |
|
2216 //Find position index within the repository for the first and last setting |
|
2217 //from user supplied array aIds[] |
|
2218 uIndex = 0; |
|
2219 TBool isRedefined = EFalse; |
|
2220 err = KErrNotFound; |
|
2221 uFirstIndex = 0; |
|
2222 while(!isRedefined && uIndex < aNum) |
|
2223 { |
|
2224 //Find first setting from user array. The importance here is that we |
|
2225 //should get value of first setting index in the repository in rMinIndex. |
|
2226 //This time the scope of search is whole repository. |
|
2227 err = this->FindSetting(*aIds[uIndex],settingRef, rMinIndex, |
|
2228 0, iRepos->iHdr.iNumSettings); |
|
2229 if(err == KErrNotFound) |
|
2230 { |
|
2231 *aErrors[uIndex] = err; |
|
2232 *aValues[uIndex] = 0; |
|
2233 //Copy type only if user provided aTypes array |
|
2234 if(aTypes) |
|
2235 *aTypes[uIndex] = ETypeUndefined; |
|
2236 |
|
2237 //As FindSetting did not find the element, let's challenge with |
|
2238 //the next one from aIds[] array |
|
2239 uIndex ++; |
|
2240 continue; |
|
2241 } |
|
2242 //fatal error here, nothing to do, just exit and return the error code |
|
2243 else if(err == KErrNotReady || err != KErrNone) |
|
2244 { |
|
2245 return err; |
|
2246 } |
|
2247 else // err == KErrNone |
|
2248 { |
|
2249 //Get the value and type |
|
2250 pSetting = (SSettingF*) settingRef.iSet; |
|
2251 //again copy the type value into the user array if it's provided |
|
2252 if(aTypes) |
|
2253 *aTypes[uIndex] = static_cast<TSettingType>(settingRef.iSet->iType); |
|
2254 |
|
2255 //Check for the found type is this word size? If it's not then |
|
2256 //indicate error for this setting |
|
2257 if(*aTypes[uIndex] > ETypeLinAddr) |
|
2258 { |
|
2259 *aErrors[uIndex] = KErrArgument; |
|
2260 *aValues[uIndex] = 0; |
|
2261 } |
|
2262 else |
|
2263 { |
|
2264 *aErrors[uIndex] = KErrNone; |
|
2265 *aValues[uIndex] = pSetting->iValue.iLit.iInt32; |
|
2266 } |
|
2267 |
|
2268 //Break the loop by setting the redefined status |
|
2269 isRedefined = ETrue; |
|
2270 } |
|
2271 } |
|
2272 |
|
2273 //At this point we should find at least one element, store this index in the |
|
2274 //local variable, this is used later in the code. Please be noticed we've |
|
2275 //also got rMinIndex - first setting index in the repository. |
|
2276 if(err == KErrNone) |
|
2277 uFirstIndex = uIndex; |
|
2278 else |
|
2279 //if we are hear it means we did not find any user settings at all |
|
2280 //we can't do any thing and just return KErrNotFound to indicate |
|
2281 //this fact |
|
2282 return KErrNotFound; |
|
2283 |
|
2284 |
|
2285 |
|
2286 //Now lets find the last setting |
|
2287 uIndex = aNum - 1; |
|
2288 isRedefined = EFalse; |
|
2289 err = KErrNotFound; |
|
2290 |
|
2291 while(!isRedefined && uIndex > uFirstIndex) |
|
2292 { |
|
2293 //Find the last setting from user array. The importance here is that we |
|
2294 //should get value of first setting index in the repository in |
|
2295 //rMinIndex. This time the scope of search is whole repository. |
|
2296 err = this->FindSetting(*aIds[uIndex],settingRef, rMaxIndex, |
|
2297 rMinIndex, iRepos->iHdr.iNumSettings); |
|
2298 if(err == KErrNotFound) |
|
2299 { |
|
2300 *aErrors[uIndex] = err; |
|
2301 *aValues[uIndex] = 0; |
|
2302 if(aTypes) |
|
2303 *aTypes[uIndex] = ETypeUndefined; |
|
2304 |
|
2305 //As FindSetting did not find the element, let's challenge with |
|
2306 //previous one |
|
2307 uIndex --; |
|
2308 continue; |
|
2309 } |
|
2310 //fatal error here, nothing to do, just exit and return the error code |
|
2311 else if(err == KErrNotReady || err != KErrNone) |
|
2312 { |
|
2313 return err; |
|
2314 } |
|
2315 else //err == KErrNone |
|
2316 { |
|
2317 pSetting = (SSettingF*) settingRef.iSet; |
|
2318 if(aTypes) |
|
2319 *aTypes[uIndex] = static_cast<TSettingType>(settingRef.iSet->iType); |
|
2320 |
|
2321 //Check for the found type is this word size? If it's not then indicate |
|
2322 //error for this setting |
|
2323 if(*aTypes[uIndex] > ETypeLinAddr) |
|
2324 { |
|
2325 *aErrors[uIndex] = KErrArgument; |
|
2326 *aValues[uIndex] = 0; |
|
2327 } |
|
2328 else |
|
2329 { |
|
2330 *aErrors[uIndex] = KErrNone; |
|
2331 *aValues[uIndex] = pSetting->iValue.iLit.iInt32; |
|
2332 } |
|
2333 |
|
2334 isRedefined = ETrue; |
|
2335 } |
|
2336 } |
|
2337 |
|
2338 //At this point we found the last setting, store it's user array index in |
|
2339 //the local variable, this is used later in the code. Please be noticed |
|
2340 //we've also got rMaxIndex - last setting index in the repository. |
|
2341 if(err == KErrNone) |
|
2342 uLastIndex = uIndex; |
|
2343 else |
|
2344 //if we are here we did not find any other elements than was found |
|
2345 //in previous iteration then just stop here |
|
2346 return KErrNotFound; |
|
2347 |
|
2348 //The scope of user array settings in the repository is found. |
|
2349 //Let's find all other settings from user array. Bare in mind the low |
|
2350 //bound for the repository index is increased each iteration to optimize the |
|
2351 //search time. |
|
2352 for(uIndex = uFirstIndex + 1; uIndex < uLastIndex; uIndex ++) |
|
2353 { |
|
2354 err = this->FindSetting(*aIds[uIndex],settingRef, rIndex, |
|
2355 rMinIndex, rMaxIndex); |
|
2356 if(err == KErrNotFound) |
|
2357 { |
|
2358 *aErrors[uIndex] = err; |
|
2359 *aValues[uIndex] = 0; |
|
2360 if(aTypes) |
|
2361 *aTypes[uIndex] = ETypeUndefined; |
|
2362 |
|
2363 //As FindSetting did not find the element, let's challenge with |
|
2364 //another one |
|
2365 continue; |
|
2366 } |
|
2367 else if(err == KErrNotReady || err != KErrNone) |
|
2368 { |
|
2369 return err; |
|
2370 } |
|
2371 else //err == KErrNone |
|
2372 { |
|
2373 |
|
2374 pSetting = (SSettingF*) settingRef.iSet; |
|
2375 |
|
2376 TSettingType type = static_cast<TSettingType>(settingRef.iSet->iType); |
|
2377 if(aTypes != NULL) |
|
2378 *aTypes[uIndex] = type; |
|
2379 |
|
2380 //Check for the found type is this word size? If it's not then indicate |
|
2381 //error for this setting |
|
2382 if(type > ETypeLinAddr) |
|
2383 { |
|
2384 *aErrors[uIndex] = KErrArgument; |
|
2385 *aValues[uIndex] = 0; |
|
2386 } |
|
2387 else |
|
2388 { |
|
2389 *aErrors[uIndex] = KErrNone; |
|
2390 *aValues[uIndex] = pSetting->iValue.iLit.iInt32; |
|
2391 } |
|
2392 |
|
2393 rMinIndex = rIndex + 1; |
|
2394 } |
|
2395 |
|
2396 } |
|
2397 |
|
2398 return KErrNone; |
|
2399 } |
|
2400 |
|
2401 |
|
2402 |
|
2403 void HCR::TRepositoryFile::GetSettingRef(TInt32 aIndex, |
|
2404 HCR::TSettingRef& aSetRef) |
|
2405 { |
|
2406 __NK_ASSERT_DEBUG(iRepos != 0); |
|
2407 __NK_ASSERT_DEBUG(aIndex >= 0 && aIndex < iRepos->iHdr.iNumSettings); |
|
2408 |
|
2409 if (iRepos->iHdr.iNumSettings == 0) |
|
2410 { |
|
2411 aSetRef.iRep = NULL; |
|
2412 aSetRef.iSet = NULL; |
|
2413 } |
|
2414 |
|
2415 SSettingF* arr = (SSettingF*)(iRepos + 1); |
|
2416 |
|
2417 aSetRef.iRep = this; |
|
2418 aSetRef.iSet = &(arr[aIndex].iName); |
|
2419 } |
|
2420 |
|
2421 |
|
2422 |
|
2423 |
|
2424 TInt HCR::TRepositoryFile::FindNumSettingsInCategory(TCategoryUid aCatUid, |
|
2425 TInt32& aFirst, TInt32& aLast) |
|
2426 { |
|
2427 HCR_FUNC("TRepositoryFile::FindNumSettingsInCategory"); |
|
2428 |
|
2429 __NK_ASSERT_DEBUG(iRepos != 0); |
|
2430 |
|
2431 if (iRepos->iHdr.iNumSettings == 0) |
|
2432 HCR_TRACE_RETURN(KErrNotFound); |
|
2433 |
|
2434 SSettingF* arr = (SSettingF*) (iRepos+1); |
|
2435 TInt32 low = 0; |
|
2436 TInt32 high = iRepos->iHdr.iNumSettings-1; |
|
2437 TInt32 mid = 0; |
|
2438 TInt32 com = 0; |
|
2439 |
|
2440 |
|
2441 //Let's find any setting within the category, mid will store the setting |
|
2442 //index in the repository |
|
2443 while (low<=high) |
|
2444 { |
|
2445 mid = (low+high) >> 1; |
|
2446 com = CompareByCategory(aCatUid, arr[mid].iName.iId); |
|
2447 if (com < 0) |
|
2448 high = mid-1; |
|
2449 else if (com > 0) |
|
2450 low = mid+1; |
|
2451 else |
|
2452 { |
|
2453 break; |
|
2454 } |
|
2455 } |
|
2456 |
|
2457 // If no one setting with the given category was found the return error |
|
2458 // to the user |
|
2459 if(low > high) |
|
2460 { |
|
2461 aFirst = 0; |
|
2462 aLast = 0; |
|
2463 return KErrNotFound; |
|
2464 } |
|
2465 |
|
2466 //Search the first element within the category |
|
2467 low = mid; |
|
2468 while(low > 0 && arr[low].iName.iId.iCat == aCatUid) |
|
2469 { |
|
2470 low --; |
|
2471 } |
|
2472 //Check the boundary conditions, there are two cases when we exit the loop |
|
2473 //either we found an element which category is not one we are looking for or |
|
2474 //we reach the beggining of the repository. If we reach the beggining of the |
|
2475 //repository we don't really know is it because this is last elment or it |
|
2476 //has required aCatUid, so we check these two conditions below |
|
2477 if(low == 0 && arr[low].iName.iId.iCat == aCatUid) |
|
2478 aFirst = low; |
|
2479 //We finish the loop either reaching the setting which category id is not |
|
2480 //what we need or this is first setting in the repository again with another |
|
2481 //category, so in both case we throw this element from the account. |
|
2482 else |
|
2483 aFirst = low + 1; |
|
2484 |
|
2485 |
|
2486 //Search the last element within the category |
|
2487 high = mid; |
|
2488 while(high < iRepos->iHdr.iNumSettings && arr[high].iName.iId.iCat == aCatUid) |
|
2489 { |
|
2490 high ++; |
|
2491 } |
|
2492 //Same situation as above, boundary conditions |
|
2493 if(high == (iRepos->iHdr.iNumSettings - 1) && arr[high].iName.iId.iCat == aCatUid) |
|
2494 aLast = high; |
|
2495 else |
|
2496 aLast = high -1; |
|
2497 |
|
2498 return KErrNone; |
|
2499 } |
|
2500 |
|
2501 |
|
2502 |
|
2503 |
|
2504 TInt HCR::TRepositoryFile::GetValue(const TSettingRef& aRef, UValueWord& aValue) |
|
2505 { |
|
2506 HCR_FUNC("TRepositoryFile::GetValue"); |
|
2507 |
|
2508 if (!IsWordValue(aRef)) |
|
2509 HCR_TRACE_RETURN(KErrArgument); |
|
2510 |
|
2511 SSettingF* sptr = (SSettingF*)(aRef.iSet); |
|
2512 aValue = sptr->iValue.iLit; |
|
2513 return KErrNone; |
|
2514 } |
|
2515 |
|
2516 |
|
2517 TInt HCR::TRepositoryFile::GetLargeValue(const TSettingRef& aRef, UValueLarge& aValue) |
|
2518 { |
|
2519 HCR_FUNC("TRepositoryFile::GetLargeValue"); |
|
2520 |
|
2521 if (!IsLargeValue(aRef)) |
|
2522 HCR_TRACE_RETURN(KErrArgument); |
|
2523 |
|
2524 SSettingF* sptr = (SSettingF*)(aRef.iSet); |
|
2525 TRepositoryFile *rptr = (TRepositoryFile *)(aRef.iRep); |
|
2526 |
|
2527 aValue.iData = (TUint8*) rptr->iRepos; |
|
2528 aValue.iData += rptr->iRepos->iLSDfirstByteOffset+sptr->iValue.iOffset; |
|
2529 |
|
2530 return KErrNone; |
|
2531 } |
|
2532 |
|
2533 |
|
2534 // -- FUNCTIONS --------------------------------------------------------------- |
|
2535 |
|
2536 #ifndef HCRTEST_NO_KEXT_ENTRY_POINT |
|
2537 #ifndef __WINS__ |
|
2538 DECLARE_EXTENSION_WITH_PRIORITY(KExtensionMaximumPriority) |
|
2539 #else |
|
2540 DECLARE_STANDARD_EXTENSION() |
|
2541 #endif // __WINS__ |
|
2542 { |
|
2543 HCR_FUNC("InitExtension"); |
|
2544 |
|
2545 HCR::MVariant* varPtr = CreateHCRVariant(); |
|
2546 if (varPtr==0) |
|
2547 HCR_TRACE_RETURN(KErrNoMemory); |
|
2548 |
|
2549 //Call of the "placement" new operator, which constructs the HCR object on |
|
2550 //the global memory address defined by gHCR and initialized with the same |
|
2551 //data given by constructor below |
|
2552 new(&gHCR) HCR::HCRInternal(varPtr); |
|
2553 |
|
2554 TInt err = HCRSingleton->Initialise(); |
|
2555 |
|
2556 if (err != KErrNone) |
|
2557 HCR_TRACE_RETURN(err); |
|
2558 |
|
2559 return err; |
|
2560 } |
|
2561 #endif // HCRTEST_NO_KEXT_ENTRY_POINT |
|
2562 |
|
2563 // -- Implementation of local functions |
|
2564 #ifndef __WINS__ |
|
2565 TInt SearchEntryInTRomDir(const TRomDir* aActDir, const TPtrC aFileName, TRomEntry* &aEntry) |
|
2566 { |
|
2567 HCR_FUNC("SearchEntryInTRomDir"); |
|
2568 TInt retVal = KErrNotFound; |
|
2569 HCR_TRACE2("--- aFileName: %S (%d)", &aFileName, aFileName.Length()); |
|
2570 |
|
2571 if( aActDir == 0) |
|
2572 { |
|
2573 HCR_TRACE_RETURN(retVal); |
|
2574 } |
|
2575 |
|
2576 TInt dirSize = aActDir->iSize; |
|
2577 aEntry = (TRomEntry*)&aActDir->iEntry; |
|
2578 HCR_TRACE3("--- dirSize: 0x%08x (%d), aEntry: 0x%08x", dirSize, dirSize, aEntry); |
|
2579 |
|
2580 TBool found = EFalse; |
|
2581 while( !found ) |
|
2582 { |
|
2583 TInt nameLength = (aEntry->iNameLength)<<1; |
|
2584 |
|
2585 // Uncommnet to get dump of ROM data when debugging.... |
|
2586 // HCR_TRACE0("Begin of loop..."); |
|
2587 // HCR_HEX_DUMP_ABS((TUint8 *)aEntry, sizeof(TRomEntry)+(nameLength - 2) ); |
|
2588 const TText* entryName = &aEntry->iName[0]; |
|
2589 HCR_TRACE1("--- entryName length: %d", nameLength); |
|
2590 TBuf<512> newEntryName( nameLength); |
|
2591 for( TInt i = 0; i != nameLength; ++i) |
|
2592 { |
|
2593 newEntryName[i] = (unsigned char)('A' <= entryName[i] && 'Z' >= entryName[i]? entryName[i]+('a'-'A'): entryName[i]); |
|
2594 } |
|
2595 |
|
2596 HCR_TRACE6("--- aFileName: %S (%d/%d), newEntryName: %S (%d/%d)", &aFileName, aFileName.Length(), aFileName.Size(), &newEntryName, newEntryName.Length(), newEntryName.Size()); |
|
2597 TInt r = aFileName.Compare(newEntryName); |
|
2598 HCR_TRACE1("--- result of CompareFileNames: 0x%08x", r); |
|
2599 |
|
2600 if ( r == 0) |
|
2601 { |
|
2602 found = ETrue; |
|
2603 HCR_TRACE1("--- aEntry: 0x%08x", aEntry); |
|
2604 } |
|
2605 else |
|
2606 { |
|
2607 |
|
2608 TInt entrySize = sizeof(TRomEntry) + (nameLength - 2); |
|
2609 HCR_TRACE2("--- entrySize: 0x%08x, (%d)", entrySize, entrySize); |
|
2610 |
|
2611 // The entrySize must be aligned to 4 bytes boundary |
|
2612 entrySize = ((entrySize&0x03) == 0 ? entrySize : ((entrySize&0xfffffffc) + 4)); |
|
2613 HCR_TRACE2("--- entrySize: 0x%08x, (%d)", entrySize, entrySize); |
|
2614 |
|
2615 aEntry = (TRomEntry*)((char *)aEntry + entrySize); |
|
2616 dirSize -= entrySize; |
|
2617 HCR_TRACE2("--- aEntry: 0x%08x, dirSize:%d", aEntry, dirSize); |
|
2618 if( dirSize <= 0) |
|
2619 { |
|
2620 break; |
|
2621 } |
|
2622 } |
|
2623 } |
|
2624 |
|
2625 if( found) |
|
2626 { |
|
2627 retVal = KErrNone; |
|
2628 } |
|
2629 |
|
2630 HCR_TRACE_RETURN(retVal); |
|
2631 } |
|
2632 |
|
2633 #endif // !__WINS__ |
|
2634 |
|
2635 |
|
2636 TInt SearchCoreImgRepository(HCR::TRepository*& aRepos, const TText * aFileName) |
|
2637 { |
|
2638 HCR_FUNC("SearchCoreImgRepository(TRepository*& aRepos, TText & aFileName)"); |
|
2639 |
|
2640 TInt retVal = KErrNotFound; |
|
2641 |
|
2642 // Convert aFileName to directory entry style Unicode |
|
2643 const TText* p = aFileName; |
|
2644 |
|
2645 if( *p == 0) |
|
2646 { |
|
2647 // Empty file name -> return with KErrNotFound! |
|
2648 HCR_TRACE_RETURN(retVal); |
|
2649 } |
|
2650 |
|
2651 while( *(++p)) {}; // Search the end of file name string. |
|
2652 TInt nameLen=(TInt)(p-aFileName); |
|
2653 |
|
2654 HCR_TRACE2("--- aFileName: %s (%d)", aFileName, nameLen ); |
|
2655 |
|
2656 TBuf<256> origFileName; |
|
2657 origFileName.Append((const TText*)aFileName, nameLen); |
|
2658 HCR_TRACE2("--- origFileName: %S (%d)", &origFileName, origFileName.Length()); |
|
2659 |
|
2660 |
|
2661 #ifdef __WINS__ |
|
2662 TBuf<KMaxFileName> wholeFilePath; |
|
2663 void* reposBuf = 0; |
|
2664 |
|
2665 #ifdef __VC32__ |
|
2666 |
|
2667 #ifdef _DEBUG |
|
2668 // - wins udeb version |
|
2669 wholeFilePath.Copy((const TText*)"\\EPOC32\\RELEASE\\WINS\\UDEB\\"); |
|
2670 #else |
|
2671 // - wins urel version |
|
2672 wholeFilePath.Copy((const TText*)"\\EPOC32\\RELEASE\\WINS\\UREL\\"); |
|
2673 #endif |
|
2674 |
|
2675 #else |
|
2676 |
|
2677 #ifdef _DEBUG |
|
2678 // - winscw udeb version |
|
2679 wholeFilePath.Copy((const TText*)"\\EPOC32\\RELEASE\\WINSCW\\UDEB\\"); |
|
2680 #else |
|
2681 // - winscw urel version |
|
2682 wholeFilePath.Copy((const TText*)"\\EPOC32\\RELEASE\\WINSCW\\UREL\\"); |
|
2683 #endif |
|
2684 |
|
2685 #endif |
|
2686 |
|
2687 for( TInt j = 0; j < nameLen; ++j) |
|
2688 { |
|
2689 wholeFilePath.Append( origFileName[j] ); |
|
2690 } |
|
2691 |
|
2692 HCR_TRACE3("--- epoc emulator file path: %S (%d/%d)", &wholeFilePath, wholeFilePath.Length(), wholeFilePath.Size()); |
|
2693 |
|
2694 TInt length = wholeFilePath.Length(); |
|
2695 |
|
2696 NKern::ThreadEnterCS(); |
|
2697 TCHAR* chFilePath = new TCHAR[length+1]; |
|
2698 NKern::ThreadLeaveCS(); |
|
2699 |
|
2700 for(int loop=0;loop<length;++loop) |
|
2701 { |
|
2702 chFilePath[loop] = wholeFilePath[loop]; |
|
2703 } |
|
2704 chFilePath[length] = '\0'; |
|
2705 |
|
2706 //try to locate file |
|
2707 WIN32_FIND_DATAW wfd; |
|
2708 HANDLE hFile = FindFirstFile(chFilePath, &wfd); |
|
2709 TBool foundFile = EFalse; |
|
2710 if (hFile == INVALID_HANDLE_VALUE) |
|
2711 { |
|
2712 HCR_TRACE0("--- file not found in \\sys\\bin; try \\sys\\data"); |
|
2713 |
|
2714 #ifdef __VC32__ |
|
2715 |
|
2716 #ifdef _DEBUG |
|
2717 // - wins udeb version |
|
2718 wholeFilePath.Copy((const TText*)"\\EPOC32\\RELEASE\\WINS\\UDEB\\Z\\sys\\data\\"); |
|
2719 #else |
|
2720 // - wins urel version |
|
2721 wholeFilePath.Copy((const TText*)"\\EPOC32\\RELEASE\\WINS\\UREL\\Z\\sys\\data\\"); |
|
2722 #endif |
|
2723 |
|
2724 #else |
|
2725 |
|
2726 #ifdef _DEBUG |
|
2727 // - winscw udeb version |
|
2728 wholeFilePath.Copy((const TText*)"\\EPOC32\\RELEASE\\WINSCW\\UDEB\\Z\\sys\\data\\"); |
|
2729 #else |
|
2730 // - winscw urel version |
|
2731 wholeFilePath.Copy((const TText*)"\\EPOC32\\RELEASE\\WINSCW\\UREL\\Z\\sys\\data\\"); |
|
2732 #endif |
|
2733 |
|
2734 #endif |
|
2735 |
|
2736 for( TInt i = 0; i < nameLen; ++i) |
|
2737 { |
|
2738 wholeFilePath.Append( origFileName[i] ); |
|
2739 } |
|
2740 |
|
2741 HCR_TRACE3("--- epoc emulator file path: %S (%d/%d)", &wholeFilePath, wholeFilePath.Length(), wholeFilePath.Size()); |
|
2742 |
|
2743 length = wholeFilePath.Length(); |
|
2744 |
|
2745 NKern::ThreadEnterCS(); |
|
2746 delete[] chFilePath; |
|
2747 chFilePath = new TCHAR[length+1]; |
|
2748 NKern::ThreadLeaveCS(); |
|
2749 |
|
2750 for(int loop=0;loop<length;++loop) |
|
2751 { |
|
2752 chFilePath[loop] = wholeFilePath[loop]; |
|
2753 } |
|
2754 chFilePath[length] = '\0'; |
|
2755 |
|
2756 hFile = FindFirstFile(chFilePath, &wfd); |
|
2757 |
|
2758 if (hFile == INVALID_HANDLE_VALUE) |
|
2759 { |
|
2760 HCR_TRACE0("--- file not found in \\sys\\data"); |
|
2761 } |
|
2762 else |
|
2763 { |
|
2764 HCR_TRACE0("--- file found in \\sys\\data"); |
|
2765 foundFile = ETrue; |
|
2766 } |
|
2767 } |
|
2768 else |
|
2769 { |
|
2770 HCR_TRACE0("--- file found in \\sys\\bin"); |
|
2771 foundFile = ETrue; |
|
2772 } |
|
2773 |
|
2774 if(!foundFile) |
|
2775 { |
|
2776 // No file found; release memory and return |
|
2777 NKern::ThreadEnterCS(); |
|
2778 delete[] chFilePath; |
|
2779 NKern::ThreadLeaveCS(); |
|
2780 |
|
2781 HCR_TRACE_RETURN(KErrNotFound); |
|
2782 } |
|
2783 |
|
2784 |
|
2785 __NK_ASSERT_ALWAYS(wfd.nFileSizeHigh==0); |
|
2786 |
|
2787 DWORD num_read = 0; |
|
2788 retVal = KErrNone; |
|
2789 |
|
2790 NKern::ThreadEnterCS(); |
|
2791 reposBuf = new BYTE[wfd.nFileSizeLow]; |
|
2792 NKern::ThreadLeaveCS(); |
|
2793 |
|
2794 if(reposBuf == NULL) |
|
2795 { |
|
2796 HCR_TRACEMSG_RETURN("--- Error allocating memory for reading file", KErrNoMemory); |
|
2797 } |
|
2798 else |
|
2799 { |
|
2800 hFile = CreateFile(chFilePath, GENERIC_READ, // open for reading |
|
2801 FILE_SHARE_READ, // share for reading |
|
2802 NULL, // default security |
|
2803 OPEN_EXISTING, // existing file only |
|
2804 FILE_ATTRIBUTE_NORMAL, // normal file |
|
2805 NULL); |
|
2806 |
|
2807 BOOL read = ReadFile(hFile, reposBuf, wfd.nFileSizeLow, &num_read, NULL); |
|
2808 if(!read) |
|
2809 { |
|
2810 retVal = GetLastError(); |
|
2811 HCR_TRACE1("--- Error reading file %d", GetLastError()); |
|
2812 } |
|
2813 } |
|
2814 |
|
2815 CloseHandle(hFile); |
|
2816 NKern::ThreadEnterCS(); |
|
2817 delete[] chFilePath; |
|
2818 NKern::ThreadLeaveCS(); |
|
2819 |
|
2820 NKern::ThreadEnterCS(); |
|
2821 aRepos = HCR::TRepositoryFile::New(reinterpret_cast<const HCR::SRepositoryFile *>(reposBuf)); |
|
2822 NKern::ThreadLeaveCS(); |
|
2823 |
|
2824 if (aRepos == NULL) |
|
2825 { |
|
2826 retVal = KErrNoMemory; |
|
2827 } |
|
2828 |
|
2829 HCR_TRACE_RETURN(retVal); |
|
2830 |
|
2831 #else |
|
2832 |
|
2833 TBuf<512> fileNameBuf; |
|
2834 for( TInt i = 0; i != nameLen; ++i) |
|
2835 { |
|
2836 fileNameBuf.Append( 'A' <= origFileName[i] && 'Z' >= origFileName[i]? origFileName[i]+('a'-'A'): origFileName[i]); |
|
2837 fileNameBuf.Append(TChar(0)); |
|
2838 } |
|
2839 |
|
2840 TPtrC fileName(fileNameBuf); |
|
2841 HCR_TRACE3("--- fileName: %S (%d/%d)", &fileName, fileName.Length(), fileName.Size()); |
|
2842 |
|
2843 // Locate ROM Root directory |
|
2844 TSuperPage& superpage = Kern::SuperPage(); |
|
2845 TRomRootDirectoryList* romRootDirAddress = (TRomRootDirectoryList*)superpage.iRootDirList; |
|
2846 |
|
2847 HCR_TRACE3("--- Superpage: 0x%08x, ROM root dir list: 0x%08x (Num of root dirs:%d)", &superpage, romRootDirAddress, romRootDirAddress->iNumRootDirs ); |
|
2848 |
|
2849 // Search the root directory which is match to the current hardware variant |
|
2850 TUint hardwareVariant = superpage.iActiveVariant; |
|
2851 TInt variantIndex; |
|
2852 TRootDirInfo* rootDirInfo = 0; |
|
2853 |
|
2854 for(variantIndex = 0; variantIndex < romRootDirAddress->iNumRootDirs; ++variantIndex ) |
|
2855 { |
|
2856 HCR_TRACE3("--- variantIndex:%d, current hardware variant: 0x%08x, root dir hardware variant:0x%08x", variantIndex, hardwareVariant, romRootDirAddress->iRootDir[variantIndex].iHardwareVariant); |
|
2857 |
|
2858 if( romRootDirAddress->iRootDir[variantIndex].iHardwareVariant == hardwareVariant) |
|
2859 { |
|
2860 rootDirInfo = &romRootDirAddress->iRootDir[variantIndex]; |
|
2861 break; |
|
2862 } |
|
2863 } |
|
2864 |
|
2865 if( rootDirInfo == 0 ) |
|
2866 { |
|
2867 // Not found root directory for this hardware variant |
|
2868 HCR_TRACE_RETURN(retVal); |
|
2869 } |
|
2870 |
|
2871 TRomDir* romDir = (TRomDir*)rootDirInfo->iAddressLin; |
|
2872 |
|
2873 HCR_TRACE3("--- romDir: 0x%08x (files:0x%08x, entries:0x%08x)", romDir, romDir->FileCount(), romDir->EntryCount() ); |
|
2874 TRomEntry* entry = (TRomEntry*)&romDir->iEntry; |
|
2875 |
|
2876 // We are searching in \sys\bin\ and \sys\Data\ directory only |
|
2877 TPtrC level1DirName((const TText*)"s\0y\0s\0", 6); // Unicode, because the entry names are unicode too. |
|
2878 TPtrC level2Dir1Name((const TText*)"b\0i\0n\0", 6); |
|
2879 TPtrC level2Dir2Name((const TText*)"d\0a\0t\0a\0", 8); // Originally \sys\Data however we search all entry in lower case |
|
2880 |
|
2881 TInt r = SearchEntryInTRomDir(romDir, level1DirName, entry); |
|
2882 HCR_TRACE1("--- result of SearchEntryInTRomDir: 0x%08x", r); |
|
2883 |
|
2884 if( r == KErrNone) |
|
2885 { |
|
2886 // \sys directory found. |
|
2887 romDir = (TRomDir*)entry->iAddressLin; |
|
2888 HCR_TRACE1("--- romDir: 0x%08x ", romDir); |
|
2889 |
|
2890 TRomDir* parentDir = romDir; |
|
2891 // Search in \sys\bin directory |
|
2892 r = SearchEntryInTRomDir(romDir, level2Dir1Name, entry); |
|
2893 |
|
2894 HCR_TRACE1("--- result of SearchEntryInTRomDir: 0x%08x", r); |
|
2895 if( r == KErrNone) |
|
2896 { |
|
2897 // \sys\bin directory found |
|
2898 romDir = (TRomDir*)entry->iAddressLin; |
|
2899 HCR_TRACE1("--- romDir: 0x%08x ", romDir); |
|
2900 // Search the repository file |
|
2901 r = SearchEntryInTRomDir(romDir, fileName, entry); |
|
2902 |
|
2903 HCR_TRACE1("--- result of SearchEntryInTRomDir: 0x%08x", r); |
|
2904 if( r == KErrNone) |
|
2905 { |
|
2906 // Repository file found |
|
2907 retVal = KErrNone; |
|
2908 HCR_TRACE1("--- Repository address: 0x%08x ", entry->iAddressLin); |
|
2909 #ifdef __EPOC32__ |
|
2910 // HCR design requires the core image file repository to be in the |
|
2911 // unpaged portion of the core ROM image. This check will Fault the |
|
2912 // kernel startup if this is not found to be the case, perhaps due |
|
2913 // to mis-configured obey files. |
|
2914 // Skipped on emulator builds as Epoc class in platform.h not |
|
2915 // defined. Hence support for core images not supported. |
|
2916 __NK_ASSERT_ALWAYS(ROMAddressIsInUnpagedSection((TLinAddr)entry->iAddressLin)); |
|
2917 #endif |
|
2918 NKern::ThreadEnterCS(); |
|
2919 aRepos = HCR::TRepositoryFile::New(reinterpret_cast<const HCR::SRepositoryFile *>(entry->iAddressLin)); |
|
2920 NKern::ThreadLeaveCS(); |
|
2921 if (aRepos == NULL) |
|
2922 retVal = KErrNoMemory; |
|
2923 |
|
2924 HCR_TRACE_RETURN(retVal); |
|
2925 } |
|
2926 } |
|
2927 |
|
2928 // \sys\bin directory or repository file in \sys\bin directory not found. |
|
2929 // Search \sys\Data directory |
|
2930 romDir = parentDir; |
|
2931 r = SearchEntryInTRomDir(romDir, level2Dir2Name, entry); |
|
2932 HCR_TRACE1("--- result of SearchEntryInTRomDir: 0x%08x", r); |
|
2933 if( r == KErrNone) |
|
2934 { |
|
2935 // \sys\Data directory found |
|
2936 romDir = (TRomDir*)entry->iAddressLin; |
|
2937 HCR_TRACE1("--- romDir: 0x%08x ", romDir); |
|
2938 |
|
2939 // Search repository file |
|
2940 r = SearchEntryInTRomDir(romDir, fileName, entry); |
|
2941 |
|
2942 HCR_TRACE1("--- result of SearchEntryInTRomDir: 0x%08x", r); |
|
2943 if( r == KErrNone) |
|
2944 { |
|
2945 // Repository file found |
|
2946 retVal = KErrNone; |
|
2947 HCR_TRACE1("--- Repository address: 0x%08x ", entry->iAddressLin); |
|
2948 #ifdef __EPOC32__ |
|
2949 // HCR design requires the core image file repository to be in the |
|
2950 // unpaged portion of the core ROM image. This check will Fault the |
|
2951 // kernel startup if this is not found to be the case, perhaps due |
|
2952 // to mis-configured obey files. |
|
2953 // Skipped on emulator builds as Epoc class in platform.h not |
|
2954 // defined. Hence support for core images not supported. |
|
2955 __NK_ASSERT_ALWAYS(ROMAddressIsInUnpagedSection((TLinAddr)entry->iAddressLin)); |
|
2956 #endif |
|
2957 NKern::ThreadEnterCS(); |
|
2958 aRepos = HCR::TRepositoryFile::New(reinterpret_cast<const HCR::SRepositoryFile *>(entry->iAddressLin)); |
|
2959 NKern::ThreadLeaveCS(); |
|
2960 if (aRepos == NULL) |
|
2961 retVal = KErrNoMemory; |
|
2962 } |
|
2963 } |
|
2964 } |
|
2965 |
|
2966 HCR_TRACE_RETURN(retVal); |
|
2967 #endif //ifdef __WINS__ |
|
2968 } |
|
2969 |
|
2970 TInt LocateCoreImgRepository(HCR::TRepository*& aRepos) |
|
2971 { |
|
2972 HCR_FUNC("LocateCoreImgRepository"); |
|
2973 |
|
2974 #ifdef HCRTEST_COREIMG_DONTUSE_ROMHDR |
|
2975 |
|
2976 // Use this testing more on Emulator platform |
|
2977 // and on hardware when ROM Header is not to be used or not implemented |
|
2978 |
|
2979 const TText8* hcrfile = (const TText8*) "hcr.dat"; |
|
2980 TInt retVal = SearchCoreImgRepository(aRepos, hcrfile); |
|
2981 if (retVal != KErrNone) |
|
2982 return retVal; |
|
2983 |
|
2984 #else |
|
2985 |
|
2986 const TRomHeader& romHeader = Epoc::RomHeader(); // 0x80000000; |
|
2987 HCR_TRACE2("--- ROM Header: 0x%08x, HCR file address: 0x%08x", &romHeader, romHeader.iHcrFileAddress); |
|
2988 |
|
2989 if(romHeader.iHcrFileAddress != 0) |
|
2990 { |
|
2991 #ifdef __EPOC32__ |
|
2992 // HCR design requires the core image file repository to be in the |
|
2993 // unpaged portion of the core ROM image. This check will Fault the |
|
2994 // kernel startup if this is not found to be the case, perhaps due |
|
2995 // to mis-configured obey files. |
|
2996 // Skipped on emulator builds as Epoc class in platform.h not |
|
2997 // defined. Hence support for core images not supported. |
|
2998 __NK_ASSERT_ALWAYS(ROMAddressIsInUnpagedSection((TLinAddr)romHeader.iHcrFileAddress)); |
|
2999 #endif |
|
3000 NKern::ThreadEnterCS(); |
|
3001 aRepos = HCR::TRepositoryFile::New(reinterpret_cast<const HCR::SRepositoryFile *>(romHeader.iHcrFileAddress)); |
|
3002 NKern::ThreadLeaveCS(); |
|
3003 if (aRepos == 0) |
|
3004 return KErrNoMemory; |
|
3005 } |
|
3006 else |
|
3007 return KErrNotFound; |
|
3008 |
|
3009 #endif // HCRTEST_COREIMG_DONTUSE_ROMHDR |
|
3010 |
|
3011 |
|
3012 return KErrNone; |
|
3013 } |
|
3014 |