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