kernel/eka/drivers/hcr/hcr_pil.cpp
changeset 47 46fffbe7b5a7
parent 43 96e5fb8b040d
equal deleted inserted replaced
46:0bf4040442f9 47:46fffbe7b5a7
   206     }
   206     }
   207     
   207     
   208 HCR::HCRInternal::~HCRInternal()
   208 HCR::HCRInternal::~HCRInternal()
   209     {
   209     {
   210     HCR_FUNC("~HCRInternal");
   210     HCR_FUNC("~HCRInternal");
       
   211     
       
   212     if (iVariant)
       
   213 		{
       
   214 		delete iVariant;
       
   215     	iVariant =0;
       
   216     	}
       
   217     if (iVariantStore)
       
   218 		{
       
   219 		delete iVariantStore;
       
   220     	iVariantStore =0;
       
   221     	}
       
   222     if (iCoreImgStore)
       
   223 		{
       
   224 		delete iCoreImgStore;
       
   225     	iCoreImgStore =0;
       
   226     	}
       
   227     if (iOverrideStore)
       
   228 		{
       
   229 		delete iOverrideStore;
       
   230     	iOverrideStore =0;
       
   231     	}
   211     }
   232     }
   212    
   233    
   213 TUint32 HCR::HCRInternal::GetStatus()
   234 TUint32 HCR::HCRInternal::GetStatus()
   214     {
   235     {
   215     HCR_FUNC("GetStatus");
   236     HCR_FUNC("GetStatus");
   394 
   415 
   395 TInt HCR::HCRInternal::FindSetting(const TSettingId& aId, TSettingType aType, 
   416 TInt HCR::HCRInternal::FindSetting(const TSettingId& aId, TSettingType aType, 
   396         TSettingRef& aSetting)
   417         TSettingRef& aSetting)
   397     {
   418     {
   398     HCR_FUNC("HCRInternal::FindSetting");
   419     HCR_FUNC("HCRInternal::FindSetting");
   399     TInt err = 0;
   420     TInt err = KErrNone;
   400     TBool found = EFalse;
   421     TBool found = EFalse;
   401     
   422     
   402     HCR_TRACE3("--- Repository state: %x, %x, %x", iOverrideStore, iCoreImgStore, iVariantStore);
   423     HCR_TRACE3("--- Repository state: %x, %x, %x", iOverrideStore, iCoreImgStore, iVariantStore);
   403     
   424     
   404     if (iOverrideStore && 
   425     if (iOverrideStore && 
   405         ((err = iOverrideStore->FindSetting(aId, aSetting)) == KErrNone))
   426         ((err = iOverrideStore->FindSetting(aId, aSetting)) == KErrNone))
   406         found = ETrue;
   427         found = ETrue;
   407     if ((err != KErrNone) && (err != KErrNotFound))
   428     __NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
   408         HCR_TRACE_RETURN(err);
       
   409         
   429         
   410     if (!found &&
   430     if (!found &&
   411         iCoreImgStore &&
   431         iCoreImgStore &&
   412         ((err = iCoreImgStore->FindSetting(aId, aSetting)) == KErrNone))
   432         ((err = iCoreImgStore->FindSetting(aId, aSetting)) == KErrNone))
   413         found = ETrue;
   433         found = ETrue;
   414     if ((err != KErrNone) && (err != KErrNotFound))
   434     __NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
   415         HCR_TRACE_RETURN(err);
       
   416 
   435 
   417     if (!found &&
   436     if (!found &&
   418         iVariantStore &&
   437         iVariantStore &&
   419         ((err = iVariantStore->FindSetting(aId, aSetting)) == KErrNone))
   438         ((err = iVariantStore->FindSetting(aId, aSetting)) == KErrNone))
   420         found = ETrue;
   439         found = ETrue;
   421         
   440     __NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
   422     if ((err != KErrNone) && (err != KErrNotFound))
       
   423         HCR_TRACE_RETURN(err);
       
   424 
   441 
   425     HCR_TRACE3("--- Search results: %d, %d, %x", found, err, aSetting.iSet);
   442     HCR_TRACE3("--- Search results: %d, %d, %x", found, err, aSetting.iSet);
   426     
   443     
   427     if (!found || (aSetting.iSet == 0))
   444     if (!found)
   428         HCR_TRACE_RETURN(KErrNotFound);
   445         HCR_TRACE_RETURN(KErrNotFound);
       
   446 
       
   447     // aSetting should now point to the found setting
       
   448     __NK_ASSERT_DEBUG(aSetting.iSet != 0);
   429 
   449 
   430     // Setting found at this point in the function
   450     // Setting found at this point in the function
   431     //
   451     //
   432     
   452     
   433     TSettingType type=static_cast<TSettingType>(aSetting.iRep->GetType(aSetting)); 
   453     TSettingType type=static_cast<TSettingType>(aSetting.iRep->GetType(aSetting)); 
   434     if (type & ~aType)
   454     if (type & ~aType)
   435         HCR_TRACE_RETURN(KErrArgument); // Wrong setting type
   455         HCR_TRACE_RETURN(KErrArgument); // Wrong setting type
   436     
   456     
   437     HCR_TRACE3("--- Setting found! ID: (%d,%d) Type: %d", aId.iCat, aId.iKey, type);
   457     HCR_TRACE3("--- Setting found! ID: (%d,%d) Type: %d", aId.iCat, aId.iKey, type);
   438     
   458     
   439     return KErrNone;
   459     return err;
   440     }
   460     }
   441 
   461 
   442 
   462 
   443 TInt HCR::HCRInternal::FindSettingWithType(const TSettingId& aId, TSettingType& aType, 
   463 TInt HCR::HCRInternal::FindSettingWithType(const TSettingId& aId, TSettingType& aType, 
   444       TSettingRef& aSetting)
   464       TSettingRef& aSetting)
   445     {
   465     {
   446     HCR_FUNC("HCRInternal::FindSettingWithType");
   466     HCR_FUNC("HCRInternal::FindSettingWithType");
   447     TInt err = 0;
   467     TInt err = KErrNone;
   448     TBool found = EFalse;
   468     TBool found = EFalse;
   449     
   469     
   450     HCR_TRACE3("--- Repository state: %x, %x, %x", iOverrideStore, iCoreImgStore, iVariantStore);
   470     HCR_TRACE3("--- Repository state: %x, %x, %x", iOverrideStore, iCoreImgStore, iVariantStore);
   451     
   471     
   452     if (iOverrideStore && 
   472     if (iOverrideStore && 
   453         ((err = iOverrideStore->FindSetting(aId, aSetting)) == KErrNone))
   473         ((err = iOverrideStore->FindSetting(aId, aSetting)) == KErrNone))
   454         found = ETrue;
   474         found = ETrue;
   455     if ((err != KErrNone) && (err != KErrNotFound))
   475     __NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
   456         HCR_TRACE_RETURN(err);
   476 
   457         
       
   458     if (!found &&
   477     if (!found &&
   459         iCoreImgStore &&
   478         iCoreImgStore &&
   460         ((err = iCoreImgStore->FindSetting(aId, aSetting)) == KErrNone))
   479         ((err = iCoreImgStore->FindSetting(aId, aSetting)) == KErrNone))
   461         found = ETrue;
   480         found = ETrue;
   462     if ((err != KErrNone) && (err != KErrNotFound))
   481     __NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
   463         HCR_TRACE_RETURN(err);
       
   464 
   482 
   465     if (!found &&
   483     if (!found &&
   466         iVariantStore &&
   484         iVariantStore &&
   467         ((err = iVariantStore->FindSetting(aId, aSetting)) == KErrNone))
   485         ((err = iVariantStore->FindSetting(aId, aSetting)) == KErrNone))
   468         found = ETrue;
   486         found = ETrue;
   469         
   487     __NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
   470     if ((err != KErrNone) && (err != KErrNotFound))
       
   471         HCR_TRACE_RETURN(err);
       
   472 
   488 
   473     HCR_TRACE3("--- Search results: %d, %d, %x", found, err, aSetting.iSet);
   489     HCR_TRACE3("--- Search results: %d, %d, %x", found, err, aSetting.iSet);
   474     
   490     
   475     if (!found || (aSetting.iSet == 0))
   491     if (!found)
   476         {
   492         {
   477         aType = ETypeUndefined;
   493         aType = ETypeUndefined;
   478         HCR_TRACE_RETURN(KErrNotFound);
   494         HCR_TRACE_RETURN(KErrNotFound);
   479         }
   495         }
   480 
   496 
       
   497     // aSetting should now point to the found setting
       
   498     __NK_ASSERT_DEBUG(aSetting.iSet != 0);
       
   499 
   481     // Setting found at this point in the function
   500     // Setting found at this point in the function
   482     //
   501     //
   483     
   502     
   484     aType=static_cast<TSettingType>(aSetting.iRep->GetType(aSetting)); 
   503     aType=static_cast<TSettingType>(aSetting.iRep->GetType(aSetting)); 
   485     
   504     
   486     HCR_TRACE3("--- Setting found! ID: (%d,%d) Type: %d", aId.iCat, aId.iKey, aType);
   505     HCR_TRACE3("--- Setting found! ID: (%d,%d) Type: %d", aId.iCat, aId.iKey, aType);
   487     
   506     
   488     return KErrNone;
   507     return err;
   489     }
   508     }
   490 
   509 
   491 
   510 
   492 TInt HCR::HCRInternal::GetWordSettings(TInt aNum, const SSettingId aIds[], 
   511 TInt HCR::HCRInternal::GetWordSettings(TInt aNum, const SSettingId aIds[], 
   493         TInt32 aValues[], TSettingType aTypes[], TInt aErrors[])
   512         TInt32 aValues[], TSettingType aTypes[], TInt aErrors[])
   924                     {
   943                     {
   925                     //if the element is found in the Override store, then store the posi-
   944                     //if the element is found in the Override store, then store the posi-
   926                     //tion of this element in lowIndex, to narrow next search procedure
   945                     //tion of this element in lowIndex, to narrow next search procedure
   927                     lowIndex = elementPos;
   946                     lowIndex = elementPos;
   928                     }
   947                     }
   929                 else if(err == KErrNotFound)
   948                 else //err == KErrNotFound
   930                     {
   949                     {
   931                     //if element is not found then it means it's not redefined in the 
   950                     //if element is not found then it means it's not redefined in the 
   932                     //Override store and this element must be counted in the total number
   951                     //Override store and this element must be counted in the total number
   933                     //of elemnts in all stores
   952                     //of elemnts in all stores
   934                     cCount ++;
   953                     cCount ++;
       
   954                     
       
   955                     //FindSetting can only return KErrNotFound, let's assert 
       
   956                     //we've only got KErrNotFound
       
   957                     __NK_ASSERT_DEBUG(err == KErrNotFound);
       
   958                     
   935                     }
   959                     }
   936                 else
   960                 
   937                     {
       
   938                     return err;
       
   939                     }
       
   940                 }
   961                 }
   941             }
   962             }
   942         else
   963         else
   943             {
   964             {
   944             cCount = cLength;
   965             cCount = cLength;
   945             }
   966             }
   946 
       
   947 
       
   948 
       
   949         //Check if the Variant store is present if it's not then just return the
       
   950         //result
       
   951         if(!iVariantStore)
       
   952             return (oCount + cCount);
       
   953 
   967 
   954         }
   968         }
   955 
   969 
   956     //First and last element index within giving category in the Variant store
   970     //First and last element index within giving category in the Variant store
   957     TInt32 vLowIndex  = 0;
   971     TInt32 vLowIndex  = 0;
   972             vLength = 0;
   986             vLength = 0;
   973         else
   987         else
   974             //Calculate the number of elements within category, in CoreImg store
   988             //Calculate the number of elements within category, in CoreImg store
   975             vLength = vHighIndex - vLowIndex + 1;
   989             vLength = vHighIndex - vLowIndex + 1;
   976 
   990 
   977         if(oCount == 0 && cCount == 0)
       
   978             {
       
   979             return vLength;
       
   980             }
       
   981 
   991 
   982         if(oCount > 0 || cCount >0)
   992         if(oCount > 0 || cCount >0)
   983             {
   993             {
   984             //Find all elemnts from Variant store which are not redefined either in the 
   994             //Find all elemnts from Variant store which are not redefined either in the 
   985             //Override or CoreImg store. These elements are added to the total 
   995             //Override or CoreImg store. These elements are added to the total 
  1020                         //if the element is found in the Override store, then store the posi-
  1030                         //if the element is found in the Override store, then store the posi-
  1021                         //tion of this element in lowIndex, to narrow next search procedure
  1031                         //tion of this element in lowIndex, to narrow next search procedure
  1022                         lowIndex = elementPos;
  1032                         lowIndex = elementPos;
  1023                         isRedefined = ETrue;
  1033                         isRedefined = ETrue;
  1024                         }
  1034                         }
  1025                     else if(err == KErrNotFound)
  1035                     else //err == KErrNotFound
  1026                         {
  1036                         {
  1027                         //the element is not presented in the Override store
  1037                         //the element is not presented in the Override store
  1028                         //nothing to do here
  1038                         //nothing to do here
       
  1039 
       
  1040                         //FindSetting can only return KErrNotFound, let's assert 
       
  1041                         //we've only got KErrNotFound
       
  1042                         __NK_ASSERT_DEBUG(err == KErrNotFound);
  1029                         }
  1043                         }
  1030                     else
  1044                     
  1031                         {
       
  1032                         return err;
       
  1033                         }
       
  1034 
  1045 
  1035                     }
  1046                     }
  1036 
  1047 
  1037 
  1048 
  1038                 if(cCount > 0 && !isRedefined)
  1049                 if(cCount > 0 && !isRedefined)
  1047                         //if the element is found in the Override store, then store the posi-
  1058                         //if the element is found in the Override store, then store the posi-
  1048                         //tion of this element in lowIndex, to narrow next search procedure
  1059                         //tion of this element in lowIndex, to narrow next search procedure
  1049                         lowIndex2 = elementPos2;
  1060                         lowIndex2 = elementPos2;
  1050                         isRedefined = ETrue;
  1061                         isRedefined = ETrue;
  1051                         }
  1062                         }
  1052                     else if(err == KErrNotFound)
  1063                     else //err == KErrNotFound
  1053                         {
  1064                         {
  1054                         //the element is not presented in the Override store
  1065                         //the element is not presented in the Override store
  1055                                                 //nothing to do here
  1066                         //nothing to do here
       
  1067 
       
  1068                         //FindSetting can only return KErrNotFound, let's assert 
       
  1069                         //we've only got KErrNotFound
       
  1070                         __NK_ASSERT_DEBUG(err == KErrNotFound);
  1056                         }
  1071                         }
  1057                     else
  1072                     
  1058                         {
       
  1059                         return err;
       
  1060                         }
       
  1061                     }
  1073                     }
  1062                 
  1074                 
  1063 
  1075 
  1064                 if(!isRedefined)
  1076                 if(!isRedefined)
  1065                     vCount ++;
  1077                     vCount ++;
  1091     HCR_TRACE3("--- Repository state: %x, %x, %x", iOverrideStore, 
  1103     HCR_TRACE3("--- Repository state: %x, %x, %x", iOverrideStore, 
  1092             iCoreImgStore, iVariantStore);
  1104             iCoreImgStore, iVariantStore);
  1093    
  1105    
  1094     //Error container
  1106     //Error container
  1095     TInt err = KErrNone;
  1107     TInt err = KErrNone;
  1096 
  1108     
  1097     //Total number of found elements
       
  1098     TInt numFound = 0;
       
  1099     //Number of found elements in the Override store
  1109     //Number of found elements in the Override store
  1100     TInt oNumFound = 0;
  1110     TInt oNumFound = 0;
  1101 
  1111 
  1102     //Low and High indexes in the Override store
  1112     //Low and High indexes in the Override store
  1103     TInt32 oLoIndex = 0;
  1113     TInt32 oLoIndex = 0;
  1161                             aIds[index], 
  1171                             aIds[index], 
  1162                             aTypes ? aTypes[index]:tmpType,
  1172                             aTypes ? aTypes[index]:tmpType,
  1163                             aLens  ? aLens[index]:tmpLen);
  1173                             aLens  ? aLens[index]:tmpLen);
  1164 
  1174 
  1165                     }
  1175                     }
  1166                 return oNumFound;
  1176                 return aMaxNum;
  1167                 }
  1177                 }
  1168             }
  1178             }
  1169         else if(err == KErrNotFound)
  1179         else // err == KErrNotFound
  1170             {
  1180             {
  1171             //Nothing to do here, oNumFound is set to zero already
  1181             //Nothing to do here, oNumFound is set to zero already
  1172             }
  1182 
  1173         else 
  1183             //FindNumSettingsInCategory can only return KErrNotFound, let's  
  1174             {
  1184             //assert we've only got KErrNotFound
  1175             return err;
  1185             __NK_ASSERT_DEBUG(err == KErrNotFound);
  1176             }
  1186             }
       
  1187 
  1177         }
  1188         }
  1178 
  1189 
  1179    
  1190    
  1180     //Low/High index in the CoreImg
  1191     //Low/High index in the CoreImg
  1181     TInt32 cLoIndex = 0;
  1192     TInt32 cLoIndex = 0;
  1224                     if(err == KErrNone)
  1235                     if(err == KErrNone)
  1225                         {
  1236                         {
  1226                         lowIndex = elementPos + 1;
  1237                         lowIndex = elementPos + 1;
  1227                         isRedefined = ETrue;
  1238                         isRedefined = ETrue;
  1228                         }
  1239                         }
  1229                     else if (err == KErrNotFound)
  1240                     else //err == KErrNotFound
  1230                         {
  1241                         {
  1231                         //Nothing to do hear, isRedefined flag is EFalse
  1242                         //Nothing to do hear, isRedefined flag is EFalse
  1232                         //all analysis is done later in the code
  1243                         //all analysis is done later in the code
       
  1244 
       
  1245                         //FindSetting can only return KErrNotFound, let's assert 
       
  1246                         //we've only got KErrNotFound
       
  1247                         __NK_ASSERT_DEBUG(err == KErrNotFound);
  1233                         }
  1248                         }
  1234                     else
  1249                     
  1235                         {
       
  1236                         return err;
       
  1237                         }
       
  1238                     }
  1250                     }
  1239 
  1251 
  1240                 //Examine the redefined status flag
  1252                 //Examine the redefined status flag
  1241                 if(!isRedefined)
  1253                 if(!isRedefined)
  1242                     {
  1254                     {
  1254                                  aLens ? aLens[usrArrIndx]:tmpLen);
  1266                                  aLens ? aLens[usrArrIndx]:tmpLen);
  1255                         cNumFound ++;
  1267                         cNumFound ++;
  1256                         }
  1268                         }
  1257                     else
  1269                     else
  1258                         {
  1270                         {
  1259                         //All required elements were found!
       
  1260                         //As vNumFound was used an index so it's value it runs 
       
  1261                         //from 0 to X-1, where X - number of found elements. To 
       
  1262                         //get number of elements found we need increase the last
       
  1263                         //counter value by 1.
       
  1264                         if(cNumFound != 0)
       
  1265                             cNumFound ++;
       
  1266                         //It reaches the goal, all required elements are found
  1271                         //It reaches the goal, all required elements are found
  1267                         //stop here and return the result
  1272                         //stop here and return the result
  1268                         break;
  1273                         break;
  1269                         }
  1274                         }
  1270                     }
  1275                     }
  1271                 else
  1276                 else
  1272                     //Element is found in other repositories, just reset a flag
  1277                     //Element is found in other repositories, just reset a flag
  1273                     isRedefined = EFalse;
  1278                     isRedefined = EFalse;
  1274                 }
  1279                 }
  1275             }
  1280             }
  1276         else if (err == KErrNotFound)
  1281         else //err == KErrNotFound
  1277             {
  1282             {
  1278             //cNumFound is already set to zero during the initialization
  1283             //cNumFound is already set to zero during the initialization
  1279             //Nothing to do here
  1284             //Nothing to do here
  1280             }
  1285 
  1281         else //any other errors
  1286             //FindNumSettingsInCategory can only return KErrNotFound, let's  
  1282             {
  1287             //assert we've only got KErrNotFound
  1283             return err;
  1288             __NK_ASSERT_DEBUG(err == KErrNotFound);
  1284             }
  1289             }
       
  1290         
  1285         }
  1291         }
  1286 
  1292 
  1287     
  1293     
  1288     //Low/High index in the CoreImg
  1294     //Low/High index in the CoreImg
  1289     TInt32 vLoIndex = 0;
  1295     TInt32 vLoIndex = 0;
  1330                     if(err == KErrNone)
  1336                     if(err == KErrNone)
  1331                         {
  1337                         {
  1332                         lowIndex = elementPos + 1;
  1338                         lowIndex = elementPos + 1;
  1333                         isRedefined = ETrue;
  1339                         isRedefined = ETrue;
  1334                         }
  1340                         }
  1335                     else if (err == KErrNotFound)
  1341                     else //err == KErrNotFound
  1336                         {
  1342                         {
  1337                         //Element is not found, nothing to proceed here
  1343                         //Element is not found, nothing to proceed here
       
  1344 
       
  1345                         //FindSetting can only return KErrNotFound, let's assert 
       
  1346                         //we've only got KErrNotFound
       
  1347                         __NK_ASSERT_DEBUG(err == KErrNotFound);
  1338                         }
  1348                         }
  1339                     else
  1349                     
  1340                         {
       
  1341                         return err;
       
  1342                         }
       
  1343                     }
  1350                     }
  1344 
  1351 
  1345                 if(cNumFound > 0 && !isRedefined)
  1352                 if(cNumFound > 0 && !isRedefined)
  1346                     {
  1353                     {
  1347                     //Check either this element is already redefined in the 
  1354                     //Check either this element is already redefined in the 
  1351                     if(err == KErrNone)
  1358                     if(err == KErrNone)
  1352                         {
  1359                         {
  1353                         lowIndex2 = elementPos2 + 1;
  1360                         lowIndex2 = elementPos2 + 1;
  1354                         isRedefined = ETrue;
  1361                         isRedefined = ETrue;
  1355                         }
  1362                         }
  1356                     else if (err == KErrNotFound)
  1363                     else //err == KErrNotFound
  1357                         {
  1364                         {
  1358                         //Element is not found, nothing to proceed here
  1365                         //Element is not found, nothing to proceed here
       
  1366 
       
  1367                         //FindSetting can only return KErrNotFound, let's assert 
       
  1368                         //we've only got KErrNotFound
       
  1369                         __NK_ASSERT_DEBUG(err == KErrNotFound);
  1359                         }
  1370                         }
  1360                     else
  1371                     
  1361                         {
       
  1362                         return err;
       
  1363                         }
       
  1364                     }
  1372                     }
  1365                
  1373                
  1366                 if(!isRedefined)
  1374                 if(!isRedefined)
  1367                     {
  1375                     {
  1368                     usrArrIndx = oNumFound + cNumFound + vNumFound;
  1376                     usrArrIndx = oNumFound + cNumFound + vNumFound;
  1376 
  1384 
  1377                         vNumFound ++;
  1385                         vNumFound ++;
  1378                         }
  1386                         }
  1379                     else
  1387                     else
  1380                         {
  1388                         {
  1381                         //All required elements were found!
       
  1382                         //As vNumFound was used an index so it's value it runs 
       
  1383                         //from 0 to X-1, where X - number of found elements. To 
       
  1384                         //get number of elements found we need increase the last
       
  1385                         //counter value by 1.
       
  1386                         if(vNumFound != 0)
       
  1387                             vNumFound ++;
       
  1388                         //It reaches the goal, all required elements are found
  1389                         //It reaches the goal, all required elements are found
  1389                         //stop here and return the result
  1390                         //stop here and return the result
  1390                         break;
  1391                         break;
  1391                         }
  1392                         }
  1392                     }
  1393                     }
  1394                     {
  1395                     {
  1395                     isRedefined = EFalse;
  1396                     isRedefined = EFalse;
  1396                     }
  1397                     }
  1397                 }
  1398                 }
  1398             }
  1399             }
  1399         else if (err == KErrNotFound)
  1400         else //err == KErrNotFound
  1400             {
  1401             {
  1401             //oNumFound is already set to zero during the initialization
  1402             //oNumFound is already set to zero during the initialization
  1402             //Nothing to do here
  1403             //Nothing to do here
  1403             }
  1404 
  1404         else
  1405             //FindNumSettingsInCategory can only return KErrNotFound, let's  
  1405             {
  1406             //assert we've only got KErrNotFound
  1406             return err;
  1407             __NK_ASSERT_DEBUG(err == KErrNotFound);
  1407             }
  1408             }
  1408         
  1409                 
  1409         }
  1410         }
  1410     
  1411     
  1411     //Let's prepare the final data
  1412     //Let's prepare the final data
  1412     numFound = oNumFound + cNumFound + vNumFound;
  1413     return (oNumFound + cNumFound + vNumFound);
  1413 
       
  1414     //Return result to the user
       
  1415     return numFound;
       
  1416     }
  1414     }
  1417 
  1415 
  1418 
  1416 
  1419 
  1417 
  1420 
  1418 
  1433     TInt numFound = 0;
  1431     TInt numFound = 0;
  1434     
  1432     
  1435     //Find the number of elements within the category
  1433     //Find the number of elements within the category
  1436     r = FindNumSettingsInCategory(aCat);
  1434     r = FindNumSettingsInCategory(aCat);
  1437     
  1435     
  1438     //Analyse the returned error
  1436     //We don't expect any errors here
  1439     //if r < 0 - this is an error return to the user 
  1437     __NK_ASSERT_DEBUG(r >= 0);
  1440     //if r > 0 - number of found settings
  1438     
  1441     if(r < 0)
  1439     if (r == 0)
  1442         {
       
  1443         HCR_TRACE_RETURN(r);
       
  1444         }
       
  1445     else if (r == 0)
       
  1446         //No any elements found for this category 
  1440         //No any elements found for this category 
  1447         return 0;
  1441         return 0;
  1448     else
  1442     else
  1449         allInCatFound = r;
  1443         allInCatFound = r;
  1450     
  1444     
  1461         //One of the allocation was unsuccessful 
  1455         //One of the allocation was unsuccessful 
  1462         HCR_TRACE_RETURN(KErrNoMemory);
  1456         HCR_TRACE_RETURN(KErrNoMemory);
  1463     
  1457     
  1464     r = FindSettings(aCat, allInCatFound, pIds(), pTypes(), pLens());
  1458     r = FindSettings(aCat, allInCatFound, pIds(), pTypes(), pLens());
  1465     
  1459     
  1466     //Exit if we've got negative result just report error
  1460     //We don't expect any errors here
  1467     if(r < 0)
  1461     __NK_ASSERT_DEBUG(r >= 0);
  1468         HCR_TRACE_RETURN(r);
  1462     
  1469     
  1463     //Check either we've got less elements than it must be
  1470     //Somehow we'got less elements than it must be!!!
       
  1471     __NK_ASSERT_DEBUG(r == allInCatFound);
  1464     __NK_ASSERT_DEBUG(r == allInCatFound);
  1472     if(r < allInCatFound)
       
  1473         HCR_TRACE_RETURN(KErrGeneral);
       
  1474     
       
  1475     
  1465     
  1476     //Choose the elements which satisfy this condition
  1466     //Choose the elements which satisfy this condition
  1477     //((elementID & aElementMask) == (aPattern & aElementMask)). The total num-
  1467     //((elementID & aElementMask) == (aPattern & aElementMask)). The total num-
  1478     //ber of returned elements should not exceed the aMaxNum
  1468     //ber of returned elements should not exceed the aMaxNum
  1479     for(TInt index = 0; index < allInCatFound; index++)
  1469     for(TInt index = 0; index < allInCatFound; index++)
  1520 
  1510 
  1521 TBool HCR::TRepository::IsLargeValue(const TSettingRef& aRef)
  1511 TBool HCR::TRepository::IsLargeValue(const TSettingRef& aRef)
  1522     {
  1512     {
  1523     HCR_FUNC("TRepository::IsLargeValue");
  1513     HCR_FUNC("TRepository::IsLargeValue");
  1524     return ((aRef.iSet->iType & KMaskLargeTypes) != 0);
  1514     return ((aRef.iSet->iType & KMaskLargeTypes) != 0);
  1525     }
       
  1526 
       
  1527 void HCR::TRepository::GetId(const TSettingRef& aRef, TCategoryUid& aCat, TElementId& aKey)
       
  1528     {
       
  1529     HCR_FUNC("TRepository::GetId1");
       
  1530     aCat = aRef.iSet->iId.iCat;
       
  1531     aKey = aRef.iSet->iId.iKey;
       
  1532     }
  1515     }
  1533 
  1516 
  1534 void HCR::TRepository::GetId(const TSettingRef& aRef, SSettingId& aId)
  1517 void HCR::TRepository::GetId(const TSettingRef& aRef, SSettingId& aId)
  1535     {
  1518     {
  1536     HCR_FUNC("TRepository::GetId2");
  1519     HCR_FUNC("TRepository::GetId2");
  1667     HCR_FUNC("TRepositoryCompiled::FindSetting within the given range");
  1650     HCR_FUNC("TRepositoryCompiled::FindSetting within the given range");
  1668     
  1651     
  1669     
  1652     
  1670     __NK_ASSERT_DEBUG(iRepos != 0);
  1653     __NK_ASSERT_DEBUG(iRepos != 0);
  1671     __NK_ASSERT_DEBUG(iRepos->iHdr != 0);
  1654     __NK_ASSERT_DEBUG(iRepos->iHdr != 0);
  1672     
  1655 	__NK_ASSERT_DEBUG(iRepos->iOrderedSettingList != 0);
  1673     if ((iRepos->iHdr->iNumSettings == 0) || 
  1656 	__NK_ASSERT_DEBUG(iRepos->iHdr->iNumSettings != 0);
  1674         (iRepos->iOrderedSettingList == 0))
       
  1675         HCR_TRACE_RETURN(KErrNotFound);
       
  1676     
  1657     
  1677     SSettingC* arr = iRepos->iOrderedSettingList;
  1658     SSettingC* arr = iRepos->iOrderedSettingList;
  1678     TInt32 low = aLow;
  1659     TInt32 low = aLow;
  1679     TInt32 high = aHigh;
  1660     TInt32 high = aHigh;
  1680     TInt32 mid;
  1661     TInt32 mid;
  1711     {
  1692     {
  1712     HCR_FUNC("TRepositoryCompiled::GetWordSettings");
  1693     HCR_FUNC("TRepositoryCompiled::GetWordSettings");
  1713     
  1694     
  1714     __NK_ASSERT_DEBUG(iRepos != 0);
  1695     __NK_ASSERT_DEBUG(iRepos != 0);
  1715     __NK_ASSERT_DEBUG(iRepos->iHdr != 0);
  1696     __NK_ASSERT_DEBUG(iRepos->iHdr != 0);
       
  1697 	__NK_ASSERT_DEBUG(aIds != NULL);
       
  1698 	__NK_ASSERT_DEBUG(aValues != NULL);
       
  1699 	__NK_ASSERT_DEBUG(aTypes != NULL);
       
  1700 	__NK_ASSERT_DEBUG(aErrors != NULL);
  1716     
  1701     
  1717     if ((iRepos->iHdr->iNumSettings == 0) || 
  1702     if ((iRepos->iHdr->iNumSettings == 0) || 
  1718         (iRepos->iOrderedSettingList == 0))
  1703         (iRepos->iOrderedSettingList == 0))
  1719         HCR_TRACE_RETURN(KErrNotFound);
  1704         HCR_TRACE_RETURN(KErrNotFound);
  1720  
  1705  
  1742         //Find first setting from user array. The importance here is that we   
  1727         //Find first setting from user array. The importance here is that we   
  1743         //should get value of first setting index in the repository in rMinIndex.
  1728         //should get value of first setting index in the repository in rMinIndex.
  1744         //This time the  scope of search is whole repository.
  1729         //This time the  scope of search is whole repository.
  1745         err = this->FindSetting(*aIds[uIndex],settingRef, rMinIndex, 
  1730         err = this->FindSetting(*aIds[uIndex],settingRef, rMinIndex, 
  1746                 0, iRepos->iHdr->iNumSettings);
  1731                 0, iRepos->iHdr->iNumSettings);
       
  1732 
       
  1733 		__NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
       
  1734 
  1747         if(err == KErrNotFound)
  1735         if(err == KErrNotFound)
  1748             {
  1736             {
  1749             *aErrors[uIndex] = err;
  1737             *aErrors[uIndex] = err;
  1750             *aValues[uIndex] = 0;
  1738             *aValues[uIndex] = 0;
  1751             //Copy type only if user provided aTypes array
  1739             *aTypes[uIndex] = ETypeUndefined;
  1752             if(aTypes)
       
  1753                 *aTypes[uIndex] = ETypeUndefined;
       
  1754             
  1740             
  1755             //As FindSetting did not find the element, let's challenge with 
  1741             //As FindSetting did not find the element, let's challenge with 
  1756             //the next one from aIds[] array
  1742             //the next one from aIds[] array
  1757             uIndex ++;
  1743             uIndex ++;
  1758             continue;
  1744             continue;
  1759             }
  1745             }
  1760         //fatal error here, nothing to do, just exit and return the error code
       
  1761         else if(err == KErrNotReady || err != KErrNone)
       
  1762             {
       
  1763             return err;
       
  1764             }
       
  1765         else // err == KErrNone
  1746         else // err == KErrNone
  1766             {
  1747             {
  1767             //Get the value and type
  1748             //Get the value and type
  1768             pSetting = (SSettingC*) settingRef.iSet;
  1749             pSetting = (SSettingC*) settingRef.iSet;
  1769             //again copy the type value into the user array if it's provided
       
  1770             if(aTypes)
       
  1771                 *aTypes[uIndex] = static_cast<TSettingType>(settingRef.iSet->iType); 
       
  1772 
       
  1773             //Check for the found type is this word size? If it's not then 
       
  1774             //indicate error for this setting
       
  1775             if(*aTypes[uIndex] > ETypeLinAddr)
       
  1776                 {
       
  1777                 *aErrors[uIndex] = KErrArgument;
       
  1778                 *aValues[uIndex] = 0;
       
  1779                 }
       
  1780             else
       
  1781                 {
       
  1782                 *aErrors[uIndex] = KErrNone;
       
  1783                 *aValues[uIndex] = pSetting->iValue.iLit.iInt32;
       
  1784                 }
       
  1785             
  1750             
       
  1751 			*aTypes[uIndex] = static_cast<TSettingType>(settingRef.iSet->iType); 
       
  1752 
       
  1753 			//Check for the found type is this word size? If it's not then 
       
  1754 			//indicate error for this setting
       
  1755 			if(*aTypes[uIndex] > ETypeLinAddr)
       
  1756 				{
       
  1757 				*aErrors[uIndex] = KErrArgument;
       
  1758 				*aValues[uIndex] = 0;
       
  1759 				}
       
  1760 			else
       
  1761 				{
       
  1762 				*aErrors[uIndex] = KErrNone;
       
  1763 				*aValues[uIndex] = pSetting->iValue.iLit.iInt32;
       
  1764 				}
       
  1765 				
  1786             //Break the loop by setting the redefined status
  1766             //Break the loop by setting the redefined status
  1787             isRedefined = ETrue;
  1767             isRedefined = ETrue;
  1788             }
  1768             }
  1789         }
  1769         }
  1790     
  1770     
  1809         //Find the last setting from user array. The importance here is that we   
  1789         //Find the last setting from user array. The importance here is that we   
  1810         //should get value of first setting index in the repository in 
  1790         //should get value of first setting index in the repository in 
  1811         //rMinIndex. This time the  scope of search is whole repository.
  1791         //rMinIndex. This time the  scope of search is whole repository.
  1812         err = this->FindSetting(*aIds[uIndex],settingRef, rMaxIndex, 
  1792         err = this->FindSetting(*aIds[uIndex],settingRef, rMaxIndex, 
  1813                 rMinIndex, iRepos->iHdr->iNumSettings);
  1793                 rMinIndex, iRepos->iHdr->iNumSettings);
       
  1794 
       
  1795 		__NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
       
  1796 
  1814         if(err == KErrNotFound)
  1797         if(err == KErrNotFound)
  1815             {
  1798             {
  1816             *aErrors[uIndex] = err;
  1799             *aErrors[uIndex] = err;
  1817             *aValues[uIndex] = 0;
  1800             *aValues[uIndex] = 0;
  1818             if(aTypes)
  1801             *aTypes[uIndex] = ETypeUndefined;
  1819                 *aTypes[uIndex] = ETypeUndefined;
       
  1820             
  1802             
  1821             //As FindSetting did not find the element, let's challenge with 
  1803             //As FindSetting did not find the element, let's challenge with 
  1822             //previous one, as we are moving in reverse direction
  1804             //previous one, as we are moving in reverse direction
  1823             uIndex --;
  1805             uIndex --;
  1824             continue;
  1806             continue;
  1825             }
  1807             }
  1826         //fatal error here, nothing to do, just exit and return the error code
       
  1827         else if(err == KErrNotReady || err != KErrNone)
       
  1828             {
       
  1829             return err;
       
  1830             }
       
  1831         else //err == KErrNone
  1808         else //err == KErrNone
  1832             {
  1809             {
  1833             pSetting = (SSettingC*) settingRef.iSet;
  1810             pSetting = (SSettingC*) settingRef.iSet;
  1834             if(aTypes)
  1811             *aTypes[uIndex] = static_cast<TSettingType>(settingRef.iSet->iType); 
  1835                 *aTypes[uIndex] = static_cast<TSettingType>(settingRef.iSet->iType); 
       
  1836             
  1812             
  1837             //Check for the found type is this word size? If it's not then indicate
  1813 			//Check for the found type is this word size? If it's not then indicate
  1838             //error for this setting
  1814 			//error for this setting
  1839             if(*aTypes[uIndex] > ETypeLinAddr)
  1815 			if(*aTypes[uIndex] > ETypeLinAddr)
  1840                 {
  1816 				{
  1841                 *aErrors[uIndex] = KErrArgument;
  1817 				*aErrors[uIndex] = KErrArgument;
  1842                 *aValues[uIndex] = 0;
  1818 				*aValues[uIndex] = 0;
  1843                 }
  1819 				}
  1844             else
  1820 			else
  1845                 {
  1821 				{
  1846                 *aErrors[uIndex] = KErrNone;
  1822 				*aErrors[uIndex] = KErrNone;
  1847                 *aValues[uIndex] = pSetting->iValue.iLit.iInt32;
  1823 				*aValues[uIndex] = pSetting->iValue.iLit.iInt32;
  1848                 }
  1824 				}
  1849 
  1825 				
  1850             isRedefined = ETrue;
  1826             isRedefined = ETrue;
  1851             }
  1827             }
  1852         }
  1828         }
  1853 
  1829 
  1854     //At this point we found the last setting, store it's user array index in   
  1830     //At this point we found the last setting, store it's user array index in   
  1867     //search time.
  1843     //search time.
  1868     for(uIndex = uFirstIndex + 1; uIndex < uLastIndex; uIndex ++)
  1844     for(uIndex = uFirstIndex + 1; uIndex < uLastIndex; uIndex ++)
  1869         {
  1845         {
  1870         err = this->FindSetting(*aIds[uIndex],settingRef, rIndex, 
  1846         err = this->FindSetting(*aIds[uIndex],settingRef, rIndex, 
  1871                 rMinIndex, rMaxIndex);
  1847                 rMinIndex, rMaxIndex);
       
  1848 
       
  1849 		__NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
       
  1850 
  1872         if(err == KErrNotFound)
  1851         if(err == KErrNotFound)
  1873             {
  1852             {
  1874             *aErrors[uIndex] = err;
  1853             *aErrors[uIndex] = err;
  1875             *aValues[uIndex] = 0;
  1854             *aValues[uIndex] = 0;
  1876             if(aTypes)
  1855             *aTypes[uIndex] = ETypeUndefined;
  1877                 *aTypes[uIndex] = ETypeUndefined;
       
  1878 
  1856 
  1879             //As FindSetting did not find the element, let's challenge with 
  1857             //As FindSetting did not find the element, let's challenge with 
  1880             //another one
  1858             //another one
  1881             continue;
  1859             continue;
  1882             }
  1860             }
  1883         else if(err == KErrNotReady || err != KErrNone)
       
  1884             {
       
  1885             return err;
       
  1886             }
       
  1887         else //err == KErrNone
  1861         else //err == KErrNone
  1888             {
  1862             {
  1889 
  1863 
  1890             pSetting = (SSettingC*) settingRef.iSet;
  1864             pSetting = (SSettingC*) settingRef.iSet;
  1891             if(aTypes)
  1865             *aTypes[uIndex] = static_cast<TSettingType>(settingRef.iSet->iType); 
  1892                 *aTypes[uIndex] = static_cast<TSettingType>(settingRef.iSet->iType); 
  1866 
  1893 
  1867 			//Check for the found type is this word size? If it's not then indicate
  1894             //Check for the found type is this word size? If it's not then indicate
  1868 			//error for this setting
  1895             //error for this setting
  1869 			if(*aTypes[uIndex] > ETypeLinAddr)
  1896             if(*aTypes[uIndex] > ETypeLinAddr)
  1870 				{
  1897                 {
  1871 				*aErrors[uIndex] = KErrArgument;
  1898                 *aErrors[uIndex] = KErrArgument;
  1872 				*aValues[uIndex] = 0;
  1899                 *aValues[uIndex] = 0;
  1873 				}
  1900                 }
  1874 			else
  1901             else
  1875 				{
  1902                 {
  1876 				*aErrors[uIndex] = KErrNone;
  1903                 *aErrors[uIndex] = KErrNone;
  1877 				*aValues[uIndex] = pSetting->iValue.iLit.iInt32;
  1904                 *aValues[uIndex] = pSetting->iValue.iLit.iInt32;
  1878 				}
  1905                 }
  1879 				
  1906 
       
  1907             rMinIndex = rIndex + 1;
  1880             rMinIndex = rIndex + 1;
  1908 
  1881 
  1909             }
  1882             }
  1910 
  1883 
  1911         }
  1884         }
  1922     {
  1895     {
  1923     HCR_FUNC("TRepositoryCompiled::FindNumSettingsInCategory");
  1896     HCR_FUNC("TRepositoryCompiled::FindNumSettingsInCategory");
  1924 
  1897 
  1925     __NK_ASSERT_DEBUG(iRepos != 0);
  1898     __NK_ASSERT_DEBUG(iRepos != 0);
  1926     __NK_ASSERT_DEBUG(iRepos->iHdr != 0);
  1899     __NK_ASSERT_DEBUG(iRepos->iHdr != 0);
  1927 
  1900 	__NK_ASSERT_DEBUG(iRepos->iOrderedSettingList != 0);
  1928     if ((iRepos->iHdr->iNumSettings == 0) || (iRepos->iOrderedSettingList == 0))
  1901     
       
  1902     if(iRepos->iHdr->iNumSettings == 0)
       
  1903         {
       
  1904         aFirst = 0;
       
  1905         aLast = 0;
  1929         HCR_TRACE_RETURN(KErrNotFound);
  1906         HCR_TRACE_RETURN(KErrNotFound);
       
  1907         }
  1930 
  1908 
  1931     SSettingC* arr = iRepos->iOrderedSettingList;
  1909     SSettingC* arr = iRepos->iOrderedSettingList;
  1932     int low = 0;
  1910     int low = 0;
  1933     int high = iRepos->iHdr->iNumSettings-1;
  1911     int high = iRepos->iHdr->iNumSettings-1;
  1934     int mid = 0;
  1912     int mid = 0;
  1959         return KErrNotFound;
  1937         return KErrNotFound;
  1960         }
  1938         }
  1961 
  1939 
  1962     //Search the first element within the category
  1940     //Search the first element within the category
  1963     low = mid;
  1941     low = mid;
  1964     while(low > 0 && arr[low].iName.iId.iCat == aCatUid)
  1942     while(low >= 0 && arr[low].iName.iId.iCat == aCatUid)
  1965         {
  1943         {
  1966         low --;
  1944         if(low > 0)
       
  1945             low --;
       
  1946         else
       
  1947             break;
  1967         }
  1948         }
  1968     //Check the boundary conditions, there are two cases when we exit the loop
  1949     //Check the boundary conditions, there are two cases when we exit the loop
  1969     //either we found an element which category is not one we are looking for or
  1950     //either we found an element which category is not one we are looking for or
  1970     //we reach the beggining of the repository. If we reach the beggining of the
  1951     //we reach the beggining of the repository. If we reach the beggining of the
  1971     //repository we don't really know is it because this is last elment or it
  1952     //repository we don't really know is it because this is last elment or it
  1972     //has required aCatUid, so we check these two conditions below
  1953     //has required aCatUid, so we check these two conditions below
  1973     if(low == 0 && arr[low].iName.iId.iCat == aCatUid)
  1954     if(arr[low].iName.iId.iCat == aCatUid)
  1974         aFirst = low;
  1955         aFirst = low;
       
  1956 
  1975     //We finish the loop either reaching the setting which category id is not
  1957     //We finish the loop either reaching the setting which category id is not
  1976     //what we need or this is first setting in the repository again with another
  1958     //what we need or this is first setting in the repository again with another
  1977     //category, so in both case we throw this element from the account.
  1959     //category, so in both case we throw this element from the account.
  1978     else
  1960     else
  1979         aFirst = low + 1;
  1961         aFirst = low + 1;
  1980 
  1962 
  1981     //Search the last element within the category
  1963     //Search the last element within the category
  1982     high = mid;
  1964     high = mid;
  1983     while(high < iRepos->iHdr->iNumSettings && arr[high].iName.iId.iCat == aCatUid)
  1965     while(high <= iRepos->iHdr->iNumSettings - 1 && arr[high].iName.iId.iCat == aCatUid)
  1984         {
  1966         {
  1985         high ++;
  1967         if(high < iRepos->iHdr->iNumSettings - 1)
  1986         }
  1968             high ++;
  1987     
  1969         else
       
  1970             break;
       
  1971         }
       
  1972 
  1988     //Same situation as above, boundary conditions
  1973     //Same situation as above, boundary conditions
  1989     if(high == (iRepos->iHdr->iNumSettings -1) && arr[high].iName.iId.iCat == aCatUid)
  1974     if(arr[high].iName.iId.iCat == aCatUid)
  1990         aLast = high;
  1975         aLast = high;
  1991     else
  1976     else
  1992         aLast = high -1;
  1977         aLast = high -1;
  1993 
  1978 
  1994 
  1979 
  2000 void HCR::TRepositoryCompiled::GetSettingRef(TInt32 aIndex, 
  1985 void HCR::TRepositoryCompiled::GetSettingRef(TInt32 aIndex, 
  2001         HCR::TSettingRef& aRef)
  1986         HCR::TSettingRef& aRef)
  2002     {
  1987     {
  2003     __NK_ASSERT_DEBUG(iRepos != 0);
  1988     __NK_ASSERT_DEBUG(iRepos != 0);
  2004     __NK_ASSERT_DEBUG(iRepos->iHdr != 0);
  1989     __NK_ASSERT_DEBUG(iRepos->iHdr != 0);
       
  1990     __NK_ASSERT_DEBUG(iRepos->iHdr->iNumSettings != 0 && iRepos->iOrderedSettingList != 0);
  2005     __NK_ASSERT_DEBUG(aIndex >=0 && aIndex < iRepos->iHdr->iNumSettings);
  1991     __NK_ASSERT_DEBUG(aIndex >=0 && aIndex < iRepos->iHdr->iNumSettings);
  2006     
  1992     
  2007     if ((iRepos->iHdr->iNumSettings == 0) || (iRepos->iOrderedSettingList == 0))
       
  2008         {
       
  2009         aRef.iRep = NULL;
       
  2010         aRef.iSet = NULL;
       
  2011         }
       
  2012 
  1993 
  2013     //Get the pointer to the repository data
  1994     //Get the pointer to the repository data
  2014     SSettingC* arr = iRepos->iOrderedSettingList;
  1995     SSettingC* arr = iRepos->iOrderedSettingList;
  2015         
  1996         
  2016     aRef.iRep = this;
  1997     aRef.iRep = this;
  2151     {
  2132     {
  2152     HCR_FUNC("TRepositoryFile::FindSetting within the given range");
  2133     HCR_FUNC("TRepositoryFile::FindSetting within the given range");
  2153 
  2134 
  2154 
  2135 
  2155     __NK_ASSERT_DEBUG(iRepos != 0);
  2136     __NK_ASSERT_DEBUG(iRepos != 0);
  2156 
  2137     __NK_ASSERT_DEBUG(iRepos->iHdr.iNumSettings != 0);
  2157     if (iRepos->iHdr.iNumSettings == 0)
       
  2158         HCR_TRACE_RETURN(KErrNotFound);
       
  2159 
  2138 
  2160     SSettingF* arr = (SSettingF*) (iRepos+1);
  2139     SSettingF* arr = (SSettingF*) (iRepos+1);
  2161     TInt32 low = aLow;
  2140     TInt32 low = aLow;
  2162     TInt32 high = aHigh;
  2141     TInt32 high = aHigh;
  2163     TInt32 mid;
  2142     TInt32 mid;
  2195     {
  2174     {
  2196     HCR_FUNC("TRepositoryFile::GetWordSettings");
  2175     HCR_FUNC("TRepositoryFile::GetWordSettings");
  2197 
  2176 
  2198 
  2177 
  2199     __NK_ASSERT_DEBUG(iRepos != 0);
  2178     __NK_ASSERT_DEBUG(iRepos != 0);
       
  2179 	__NK_ASSERT_DEBUG(aIds != NULL);
       
  2180 	__NK_ASSERT_DEBUG(aValues != NULL);
       
  2181 	__NK_ASSERT_DEBUG(aTypes != NULL);
       
  2182 	__NK_ASSERT_DEBUG(aErrors != NULL);
  2200    
  2183    
  2201     if (iRepos->iHdr.iNumSettings == 0)
  2184     if (iRepos->iHdr.iNumSettings == 0)
  2202         return KErrNotFound;
  2185         return KErrNotFound;
  2203 
  2186 
  2204     TInt err = KErrNone;
  2187     TInt err = KErrNone;
  2224             //Find first setting from user array. The importance here is that we   
  2207             //Find first setting from user array. The importance here is that we   
  2225             //should get value of first setting index in the repository in rMinIndex.
  2208             //should get value of first setting index in the repository in rMinIndex.
  2226             //This time the  scope of search is whole repository.
  2209             //This time the  scope of search is whole repository.
  2227             err = this->FindSetting(*aIds[uIndex],settingRef, rMinIndex, 
  2210             err = this->FindSetting(*aIds[uIndex],settingRef, rMinIndex, 
  2228                     0, iRepos->iHdr.iNumSettings);
  2211                     0, iRepos->iHdr.iNumSettings);
       
  2212 
       
  2213 			__NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
       
  2214 
  2229             if(err == KErrNotFound)
  2215             if(err == KErrNotFound)
  2230                 {
  2216                 {
  2231                 *aErrors[uIndex] = err;
  2217                 *aErrors[uIndex] = err;
  2232                 *aValues[uIndex] = 0;
  2218                 *aValues[uIndex] = 0;
  2233                 //Copy type only if user provided aTypes array
  2219                 *aTypes[uIndex] = ETypeUndefined;
  2234                 if(aTypes)
       
  2235                     *aTypes[uIndex] = ETypeUndefined;
       
  2236                 
  2220                 
  2237                 //As FindSetting did not find the element, let's challenge with 
  2221                 //As FindSetting did not find the element, let's challenge with 
  2238                 //the next one from aIds[] array
  2222                 //the next one from aIds[] array
  2239                 uIndex ++;
  2223                 uIndex ++;
  2240                 continue;
  2224                 continue;
  2241                 }
  2225                 }
  2242             //fatal error here, nothing to do, just exit and return the error code
       
  2243             else if(err == KErrNotReady || err != KErrNone)
       
  2244                 {
       
  2245                 return err;
       
  2246                 }
       
  2247             else // err == KErrNone
  2226             else // err == KErrNone
  2248                 {
  2227                 {
  2249                 //Get the value and type
  2228                 //Get the value and type
  2250                 pSetting = (SSettingF*) settingRef.iSet;
  2229                 pSetting = (SSettingF*) settingRef.iSet;
  2251                 //again copy the type value into the user array if it's provided
  2230                 //again copy the type value into the user array if it's provided
  2252                 if(aTypes)
  2231                 *aTypes[uIndex] = static_cast<TSettingType>(settingRef.iSet->iType); 
  2253                     *aTypes[uIndex] = static_cast<TSettingType>(settingRef.iSet->iType); 
       
  2254             
  2232             
  2255                 //Check for the found type is this word size? If it's not then 
  2233 				//Check for the found type is this word size? If it's not then 
  2256                 //indicate error for this setting
  2234 				//indicate error for this setting
  2257                 if(*aTypes[uIndex] > ETypeLinAddr)
  2235 				if(*aTypes[uIndex] > ETypeLinAddr)
  2258                     {
  2236 					{
  2259                     *aErrors[uIndex] = KErrArgument;
  2237 					*aErrors[uIndex] = KErrArgument;
  2260                     *aValues[uIndex] = 0;
  2238 					*aValues[uIndex] = 0;
  2261                     }
  2239 					}
  2262                 else
  2240 				else
  2263                     {
  2241 					{
  2264                     *aErrors[uIndex] = KErrNone;
  2242 					*aErrors[uIndex] = KErrNone;
  2265                     *aValues[uIndex] = pSetting->iValue.iLit.iInt32;
  2243 					*aValues[uIndex] = pSetting->iValue.iLit.iInt32;
  2266                     }
  2244 					}
  2267                 
  2245 					
  2268                 //Break the loop by setting the redefined status
  2246                 //Break the loop by setting the redefined status
  2269                 isRedefined = ETrue;
  2247                 isRedefined = ETrue;
  2270                 }
  2248                 }
  2271             }
  2249             }
  2272         
  2250         
  2293             //Find the last setting from user array. The importance here is that we   
  2271             //Find the last setting from user array. The importance here is that we   
  2294             //should get value of first setting index in the repository in 
  2272             //should get value of first setting index in the repository in 
  2295             //rMinIndex. This time the  scope of search is whole repository.
  2273             //rMinIndex. This time the  scope of search is whole repository.
  2296             err = this->FindSetting(*aIds[uIndex],settingRef, rMaxIndex, 
  2274             err = this->FindSetting(*aIds[uIndex],settingRef, rMaxIndex, 
  2297                     rMinIndex, iRepos->iHdr.iNumSettings);
  2275                     rMinIndex, iRepos->iHdr.iNumSettings);
       
  2276 
       
  2277 			__NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
       
  2278 			
  2298             if(err == KErrNotFound)
  2279             if(err == KErrNotFound)
  2299                 {
  2280                 {
  2300                 *aErrors[uIndex] = err;
  2281                 *aErrors[uIndex] = err;
  2301                 *aValues[uIndex] = 0;
  2282                 *aValues[uIndex] = 0;
  2302                 if(aTypes)
  2283                 *aTypes[uIndex] = ETypeUndefined;
  2303                     *aTypes[uIndex] = ETypeUndefined;
       
  2304                 
  2284                 
  2305                 //As FindSetting did not find the element, let's challenge with 
  2285                 //As FindSetting did not find the element, let's challenge with 
  2306                 //previous one
  2286                 //previous one
  2307                 uIndex --;
  2287                 uIndex --;
  2308                 continue;
  2288                 continue;
  2309                 }
  2289                 }
  2310             //fatal error here, nothing to do, just exit and return the error code
       
  2311             else if(err == KErrNotReady || err != KErrNone)
       
  2312                 {
       
  2313                 return err;
       
  2314                 }
       
  2315             else //err == KErrNone
  2290             else //err == KErrNone
  2316                 {
  2291                 {
  2317                 pSetting = (SSettingF*) settingRef.iSet;
  2292                 pSetting = (SSettingF*) settingRef.iSet;
  2318                 if(aTypes)
  2293                 *aTypes[uIndex] = static_cast<TSettingType>(settingRef.iSet->iType); 
  2319                     *aTypes[uIndex] = static_cast<TSettingType>(settingRef.iSet->iType); 
  2294 
  2320 
  2295 				//Check for the found type is this word size? If it's not then indicate
  2321                 //Check for the found type is this word size? If it's not then indicate
  2296 				//error for this setting
  2322                 //error for this setting
  2297 				if(*aTypes[uIndex] > ETypeLinAddr)
  2323                 if(*aTypes[uIndex] > ETypeLinAddr)
  2298 					{
  2324                     {
  2299 					*aErrors[uIndex] = KErrArgument;
  2325                     *aErrors[uIndex] = KErrArgument;
  2300 					*aValues[uIndex] = 0;
  2326                     *aValues[uIndex] = 0;
  2301 					}
  2327                     }
  2302 				else
  2328                 else
  2303 					{
  2329                     {
  2304 					*aErrors[uIndex] = KErrNone;
  2330                     *aErrors[uIndex] = KErrNone;
  2305 					*aValues[uIndex] = pSetting->iValue.iLit.iInt32;
  2331                     *aValues[uIndex] = pSetting->iValue.iLit.iInt32;
  2306 					}
  2332                     }
  2307 					
  2333                 
       
  2334                 isRedefined = ETrue;
  2308                 isRedefined = ETrue;
  2335                 }
  2309                 }
  2336             }
  2310             }
  2337 
  2311 
  2338         //At this point we found the last setting, store it's user array index in   
  2312         //At this point we found the last setting, store it's user array index in   
  2351         //search time.
  2325         //search time.
  2352         for(uIndex = uFirstIndex + 1; uIndex < uLastIndex; uIndex ++)
  2326         for(uIndex = uFirstIndex + 1; uIndex < uLastIndex; uIndex ++)
  2353             {
  2327             {
  2354             err = this->FindSetting(*aIds[uIndex],settingRef, rIndex, 
  2328             err = this->FindSetting(*aIds[uIndex],settingRef, rIndex, 
  2355                     rMinIndex, rMaxIndex);
  2329                     rMinIndex, rMaxIndex);
       
  2330 
       
  2331 			__NK_ASSERT_DEBUG(err == KErrNotFound || err == KErrNone);
       
  2332 
  2356             if(err == KErrNotFound)
  2333             if(err == KErrNotFound)
  2357                 {
  2334                 {
  2358                 *aErrors[uIndex] = err;
  2335                 *aErrors[uIndex] = err;
  2359                 *aValues[uIndex] = 0;
  2336                 *aValues[uIndex] = 0;
  2360                 if(aTypes)
  2337                 *aTypes[uIndex] = ETypeUndefined;
  2361                     *aTypes[uIndex] = ETypeUndefined;
       
  2362 
  2338 
  2363                 //As FindSetting did not find the element, let's challenge with 
  2339                 //As FindSetting did not find the element, let's challenge with 
  2364                 //another one
  2340                 //another one
  2365                 continue;
  2341                 continue;
  2366                 }
  2342                 }
  2367             else if(err == KErrNotReady || err != KErrNone)
       
  2368                 {
       
  2369                 return err;
       
  2370                 }
       
  2371             else //err == KErrNone
  2343             else //err == KErrNone
  2372                 {
  2344                 {
  2373 
  2345 
  2374                 pSetting = (SSettingF*) settingRef.iSet;
  2346                 pSetting = (SSettingF*) settingRef.iSet;
  2375                 
  2347                 
  2376                 TSettingType type = static_cast<TSettingType>(settingRef.iSet->iType); 
  2348                 TSettingType type = static_cast<TSettingType>(settingRef.iSet->iType); 
  2377                 if(aTypes != NULL)
  2349                 *aTypes[uIndex] = type; 
  2378                     *aTypes[uIndex] = type; 
       
  2379 
  2350 
  2380                 //Check for the found type is this word size? If it's not then indicate
  2351                 //Check for the found type is this word size? If it's not then indicate
  2381                 //error for this setting
  2352                 //error for this setting
  2382                 if(type > ETypeLinAddr)
  2353                 if(type > ETypeLinAddr)
  2383                     {
  2354                     {
  2402 
  2373 
  2403 void HCR::TRepositoryFile::GetSettingRef(TInt32 aIndex, 
  2374 void HCR::TRepositoryFile::GetSettingRef(TInt32 aIndex, 
  2404          HCR::TSettingRef& aSetRef)
  2375          HCR::TSettingRef& aSetRef)
  2405     {
  2376     {
  2406     __NK_ASSERT_DEBUG(iRepos != 0);
  2377     __NK_ASSERT_DEBUG(iRepos != 0);
       
  2378     __NK_ASSERT_DEBUG(iRepos->iHdr.iNumSettings != 0);
  2407     __NK_ASSERT_DEBUG(aIndex >= 0 && aIndex < iRepos->iHdr.iNumSettings);
  2379     __NK_ASSERT_DEBUG(aIndex >= 0 && aIndex < iRepos->iHdr.iNumSettings);
  2408 
       
  2409     if (iRepos->iHdr.iNumSettings == 0)
       
  2410         {
       
  2411         aSetRef.iRep = NULL;
       
  2412         aSetRef.iSet = NULL;
       
  2413         }
       
  2414 
  2380 
  2415     SSettingF* arr = (SSettingF*)(iRepos + 1);
  2381     SSettingF* arr = (SSettingF*)(iRepos + 1);
  2416     
  2382     
  2417     aSetRef.iRep = this;
  2383     aSetRef.iRep = this;
  2418     aSetRef.iSet = &(arr[aIndex].iName);
  2384     aSetRef.iSet = &(arr[aIndex].iName);
  2425         TInt32& aFirst, TInt32& aLast)
  2391         TInt32& aFirst, TInt32& aLast)
  2426     {
  2392     {
  2427     HCR_FUNC("TRepositoryFile::FindNumSettingsInCategory");
  2393     HCR_FUNC("TRepositoryFile::FindNumSettingsInCategory");
  2428 
  2394 
  2429     __NK_ASSERT_DEBUG(iRepos != 0);
  2395     __NK_ASSERT_DEBUG(iRepos != 0);
  2430 
  2396     
  2431     if (iRepos->iHdr.iNumSettings == 0)
  2397     if(iRepos->iHdr.iNumSettings == 0)
       
  2398         {
       
  2399         aFirst = 0;
       
  2400         aLast = 0;
  2432         HCR_TRACE_RETURN(KErrNotFound);
  2401         HCR_TRACE_RETURN(KErrNotFound);
  2433 
  2402         }
       
  2403     
  2434     SSettingF* arr = (SSettingF*) (iRepos+1);
  2404     SSettingF* arr = (SSettingF*) (iRepos+1);
  2435     TInt32 low = 0;
  2405     TInt32 low = 0;
  2436     TInt32 high = iRepos->iHdr.iNumSettings-1;
  2406     TInt32 high = iRepos->iHdr.iNumSettings-1;
  2437     TInt32 mid = 0;
  2407     TInt32 mid = 0;
  2438     TInt32 com = 0;
  2408     TInt32 com = 0;
  2463         return KErrNotFound;
  2433         return KErrNotFound;
  2464         }
  2434         }
  2465 
  2435 
  2466     //Search the first element within the category
  2436     //Search the first element within the category
  2467     low = mid;
  2437     low = mid;
  2468     while(low > 0 && arr[low].iName.iId.iCat == aCatUid)
  2438     while(low >= 0 && arr[low].iName.iId.iCat == aCatUid)
  2469         {
  2439         {
  2470         low --;
  2440         if(low > 0)
  2471         }
  2441             low --;
       
  2442         else
       
  2443             break;
       
  2444         }
       
  2445 
  2472     //Check the boundary conditions, there are two cases when we exit the loop
  2446     //Check the boundary conditions, there are two cases when we exit the loop
  2473     //either we found an element which category is not one we are looking for or
  2447     //either we found an element which category is not one we are looking for or
  2474     //we reach the beggining of the repository. If we reach the beggining of the
  2448     //we reach the beggining of the repository. If we reach the beggining of the
  2475     //repository we don't really know is it because this is last elment or it
  2449     //repository we don't really know is it because this is last elment or it
  2476     //has required aCatUid, so we check these two conditions below
  2450     //has required aCatUid, so we check these two conditions below
  2477     if(low == 0 && arr[low].iName.iId.iCat == aCatUid)
  2451     if(arr[low].iName.iId.iCat == aCatUid)
  2478         aFirst = low;
  2452         aFirst = low;
       
  2453         
  2479     //We finish the loop either reaching the setting which category id is not
  2454     //We finish the loop either reaching the setting which category id is not
  2480     //what we need or this is first setting in the repository again with another
  2455     //what we need or this is first setting in the repository again with another
  2481     //category, so in both case we throw this element from the account.
  2456     //category, so in both case we throw this element from the account.
  2482     else
  2457     else
  2483         aFirst = low + 1;
  2458         aFirst = low + 1;
  2484 
  2459 
  2485 
  2460 
  2486     //Search the last element within the category
  2461     //Search the last element within the category
  2487     high = mid;
  2462     high = mid;
  2488     while(high < iRepos->iHdr.iNumSettings && arr[high].iName.iId.iCat == aCatUid)
  2463     while(high <= iRepos->iHdr.iNumSettings - 1 && arr[high].iName.iId.iCat == aCatUid)
  2489         {
  2464         {
  2490         high ++;
  2465         if(high < iRepos->iHdr.iNumSettings - 1)
  2491         }
  2466             high ++;
       
  2467         else
       
  2468             break;
       
  2469         }
       
  2470 
  2492     //Same situation as above, boundary conditions
  2471     //Same situation as above, boundary conditions
  2493        if(high == (iRepos->iHdr.iNumSettings - 1) && arr[high].iName.iId.iCat == aCatUid)
  2472     if(arr[high].iName.iId.iCat == aCatUid)
  2494            aLast = high;
  2473         aLast = high;
  2495        else
  2474     else
  2496            aLast = high -1;
  2475         aLast = high - 1;
  2497 
  2476 
  2498     return KErrNone;
  2477     return KErrNone;
  2499     }
  2478     }
  2500 
  2479 
  2501 
  2480