kernel/eka/drivers/hcr/hcr_pil.cpp
changeset 31 56f325a607ea
parent 0 a41df078684a
child 39 5d2844f35677
equal deleted inserted replaced
15:4122176ea935 31:56f325a607ea
    21 #include "hcr_debug.h"
    21 #include "hcr_debug.h"
    22 
    22 
    23 #include <e32def.h>
    23 #include <e32def.h>
    24 #include <e32err.h>
    24 #include <e32err.h>
    25 #include <e32des8.h>
    25 #include <e32des8.h>
       
    26 #include <e32cmn.h>
       
    27 
    26 #include <nkern/nkern.h>
    28 #include <nkern/nkern.h>
    27 #include <kernel/kernel.h>
    29 #include <kernel/kernel.h>
    28 
    30 
    29 #include <e32rom.h>
    31 #include <e32rom.h>
    30 #include <plat_priv.h>
    32 #include <plat_priv.h>
    33 
    35 
    34 
    36 
    35 #include "hcr_hai.h"
    37 #include "hcr_hai.h"
    36 #include "hcr_pil.h"
    38 #include "hcr_pil.h"
    37 
    39 
    38 
       
    39 // -- GLOBALS -----------------------------------------------------------------
    40 // -- GLOBALS -----------------------------------------------------------------
    40 
       
    41 
    41 
    42 GLDEF_C HCR::HCRInternal gHCR;
    42 GLDEF_C HCR::HCRInternal gHCR;
    43 
    43 
    44 #ifdef HCR_TRACE
    44 #ifdef HCR_TRACE
    45 GLDEF_C TBuf<81> gTraceBuffer;
    45 GLDEF_C TBuf<81> gTraceBuffer;
    51 Retrive Repository file address stored in the iHcrFileAddress field of ROM Image header.
    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 
    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.
    53 aRepos parameter and signals it with the retun value.
    54 
    54 
    55 
    55 
    56 @param aRepos     		The reference to a repository variable
    56 @param aRepos     		The reference to a repository variable    
    57     
       
    58 @return	KErrNone 		if successful, the aRepos parameter references to the file in ROM Image.
    57 @return	KErrNone 		if successful, the aRepos parameter references to the file in ROM Image.
    59         KErrNotFound 	if the ROM Image header contains zero or a special value as the repository file address
    58         KErrNotFound 	if the ROM Image header contains zero or a special value as the repository file address
    60 
    59 
    61 
    60 
    62 */    
    61 */    
    90 */    
    89 */    
    91 
    90 
    92 LOCAL_C TInt SearchEntryInTRomDir(const TRomDir* aActDir, const TPtrC aFileName, TRomEntry* &aEntry);
    91 LOCAL_C TInt SearchEntryInTRomDir(const TRomDir* aActDir, const TPtrC aFileName, TRomEntry* &aEntry);
    93 
    92 
    94 
    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
    95 
   106 
    96 // -- FUNCTIONS ---------------------------------------------------------------
   107 // -- FUNCTIONS ---------------------------------------------------------------
    97 
   108 
    98 /**
   109 /**
    99  Returns 1 when a1 > a2
   110  Returns 1 when a1 > a2
   100  Returns -1 when a1 < a2
   111  Returns -1 when a1 < a2
   101  Returns 0 when identical.
   112  Returns 0 when identical.
   102  */
   113  */
   103 TInt CompareSSettingIds(const HCR::TSettingId& a1, const HCR::SSettingId& a2)    
   114 TInt CompareSSettingIds(const HCR::TSettingId& a1, const HCR::SSettingId& a2)    
   104 {
   115 	{
   105     // HCR_FUNC("CompareSSettingIds");
   116     // HCR_FUNC("CompareSSettingIds");
   106     if (a1.iCat > a2.iCat)
   117     if (a1.iCat > a2.iCat)
   107         return (1); // HCR_TRACE_RETURN(1);
   118         return (1); // HCR_TRACE_RETURN(1);
   108     if (a1.iCat < a2.iCat)
   119     if (a1.iCat < a2.iCat)
   109         return (-1); // HCR_TRACE_RETURN(-1);
   120         return (-1); // HCR_TRACE_RETURN(-1);
   114     if (a1.iKey < a2.iKey)
   125     if (a1.iKey < a2.iKey)
   115         return (-1); // HCR_TRACE_RETURN(-1);
   126         return (-1); // HCR_TRACE_RETURN(-1);
   116    
   127    
   117     // Both Categories and jeys are the same here.
   128     // Both Categories and jeys are the same here.
   118     return (0); // HCR_TRACE_RETURN(0);
   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);
   119     }
   189     }
   120 
   190 
   121 
   191 
   122 // -- METHODS -----------------------------------------------------------------
   192 // -- METHODS -----------------------------------------------------------------
   123 //
   193 //
   191     	{
   261     	{
   192     	err = LocateCoreImgRepository(iCoreImgStore);
   262     	err = LocateCoreImgRepository(iCoreImgStore);
   193     	if (err == KErrNone)
   263     	if (err == KErrNone)
   194      	   {
   264      	   {
   195         	if (iCoreImgStore == 0) {
   265         	if (iCoreImgStore == 0) {
   196 				err = KErrNoMemory; goto failed; }
   266 				err = KErrNoMemory; goto failed; }	
   197         	}
   267         	}
   198     	else if (err != KErrNotFound)
   268     	else if (err != KErrNotFound)
   199     		goto failed;
   269     		goto failed;
   200 		}       
   270 		}       
   201   
   271   
   236 	iStatus = EStatReady;
   306 	iStatus = EStatReady;
   237 	return KErrNone;
   307 	return KErrNone;
   238 
   308 
   239 failed:
   309 failed:
   240     iStatus = (iStatus & EStatMinorMask) | EStatFailed;
   310     iStatus = (iStatus & EStatMinorMask) | EStatFailed;
   241 	HCR_LOG_RETURN(err);
   311 	HCR_TRACE_RETURN(err);
   242     }
   312     }
   243 
   313 
   244 
   314 
   245 TInt HCR::HCRInternal::SwitchRepository(const TText * aFileName, const TReposId aId)
   315 TInt HCR::HCRInternal::SwitchRepository(const TText * aFileName, const TReposId aId)
   246 	{
   316 	{
   261 			{
   331 			{
   262 			case ECoreRepos:
   332 			case ECoreRepos:
   263 			    HCR_TRACE0("--- ECoreRepos");
   333 			    HCR_TRACE0("--- ECoreRepos");
   264 				if( iCoreImgStore )
   334 				if( iCoreImgStore )
   265 					{
   335 					{
       
   336 					NKern::ThreadEnterCS();
   266 					delete iCoreImgStore;
   337 					delete iCoreImgStore;
       
   338 					NKern::ThreadLeaveCS();
   267 					}
   339 					}
   268 				iCoreImgStore = store;
   340 				iCoreImgStore = store;
   269 				break;
   341 				break;
   270 				
   342 				
   271 			case EOverrideRepos:
   343 			case EOverrideRepos:
   272 			    HCR_TRACE0("--- EOverrideRepos");
   344 			    HCR_TRACE0("--- EOverrideRepos");
   273 				if( iCoreImgStore )
   345 				if( iOverrideStore )
   274     				{
   346     				{
       
   347 	    			NKern::ThreadEnterCS();
   275 					delete iOverrideStore;
   348 					delete iOverrideStore;
       
   349 					NKern::ThreadLeaveCS();
   276 					}
   350 					}
   277 				iOverrideStore = store;
   351 				iOverrideStore = store;
   278 				break;
   352 				break;
   279 		
   353 		
   280 			default:
   354 			default:
   282 				retVal = KErrNotSupported;
   356 				retVal = KErrNotSupported;
   283 				break;		
   357 				break;		
   284 			}
   358 			}
   285 		}
   359 		}
   286 
   360 
   287 	HCR_LOG_RETURN(retVal);
   361 	HCR_TRACE_RETURN(retVal);
   288     }
   362     }
   289 
   363 
   290 TInt HCR::HCRInternal::CheckIntegrity()
   364 TInt HCR::HCRInternal::CheckIntegrity()
   291 	{
   365 	{
   292 	HCR_FUNC("HCRInternal::CheckIntegrity");
   366 	HCR_FUNC("HCRInternal::CheckIntegrity");
   294 	TInt err = KErrNone;
   368 	TInt err = KErrNone;
   295 	if (iVariantStore)
   369 	if (iVariantStore)
   296 		{
   370 		{
   297 		err = iVariantStore->CheckIntegrity();
   371 		err = iVariantStore->CheckIntegrity();
   298 		if (err != KErrNone)
   372 		if (err != KErrNone)
   299 			HCR_LOGMSG_RETURN("HCR iVariantStore failed integrity check", err);
   373 			HCR_TRACEMSG_RETURN("HCR iVariantStore failed integrity check", err);
   300 		}
   374 		}
   301 
   375 
   302 	if (iCoreImgStore)
   376 	if (iCoreImgStore)
   303 		{
   377 		{
   304 		err = iCoreImgStore->CheckIntegrity();
   378 		err = iCoreImgStore->CheckIntegrity();
   305 		if (err != KErrNone)
   379 		if (err != KErrNone)
   306 			HCR_LOGMSG_RETURN("HCR iCoreImgStore failed integrity check", err);
   380 			HCR_TRACEMSG_RETURN("HCR iCoreImgStore failed integrity check", err);
   307 		}	
   381 		}	
   308 	
   382 	
   309 	if (iOverrideStore)
   383 	if (iOverrideStore)
   310 		{
   384 		{
   311 		err = iOverrideStore->CheckIntegrity();
   385 		err = iOverrideStore->CheckIntegrity();
   312 		if (err != KErrNone)
   386 		if (err != KErrNone)
   313 			HCR_LOGMSG_RETURN("HCR iOverrideStore failed integrity check", err);
   387 			HCR_TRACEMSG_RETURN("HCR iOverrideStore failed integrity check", err);
   314 		}
   388 		}
   315 
   389 
   316 	HCR_TRACE0("=== HCR Repository integrity checks PASSED!");
   390 	HCR_TRACE0("=== HCR Repository integrity checks PASSED!");
   317 	return KErrNone;	
   391 	return KErrNone;	
   318 	}
   392 	}
   319 
   393 
   320 TInt HCR::HCRInternal::FindSetting(const TSettingId& aId, TSettingType aType, TSettingRef& aSetting)
   394 
       
   395 TInt HCR::HCRInternal::FindSetting(const TSettingId& aId, TSettingType aType, 
       
   396         TSettingRef& aSetting)
   321     {
   397     {
   322     HCR_FUNC("HCRInternal::FindSetting");
   398     HCR_FUNC("HCRInternal::FindSetting");
   323     TInt err = 0;
   399     TInt err = 0;
   324     TBool found = EFalse;
   400     TBool found = EFalse;
   325     
   401     
   327     
   403     
   328     if (iOverrideStore && 
   404     if (iOverrideStore && 
   329         ((err = iOverrideStore->FindSetting(aId, aSetting)) == KErrNone))
   405         ((err = iOverrideStore->FindSetting(aId, aSetting)) == KErrNone))
   330         found = ETrue;
   406         found = ETrue;
   331     if ((err != KErrNone) && (err != KErrNotFound))
   407     if ((err != KErrNone) && (err != KErrNotFound))
   332         HCR_LOG_RETURN(err);
   408         HCR_TRACE_RETURN(err);
   333         
   409         
   334     if (!found &&
   410     if (!found &&
   335         iCoreImgStore &&
   411         iCoreImgStore &&
   336         ((err = iCoreImgStore->FindSetting(aId, aSetting)) == KErrNone))
   412         ((err = iCoreImgStore->FindSetting(aId, aSetting)) == KErrNone))
   337         found = ETrue;
   413         found = ETrue;
   338     if ((err != KErrNone) && (err != KErrNotFound))
   414     if ((err != KErrNone) && (err != KErrNotFound))
   339         HCR_LOG_RETURN(err);
   415         HCR_TRACE_RETURN(err);
   340 
   416 
   341     if (!found &&
   417     if (!found &&
   342         iVariantStore &&
   418         iVariantStore &&
   343         ((err = iVariantStore->FindSetting(aId, aSetting)) == KErrNone))
   419         ((err = iVariantStore->FindSetting(aId, aSetting)) == KErrNone))
   344         found = ETrue;
   420         found = ETrue;
   345         
   421         
   346     if ((err != KErrNone) && (err != KErrNotFound))
   422     if ((err != KErrNone) && (err != KErrNotFound))
   347         HCR_LOG_RETURN(err);
   423         HCR_TRACE_RETURN(err);
   348 
   424 
   349     HCR_TRACE3("--- Search results: %d, %d, %x", found, err, aSetting.iSet);
   425     HCR_TRACE3("--- Search results: %d, %d, %x", found, err, aSetting.iSet);
   350     
   426     
   351     if (!found || (aSetting.iSet == 0))
   427     if (!found || (aSetting.iSet == 0))
   352         HCR_LOG_RETURN(KErrNotFound);
   428         HCR_TRACE_RETURN(KErrNotFound);
   353 
   429 
   354     // Setting found at this point in the function
   430     // Setting found at this point in the function
   355     //
   431     //
   356     
   432     
   357     TSettingType type=static_cast<TSettingType>(aSetting.iRep->GetType(aSetting)); 
   433     TSettingType type=static_cast<TSettingType>(aSetting.iRep->GetType(aSetting)); 
   358     if (type & ~aType)
   434     if (type & ~aType)
   359         HCR_LOG_RETURN(KErrArgument); // Wrong setting type
   435         HCR_TRACE_RETURN(KErrArgument); // Wrong setting type
   360     
   436     
   361     HCR_TRACE3("--- Setting found! ID: (%d,%d) Type: %d", aId.iCat, aId.iKey, type);
   437     HCR_TRACE3("--- Setting found! ID: (%d,%d) Type: %d", aId.iCat, aId.iKey, type);
   362     
   438     
   363     return KErrNone;
   439     return KErrNone;
   364     }
   440     }
   365     
   441 
   366 TInt HCR::HCRInternal::FindWordSettings(TInt /*aNum*/, const TSettingId* /*aIds*/, 
   442 
   367                         TInt32* /*aValues*/, TSettingType* /*aTypes*/, TInt* /*aErrors*/)
   443 TInt HCR::HCRInternal::FindSettingWithType(const TSettingId& aId, TSettingType& aType, 
   368     {
   444       TSettingRef& aSetting)
   369     HCR_FUNC("HCRInternal::FindWordSettings");
   445     {
   370 
   446     HCR_FUNC("HCRInternal::FindSettingWithType");
   371     return KErrNotSupported;
   447     TInt err = 0;
   372     }
   448     TBool found = EFalse;
   373 
   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     }
   374 
  1504 
   375 
  1505 
   376 // -- METHODS -----------------------------------------------------------------
  1506 // -- METHODS -----------------------------------------------------------------
   377 //
  1507 //
   378 // TRepository
  1508 // TRepository
   379 
  1509 
       
  1510 HCR::TRepository::~TRepository()
       
  1511 	{
       
  1512     HCR_FUNC("~TRepository");
       
  1513 	}
   380 
  1514 
   381 TBool HCR::TRepository::IsWordValue(const TSettingRef& aRef)
  1515 TBool HCR::TRepository::IsWordValue(const TSettingRef& aRef)
   382     {
  1516     {
   383     HCR_FUNC("TRepository::IsWordValue");
  1517     HCR_FUNC("TRepository::IsWordValue");
   384     return ((aRef.iSet->iType & KMaskWordTypes) != 0);
  1518     return ((aRef.iSet->iType & KMaskWordTypes) != 0);
   417 	// Saves some CPU cycles...
  1551 	// Saves some CPU cycles...
   418 	// if (IsLargeValue(aRef))
  1552 	// if (IsLargeValue(aRef))
   419     return (aRef.iSet->iLen);
  1553     return (aRef.iSet->iLen);
   420     }
  1554     }
   421 
  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     }
   422 
  1567 
   423 // -- METHODS -----------------------------------------------------------------
  1568 // -- METHODS -----------------------------------------------------------------
   424 //
  1569 //
   425 // TRepositoryCompiled
  1570 // TRepositoryCompiled
   426 
  1571 
   427 
  1572 
   428 HCR::TRepository* HCR::TRepositoryCompiled::New(const SRepositoryCompiled* aRepos)
  1573 HCR::TRepository* HCR::TRepositoryCompiled::New(const SRepositoryCompiled* aRepos)
   429     {
  1574     {
   430     HCR_FUNC("TRepositoryCompiled::New");
  1575     HCR_FUNC("TRepositoryCompiled::New");
       
  1576     
       
  1577     __NK_ASSERT_ALWAYS(aRepos != 0);
   431     return new TRepositoryCompiled(aRepos);
  1578     return new TRepositoryCompiled(aRepos);
   432     }
  1579     }
   433 
  1580 
   434 HCR::TRepositoryCompiled::TRepositoryCompiled(const SRepositoryCompiled* aRepos)
  1581 HCR::TRepositoryCompiled::TRepositoryCompiled(const SRepositoryCompiled* aRepos)
   435  : iRepos(aRepos)
  1582  : iRepos(aRepos)
   440 HCR::TRepositoryCompiled::~TRepositoryCompiled()
  1587 HCR::TRepositoryCompiled::~TRepositoryCompiled()
   441     {
  1588     {
   442     HCR_FUNC("~TRepositoryCompiled");
  1589     HCR_FUNC("~TRepositoryCompiled");
   443     }
  1590     }
   444         
  1591         
   445 TInt HCR::TRepositoryCompiled::Initialise()
       
   446     {
       
   447     HCR_FUNC("TRepositoryCompiled::Initialise");
       
   448     return KErrNone;
       
   449     }
       
   450     
       
   451 TInt HCR::TRepositoryCompiled::CheckIntegrity()
  1592 TInt HCR::TRepositoryCompiled::CheckIntegrity()
   452     {
  1593     {
   453     HCR_FUNC("TRepositoryCompiled::CheckIntegrity");
  1594     HCR_FUNC("TRepositoryCompiled::CheckIntegrity");
   454     
  1595     
       
  1596     __NK_ASSERT_ALWAYS(this != 0);   
       
  1597     __NK_ASSERT_ALWAYS(iRepos != 0);
       
  1598 
   455 	if (iRepos->iOrderedSettingList == 0)
  1599 	if (iRepos->iOrderedSettingList == 0)
   456         HCR_LOGMSG_RETURN("Compiled Repository header missing setting array list", KErrNotFound);
  1600         HCR_TRACEMSG_RETURN("Compiled Repository header missing setting array list", KErrNotFound);
   457     
  1601     
   458 	HCR_TRACE2("Compiled repository 0x%x contains %05d entries", iRepos, iRepos->iHdr->iNumSettings);
  1602 	HCR_TRACE2("Compiled repository 0x%x contains %05d entries", iRepos, iRepos->iHdr->iNumSettings);
   459 
  1603 
   460     SSettingC* arr = iRepos->iOrderedSettingList;
  1604     SSettingC* arr = iRepos->iOrderedSettingList;
   461     TSettingId prev(0,0);
  1605     TSettingId prev(0,0);
   462     TInt rc=0;
  1606     TInt rc=0;
   463     for (int i=0; i < iRepos->iHdr->iNumSettings; i++, arr++)
  1607     for (int i=0; i < iRepos->iHdr->iNumSettings; i++, arr++)
   464     	{
  1608     	{
   465     	HCR_TRACE3("Checking entry %05d - (0x%x,%d)", i, arr->iName.iId.iCat,  arr->iName.iId.iKey);
  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);
   466     	rc = CompareSSettingIds(prev, arr->iName.iId);
  1611     	rc = CompareSSettingIds(prev, arr->iName.iId);
   467 		// Check for duplicates that reside next to each other
  1612 		// Check for duplicates that reside next to each other
   468     	if ((i > 0) && (rc == 0))
  1613     	if ((i > 0) && (rc == 0))
   469     		HCR_TRACE_RETURN (KErrAlreadyExists);
  1614     		HCR_TRACE_RETURN (KErrAlreadyExists);
   470     	// Check that the entries are in ascending order	
  1615     	// Check that the entries are in ascending order	
   477     
  1622     
   478 TInt HCR::TRepositoryCompiled::FindSetting(const TSettingId& aId, TSettingRef& aSetting)
  1623 TInt HCR::TRepositoryCompiled::FindSetting(const TSettingId& aId, TSettingRef& aSetting)
   479     {
  1624     {
   480     HCR_FUNC("TRepositoryCompiled::FindSetting");
  1625     HCR_FUNC("TRepositoryCompiled::FindSetting");
   481     
  1626     
       
  1627     __NK_ASSERT_DEBUG(iRepos != 0);
       
  1628     __NK_ASSERT_DEBUG(iRepos->iHdr != 0);
       
  1629     
   482     if ((iRepos->iHdr->iNumSettings == 0) || 
  1630     if ((iRepos->iHdr->iNumSettings == 0) || 
   483         (iRepos->iOrderedSettingList == 0))
  1631         (iRepos->iOrderedSettingList == 0))
   484         HCR_LOG_RETURN(KErrNotFound);
  1632         HCR_TRACE_RETURN(KErrNotFound);
   485     
  1633     
   486     SSettingC* arr = iRepos->iOrderedSettingList;
  1634     SSettingC* arr = iRepos->iOrderedSettingList;
   487     int low = 0;
  1635     int low = 0;
   488     int high = iRepos->iHdr->iNumSettings-1;
  1636     int high = iRepos->iHdr->iNumSettings-1;
   489     int mid;
  1637     int mid;
   507         
  1655         
   508     aSetting.iRep = 0;
  1656     aSetting.iRep = 0;
   509 	aSetting.iSet = 0; 
  1657 	aSetting.iSet = 0; 
   510     return KErrNotFound;
  1658     return KErrNotFound;
   511     }
  1659     }
   512     
  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 
   513 TInt HCR::TRepositoryCompiled::GetValue(const TSettingRef& aRef, UValueWord& aValue)
  2021 TInt HCR::TRepositoryCompiled::GetValue(const TSettingRef& aRef, UValueWord& aValue)
   514     {
  2022     {
   515     HCR_FUNC("TRepositoryCompiled::GetValue");
  2023     HCR_FUNC("TRepositoryCompiled::GetValue");
   516     if (!IsWordValue(aRef))
  2024     if (!IsWordValue(aRef))
   517         HCR_LOG_RETURN(KErrArgument);
  2025         HCR_TRACE_RETURN(KErrArgument);
   518         
  2026         
   519 	SSettingC* sptr = (SSettingC*)(aRef.iSet);
  2027 	SSettingC* sptr = (SSettingC*)(aRef.iSet);
   520     aValue = sptr->iValue.iLit;
  2028     aValue = sptr->iValue.iLit;
   521 	return KErrNone;
  2029 	return KErrNone;
   522     }
  2030     }
   523 
  2031 
   524 TInt HCR::TRepositoryCompiled::GetLargeValue(const TSettingRef& aRef, UValueLarge& aValue)
  2032 TInt HCR::TRepositoryCompiled::GetLargeValue(const TSettingRef& aRef, UValueLarge& aValue)
   525     {
  2033     {
   526     HCR_FUNC("TRepositoryCompiled::GetLargeValue");
  2034     HCR_FUNC("TRepositoryCompiled::GetLargeValue");
   527     if (!IsLargeValue(aRef))
  2035     if (!IsLargeValue(aRef))
   528         HCR_LOG_RETURN(KErrArgument);
  2036         HCR_TRACE_RETURN(KErrArgument);
   529 
  2037 
   530 	SSettingC* sptr = (SSettingC*)(aRef.iSet);
  2038 	SSettingC* sptr = (SSettingC*)(aRef.iSet);
   531     aValue = sptr->iValue.iPtr;
  2039     aValue = sptr->iValue.iPtr;
   532     return KErrNone;
  2040     return KErrNone;
   533     }
  2041     }
   539 
  2047 
   540 
  2048 
   541 HCR::TRepository* HCR::TRepositoryFile::New(const SRepositoryFile* aRepos)
  2049 HCR::TRepository* HCR::TRepositoryFile::New(const SRepositoryFile* aRepos)
   542     {
  2050     {
   543     HCR_FUNC("TRepositoryFile::New");
  2051     HCR_FUNC("TRepositoryFile::New");
       
  2052 
       
  2053     __NK_ASSERT_ALWAYS(aRepos != 0);
   544     return new TRepositoryFile(aRepos);
  2054     return new TRepositoryFile(aRepos);
   545     }
  2055     }
   546 
  2056 
   547 HCR::TRepositoryFile::TRepositoryFile(const SRepositoryFile* aRepos)
  2057 HCR::TRepositoryFile::TRepositoryFile(const SRepositoryFile* aRepos)
   548  : iRepos(aRepos)
  2058  : iRepos(aRepos)
   550     HCR_FUNC("TRepositoryFile");
  2060     HCR_FUNC("TRepositoryFile");
   551     }
  2061     }
   552 
  2062 
   553 HCR::TRepositoryFile::~TRepositoryFile()
  2063 HCR::TRepositoryFile::~TRepositoryFile()
   554     {
  2064     {
   555     HCR_FUNC("~TRepositoryFile");
  2065     HCR_FUNC("~TRepositoryFile"); 
   556     
       
   557     }
       
   558         
       
   559 TInt HCR::TRepositoryFile::Initialise()
       
   560     {
       
   561     HCR_FUNC("TRepositoryFile::Initialise");
       
   562     
       
   563 	
  2066 	
   564     return KErrNone;
  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 
   565     }
  2078     }
   566     
  2079     
   567 TInt HCR::TRepositoryFile::CheckIntegrity()
  2080 TInt HCR::TRepositoryFile::CheckIntegrity()
   568     {
  2081     {
   569     HCR_FUNC("TRepositoryFile::CheckIntegrity");
  2082     HCR_FUNC("TRepositoryFile::CheckIntegrity");
   570     
  2083     
       
  2084     __NK_ASSERT_ALWAYS(this != 0);   
       
  2085     __NK_ASSERT_ALWAYS(iRepos != 0);
   571     
  2086     
   572 	if ((*((TUint32*)&(iRepos->iHdr)) != 0x66524348) || 
  2087 	if ((*((TUint32*)&(iRepos->iHdr)) != 0x66524348) || 
   573 		(iRepos->iHdr.iFormatVersion != 0x0001))
  2088 		(iRepos->iHdr.iFormatVersion != 0x0001))
   574         HCR_LOGMSG_RETURN("File Repository header describes an unsupported repository type", KErrCorrupt);
  2089         HCR_TRACEMSG_RETURN("File Repository header describes an unsupported repository type", KErrCorrupt); 
   575     
  2090 	
   576     HCR_TRACE2("File repository 0x%x contains %05d entries", iRepos, iRepos->iHdr.iNumSettings);
  2091     HCR_TRACE2("File repository 0x%x contains %05d entries", iRepos, iRepos->iHdr.iNumSettings);
   577     
  2092     
   578     SSettingF* arr = (SSettingF*) (iRepos+1);
  2093     SSettingF* arr = (SSettingF*) (iRepos+1);
   579     TSettingId prev(0,0);
  2094     TSettingId prev(0,0);
   580     TInt rc=0;
  2095     TInt rc=0;
   581     for (int i=0; i < iRepos->iHdr.iNumSettings; i++, arr++)
  2096     for (int i=0; i < iRepos->iHdr.iNumSettings; i++, arr++)
   582     	{
  2097     	{
   583     	HCR_TRACE3("Checking entry %05d - (0x%x,%d)", i, arr->iName.iId.iCat,  arr->iName.iId.iKey);
  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);
   584     	rc = CompareSSettingIds(prev, arr->iName.iId);
  2100     	rc = CompareSSettingIds(prev, arr->iName.iId);
   585 	   	// Check for duplicates that reside next to each other
  2101 	   	// Check for duplicates that reside next to each other
   586     	if ((i > 0) && (rc == 0))
  2102     	if ((i > 0) && (rc == 0))
   587     		HCR_TRACE_RETURN (KErrAlreadyExists);
  2103     		HCR_TRACE_RETURN (KErrAlreadyExists);
   588     	// Check that the entries are in ascending order	
  2104     	// Check that the entries are in ascending order	
   594     }
  2110     }
   595 
  2111 
   596 TInt HCR::TRepositoryFile::FindSetting(const TSettingId& aId, TSettingRef& aSetting)
  2112 TInt HCR::TRepositoryFile::FindSetting(const TSettingId& aId, TSettingRef& aSetting)
   597     {
  2113     {
   598     HCR_FUNC("TRepositoryFile::FindSetting");
  2114     HCR_FUNC("TRepositoryFile::FindSetting");
   599     
  2115  
       
  2116     __NK_ASSERT_DEBUG(iRepos != 0);
       
  2117    
   600     if (iRepos->iHdr.iNumSettings == 0)
  2118     if (iRepos->iHdr.iNumSettings == 0)
   601         HCR_LOG_RETURN(KErrNotFound);
  2119         HCR_TRACE_RETURN(KErrNotFound);
   602     
  2120     
   603     SSettingF* arr = (SSettingF*) (iRepos+1);
  2121     SSettingF* arr = (SSettingF*) (iRepos+1);
   604     int low = 0;
  2122     int low = 0;
   605     int high = iRepos->iHdr.iNumSettings-1;
  2123     int high = iRepos->iHdr.iNumSettings-1;
   606     int mid;
  2124     int mid;
   625     aSetting.iRep = 0;
  2143     aSetting.iRep = 0;
   626 	aSetting.iSet = 0; 
  2144 	aSetting.iSet = 0; 
   627     return KErrNotFound;
  2145     return KErrNotFound;
   628     }
  2146     }
   629 
  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 
   630 TInt HCR::TRepositoryFile::GetValue(const TSettingRef& aRef, UValueWord& aValue)
  2504 TInt HCR::TRepositoryFile::GetValue(const TSettingRef& aRef, UValueWord& aValue)
   631     {
  2505     {
   632     HCR_FUNC("TRepositoryFile::GetValue");
  2506     HCR_FUNC("TRepositoryFile::GetValue");
   633 
  2507 
   634     if (!IsWordValue(aRef))
  2508     if (!IsWordValue(aRef))
   635         HCR_LOG_RETURN(KErrArgument);
  2509         HCR_TRACE_RETURN(KErrArgument);
   636         
  2510         
   637 	SSettingF* sptr = (SSettingF*)(aRef.iSet);
  2511 	SSettingF* sptr = (SSettingF*)(aRef.iSet);
   638     aValue = sptr->iValue.iLit;
  2512     aValue = sptr->iValue.iLit;
   639 	return KErrNone;
  2513 	return KErrNone;
   640     }
  2514     }
   641 
  2515 
       
  2516 
   642 TInt HCR::TRepositoryFile::GetLargeValue(const TSettingRef& aRef, UValueLarge& aValue)
  2517 TInt HCR::TRepositoryFile::GetLargeValue(const TSettingRef& aRef, UValueLarge& aValue)
   643     {
  2518     {
   644     HCR_FUNC("TRepositoryFile::GetLargeValue");
  2519     HCR_FUNC("TRepositoryFile::GetLargeValue");
   645 
  2520 
   646     if (!IsLargeValue(aRef))
  2521     if (!IsLargeValue(aRef))
   647         HCR_LOG_RETURN(KErrArgument);
  2522         HCR_TRACE_RETURN(KErrArgument);
   648 
  2523 
   649 	SSettingF* sptr = (SSettingF*)(aRef.iSet);
  2524 	SSettingF* sptr = (SSettingF*)(aRef.iSet);
   650 	TRepositoryFile *rptr = (TRepositoryFile *)(aRef.iRep);
  2525 	TRepositoryFile *rptr = (TRepositoryFile *)(aRef.iRep);
   651 	
  2526 	
   652     aValue.iData = (TUint8*) rptr->iRepos;
  2527     aValue.iData = (TUint8*) rptr->iRepos;
   653 	aValue.iData += rptr->iRepos->iLSDfirstByteOffset+sptr->iValue.iOffset;
  2528 	aValue.iData += rptr->iRepos->iLSDfirstByteOffset+sptr->iValue.iOffset;
       
  2529 	
   654     return KErrNone;
  2530     return KErrNone;
   655     }
  2531     }
   656 
       
   657 
  2532 
   658 
  2533 
   659 // -- FUNCTIONS ---------------------------------------------------------------
  2534 // -- FUNCTIONS ---------------------------------------------------------------
   660 
  2535 
   661 #ifndef HCRTEST_NO_KEXT_ENTRY_POINT
  2536 #ifndef HCRTEST_NO_KEXT_ENTRY_POINT
   667 	{
  2542 	{
   668 	HCR_FUNC("InitExtension");
  2543 	HCR_FUNC("InitExtension");
   669 
  2544 
   670 	HCR::MVariant* varPtr = CreateHCRVariant();
  2545 	HCR::MVariant* varPtr = CreateHCRVariant();
   671 	if (varPtr==0)
  2546 	if (varPtr==0)
   672 		HCR_LOG_RETURN(KErrNoMemory);
  2547 		HCR_TRACE_RETURN(KErrNoMemory);
   673 
  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
   674 	new(&gHCR) HCR::HCRInternal(varPtr);
  2552 	new(&gHCR) HCR::HCRInternal(varPtr);
   675 
  2553 
   676 	TInt err = HCRSingleton->Initialise();
  2554 	TInt err = HCRSingleton->Initialise();
   677 
  2555 
   678 	if (err != KErrNone)
  2556 	if (err != KErrNone)
   679 		HCR_LOG_RETURN(err);
  2557 		HCR_TRACE_RETURN(err);
   680 
  2558 
   681 	return err;
  2559 	return err;
   682 	}
  2560 	}
   683 #endif // HCRTEST_NO_KEXT_ENTRY_POINT
  2561 #endif // HCRTEST_NO_KEXT_ENTRY_POINT
   684 
  2562 
   685 // -- Implementation of local functions
  2563 // -- Implementation of local functions
   686 
  2564 #ifndef __WINS__
   687 TInt SearchEntryInTRomDir(const TRomDir* aActDir, const TPtrC aFileName, TRomEntry* &aEntry)
  2565 TInt SearchEntryInTRomDir(const TRomDir* aActDir, const TPtrC aFileName, TRomEntry* &aEntry)
   688 	{
  2566 	{
   689 	HCR_FUNC("SearchEntryInTRomDir");
  2567 	HCR_FUNC("SearchEntryInTRomDir");
   690 	TInt retVal = KErrNotFound;
  2568 	TInt retVal = KErrNotFound;
   691 	HCR_TRACE2("--- aFileName: %S (%d)", &aFileName, aFileName.Length());
  2569 	HCR_TRACE2("--- aFileName: %S (%d)", &aFileName, aFileName.Length());
   700 	HCR_TRACE3("--- dirSize: 0x%08x (%d), aEntry: 0x%08x", dirSize, dirSize, aEntry);
  2578 	HCR_TRACE3("--- dirSize: 0x%08x (%d), aEntry: 0x%08x", dirSize, dirSize, aEntry);
   701 	
  2579 	
   702 	TBool found = EFalse;
  2580 	TBool found = EFalse;
   703 	while( !found )
  2581 	while( !found )
   704 		{
  2582 		{
   705 		HCR_TRACE0("Begin of loop...");
       
   706 		TInt nameLength = (aEntry->iNameLength)<<1;
  2583 		TInt nameLength = (aEntry->iNameLength)<<1;
   707 		
  2584 		
   708 		HCR_HEX_DUMP_ABS((TUint8 *)aEntry, sizeof(TRomEntry)+(nameLength - 2) );
  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) );
   709 		const TText* entryName = &aEntry->iName[0];
  2588 		const TText* entryName = &aEntry->iName[0];
   710 		HCR_TRACE1("--- entryName length: %d", nameLength);
  2589 		HCR_TRACE1("--- entryName length: %d", nameLength);
   711 		TBuf<512> newEntryName( nameLength);
  2590 		TBuf<512> newEntryName( nameLength);
   712 		for( TInt i = 0; i != nameLength; ++i)
  2591 		for( TInt i = 0; i != nameLength; ++i)
   713 			{
  2592 			{
   749 		}
  2628 		}
   750 		
  2629 		
   751 	HCR_TRACE_RETURN(retVal);		
  2630 	HCR_TRACE_RETURN(retVal);		
   752 	}
  2631 	}
   753 	
  2632 	
       
  2633 #endif // !__WINS__
       
  2634 
       
  2635 
   754 TInt SearchCoreImgRepository(HCR::TRepository*& aRepos, const TText * aFileName)
  2636 TInt SearchCoreImgRepository(HCR::TRepository*& aRepos, const TText * aFileName)
   755     {
  2637     {
   756     HCR_FUNC("SearchCoreImgRepository(TRepository*& aRepos, TText & aFileName)");
  2638     HCR_FUNC("SearchCoreImgRepository(TRepository*& aRepos, TText & aFileName)");
   757     
  2639     
   758     TInt retVal = KErrNotFound;
  2640     TInt retVal = KErrNotFound;
   773 	
  2655 	
   774 	TBuf<256> origFileName;
  2656 	TBuf<256> origFileName;
   775 	origFileName.Append((const TText*)aFileName, nameLen);
  2657 	origFileName.Append((const TText*)aFileName, nameLen);
   776 	HCR_TRACE2("--- origFileName: %S (%d)", &origFileName, origFileName.Length());
  2658 	HCR_TRACE2("--- origFileName: %S (%d)", &origFileName, origFileName.Length());
   777 	
  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
   778 	
  2832 	
   779 	TBuf<512> fileNameBuf;
  2833 	TBuf<512> fileNameBuf;
   780 	for( TInt i = 0; i != nameLen; ++i)
  2834 	for( TInt i = 0; i != nameLen; ++i)
   781 		{
  2835 		{
   782 		fileNameBuf.Append( 'A' <= origFileName[i] && 'Z' >= origFileName[i]? origFileName[i]+('a'-'A'): origFileName[i]);
  2836 		fileNameBuf.Append( 'A' <= origFileName[i] && 'Z' >= origFileName[i]? origFileName[i]+('a'-'A'): origFileName[i]);
   811     if( rootDirInfo == 0 )
  2865     if( rootDirInfo == 0 )
   812 	    {
  2866 	    {
   813 	    // Not found root directory for this hardware variant
  2867 	    // Not found root directory for this hardware variant
   814 	    HCR_TRACE_RETURN(retVal);
  2868 	    HCR_TRACE_RETURN(retVal);
   815 	    }
  2869 	    }
   816 	    
  2870     
   817 	TRomDir* romDir = (TRomDir*)rootDirInfo->iAddressLin;
  2871 	TRomDir* romDir = (TRomDir*)rootDirInfo->iAddressLin;
   818 
  2872 
   819 	HCR_TRACE3("--- romDir: 0x%08x (files:0x%08x, entries:0x%08x)", romDir, romDir->FileCount(), romDir->EntryCount() );
  2873 	HCR_TRACE3("--- romDir: 0x%08x (files:0x%08x, entries:0x%08x)", romDir, romDir->FileCount(), romDir->EntryCount() );
   820 	TRomEntry* entry = (TRomEntry*)&romDir->iEntry;
  2874 	TRomEntry* entry = (TRomEntry*)&romDir->iEntry;
   821 	
  2875 	
   850 			if( r == KErrNone)
  2904 			if( r == KErrNone)
   851 				{
  2905 				{
   852 				// Repository file found
  2906 				// Repository file found
   853 				retVal = KErrNone;				
  2907 				retVal = KErrNone;				
   854 				HCR_TRACE1("--- Repository address: 0x%08x ", entry->iAddressLin);
  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();
   855 				aRepos = HCR::TRepositoryFile::New(reinterpret_cast<const HCR::SRepositoryFile *>(entry->iAddressLin));	
  2919 				aRepos = HCR::TRepositoryFile::New(reinterpret_cast<const HCR::SRepositoryFile *>(entry->iAddressLin));	
       
  2920 				NKern::ThreadLeaveCS();
   856 				if (aRepos == NULL)
  2921 				if (aRepos == NULL)
   857                         retVal = KErrNoMemory;					
  2922                         retVal = KErrNoMemory;					
   858                         
  2923                         
   859                 HCR_TRACE_RETURN(retVal);
  2924                 HCR_TRACE_RETURN(retVal);
   860 				}
  2925 				}
   878 			if( r == KErrNone)
  2943 			if( r == KErrNone)
   879 				{
  2944 				{
   880 				// Repository file found    
  2945 				// Repository file found    
   881 				retVal = KErrNone;				
  2946 				retVal = KErrNone;				
   882 				HCR_TRACE1("--- Repository address: 0x%08x ", entry->iAddressLin);
  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();
   883 				aRepos = HCR::TRepositoryFile::New(reinterpret_cast<const HCR::SRepositoryFile *>(entry->iAddressLin));
  2958 				aRepos = HCR::TRepositoryFile::New(reinterpret_cast<const HCR::SRepositoryFile *>(entry->iAddressLin));
       
  2959 				NKern::ThreadLeaveCS();
   884 				if (aRepos == NULL)
  2960 				if (aRepos == NULL)
   885                     retVal = KErrNoMemory;					
  2961                     retVal = KErrNoMemory;					
   886 				}
  2962 				}
   887 			}
  2963 			}
   888 		}
  2964 		}
   889 	
  2965 	
   890     HCR_TRACE_RETURN(retVal);
  2966     HCR_TRACE_RETURN(retVal);
       
  2967 #endif //ifdef __WINS__
   891     }
  2968     }
   892 
  2969 
   893 TInt LocateCoreImgRepository(HCR::TRepository*& aRepos)
  2970 TInt LocateCoreImgRepository(HCR::TRepository*& aRepos)
   894     {
  2971     {
   895     HCR_FUNC("LocateCoreImgRepository");
  2972     HCR_FUNC("LocateCoreImgRepository");
   896 
  2973 
   897 #ifdef __WINS__
       
   898     aRepos = 0;                     // To avoid warning on WINS
       
   899     return KErrNotFound;
       
   900 #else
       
   901 
       
   902 #ifdef HCRTEST_COREIMG_DONTUSE_ROMHDR
  2974 #ifdef HCRTEST_COREIMG_DONTUSE_ROMHDR
   903 
  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     
   904 	const TText8* hcrfile = (const TText8*) "hcr.dat";
  2979 	const TText8* hcrfile = (const TText8*) "hcr.dat";
   905 	TInt retVal = SearchCoreImgRepository(aRepos, hcrfile);
  2980 	TInt retVal = SearchCoreImgRepository(aRepos, hcrfile);
   906 	if (retVal != KErrNone)
  2981 	if (retVal != KErrNone)
   907 		return retVal;
  2982 		return retVal;
   908 	
  2983 	
   911 	const TRomHeader& romHeader = Epoc::RomHeader(); 	// 0x80000000;
  2986 	const TRomHeader& romHeader = Epoc::RomHeader(); 	// 0x80000000;
   912 	HCR_TRACE2("--- ROM Header: 0x%08x, HCR file address: 0x%08x", &romHeader, romHeader.iHcrFileAddress);
  2987 	HCR_TRACE2("--- ROM Header: 0x%08x, HCR file address: 0x%08x", &romHeader, romHeader.iHcrFileAddress);
   913 	
  2988 	
   914 	if(romHeader.iHcrFileAddress != 0)
  2989 	if(romHeader.iHcrFileAddress != 0)
   915 			{
  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();
   916 			aRepos = HCR::TRepositoryFile::New(reinterpret_cast<const HCR::SRepositoryFile *>(romHeader.iHcrFileAddress));
  3001 			aRepos = HCR::TRepositoryFile::New(reinterpret_cast<const HCR::SRepositoryFile *>(romHeader.iHcrFileAddress));
       
  3002 			NKern::ThreadLeaveCS();
   917 			if (aRepos == 0)
  3003 			if (aRepos == 0)
   918 				return KErrNoMemory;
  3004 				return KErrNoMemory;
   919 			}
  3005 			}
   920 	else
  3006 	else
   921 		return KErrNotFound;
  3007 		return KErrNotFound;
   922 		
  3008 		
   923 #endif // HCRTEST_COREIMG_DONTUSE_ROMHDR
  3009 #endif // HCRTEST_COREIMG_DONTUSE_ROMHDR
       
  3010 
       
  3011 
   924 	return KErrNone;
  3012 	return KErrNone;
   925 #endif // __WINS__
       
   926     }
  3013     }
   927 	
  3014