Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Hardware Configuration Respoitory Platform Independent Layer (PIL)
18 // -- INCLUDES ----------------------------------------------------------------
21 #include "hcr_debug.h"
28 #include <nkern/nkern.h>
29 #include <kernel/kernel.h>
32 #include <plat_priv.h>
34 #include <kernel/kernboot.h>
40 // -- GLOBALS -----------------------------------------------------------------
42 GLDEF_C HCR::HCRInternal gHCR;
45 GLDEF_C TBuf<81> gTraceBuffer;
49 // -- Local functions prototypes
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.
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
62 LOCAL_C TInt LocateCoreImgRepository(HCR::TRepository*& aRepos);
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.
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.
73 @return KErrNone if successful
74 KErrNotFound if file not found in \sys\bin or \sys\Data
78 LOCAL_C TInt SearchCoreImgRepository(HCR::TRepository* & aRepos, const TText * aFileName);
81 Scanning a given directory for the given entry name. The entry name can be sub-directory or file.
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
87 @return KErrNone if the entry found
88 KErrNotFound if the entry not found
91 LOCAL_C TInt SearchEntryInTRomDir(const TRomDir* aActDir, const TPtrC aFileName, TRomEntry* &aEntry);
94 // -- WINS Specific ----------------------------------------------------------
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.
102 #undef HCRTEST_COREIMG_DONTUSE_ROMHDR
103 #define HCRTEST_COREIMG_DONTUSE_ROMHDR
107 // -- FUNCTIONS ---------------------------------------------------------------
110 Returns 1 when a1 > a2
111 Returns -1 when a1 < a2
112 Returns 0 when identical.
114 TInt CompareSSettingIds(const HCR::TSettingId& a1, const HCR::SSettingId& a2)
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);
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);
128 // Both Categories and jeys are the same here.
129 return (0); // HCR_TRACE_RETURN(0);
133 TBool ROMAddressIsInUnpagedSection(const TLinAddr address)
135 HCR_FUNC("ROMAddressIsInUnpagedSection");
137 const TRomHeader& romHdr = Epoc::RomHeader();
138 TLinAddr romBase = romHdr.iRomBase;
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);
143 if ((address < romBase) || (romBase > romBase+romHdr.iRomSize))
145 if (romHdr.iPageableRomStart == 0)
147 if (address < romBase+romHdr.iPageableRomStart)
154 TInt CompareByCategory(const HCR::TCategoryUid aCatId, const HCR::SSettingId& aSetId)
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);
162 // Both Categories and jeys are the same here.
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
179 * operator=() changes the memory ownership by
180 * reinitiazing SafeArray class object with the address to
181 * already allocated array.
184 HCR::TSa<T>& HCR::TSa<T>::operator=(T* aP)
192 // -- METHODS -----------------------------------------------------------------
196 HCR::HCRInternal::HCRInternal()
197 : iStatus(EStatConstructed), iVariant(0), iVariantStore(0), iCoreImgStore(0), iOverrideStore(0)
199 HCR_FUNC("HCRInternal(Defualt)");
202 HCR::HCRInternal::HCRInternal(HCR::MVariant* aVar)
203 : iVariant(aVar), iVariantStore(0), iCoreImgStore(0), iOverrideStore(0)
205 HCR_FUNC("HCRInternal");
208 HCR::HCRInternal::~HCRInternal()
210 HCR_FUNC("~HCRInternal");
219 delete iVariantStore;
224 delete iCoreImgStore;
229 delete iOverrideStore;
234 TUint32 HCR::HCRInternal::GetStatus()
236 HCR_FUNC("GetStatus");
241 TInt HCR::HCRInternal::Initialise()
243 HCR_FUNC("HCRInternal::Initialise");
248 // Variant PSL object must exist before PIL initalised.
250 err = KErrGeneral; goto failed; }
252 // Inform the PSL that we are initialising, give them an opportunity to do
253 // initialisation work too.
254 err = iVariant->Initialise();
258 iStatus = EStatVariantInitialised;
260 // Ask the PSL for the address of the SRepositoryCompiled object. PSL
261 // can return KErrNotSupported & NULL if compiled repository not
262 // used/support by PSL.
263 err = iVariant->GetCompiledRepositoryAddress(store);
266 if (store == 0) { // Programming error in PSL, ptr/rc mismatch
267 err = KErrArgument; goto failed; }
269 iVariantStore = TRepositoryCompiled::New(reinterpret_cast<const HCR::SRepositoryCompiled *>(store));
270 if (iVariantStore == 0) {
271 err = KErrNoMemory; goto failed; }
274 else if (err != KErrNotSupported)
278 // Ask the PSL if it wants the PIL not to search for the Core Image
279 // SRepositoryFile settings.
281 if (!iVariant->IgnoreCoreImgRepository())
283 err = LocateCoreImgRepository(iCoreImgStore);
286 if (iCoreImgStore == 0) {
287 err = KErrNoMemory; goto failed; }
289 else if (err != KErrNotFound)
294 // Ask the PSL for the address of the SRepositoryFile object. PSL
295 // can return KErrNotSupported & NULL if a local media based file
296 // repository is not used/support by PSL.
298 err = iVariant->GetOverrideRepositoryAddress(store);
301 if (store == 0) { // Programming error in PSL, ptr/rc mismatch
302 err = KErrArgument; goto failed; }
304 iOverrideStore = TRepositoryFile::New(reinterpret_cast<const HCR::SRepositoryFile *>(store));
305 if (iOverrideStore == 0) {
306 err = KErrNoMemory; goto failed; }
309 else if (err != KErrNotSupported)
312 iStatus = EStatInitialised;
314 // Sanity check here to ensure we have atleast one repository to use and run
315 // sanity check on their contents to look for ordering issues and duplicates.
316 HCR_TRACE3("=== HCR Ready: compiled:%x, coreimg:%x, override:%x", iVariantStore, iCoreImgStore, iOverrideStore);
317 if ((iVariantStore == 0) && (iCoreImgStore == 0) && (iOverrideStore == 0)) {
318 err = KErrArgument; goto failed; }
322 err = CheckIntegrity();
327 iStatus = EStatReady;
331 iStatus = (iStatus & EStatMinorMask) | EStatFailed;
332 HCR_TRACE_RETURN(err);
336 TInt HCR::HCRInternal::SwitchRepository(const TText * aFileName, const TReposId aId)
338 HCR_FUNC("HCRInternal::SwitchRepository");
340 TInt retVal = KErrNone;
341 TRepository* store = NULL;
343 if( aFileName != NULL)
345 retVal = SearchCoreImgRepository(store, aFileName);
346 HCR_TRACE2("--- SearchCoreImgRepository()->%d (0x%08x)", retVal, retVal);
349 if( retVal == KErrNone )
354 HCR_TRACE0("--- ECoreRepos");
357 NKern::ThreadEnterCS();
358 delete iCoreImgStore;
359 NKern::ThreadLeaveCS();
361 iCoreImgStore = store;
365 HCR_TRACE0("--- EOverrideRepos");
368 NKern::ThreadEnterCS();
369 delete iOverrideStore;
370 NKern::ThreadLeaveCS();
372 iOverrideStore = store;
376 HCR_TRACE0("--- default:");
377 retVal = KErrNotSupported;
382 HCR_TRACE_RETURN(retVal);
385 TInt HCR::HCRInternal::CheckIntegrity()
387 HCR_FUNC("HCRInternal::CheckIntegrity");
392 err = iVariantStore->CheckIntegrity();
394 HCR_TRACEMSG_RETURN("HCR iVariantStore failed integrity check", err);
399 err = iCoreImgStore->CheckIntegrity();
401 HCR_TRACEMSG_RETURN("HCR iCoreImgStore failed integrity check", err);
406 err = iOverrideStore->CheckIntegrity();
408 HCR_TRACEMSG_RETURN("HCR iOverrideStore failed integrity check", err);
411 HCR_TRACE0("=== HCR Repository integrity checks PASSED!");
416 TInt HCR::HCRInternal::FindSetting(const TSettingId& aId, TSettingType aType,
417 TSettingRef& aSetting)
419 HCR_FUNC("HCRInternal::FindSetting");
421 TBool found = EFalse;
423 HCR_TRACE3("--- Repository state: %x, %x, %x", iOverrideStore, iCoreImgStore, iVariantStore);
425 if (iOverrideStore &&
426 ((err = iOverrideStore->FindSetting(aId, aSetting)) == KErrNone))
428 __NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
432 ((err = iCoreImgStore->FindSetting(aId, aSetting)) == KErrNone))
434 __NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
438 ((err = iVariantStore->FindSetting(aId, aSetting)) == KErrNone))
440 __NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
442 HCR_TRACE3("--- Search results: %d, %d, %x", found, err, aSetting.iSet);
445 HCR_TRACE_RETURN(KErrNotFound);
447 // aSetting should now point to the found setting
448 __NK_ASSERT_DEBUG(aSetting.iSet != 0);
450 // Setting found at this point in the function
453 TSettingType type=static_cast<TSettingType>(aSetting.iRep->GetType(aSetting));
455 HCR_TRACE_RETURN(KErrArgument); // Wrong setting type
457 HCR_TRACE3("--- Setting found! ID: (%d,%d) Type: %d", aId.iCat, aId.iKey, type);
463 TInt HCR::HCRInternal::FindSettingWithType(const TSettingId& aId, TSettingType& aType,
464 TSettingRef& aSetting)
466 HCR_FUNC("HCRInternal::FindSettingWithType");
468 TBool found = EFalse;
470 HCR_TRACE3("--- Repository state: %x, %x, %x", iOverrideStore, iCoreImgStore, iVariantStore);
472 if (iOverrideStore &&
473 ((err = iOverrideStore->FindSetting(aId, aSetting)) == KErrNone))
475 __NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
479 ((err = iCoreImgStore->FindSetting(aId, aSetting)) == KErrNone))
481 __NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
485 ((err = iVariantStore->FindSetting(aId, aSetting)) == KErrNone))
487 __NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
489 HCR_TRACE3("--- Search results: %d, %d, %x", found, err, aSetting.iSet);
493 aType = ETypeUndefined;
494 HCR_TRACE_RETURN(KErrNotFound);
497 // aSetting should now point to the found setting
498 __NK_ASSERT_DEBUG(aSetting.iSet != 0);
500 // Setting found at this point in the function
503 aType=static_cast<TSettingType>(aSetting.iRep->GetType(aSetting));
505 HCR_TRACE3("--- Setting found! ID: (%d,%d) Type: %d", aId.iCat, aId.iKey, aType);
511 TInt HCR::HCRInternal::GetWordSettings(TInt aNum, const SSettingId aIds[],
512 TInt32 aValues[], TSettingType aTypes[], TInt aErrors[])
514 HCR_FUNC("++ HCRInternal::GetWordSettings");
515 HCR_TRACE3("--- Repository state: %x, %x, %x", iOverrideStore, iCoreImgStore, iVariantStore);
517 if(aNum <= 0 || aIds == NULL || aErrors == NULL)
518 HCR_TRACE_RETURN(KErrArgument);
521 //If the user only supplies a single setting then there is no reasons to
522 //continue with multiple searach and it should be limited by internal
523 //invocation of FindSettingWithType.
526 TSettingRef sref(0,0);
527 TSettingType* pTypes;
529 //aTypes array is optional and user may not provided it for us. So we
530 //need to be sure it's not a null pointer
533 //If this is a null pointer then just create our own element and
534 //assign it to the pTypes pointer
535 TSettingType types[1];
540 //else we use the user supplied array
544 //Let's find this setting
545 err = HCRSingleton->FindSettingWithType(aIds[0], *pTypes, sref);
547 //and analyse the result of operation
549 //If setting is not found or it's larger than 4 bytes then store this
550 //error cause in the user error array
551 if(err == KErrNotFound || err == KErrArgument)
553 //Indicate the error for the element and set the value to 0
558 //fatal error here, nothing to do, just exit and return the error code
559 else if(err == KErrNotReady || err != KErrNone)
561 HCR_TRACE_RETURN(err);
563 else //err == KErrNone
565 //Get the value of the setting
566 err = sref.iRep->GetValue(sref, reinterpret_cast<UValueWord&>(aValues[0]));
568 //The GetValue can only return either KErrArgument or KErrNone
569 if(err == KErrArgument)
571 aErrors[0] = KErrArgument;
575 else //err == KErrNone
577 aErrors[0] = KErrNone;
582 //This single setting was found so indicate it to the user
587 //Introducing a SafeArray of pointers to the settings, which is passed to ver-
588 //sion of GetWordSettings() method declared in TRepository, and implemented
589 //in TRepositoryCompiled and TRepositoryFile
590 TSa<SSettingId*> ids;
592 //SafeArray of pointers to the aValues user array elements
595 //SafeArray of pointers to the aErrors user array elements
598 //SafeArray of pointers to the aTypes user array elements
599 TSa<TSettingType*> types;
602 //Local replacement for the aTypes[] array if it's not provided by user
603 TSa<TSettingType> typesHolder;
605 //Allocate the arrays of pointers in the heap
606 ids = new SSettingId*[aNum];
607 values = new TInt32*[aNum];
608 errors = new TInt*[aNum];
609 types = new TSettingType*[aNum];
612 //Check all arrays allocations
613 if(!ids() || !values() || !errors() || !types())
615 //One of the allocation was unsuccessful
616 HCR_TRACE_RETURN(KErrNoMemory);
619 //If the user did not supply the aTypes array for us we need to create one
623 typesHolder = new TSettingType[aNum];
625 HCR_TRACE_RETURN(KErrNoMemory);
629 //Ininialize newly created array of pointers to the user supplied settings
630 for (TInt index = 0; index < aNum; index++)
632 ids[index] = const_cast<SSettingId*>(&aIds[index]);
633 values[index] = const_cast<TInt32*>(&aValues[index]);
634 errors[index] = &aErrors[index];
637 types[index] = &typesHolder[index];
639 types[index] = &aTypes[index];
643 //nfCount represents a total number of settings which were not found in all
647 //nfReposCount represents a number of settings "not found - nf" in the searched
649 TInt nfReposCount = 0;
651 //It represents a number of setting found in the repository
655 //First step through the Override store and gather all settings we need.
656 //In the end of this procedure we'll have number of settings not found here
657 //and found settings data are copied to the user arrays.
661 //Call the sibling method from the TRepositoryFile object
662 err = iOverrideStore->GetWordSettings(aNum, ids(),
663 values(), types(), errors());
665 //Analyse the err we've got
666 if(err != KErrNone && err != KErrNotFound)
668 HCR_TRACE_RETURN(err);
670 else if(err == KErrNone)
672 //Search for number of not found parameters
673 for(TInt index = 0; index < aNum; index ++)
675 switch(*(errors[index]))
677 //The setting was found or it's found but the type is larger
678 //than 4 bytes then we just increase a counter of the found
679 //settings in the repository
686 //The setting was not found, then re-initialize all the
687 //arrays of pointers with the pointer to this element.
688 //nfReposCount depict the counter of not found element and
689 //index shows the intial element position.
690 //As nfReposCount is always less or equal to index then we
691 //can easily make reassignment as nfReposCoun element was
692 //already analysed. In the end the nfReposCount is increased.
694 ids[nfReposCount] = ids[index];
695 values[nfReposCount] = values[index];
696 types[nfReposCount] = types[index];
697 errors[nfReposCount] = errors[index];
703 //No any action is needed
709 else //err == KErrNotFound
711 //No settings were found in the repository
712 //reposCount is zero intialized, so nothing to do here
715 //Update the global counter only if there are some settings were found,
716 //otherwise it can be situation when we overwrite the nfCount with zero
717 //when either no any setting presents or no settings were found in the
720 nfCount = nfReposCount;
723 //Go through core image and search for the rest of settings
727 if (iCoreImgStore && nfCount > 0)
730 err = iCoreImgStore->GetWordSettings(nfCount, ids(),
731 values(), types(), errors());
733 if (err != KErrNone && err != KErrNotFound)
735 HCR_TRACE_RETURN(err);
737 else if(err == KErrNone)
739 //Search for number of errors
740 for(TInt index = 0; index < nfCount; index ++)
742 switch(*(errors[index]))
744 //The setting was found or it's found but the type is larger
745 //than 4 bytes then we just increase a counter of the found
746 //settings in the repository
752 //The setting was not found, then re-initialize all the
753 //arrays of pointers with the pointer to this element.
754 //nfReposCount depict the counter of not found element and
755 //index shows the intial element position.
756 //As nfReposCount is always less or equal to index then we
757 //can easily make reassignment as nfReposCoun element was
758 //already analysed. In the end the nfReposCount is increased.
760 ids[nfReposCount] = ids[index];
761 values[nfReposCount] = values[index];
762 types[nfReposCount] = types[index];
763 errors[nfReposCount] = errors[index];
769 //No any action is needed
777 else //err == KErrNotFound
779 //No settings were found in the repository
780 //reposCount is zero intialized, so nothing to do here
784 //Update the global counter only if there are some settings were found,
785 //otherwise it can be situation when we overwrite the nfCount with zero
786 //when either no any setting presents or no settings were found in the
789 nfCount = nfReposCount;
792 //let's go through the last Variant store
795 if(iVariantStore && nfCount > 0)
797 err = iVariantStore->GetWordSettings(nfCount, ids(), values(),
800 if (err != KErrNone && err != KErrNotFound)
802 HCR_TRACE_RETURN(err);
804 else if(err == KErrNone)
806 //Search for number of errors
807 for(TInt index = 0; index < nfCount; index ++)
809 switch(*(errors[index]))
811 //The setting was found or it's found but the type is larger
812 //than 4 bytes then we just increase a counter of the found
813 //settings in the repository
819 //The setting was not found, then re-initialize all the
820 //arrays of pointers with the pointer to this element.
821 //nfReposCount depict the counter of not found element and
822 //index shows the intial element position.
823 //As nfReposCount is always less or equal to index then we
824 //can easily make reassignment as nfReposCoun element was
825 //already analysed. In the end the nfReposCount is increased.
827 *values[nfReposCount] = 0;
828 *types[nfReposCount] = ETypeUndefined;
829 *errors[nfReposCount] = KErrNotFound;
835 //No any action is needed
842 else //err == KErrNotFound
844 //No settings were found in the repository
845 //reposCount is zero intialized, so nothing to do here
848 //Update the global counter only if there are some settings were found,
849 //otherwise it can be situation when we overwrite the nfCount with zero
850 //when either no any setting presents or no settings were found in the
853 nfCount = nfReposCount;
855 //Return the number of found elements
856 return (aNum - nfCount);
863 TInt HCR::HCRInternal::FindNumSettingsInCategory (TCategoryUid aCatUid)
865 HCR_FUNC("++ HCRInternal::FindNumSettingsInCategory");
868 HCR_TRACE3("--- Repository state: %x, %x, %x", iOverrideStore, iCoreImgStore, iVariantStore);
870 //First and last element index within category in the Override store
871 TInt32 oLowIndex = 0;
872 TInt32 oHighIndex = 0;
875 //Find numOverride number of settings within the category in the OverrideStore
879 err = iOverrideStore->FindNumSettingsInCategory(aCatUid,
880 oLowIndex, oHighIndex);
882 if(err == KErrNotFound)
885 oCount = oHighIndex - oLowIndex + 1;
887 //If CoreImg and Variant store are not activated so just return the
888 //number of elements found in the Override store
889 if(!iCoreImgStore && !iVariantStore)
894 //First and last element index within category in the CoreImg store
895 TInt32 cLowIndex = 0;
896 TInt32 cHighIndex = 0;
902 //Temproary holder for the found element position
904 //Temproary holder for the low index, which is used to decrease the scope
906 TInt32 lowIndex = oLowIndex;
908 //Setting data holders
914 //Find numCoreImg number of settings within the category in the CoreImg re-
916 err = iCoreImgStore->FindNumSettingsInCategory(aCatUid,
917 cLowIndex, cHighIndex);
919 if(err == KErrNotFound)
922 //Calculate the number of elements within category, in CoreImg store
923 cLength = cHighIndex - cLowIndex + 1;
927 //Find all elemnts from CoreImg store which are not redefined in the
928 //Override store. When element is not found in the Override store
929 //then cCount is increased.
930 for(TInt element = 0; element < cLength; element ++)
932 //Find element in the repository by its index
933 iCoreImgStore->GetSettingRef(cLowIndex + element, setRef);
935 iCoreImgStore->GetId(setRef, setId);
937 //Check either this element is already redefined in the Override
939 err = iOverrideStore->FindSetting( setId, setRef,
940 elementPos, lowIndex, oHighIndex);
944 //if the element is found in the Override store, then store the posi-
945 //tion of this element in lowIndex, to narrow next search procedure
946 lowIndex = elementPos;
948 else //err == KErrNotFound
950 //if element is not found then it means it's not redefined in the
951 //Override store and this element must be counted in the total number
952 //of elemnts in all stores
955 //FindSetting can only return KErrNotFound, let's assert
956 //we've only got KErrNotFound
957 __NK_ASSERT_DEBUG(err == KErrNotFound);
970 //First and last element index within giving category in the Variant store
971 TInt32 vLowIndex = 0;
972 TInt32 vHighIndex = 0;
978 //Find numVariant number of settings within the category in the VariantStore
980 err = iVariantStore->FindNumSettingsInCategory(aCatUid, vLowIndex,
983 //Analyze returned error code
985 if(err == KErrNotFound)
988 //Calculate the number of elements within category, in CoreImg store
989 vLength = vHighIndex - vLowIndex + 1;
992 if(oCount > 0 || cCount >0)
994 //Find all elemnts from Variant store which are not redefined either in the
995 //Override or CoreImg store. These elements are added to the total
998 // Some additional containers. They are needed because we
999 // must check two stores Override and Variant in this iteration. Making a
1000 // decision of uniqueness of the element is made from the analyse of both
1001 // result. The element is only unique defined in the Variant store if it's
1002 // not redefined either in the Override or Variant store
1004 //Temproary holder for the found element position
1005 TInt32 elementPos2 = 0;
1006 //Temproary holder for the low index, which is used to decrease the scope
1008 TInt32 lowIndex2 = cLowIndex;
1009 // This index contains Override low index and will be changed by the position
1010 // of a new found element
1011 lowIndex= oLowIndex;
1013 TBool isRedefined = EFalse;
1015 for(TInt element = 0; element < vLength; element ++)
1017 //Find the setting in the repository by its index and
1018 iVariantStore->GetSettingRef(vLowIndex + element, setRef);
1020 iVariantStore->GetId(setRef, setId);
1024 //Check either this element is already redefined in the Override store
1025 err = iOverrideStore->FindSetting(setId, tmpRef,
1026 elementPos, lowIndex, oHighIndex);
1030 //if the element is found in the Override store, then store the posi-
1031 //tion of this element in lowIndex, to narrow next search procedure
1032 lowIndex = elementPos;
1033 isRedefined = ETrue;
1035 else //err == KErrNotFound
1037 //the element is not presented in the Override store
1038 //nothing to do here
1040 //FindSetting can only return KErrNotFound, let's assert
1041 //we've only got KErrNotFound
1042 __NK_ASSERT_DEBUG(err == KErrNotFound);
1049 if(cCount > 0 && !isRedefined)
1051 //Check either this element is already redefined in the CoreImg store
1052 err = iCoreImgStore->FindSetting(setId, tmpRef,
1053 elementPos2, lowIndex2, cHighIndex);
1058 //if the element is found in the Override store, then store the posi-
1059 //tion of this element in lowIndex, to narrow next search procedure
1060 lowIndex2 = elementPos2;
1061 isRedefined = ETrue;
1063 else //err == KErrNotFound
1065 //the element is not presented in the Override store
1066 //nothing to do here
1068 //FindSetting can only return KErrNotFound, let's assert
1069 //we've only got KErrNotFound
1070 __NK_ASSERT_DEBUG(err == KErrNotFound);
1079 isRedefined = EFalse;
1081 }//for(TInt element = 0; element < vLength; element ++)
1090 //Return the total number of elements found in the category
1091 return (oCount + cCount + vCount);
1097 TInt HCR::HCRInternal::FindSettings(TCategoryUid aCatUid,
1098 TInt aMaxNum, TElementId aIds[],
1099 TSettingType aTypes[], TUint16 aLens[])
1101 HCR_FUNC("++ HCRInternal::FindSettings w/o patterns");
1103 HCR_TRACE3("--- Repository state: %x, %x, %x", iOverrideStore,
1104 iCoreImgStore, iVariantStore);
1107 TInt err = KErrNone;
1109 //Number of found elements in the Override store
1112 //Low and High indexes in the Override store
1113 TInt32 oLoIndex = 0;
1114 TInt32 oHiIndex = 0;
1116 //Temproary holder for the found element position
1117 TInt32 elementPos = 0;
1118 TInt32 lowIndex = 0;
1121 //Tempoary type and length value holders if the
1122 //user does not provide these arrays for us
1123 TSettingType tmpType;
1127 //Setting datat holders
1132 //Find number of elements, low and hingh index in the Override store
1135 err = iOverrideStore->FindNumSettingsInCategory(aCatUid, oLoIndex,
1139 //If number of elements in the Override Store is larger than aMaxNum or
1140 //CoreImage/Variant stores are not present then write all found
1141 //settings into the user array, return the number of found elements and
1143 oNumFound = (oHiIndex - oLoIndex + 1);
1144 lowIndex = oLoIndex;
1146 if(oNumFound < aMaxNum)
1148 for(TInt index = 0; index < oNumFound; index ++)
1150 //Get setting reference data from the repository
1151 iOverrideStore->GetSettingRef(oLoIndex + index, setRef);
1153 //Copy the settings data into the user arrays
1154 iOverrideStore->GetSettingInfo(setRef,
1156 aTypes ? aTypes[index]:tmpType,
1157 aLens ? aLens[index]:tmpLen);
1162 else //oNumFound >= aMaxNum
1164 //Copy data to the user array
1165 for(TInt index = 0; index < aMaxNum; index++)
1167 //Get setting reference data from the repository
1168 iOverrideStore->GetSettingRef(oLoIndex + index, setRef);
1169 //Copy the settings data into the user arrays
1170 iOverrideStore->GetSettingInfo(setRef,
1172 aTypes ? aTypes[index]:tmpType,
1173 aLens ? aLens[index]:tmpLen);
1179 else // err == KErrNotFound
1181 //Nothing to do here, oNumFound is set to zero already
1183 //FindNumSettingsInCategory can only return KErrNotFound, let's
1184 //assert we've only got KErrNotFound
1185 __NK_ASSERT_DEBUG(err == KErrNotFound);
1191 //Low/High index in the CoreImg
1192 TInt32 cLoIndex = 0;
1193 TInt32 cHiIndex = 0;
1196 //Temproary setting reference holder
1199 //Temproary holder for the found element position
1201 lowIndex = oLoIndex;
1203 //Redefined status flag, it's used to flag that the element is found in the
1205 TBool isRedefined = EFalse;
1208 TInt usrArrIndx = 0;
1210 //If the count is still less than aMaxNum then continue with searching
1211 //settings in the CoreImage store
1215 //Find number of elements and low/high indexes
1216 err = iCoreImgStore->FindNumSettingsInCategory(aCatUid, cLoIndex,
1221 for(TInt index = 0; index < (cHiIndex - cLoIndex + 1); index ++)
1223 //Get the setting data by its index in the repository
1224 iCoreImgStore->GetSettingRef(cLoIndex + index, setRef);
1226 iCoreImgStore->GetId(setRef, setId);
1230 //Check either this element is already redefined in the
1231 err = iOverrideStore->FindSetting(setId, tmpRef,
1232 elementPos, lowIndex, oHiIndex);
1237 lowIndex = elementPos + 1;
1238 isRedefined = ETrue;
1240 else //err == KErrNotFound
1242 //Nothing to do hear, isRedefined flag is EFalse
1243 //all analysis is done later in the code
1245 //FindSetting can only return KErrNotFound, let's assert
1246 //we've only got KErrNotFound
1247 __NK_ASSERT_DEBUG(err == KErrNotFound);
1252 //Examine the redefined status flag
1255 // If the element was not found then we need to copy to
1256 // the pA array and increase the counter of setting data
1257 // only if we did not reach the aMaxNum of found elements
1259 usrArrIndx = oNumFound + cNumFound;
1260 if(usrArrIndx < aMaxNum)
1262 //Copy the settings data into the user arrays
1263 iCoreImgStore->GetSettingInfo(setRef,
1265 aTypes ? aTypes[usrArrIndx]:tmpType,
1266 aLens ? aLens[usrArrIndx]:tmpLen);
1271 //It reaches the goal, all required elements are found
1272 //stop here and return the result
1277 //Element is found in other repositories, just reset a flag
1278 isRedefined = EFalse;
1281 else //err == KErrNotFound
1283 //cNumFound is already set to zero during the initialization
1284 //Nothing to do here
1286 //FindNumSettingsInCategory can only return KErrNotFound, let's
1287 //assert we've only got KErrNotFound
1288 __NK_ASSERT_DEBUG(err == KErrNotFound);
1294 //Low/High index in the CoreImg
1295 TInt32 vLoIndex = 0;
1296 TInt32 vHiIndex = 0;
1299 //Temproary holder for the found element position
1300 TInt32 elementPos2 = 0;
1302 TInt32 lowIndex2 = cLoIndex;
1303 lowIndex = oLoIndex;
1305 isRedefined = EFalse;
1308 //If the count is still less than aMaxNum then continue with searching
1309 //settings in the CoreImage store
1313 //Find number of elements and low/high indexes
1314 err = iVariantStore->FindNumSettingsInCategory(aCatUid, vLoIndex,
1319 for(TInt index = 0; index < (vHiIndex - vLoIndex + 1); index ++)
1321 //Get setting reference data by its index in the repository
1322 iVariantStore->GetSettingRef(vLoIndex + index, setRef);
1324 //and get setting id
1325 iVariantStore->GetId(setRef, setId);
1329 //Check either this element is already redefined in the
1330 err = iOverrideStore->FindSetting(setId, tmpRef, elementPos,
1331 lowIndex, oHiIndex);
1334 //Also suppress the error checking due the reason described
1338 lowIndex = elementPos + 1;
1339 isRedefined = ETrue;
1341 else //err == KErrNotFound
1343 //Element is not found, nothing to proceed here
1345 //FindSetting can only return KErrNotFound, let's assert
1346 //we've only got KErrNotFound
1347 __NK_ASSERT_DEBUG(err == KErrNotFound);
1352 if(cNumFound > 0 && !isRedefined)
1354 //Check either this element is already redefined in the
1355 err = iCoreImgStore->FindSetting(setId, tmpRef, elementPos2,
1356 lowIndex2, cHiIndex);
1360 lowIndex2 = elementPos2 + 1;
1361 isRedefined = ETrue;
1363 else //err == KErrNotFound
1365 //Element is not found, nothing to proceed here
1367 //FindSetting can only return KErrNotFound, let's assert
1368 //we've only got KErrNotFound
1369 __NK_ASSERT_DEBUG(err == KErrNotFound);
1376 usrArrIndx = oNumFound + cNumFound + vNumFound;
1377 if(usrArrIndx < aMaxNum)
1379 //Copy the settings data into the user arrays
1380 iVariantStore->GetSettingInfo(setRef,
1382 aTypes ? aTypes[usrArrIndx]:tmpType,
1383 aLens ? aLens[usrArrIndx]:tmpLen);
1389 //It reaches the goal, all required elements are found
1390 //stop here and return the result
1396 isRedefined = EFalse;
1400 else //err == KErrNotFound
1402 //oNumFound is already set to zero during the initialization
1403 //Nothing to do here
1405 //FindNumSettingsInCategory can only return KErrNotFound, let's
1406 //assert we've only got KErrNotFound
1407 __NK_ASSERT_DEBUG(err == KErrNotFound);
1412 //Let's prepare the final data
1413 return (oNumFound + cNumFound + vNumFound);
1422 TInt HCR::HCRInternal::FindSettings(TCategoryUid aCat, TInt aMaxNum,
1423 TUint32 aMask, TUint32 aPattern,
1424 TElementId aIds[], TSettingType aTypes[], TUint16 aLens[])
1426 //Holder for errors and number of elements
1428 //Total number of elements within the given category
1429 TInt allInCatFound = 0;
1430 //Number of elements which corresponds to the aMask and aPattern
1433 //Find the number of elements within the category
1434 r = FindNumSettingsInCategory(aCat);
1436 //We don't expect any errors here
1437 __NK_ASSERT_DEBUG(r >= 0);
1440 //No any elements found for this category
1445 //Result data array holder
1446 TSa<TElementId> pIds;
1447 TSa<TSettingType> pTypes;
1450 pIds = new TElementId[allInCatFound];
1451 pTypes = new TSettingType[allInCatFound];
1452 pLens = new TUint16[allInCatFound];
1454 if(pIds() == NULL || pTypes() == NULL || pLens() == NULL)
1455 //One of the allocation was unsuccessful
1456 HCR_TRACE_RETURN(KErrNoMemory);
1458 r = FindSettings(aCat, allInCatFound, pIds(), pTypes(), pLens());
1460 //We don't expect any errors here
1461 __NK_ASSERT_DEBUG(r >= 0);
1463 //Check either we've got less elements than it must be
1464 __NK_ASSERT_DEBUG(r == allInCatFound);
1466 //Choose the elements which satisfy this condition
1467 //((elementID & aElementMask) == (aPattern & aElementMask)). The total num-
1468 //ber of returned elements should not exceed the aMaxNum
1469 for(TInt index = 0; index < allInCatFound; index++)
1471 if(((pIds[index] & aMask) == (aPattern & aMask)))
1473 aIds[numFound] = pIds[index];
1476 aTypes[numFound] = pTypes[index];
1479 aLens[numFound] = pLens[index];
1486 //Check either we already found or not enough elements
1487 //If we did then break the loop
1488 if(numFound == aMaxNum)
1496 // -- METHODS -----------------------------------------------------------------
1500 HCR::TRepository::~TRepository()
1502 HCR_FUNC("~TRepository");
1505 TBool HCR::TRepository::IsWordValue(const TSettingRef& aRef)
1507 HCR_FUNC("TRepository::IsWordValue");
1508 return ((aRef.iSet->iType & KMaskWordTypes) != 0);
1511 TBool HCR::TRepository::IsLargeValue(const TSettingRef& aRef)
1513 HCR_FUNC("TRepository::IsLargeValue");
1514 return ((aRef.iSet->iType & KMaskLargeTypes) != 0);
1517 void HCR::TRepository::GetId(const TSettingRef& aRef, SSettingId& aId)
1519 HCR_FUNC("TRepository::GetId2");
1520 aId = aRef.iSet->iId;
1523 TInt32 HCR::TRepository::GetType(const TSettingRef& aRef)
1525 HCR_FUNC("TRepository::GetType");
1526 return (aRef.iSet->iType);
1529 TUint16 HCR::TRepository::GetLength(const TSettingRef& aRef)
1531 HCR_FUNC("TRepository::GetLength");
1533 // Assume large value, will be caught when value retreived if not correct.
1534 // Saves some CPU cycles...
1535 // if (IsLargeValue(aRef))
1536 return (aRef.iSet->iLen);
1539 void HCR::TRepository::GetSettingInfo(const HCR::TSettingRef& aSetRef,
1540 HCR::TElementId& aId, HCR::TSettingType& aType, TUint16& aLen)
1542 HCR_FUNC("TRepository::GetSettingInfo");
1544 aId = aSetRef.iSet->iId.iKey;
1546 aType = static_cast<TSettingType>(aSetRef.iSet->iType);
1548 aLen = aSetRef.iSet->iLen;
1551 // -- METHODS -----------------------------------------------------------------
1553 // TRepositoryCompiled
1556 HCR::TRepository* HCR::TRepositoryCompiled::New(const SRepositoryCompiled* aRepos)
1558 HCR_FUNC("TRepositoryCompiled::New");
1560 __NK_ASSERT_ALWAYS(aRepos != 0);
1561 return new TRepositoryCompiled(aRepos);
1564 HCR::TRepositoryCompiled::TRepositoryCompiled(const SRepositoryCompiled* aRepos)
1567 HCR_FUNC("TRepositoryCompiled");
1570 HCR::TRepositoryCompiled::~TRepositoryCompiled()
1572 HCR_FUNC("~TRepositoryCompiled");
1575 TInt HCR::TRepositoryCompiled::CheckIntegrity()
1577 HCR_FUNC("TRepositoryCompiled::CheckIntegrity");
1579 __NK_ASSERT_ALWAYS(this != 0);
1580 __NK_ASSERT_ALWAYS(iRepos != 0);
1582 if (iRepos->iOrderedSettingList == 0)
1583 HCR_TRACEMSG_RETURN("Compiled Repository header missing setting array list", KErrNotFound);
1585 HCR_TRACE2("Compiled repository 0x%x contains %05d entries", iRepos, iRepos->iHdr->iNumSettings);
1587 SSettingC* arr = iRepos->iOrderedSettingList;
1588 TSettingId prev(0,0);
1590 for (int i=0; i < iRepos->iHdr->iNumSettings; i++, arr++)
1592 __NK_ASSERT_ALWAYS(arr != 0);
1593 HCR_TRACE3("Checking entry %05d - (0x%x,0x%x)", i, arr->iName.iId.iCat, arr->iName.iId.iKey);
1594 rc = CompareSSettingIds(prev, arr->iName.iId);
1595 // Check for duplicates that reside next to each other
1596 if ((i > 0) && (rc == 0))
1597 HCR_TRACE_RETURN (KErrAlreadyExists);
1598 // Check that the entries are in ascending order
1600 HCR_TRACE_RETURN (KErrCorrupt);
1601 prev = arr->iName.iId;
1606 TInt HCR::TRepositoryCompiled::FindSetting(const TSettingId& aId, TSettingRef& aSetting)
1608 HCR_FUNC("TRepositoryCompiled::FindSetting");
1610 __NK_ASSERT_DEBUG(iRepos != 0);
1611 __NK_ASSERT_DEBUG(iRepos->iHdr != 0);
1613 if ((iRepos->iHdr->iNumSettings == 0) ||
1614 (iRepos->iOrderedSettingList == 0))
1615 HCR_TRACE_RETURN(KErrNotFound);
1617 SSettingC* arr = iRepos->iOrderedSettingList;
1619 int high = iRepos->iHdr->iNumSettings-1;
1625 mid = (low+high) >> 1;
1626 com = CompareSSettingIds(aId, arr[mid].iName.iId);
1633 aSetting.iRep = this;
1634 aSetting.iSet = &((arr[mid]).iName);
1641 return KErrNotFound;
1647 TInt HCR::TRepositoryCompiled::FindSetting(const TSettingId& aId,
1648 TSettingRef& aSetting, TInt32& aPosition, TInt32 aLow, TInt32 aHigh)
1650 HCR_FUNC("TRepositoryCompiled::FindSetting within the given range");
1653 __NK_ASSERT_DEBUG(iRepos != 0);
1654 __NK_ASSERT_DEBUG(iRepos->iHdr != 0);
1655 __NK_ASSERT_DEBUG(iRepos->iOrderedSettingList != 0);
1656 __NK_ASSERT_DEBUG(iRepos->iHdr->iNumSettings != 0);
1658 SSettingC* arr = iRepos->iOrderedSettingList;
1660 TInt32 high = aHigh;
1666 mid = (low+high) >> 1;
1667 com = CompareSSettingIds(aId, arr[mid].iName.iId);
1674 aSetting.iRep = this;
1675 aSetting.iSet = &((arr[mid]).iName);
1684 return KErrNotFound;
1689 TInt HCR::TRepositoryCompiled::GetWordSettings(TInt aNum,
1690 SSettingId* aIds[], TInt32* aValues[], TSettingType* aTypes[],
1693 HCR_FUNC("TRepositoryCompiled::GetWordSettings");
1695 __NK_ASSERT_DEBUG(iRepos != 0);
1696 __NK_ASSERT_DEBUG(iRepos->iHdr != 0);
1697 __NK_ASSERT_DEBUG(aIds != NULL);
1698 __NK_ASSERT_DEBUG(aValues != NULL);
1699 __NK_ASSERT_DEBUG(aTypes != NULL);
1700 __NK_ASSERT_DEBUG(aErrors != NULL);
1702 if ((iRepos->iHdr->iNumSettings == 0) ||
1703 (iRepos->iOrderedSettingList == 0))
1704 HCR_TRACE_RETURN(KErrNotFound);
1706 TInt err = KErrNone;
1708 TInt32 rMaxIndex = 0;
1709 TInt32 rMinIndex = 0;
1710 TInt32 uFirstIndex = 0;
1711 TInt32 uLastIndex = 0;
1715 TSettingRef settingRef(NULL, NULL);
1716 SSettingC* pSetting = NULL;
1719 //Find position index within the repository for the first and last setting
1720 //from user supplied array aIds[]
1722 TBool isRedefined = EFalse;
1725 while(!isRedefined && uIndex < aNum)
1727 //Find first setting from user array. The importance here is that we
1728 //should get value of first setting index in the repository in rMinIndex.
1729 //This time the scope of search is whole repository.
1730 err = this->FindSetting(*aIds[uIndex],settingRef, rMinIndex,
1731 0, iRepos->iHdr->iNumSettings);
1733 __NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
1735 if(err == KErrNotFound)
1737 *aErrors[uIndex] = err;
1738 *aValues[uIndex] = 0;
1739 *aTypes[uIndex] = ETypeUndefined;
1741 //As FindSetting did not find the element, let's challenge with
1742 //the next one from aIds[] array
1746 else // err == KErrNone
1748 //Get the value and type
1749 pSetting = (SSettingC*) settingRef.iSet;
1751 *aTypes[uIndex] = static_cast<TSettingType>(settingRef.iSet->iType);
1753 //Check for the found type is this word size? If it's not then
1754 //indicate error for this setting
1755 if(*aTypes[uIndex] > ETypeLinAddr)
1757 *aErrors[uIndex] = KErrArgument;
1758 *aValues[uIndex] = 0;
1762 *aErrors[uIndex] = KErrNone;
1763 *aValues[uIndex] = pSetting->iValue.iLit.iInt32;
1766 //Break the loop by setting the redefined status
1767 isRedefined = ETrue;
1771 //At this point we should find at least one element from the user array,
1772 //store this index in the local variable, it is used later in the code.
1773 //Please be noticed we've also got rMinIndex - first setting index in the
1776 uFirstIndex = uIndex;
1777 //if we did not find any elements at all just return KErrNotFound
1779 return KErrNotFound;
1783 //Now lets find the last setting
1785 isRedefined = EFalse;
1787 while(!isRedefined && uIndex > uFirstIndex)
1789 //Find the last setting from user array. The importance here is that we
1790 //should get value of first setting index in the repository in
1791 //rMinIndex. This time the scope of search is whole repository.
1792 err = this->FindSetting(*aIds[uIndex],settingRef, rMaxIndex,
1793 rMinIndex, iRepos->iHdr->iNumSettings);
1795 __NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
1797 if(err == KErrNotFound)
1799 *aErrors[uIndex] = err;
1800 *aValues[uIndex] = 0;
1801 *aTypes[uIndex] = ETypeUndefined;
1803 //As FindSetting did not find the element, let's challenge with
1804 //previous one, as we are moving in reverse direction
1808 else //err == KErrNone
1810 pSetting = (SSettingC*) settingRef.iSet;
1811 *aTypes[uIndex] = static_cast<TSettingType>(settingRef.iSet->iType);
1813 //Check for the found type is this word size? If it's not then indicate
1814 //error for this setting
1815 if(*aTypes[uIndex] > ETypeLinAddr)
1817 *aErrors[uIndex] = KErrArgument;
1818 *aValues[uIndex] = 0;
1822 *aErrors[uIndex] = KErrNone;
1823 *aValues[uIndex] = pSetting->iValue.iLit.iInt32;
1826 isRedefined = ETrue;
1830 //At this point we found the last setting, store it's user array index in
1831 //the local variable, it is used later in the code. Please be noticed
1832 //we've also got rMaxIndex - last setting index in the repository.
1834 uLastIndex = uIndex;
1836 //if we are here we did not find any other elements than was found
1837 //in previous iteration then just stop here
1838 return KErrNotFound;
1840 //The scope of user array settings in the repository is found.
1841 //Let's find all other settings from user array. Bare in mind the low
1842 //bound for the repository index is increased each iteration to optimize the
1844 for(uIndex = uFirstIndex + 1; uIndex < uLastIndex; uIndex ++)
1846 err = this->FindSetting(*aIds[uIndex],settingRef, rIndex,
1847 rMinIndex, rMaxIndex);
1849 __NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
1851 if(err == KErrNotFound)
1853 *aErrors[uIndex] = err;
1854 *aValues[uIndex] = 0;
1855 *aTypes[uIndex] = ETypeUndefined;
1857 //As FindSetting did not find the element, let's challenge with
1861 else //err == KErrNone
1864 pSetting = (SSettingC*) settingRef.iSet;
1865 *aTypes[uIndex] = static_cast<TSettingType>(settingRef.iSet->iType);
1867 //Check for the found type is this word size? If it's not then indicate
1868 //error for this setting
1869 if(*aTypes[uIndex] > ETypeLinAddr)
1871 *aErrors[uIndex] = KErrArgument;
1872 *aValues[uIndex] = 0;
1876 *aErrors[uIndex] = KErrNone;
1877 *aValues[uIndex] = pSetting->iValue.iLit.iInt32;
1880 rMinIndex = rIndex + 1;
1893 TInt HCR::TRepositoryCompiled::FindNumSettingsInCategory(TCategoryUid aCatUid,
1894 TInt32& aFirst, TInt32& aLast)
1896 HCR_FUNC("TRepositoryCompiled::FindNumSettingsInCategory");
1898 __NK_ASSERT_DEBUG(iRepos != 0);
1899 __NK_ASSERT_DEBUG(iRepos->iHdr != 0);
1900 __NK_ASSERT_DEBUG(iRepos->iOrderedSettingList != 0);
1902 if(iRepos->iHdr->iNumSettings == 0)
1906 HCR_TRACE_RETURN(KErrNotFound);
1909 SSettingC* arr = iRepos->iOrderedSettingList;
1911 int high = iRepos->iHdr->iNumSettings-1;
1915 //Let's find any setting within the category, mid will store the setting
1916 //index in the repository
1919 mid = (low+high) >> 1;
1920 com = CompareByCategory(aCatUid, arr[mid].iName.iId);
1931 // If no one setting with the given category was found the return error
1937 return KErrNotFound;
1940 //Search the first element within the category
1942 while(low >= 0 && arr[low].iName.iId.iCat == aCatUid)
1949 //Check the boundary conditions, there are two cases when we exit the loop
1950 //either we found an element which category is not one we are looking for or
1951 //we reach the beggining of the repository. If we reach the beggining of the
1952 //repository we don't really know is it because this is last elment or it
1953 //has required aCatUid, so we check these two conditions below
1954 if(arr[low].iName.iId.iCat == aCatUid)
1957 //We finish the loop either reaching the setting which category id is not
1958 //what we need or this is first setting in the repository again with another
1959 //category, so in both case we throw this element from the account.
1963 //Search the last element within the category
1965 while(high <= iRepos->iHdr->iNumSettings - 1 && arr[high].iName.iId.iCat == aCatUid)
1967 if(high < iRepos->iHdr->iNumSettings - 1)
1973 //Same situation as above, boundary conditions
1974 if(arr[high].iName.iId.iCat == aCatUid)
1985 void HCR::TRepositoryCompiled::GetSettingRef(TInt32 aIndex,
1986 HCR::TSettingRef& aRef)
1988 __NK_ASSERT_DEBUG(iRepos != 0);
1989 __NK_ASSERT_DEBUG(iRepos->iHdr != 0);
1990 __NK_ASSERT_DEBUG(iRepos->iHdr->iNumSettings != 0 && iRepos->iOrderedSettingList != 0);
1991 __NK_ASSERT_DEBUG(aIndex >=0 && aIndex < iRepos->iHdr->iNumSettings);
1994 //Get the pointer to the repository data
1995 SSettingC* arr = iRepos->iOrderedSettingList;
1998 aRef.iSet = &(arr[aIndex].iName);
2002 TInt HCR::TRepositoryCompiled::GetValue(const TSettingRef& aRef, UValueWord& aValue)
2004 HCR_FUNC("TRepositoryCompiled::GetValue");
2005 if (!IsWordValue(aRef))
2006 HCR_TRACE_RETURN(KErrArgument);
2008 SSettingC* sptr = (SSettingC*)(aRef.iSet);
2009 aValue = sptr->iValue.iLit;
2013 TInt HCR::TRepositoryCompiled::GetLargeValue(const TSettingRef& aRef, UValueLarge& aValue)
2015 HCR_FUNC("TRepositoryCompiled::GetLargeValue");
2016 if (!IsLargeValue(aRef))
2017 HCR_TRACE_RETURN(KErrArgument);
2019 SSettingC* sptr = (SSettingC*)(aRef.iSet);
2020 aValue = sptr->iValue.iPtr;
2025 // -- METHODS -----------------------------------------------------------------
2030 HCR::TRepository* HCR::TRepositoryFile::New(const SRepositoryFile* aRepos)
2032 HCR_FUNC("TRepositoryFile::New");
2034 __NK_ASSERT_ALWAYS(aRepos != 0);
2035 return new TRepositoryFile(aRepos);
2038 HCR::TRepositoryFile::TRepositoryFile(const SRepositoryFile* aRepos)
2041 HCR_FUNC("TRepositoryFile");
2044 HCR::TRepositoryFile::~TRepositoryFile()
2046 HCR_FUNC("~TRepositoryFile");
2049 // On target hardware the iRepos pointer always points to a file in the Core
2050 // rom image and hence is not memory allocated on kernel heap. Hence it does
2051 // not need to be freeded.
2052 // When running under the emulator the file repositories are loaded into
2053 // allocated memory which needs to be freed here.
2055 delete const_cast<SRepositoryFile*>(iRepos);
2061 TInt HCR::TRepositoryFile::CheckIntegrity()
2063 HCR_FUNC("TRepositoryFile::CheckIntegrity");
2065 __NK_ASSERT_ALWAYS(this != 0);
2066 __NK_ASSERT_ALWAYS(iRepos != 0);
2068 if ((*((TUint32*)&(iRepos->iHdr)) != 0x66524348) ||
2069 (iRepos->iHdr.iFormatVersion != 0x0001))
2070 HCR_TRACEMSG_RETURN("File Repository header describes an unsupported repository type", KErrCorrupt);
2072 HCR_TRACE2("File repository 0x%x contains %05d entries", iRepos, iRepos->iHdr.iNumSettings);
2074 SSettingF* arr = (SSettingF*) (iRepos+1);
2075 TSettingId prev(0,0);
2077 for (int i=0; i < iRepos->iHdr.iNumSettings; i++, arr++)
2079 __NK_ASSERT_ALWAYS(arr != 0);
2080 HCR_TRACE3("Checking entry %05d - (0x%x,0x%x)", i, arr->iName.iId.iCat, arr->iName.iId.iKey);
2081 rc = CompareSSettingIds(prev, arr->iName.iId);
2082 // Check for duplicates that reside next to each other
2083 if ((i > 0) && (rc == 0))
2084 HCR_TRACE_RETURN (KErrAlreadyExists);
2085 // Check that the entries are in ascending order
2087 HCR_TRACE_RETURN (KErrCorrupt);
2088 prev = arr->iName.iId;
2093 TInt HCR::TRepositoryFile::FindSetting(const TSettingId& aId, TSettingRef& aSetting)
2095 HCR_FUNC("TRepositoryFile::FindSetting");
2097 __NK_ASSERT_DEBUG(iRepos != 0);
2099 if (iRepos->iHdr.iNumSettings == 0)
2100 HCR_TRACE_RETURN(KErrNotFound);
2102 SSettingF* arr = (SSettingF*) (iRepos+1);
2104 int high = iRepos->iHdr.iNumSettings-1;
2110 mid = (low+high) >> 1;
2111 com = CompareSSettingIds(aId, arr[mid].iName.iId);
2118 aSetting.iRep = this;
2119 aSetting.iSet = &((arr[mid]).iName);
2126 return KErrNotFound;
2130 TInt HCR::TRepositoryFile::FindSetting (const TSettingId& aId,
2131 TSettingRef& aSetting, TInt32& aPosition, TInt32 aLow, TInt32 aHigh)
2133 HCR_FUNC("TRepositoryFile::FindSetting within the given range");
2136 __NK_ASSERT_DEBUG(iRepos != 0);
2137 __NK_ASSERT_DEBUG(iRepos->iHdr.iNumSettings != 0);
2139 SSettingF* arr = (SSettingF*) (iRepos+1);
2141 TInt32 high = aHigh;
2147 mid = (low+high) >> 1;
2148 com = CompareSSettingIds(aId, arr[mid].iName.iId);
2155 aSetting.iRep = this;
2156 aSetting.iSet = &((arr[mid]).iName);
2165 return KErrNotFound;
2171 TInt HCR::TRepositoryFile::GetWordSettings(TInt aNum,
2172 SSettingId* aIds[], TInt32* aValues[], TSettingType* aTypes[],
2175 HCR_FUNC("TRepositoryFile::GetWordSettings");
2178 __NK_ASSERT_DEBUG(iRepos != 0);
2179 __NK_ASSERT_DEBUG(aIds != NULL);
2180 __NK_ASSERT_DEBUG(aValues != NULL);
2181 __NK_ASSERT_DEBUG(aTypes != NULL);
2182 __NK_ASSERT_DEBUG(aErrors != NULL);
2184 if (iRepos->iHdr.iNumSettings == 0)
2185 return KErrNotFound;
2187 TInt err = KErrNone;
2189 TInt32 rMaxIndex = 0;
2190 TInt32 rMinIndex = 0;
2191 TInt32 uFirstIndex = 0;
2192 TInt32 uLastIndex = 0;
2196 TSettingRef settingRef(NULL, NULL);
2197 SSettingF* pSetting = NULL;
2199 //Find position index within the repository for the first and last setting
2200 //from user supplied array aIds[]
2202 TBool isRedefined = EFalse;
2205 while(!isRedefined && uIndex < aNum)
2207 //Find first setting from user array. The importance here is that we
2208 //should get value of first setting index in the repository in rMinIndex.
2209 //This time the scope of search is whole repository.
2210 err = this->FindSetting(*aIds[uIndex],settingRef, rMinIndex,
2211 0, iRepos->iHdr.iNumSettings);
2213 __NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
2215 if(err == KErrNotFound)
2217 *aErrors[uIndex] = err;
2218 *aValues[uIndex] = 0;
2219 *aTypes[uIndex] = ETypeUndefined;
2221 //As FindSetting did not find the element, let's challenge with
2222 //the next one from aIds[] array
2226 else // err == KErrNone
2228 //Get the value and type
2229 pSetting = (SSettingF*) settingRef.iSet;
2230 //again copy the type value into the user array if it's provided
2231 *aTypes[uIndex] = static_cast<TSettingType>(settingRef.iSet->iType);
2233 //Check for the found type is this word size? If it's not then
2234 //indicate error for this setting
2235 if(*aTypes[uIndex] > ETypeLinAddr)
2237 *aErrors[uIndex] = KErrArgument;
2238 *aValues[uIndex] = 0;
2242 *aErrors[uIndex] = KErrNone;
2243 *aValues[uIndex] = pSetting->iValue.iLit.iInt32;
2246 //Break the loop by setting the redefined status
2247 isRedefined = ETrue;
2251 //At this point we should find at least one element, store this index in the
2252 //local variable, this is used later in the code. Please be noticed we've
2253 //also got rMinIndex - first setting index in the repository.
2255 uFirstIndex = uIndex;
2257 //if we are hear it means we did not find any user settings at all
2258 //we can't do any thing and just return KErrNotFound to indicate
2260 return KErrNotFound;
2264 //Now lets find the last setting
2266 isRedefined = EFalse;
2269 while(!isRedefined && uIndex > uFirstIndex)
2271 //Find the last setting from user array. The importance here is that we
2272 //should get value of first setting index in the repository in
2273 //rMinIndex. This time the scope of search is whole repository.
2274 err = this->FindSetting(*aIds[uIndex],settingRef, rMaxIndex,
2275 rMinIndex, iRepos->iHdr.iNumSettings);
2277 __NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
2279 if(err == KErrNotFound)
2281 *aErrors[uIndex] = err;
2282 *aValues[uIndex] = 0;
2283 *aTypes[uIndex] = ETypeUndefined;
2285 //As FindSetting did not find the element, let's challenge with
2290 else //err == KErrNone
2292 pSetting = (SSettingF*) settingRef.iSet;
2293 *aTypes[uIndex] = static_cast<TSettingType>(settingRef.iSet->iType);
2295 //Check for the found type is this word size? If it's not then indicate
2296 //error for this setting
2297 if(*aTypes[uIndex] > ETypeLinAddr)
2299 *aErrors[uIndex] = KErrArgument;
2300 *aValues[uIndex] = 0;
2304 *aErrors[uIndex] = KErrNone;
2305 *aValues[uIndex] = pSetting->iValue.iLit.iInt32;
2308 isRedefined = ETrue;
2312 //At this point we found the last setting, store it's user array index in
2313 //the local variable, this is used later in the code. Please be noticed
2314 //we've also got rMaxIndex - last setting index in the repository.
2316 uLastIndex = uIndex;
2318 //if we are here we did not find any other elements than was found
2319 //in previous iteration then just stop here
2320 return KErrNotFound;
2322 //The scope of user array settings in the repository is found.
2323 //Let's find all other settings from user array. Bare in mind the low
2324 //bound for the repository index is increased each iteration to optimize the
2326 for(uIndex = uFirstIndex + 1; uIndex < uLastIndex; uIndex ++)
2328 err = this->FindSetting(*aIds[uIndex],settingRef, rIndex,
2329 rMinIndex, rMaxIndex);
2331 __NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
2333 if(err == KErrNotFound)
2335 *aErrors[uIndex] = err;
2336 *aValues[uIndex] = 0;
2337 *aTypes[uIndex] = ETypeUndefined;
2339 //As FindSetting did not find the element, let's challenge with
2343 else //err == KErrNone
2346 pSetting = (SSettingF*) settingRef.iSet;
2348 TSettingType type = static_cast<TSettingType>(settingRef.iSet->iType);
2349 *aTypes[uIndex] = type;
2351 //Check for the found type is this word size? If it's not then indicate
2352 //error for this setting
2353 if(type > ETypeLinAddr)
2355 *aErrors[uIndex] = KErrArgument;
2356 *aValues[uIndex] = 0;
2360 *aErrors[uIndex] = KErrNone;
2361 *aValues[uIndex] = pSetting->iValue.iLit.iInt32;
2364 rMinIndex = rIndex + 1;
2374 void HCR::TRepositoryFile::GetSettingRef(TInt32 aIndex,
2375 HCR::TSettingRef& aSetRef)
2377 __NK_ASSERT_DEBUG(iRepos != 0);
2378 __NK_ASSERT_DEBUG(iRepos->iHdr.iNumSettings != 0);
2379 __NK_ASSERT_DEBUG(aIndex >= 0 && aIndex < iRepos->iHdr.iNumSettings);
2381 SSettingF* arr = (SSettingF*)(iRepos + 1);
2383 aSetRef.iRep = this;
2384 aSetRef.iSet = &(arr[aIndex].iName);
2390 TInt HCR::TRepositoryFile::FindNumSettingsInCategory(TCategoryUid aCatUid,
2391 TInt32& aFirst, TInt32& aLast)
2393 HCR_FUNC("TRepositoryFile::FindNumSettingsInCategory");
2395 __NK_ASSERT_DEBUG(iRepos != 0);
2397 if(iRepos->iHdr.iNumSettings == 0)
2401 HCR_TRACE_RETURN(KErrNotFound);
2404 SSettingF* arr = (SSettingF*) (iRepos+1);
2406 TInt32 high = iRepos->iHdr.iNumSettings-1;
2411 //Let's find any setting within the category, mid will store the setting
2412 //index in the repository
2415 mid = (low+high) >> 1;
2416 com = CompareByCategory(aCatUid, arr[mid].iName.iId);
2427 // If no one setting with the given category was found the return error
2433 return KErrNotFound;
2436 //Search the first element within the category
2438 while(low >= 0 && arr[low].iName.iId.iCat == aCatUid)
2446 //Check the boundary conditions, there are two cases when we exit the loop
2447 //either we found an element which category is not one we are looking for or
2448 //we reach the beggining of the repository. If we reach the beggining of the
2449 //repository we don't really know is it because this is last elment or it
2450 //has required aCatUid, so we check these two conditions below
2451 if(arr[low].iName.iId.iCat == aCatUid)
2454 //We finish the loop either reaching the setting which category id is not
2455 //what we need or this is first setting in the repository again with another
2456 //category, so in both case we throw this element from the account.
2461 //Search the last element within the category
2463 while(high <= iRepos->iHdr.iNumSettings - 1 && arr[high].iName.iId.iCat == aCatUid)
2465 if(high < iRepos->iHdr.iNumSettings - 1)
2471 //Same situation as above, boundary conditions
2472 if(arr[high].iName.iId.iCat == aCatUid)
2483 TInt HCR::TRepositoryFile::GetValue(const TSettingRef& aRef, UValueWord& aValue)
2485 HCR_FUNC("TRepositoryFile::GetValue");
2487 if (!IsWordValue(aRef))
2488 HCR_TRACE_RETURN(KErrArgument);
2490 SSettingF* sptr = (SSettingF*)(aRef.iSet);
2491 aValue = sptr->iValue.iLit;
2496 TInt HCR::TRepositoryFile::GetLargeValue(const TSettingRef& aRef, UValueLarge& aValue)
2498 HCR_FUNC("TRepositoryFile::GetLargeValue");
2500 if (!IsLargeValue(aRef))
2501 HCR_TRACE_RETURN(KErrArgument);
2503 SSettingF* sptr = (SSettingF*)(aRef.iSet);
2504 TRepositoryFile *rptr = (TRepositoryFile *)(aRef.iRep);
2506 aValue.iData = (TUint8*) rptr->iRepos;
2507 aValue.iData += rptr->iRepos->iLSDfirstByteOffset+sptr->iValue.iOffset;
2513 // -- FUNCTIONS ---------------------------------------------------------------
2515 #ifndef HCRTEST_NO_KEXT_ENTRY_POINT
2517 DECLARE_EXTENSION_WITH_PRIORITY(KExtensionMaximumPriority)
2519 DECLARE_STANDARD_EXTENSION()
2522 HCR_FUNC("InitExtension");
2524 HCR::MVariant* varPtr = CreateHCRVariant();
2526 HCR_TRACE_RETURN(KErrNoMemory);
2528 //Call of the "placement" new operator, which constructs the HCR object on
2529 //the global memory address defined by gHCR and initialized with the same
2530 //data given by constructor below
2531 new(&gHCR) HCR::HCRInternal(varPtr);
2533 TInt err = HCRSingleton->Initialise();
2535 if (err != KErrNone)
2536 HCR_TRACE_RETURN(err);
2540 #endif // HCRTEST_NO_KEXT_ENTRY_POINT
2542 // -- Implementation of local functions
2544 TInt SearchEntryInTRomDir(const TRomDir* aActDir, const TPtrC aFileName, TRomEntry* &aEntry)
2546 HCR_FUNC("SearchEntryInTRomDir");
2547 TInt retVal = KErrNotFound;
2548 HCR_TRACE2("--- aFileName: %S (%d)", &aFileName, aFileName.Length());
2552 HCR_TRACE_RETURN(retVal);
2555 TInt dirSize = aActDir->iSize;
2556 aEntry = (TRomEntry*)&aActDir->iEntry;
2557 HCR_TRACE3("--- dirSize: 0x%08x (%d), aEntry: 0x%08x", dirSize, dirSize, aEntry);
2559 TBool found = EFalse;
2562 TInt nameLength = (aEntry->iNameLength)<<1;
2564 // Uncommnet to get dump of ROM data when debugging....
2565 // HCR_TRACE0("Begin of loop...");
2566 // HCR_HEX_DUMP_ABS((TUint8 *)aEntry, sizeof(TRomEntry)+(nameLength - 2) );
2567 const TText* entryName = &aEntry->iName[0];
2568 HCR_TRACE1("--- entryName length: %d", nameLength);
2569 TBuf<512> newEntryName( nameLength);
2570 for( TInt i = 0; i != nameLength; ++i)
2572 newEntryName[i] = (unsigned char)('A' <= entryName[i] && 'Z' >= entryName[i]? entryName[i]+('a'-'A'): entryName[i]);
2575 HCR_TRACE6("--- aFileName: %S (%d/%d), newEntryName: %S (%d/%d)", &aFileName, aFileName.Length(), aFileName.Size(), &newEntryName, newEntryName.Length(), newEntryName.Size());
2576 TInt r = aFileName.Compare(newEntryName);
2577 HCR_TRACE1("--- result of CompareFileNames: 0x%08x", r);
2582 HCR_TRACE1("--- aEntry: 0x%08x", aEntry);
2587 TInt entrySize = sizeof(TRomEntry) + (nameLength - 2);
2588 HCR_TRACE2("--- entrySize: 0x%08x, (%d)", entrySize, entrySize);
2590 // The entrySize must be aligned to 4 bytes boundary
2591 entrySize = ((entrySize&0x03) == 0 ? entrySize : ((entrySize&0xfffffffc) + 4));
2592 HCR_TRACE2("--- entrySize: 0x%08x, (%d)", entrySize, entrySize);
2594 aEntry = (TRomEntry*)((char *)aEntry + entrySize);
2595 dirSize -= entrySize;
2596 HCR_TRACE2("--- aEntry: 0x%08x, dirSize:%d", aEntry, dirSize);
2609 HCR_TRACE_RETURN(retVal);
2615 TInt SearchCoreImgRepository(HCR::TRepository*& aRepos, const TText * aFileName)
2617 HCR_FUNC("SearchCoreImgRepository(TRepository*& aRepos, TText & aFileName)");
2619 TInt retVal = KErrNotFound;
2621 // Convert aFileName to directory entry style Unicode
2622 const TText* p = aFileName;
2626 // Empty file name -> return with KErrNotFound!
2627 HCR_TRACE_RETURN(retVal);
2630 while( *(++p)) {}; // Search the end of file name string.
2631 TInt nameLen=(TInt)(p-aFileName);
2633 HCR_TRACE2("--- aFileName: %s (%d)", aFileName, nameLen );
2635 TBuf<256> origFileName;
2636 origFileName.Append((const TText*)aFileName, nameLen);
2637 HCR_TRACE2("--- origFileName: %S (%d)", &origFileName, origFileName.Length());
2641 TBuf<KMaxFileName> wholeFilePath;
2647 // - wins udeb version
2648 wholeFilePath.Copy((const TText*)"\\EPOC32\\RELEASE\\WINS\\UDEB\\");
2650 // - wins urel version
2651 wholeFilePath.Copy((const TText*)"\\EPOC32\\RELEASE\\WINS\\UREL\\");
2657 // - winscw udeb version
2658 wholeFilePath.Copy((const TText*)"\\EPOC32\\RELEASE\\WINSCW\\UDEB\\");
2660 // - winscw urel version
2661 wholeFilePath.Copy((const TText*)"\\EPOC32\\RELEASE\\WINSCW\\UREL\\");
2666 for( TInt j = 0; j < nameLen; ++j)
2668 wholeFilePath.Append( origFileName[j] );
2671 HCR_TRACE3("--- epoc emulator file path: %S (%d/%d)", &wholeFilePath, wholeFilePath.Length(), wholeFilePath.Size());
2673 TInt length = wholeFilePath.Length();
2675 NKern::ThreadEnterCS();
2676 TCHAR* chFilePath = new TCHAR[length+1];
2677 NKern::ThreadLeaveCS();
2679 for(int loop=0;loop<length;++loop)
2681 chFilePath[loop] = wholeFilePath[loop];
2683 chFilePath[length] = '\0';
2685 //try to locate file
2686 WIN32_FIND_DATAW wfd;
2687 HANDLE hFile = FindFirstFile(chFilePath, &wfd);
2688 TBool foundFile = EFalse;
2689 if (hFile == INVALID_HANDLE_VALUE)
2691 HCR_TRACE0("--- file not found in \\sys\\bin; try \\sys\\data");
2696 // - wins udeb version
2697 wholeFilePath.Copy((const TText*)"\\EPOC32\\RELEASE\\WINS\\UDEB\\Z\\sys\\data\\");
2699 // - wins urel version
2700 wholeFilePath.Copy((const TText*)"\\EPOC32\\RELEASE\\WINS\\UREL\\Z\\sys\\data\\");
2706 // - winscw udeb version
2707 wholeFilePath.Copy((const TText*)"\\EPOC32\\RELEASE\\WINSCW\\UDEB\\Z\\sys\\data\\");
2709 // - winscw urel version
2710 wholeFilePath.Copy((const TText*)"\\EPOC32\\RELEASE\\WINSCW\\UREL\\Z\\sys\\data\\");
2715 for( TInt i = 0; i < nameLen; ++i)
2717 wholeFilePath.Append( origFileName[i] );
2720 HCR_TRACE3("--- epoc emulator file path: %S (%d/%d)", &wholeFilePath, wholeFilePath.Length(), wholeFilePath.Size());
2722 length = wholeFilePath.Length();
2724 NKern::ThreadEnterCS();
2725 delete[] chFilePath;
2726 chFilePath = new TCHAR[length+1];
2727 NKern::ThreadLeaveCS();
2729 for(int loop=0;loop<length;++loop)
2731 chFilePath[loop] = wholeFilePath[loop];
2733 chFilePath[length] = '\0';
2735 hFile = FindFirstFile(chFilePath, &wfd);
2737 if (hFile == INVALID_HANDLE_VALUE)
2739 HCR_TRACE0("--- file not found in \\sys\\data");
2743 HCR_TRACE0("--- file found in \\sys\\data");
2749 HCR_TRACE0("--- file found in \\sys\\bin");
2755 // No file found; release memory and return
2756 NKern::ThreadEnterCS();
2757 delete[] chFilePath;
2758 NKern::ThreadLeaveCS();
2760 HCR_TRACE_RETURN(KErrNotFound);
2764 __NK_ASSERT_ALWAYS(wfd.nFileSizeHigh==0);
2769 NKern::ThreadEnterCS();
2770 reposBuf = new BYTE[wfd.nFileSizeLow];
2771 NKern::ThreadLeaveCS();
2773 if(reposBuf == NULL)
2775 HCR_TRACEMSG_RETURN("--- Error allocating memory for reading file", KErrNoMemory);
2779 hFile = CreateFile(chFilePath, GENERIC_READ, // open for reading
2780 FILE_SHARE_READ, // share for reading
2781 NULL, // default security
2782 OPEN_EXISTING, // existing file only
2783 FILE_ATTRIBUTE_NORMAL, // normal file
2786 BOOL read = ReadFile(hFile, reposBuf, wfd.nFileSizeLow, &num_read, NULL);
2789 retVal = GetLastError();
2790 HCR_TRACE1("--- Error reading file %d", GetLastError());
2795 NKern::ThreadEnterCS();
2796 delete[] chFilePath;
2797 NKern::ThreadLeaveCS();
2799 NKern::ThreadEnterCS();
2800 aRepos = HCR::TRepositoryFile::New(reinterpret_cast<const HCR::SRepositoryFile *>(reposBuf));
2801 NKern::ThreadLeaveCS();
2805 retVal = KErrNoMemory;
2808 HCR_TRACE_RETURN(retVal);
2812 TBuf<512> fileNameBuf;
2813 for( TInt i = 0; i != nameLen; ++i)
2815 fileNameBuf.Append( 'A' <= origFileName[i] && 'Z' >= origFileName[i]? origFileName[i]+('a'-'A'): origFileName[i]);
2816 fileNameBuf.Append(TChar(0));
2819 TPtrC fileName(fileNameBuf);
2820 HCR_TRACE3("--- fileName: %S (%d/%d)", &fileName, fileName.Length(), fileName.Size());
2822 // Locate ROM Root directory
2823 TSuperPage& superpage = Kern::SuperPage();
2824 TRomRootDirectoryList* romRootDirAddress = (TRomRootDirectoryList*)superpage.iRootDirList;
2826 HCR_TRACE3("--- Superpage: 0x%08x, ROM root dir list: 0x%08x (Num of root dirs:%d)", &superpage, romRootDirAddress, romRootDirAddress->iNumRootDirs );
2828 // Search the root directory which is match to the current hardware variant
2829 TUint hardwareVariant = superpage.iActiveVariant;
2831 TRootDirInfo* rootDirInfo = 0;
2833 for(variantIndex = 0; variantIndex < romRootDirAddress->iNumRootDirs; ++variantIndex )
2835 HCR_TRACE3("--- variantIndex:%d, current hardware variant: 0x%08x, root dir hardware variant:0x%08x", variantIndex, hardwareVariant, romRootDirAddress->iRootDir[variantIndex].iHardwareVariant);
2837 if( romRootDirAddress->iRootDir[variantIndex].iHardwareVariant == hardwareVariant)
2839 rootDirInfo = &romRootDirAddress->iRootDir[variantIndex];
2844 if( rootDirInfo == 0 )
2846 // Not found root directory for this hardware variant
2847 HCR_TRACE_RETURN(retVal);
2850 TRomDir* romDir = (TRomDir*)rootDirInfo->iAddressLin;
2852 HCR_TRACE3("--- romDir: 0x%08x (files:0x%08x, entries:0x%08x)", romDir, romDir->FileCount(), romDir->EntryCount() );
2853 TRomEntry* entry = (TRomEntry*)&romDir->iEntry;
2855 // We are searching in \sys\bin\ and \sys\Data\ directory only
2856 TPtrC level1DirName((const TText*)"s\0y\0s\0", 6); // Unicode, because the entry names are unicode too.
2857 TPtrC level2Dir1Name((const TText*)"b\0i\0n\0", 6);
2858 TPtrC level2Dir2Name((const TText*)"d\0a\0t\0a\0", 8); // Originally \sys\Data however we search all entry in lower case
2860 TInt r = SearchEntryInTRomDir(romDir, level1DirName, entry);
2861 HCR_TRACE1("--- result of SearchEntryInTRomDir: 0x%08x", r);
2865 // \sys directory found.
2866 romDir = (TRomDir*)entry->iAddressLin;
2867 HCR_TRACE1("--- romDir: 0x%08x ", romDir);
2869 TRomDir* parentDir = romDir;
2870 // Search in \sys\bin directory
2871 r = SearchEntryInTRomDir(romDir, level2Dir1Name, entry);
2873 HCR_TRACE1("--- result of SearchEntryInTRomDir: 0x%08x", r);
2876 // \sys\bin directory found
2877 romDir = (TRomDir*)entry->iAddressLin;
2878 HCR_TRACE1("--- romDir: 0x%08x ", romDir);
2879 // Search the repository file
2880 r = SearchEntryInTRomDir(romDir, fileName, entry);
2882 HCR_TRACE1("--- result of SearchEntryInTRomDir: 0x%08x", r);
2885 // Repository file found
2887 HCR_TRACE1("--- Repository address: 0x%08x ", entry->iAddressLin);
2889 // HCR design requires the core image file repository to be in the
2890 // unpaged portion of the core ROM image. This check will Fault the
2891 // kernel startup if this is not found to be the case, perhaps due
2892 // to mis-configured obey files.
2893 // Skipped on emulator builds as Epoc class in platform.h not
2894 // defined. Hence support for core images not supported.
2895 __NK_ASSERT_ALWAYS(ROMAddressIsInUnpagedSection((TLinAddr)entry->iAddressLin));
2897 NKern::ThreadEnterCS();
2898 aRepos = HCR::TRepositoryFile::New(reinterpret_cast<const HCR::SRepositoryFile *>(entry->iAddressLin));
2899 NKern::ThreadLeaveCS();
2901 retVal = KErrNoMemory;
2903 HCR_TRACE_RETURN(retVal);
2907 // \sys\bin directory or repository file in \sys\bin directory not found.
2908 // Search \sys\Data directory
2910 r = SearchEntryInTRomDir(romDir, level2Dir2Name, entry);
2911 HCR_TRACE1("--- result of SearchEntryInTRomDir: 0x%08x", r);
2914 // \sys\Data directory found
2915 romDir = (TRomDir*)entry->iAddressLin;
2916 HCR_TRACE1("--- romDir: 0x%08x ", romDir);
2918 // Search repository file
2919 r = SearchEntryInTRomDir(romDir, fileName, entry);
2921 HCR_TRACE1("--- result of SearchEntryInTRomDir: 0x%08x", r);
2924 // Repository file found
2926 HCR_TRACE1("--- Repository address: 0x%08x ", entry->iAddressLin);
2928 // HCR design requires the core image file repository to be in the
2929 // unpaged portion of the core ROM image. This check will Fault the
2930 // kernel startup if this is not found to be the case, perhaps due
2931 // to mis-configured obey files.
2932 // Skipped on emulator builds as Epoc class in platform.h not
2933 // defined. Hence support for core images not supported.
2934 __NK_ASSERT_ALWAYS(ROMAddressIsInUnpagedSection((TLinAddr)entry->iAddressLin));
2936 NKern::ThreadEnterCS();
2937 aRepos = HCR::TRepositoryFile::New(reinterpret_cast<const HCR::SRepositoryFile *>(entry->iAddressLin));
2938 NKern::ThreadLeaveCS();
2940 retVal = KErrNoMemory;
2945 HCR_TRACE_RETURN(retVal);
2946 #endif //ifdef __WINS__
2949 TInt LocateCoreImgRepository(HCR::TRepository*& aRepos)
2951 HCR_FUNC("LocateCoreImgRepository");
2953 #ifdef HCRTEST_COREIMG_DONTUSE_ROMHDR
2955 // Use this testing more on Emulator platform
2956 // and on hardware when ROM Header is not to be used or not implemented
2958 const TText8* hcrfile = (const TText8*) "hcr.dat";
2959 TInt retVal = SearchCoreImgRepository(aRepos, hcrfile);
2960 if (retVal != KErrNone)
2965 const TRomHeader& romHeader = Epoc::RomHeader(); // 0x80000000;
2966 HCR_TRACE2("--- ROM Header: 0x%08x, HCR file address: 0x%08x", &romHeader, romHeader.iHcrFileAddress);
2968 if(romHeader.iHcrFileAddress != 0)
2971 // HCR design requires the core image file repository to be in the
2972 // unpaged portion of the core ROM image. This check will Fault the
2973 // kernel startup if this is not found to be the case, perhaps due
2974 // to mis-configured obey files.
2975 // Skipped on emulator builds as Epoc class in platform.h not
2976 // defined. Hence support for core images not supported.
2977 __NK_ASSERT_ALWAYS(ROMAddressIsInUnpagedSection((TLinAddr)romHeader.iHcrFileAddress));
2979 NKern::ThreadEnterCS();
2980 aRepos = HCR::TRepositoryFile::New(reinterpret_cast<const HCR::SRepositoryFile *>(romHeader.iHcrFileAddress));
2981 NKern::ThreadLeaveCS();
2983 return KErrNoMemory;
2986 return KErrNotFound;
2988 #endif // HCRTEST_COREIMG_DONTUSE_ROMHDR