os/kernelhwsrv/kernel/eka/drivers/hcr/hcr_api.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Hardware Configuration Respoitory Platform Independent Layer (PIL)
    15 //
    16 
    17 // -- INCLUDES ----------------------------------------------------------------
    18 
    19 
    20 #include <nkern/nkern.h>
    21 #include <kernel/kernel.h>
    22 
    23 #ifdef HCRTEST_NO_EXPORT
    24 #undef EXPORT_C
    25 #undef IMPORT_C
    26 #define EXPORT_C
    27 #define IMPORT_C
    28 #endif // HCRTEST_NO_EXPORT
    29 
    30 #include <drivers/hcr.h>
    31 #include "hcr_debug.h"
    32 #include "hcr_pil.h"
    33 
    34 
    35 // -- FUNCTIONS ---------------------------------------------------------------
    36 
    37 #ifndef MAKE_DEF_FILE
    38 namespace HCR 
    39 {
    40 
    41 LOCAL_C TInt GetUValueWordSetting (const TSettingId& aId, 
    42                                     TSettingType aType, UValueWord& aValue)
    43     {
    44     HCR_FUNC("GetUValueWordSetting");
    45                  
    46     if (HCRNotReady)
    47         HCR_TRACE_RETURN(KErrNotReady);
    48 
    49 	__NK_ASSERT_DEBUG((aType & KMaskWordTypes) != 0);
    50 
    51     TSettingRef sref(0,0);
    52     TInt err = 0;
    53     err = HCRSingleton->FindSetting(aId, aType, sref);
    54     if (err != KErrNone)
    55         HCR_TRACE_RETURN(err);
    56 
    57     err = sref.iRep->GetValue(sref, aValue);
    58 	__NK_ASSERT_DEBUG(err == KErrNone);
    59     
    60     return KErrNone;	
    61     }
    62     
    63 LOCAL_C TInt GetUValueLargeSetting64 (const TSettingId& aId, 
    64                                     TSettingType aType, UValueLarge& aValue)
    65     {
    66     HCR_FUNC("GetUValueLargeSetting64");
    67                  
    68     if (HCRNotReady)
    69 		HCR_TRACE_RETURN(KErrNotReady);
    70 
    71     __NK_ASSERT_DEBUG(aType == ETypeInt64 || aType == ETypeUInt64);
    72     
    73     TSettingRef sref(0,0);
    74     TInt err = 0;
    75     err = HCRSingleton->FindSetting(aId, aType, sref);
    76     if (err != KErrNone)
    77         HCR_TRACE_RETURN(err);
    78 
    79     err = sref.iRep->GetLargeValue(sref, aValue);
    80 	__NK_ASSERT_DEBUG(err == KErrNone);
    81     
    82     return KErrNone;	
    83     }
    84     
    85 
    86 LOCAL_C TInt GetUValueLargeSettingTDes8 (const TSettingId& aId, 
    87                                         TSettingType aType, TDes8& aValue)
    88     {
    89     HCR_FUNC("GetUValueLargeSettingTDes8");
    90                  
    91     if (HCRNotReady)
    92 	    HCR_TRACE_RETURN(KErrNotReady);
    93 
    94     __NK_ASSERT_DEBUG(aType == ETypeBinData || aType == ETypeText8);
    95     
    96     TSettingRef sref(0,0);
    97     TInt err = 0;
    98     err = HCRSingleton->FindSetting(aId, aType, sref);
    99     if (err != KErrNone)
   100         HCR_TRACE_RETURN(err);
   101 
   102     UValueLarge value;
   103     err = sref.iRep->GetLargeValue(sref, value);
   104     __NK_ASSERT_DEBUG(err == KErrNone);
   105    
   106     TInt len = sref.iRep->GetLength(sref);
   107     if (len > aValue.MaxSize())
   108         HCR_TRACE_RETURN(KErrTooBig);    
   109     
   110     if (aType == ETypeBinData)
   111         aValue.Copy(value.iData, len);
   112     else
   113         aValue.Copy(value.iString8, len);
   114     
   115     return KErrNone;	
   116     }
   117 
   118 LOCAL_C TInt GetUValueLargeSettingTUint8 (const TSettingId& aId, TSettingType aType, 
   119                                     TUint16 aMaxLen, TUint8* aValue, TUint16& aLen)
   120     {
   121     HCR_FUNC("GetUValueLargeSettingTUint8");
   122                  
   123     if (HCRNotReady)
   124 	    HCR_TRACE_RETURN(KErrNotReady);
   125 
   126     __NK_ASSERT_DEBUG(aType == ETypeBinData || aType == ETypeText8);
   127     
   128     TSettingRef sref(0,0);
   129     TInt err = 0;
   130     err = HCRSingleton->FindSetting(aId, aType, sref);
   131     if (err != KErrNone)
   132         HCR_TRACE_RETURN(err);
   133 
   134     UValueLarge value;
   135     err = sref.iRep->GetLargeValue(sref, value);
   136 	__NK_ASSERT_DEBUG(err == KErrNone);
   137     
   138     aLen = sref.iRep->GetLength(sref);
   139     if (aLen > aMaxLen)
   140         HCR_TRACE_RETURN(KErrTooBig);    
   141     
   142     if (aType == ETypeBinData)
   143         memcpy (aValue, value.iData, aLen);
   144     else
   145         memcpy (aValue, value.iString8, aLen);
   146     
   147     return KErrNone;	
   148     }
   149     
   150 LOCAL_C TInt GetUValueLargeSettingArray (const TSettingId& aId, TSettingType aType, 
   151                                     TUint16 aMaxLen, TUint32* aValue, TUint16& aLen)
   152     {
   153     HCR_FUNC("GetUValueLargeSettingArray");
   154                  
   155     if (HCRNotReady)
   156 	    HCR_TRACE_RETURN(KErrNotReady);
   157 
   158 	__NK_ASSERT_DEBUG(aType == ETypeArrayInt32 || aType == ETypeArrayUInt32);
   159 	
   160     TSettingRef sref(0,0);
   161     TInt err = 0;
   162     err = HCRSingleton->FindSetting(aId, aType, sref);
   163     if (err != KErrNone)
   164         HCR_TRACE_RETURN(err);
   165 
   166     UValueLarge value;
   167     err = sref.iRep->GetLargeValue(sref, value);
   168 	__NK_ASSERT_DEBUG(err == KErrNone);
   169    
   170     aLen = sref.iRep->GetLength(sref);
   171     if (aLen > aMaxLen)
   172         HCR_TRACE_RETURN(KErrTooBig);    
   173     
   174     if (aType == ETypeArrayInt32)
   175         memcpy (aValue, value.iArrayInt32, aLen);
   176     else 
   177         memcpy (aValue, value.iArrayUInt32, aLen);
   178     
   179     return KErrNone;	
   180     }
   181     
   182 }
   183 
   184 #endif // MAKE_DEF_FILE
   185 
   186 
   187 // -- SETTING GET -------------------------------------------------------------
   188 
   189 
   190 EXPORT_C TInt HCR::GetInt(const TSettingId& aId, TInt8& aValue)
   191     {
   192 #ifndef MAKE_DEF_FILE
   193     HCR_FUNC("HCR::GetInt8");
   194     
   195     UValueWord value;
   196     TInt err = GetUValueWordSetting(aId, ETypeInt8, value);
   197     if (err != KErrNone)
   198         HCR_TRACE_RETURN(err);        
   199     
   200     aValue = value.iInt8;
   201     return KErrNone;    
   202 #else    
   203     HCR_TRACE_RETURN(KErrGeneral);
   204 #endif // MAKE_DEF_FILE
   205     }
   206     
   207     
   208 EXPORT_C TInt HCR::GetInt(const TSettingId& aId, TInt16& aValue) 
   209     {
   210 #ifndef MAKE_DEF_FILE
   211     HCR_FUNC("HCR::GetInt16");
   212     
   213     UValueWord value;
   214     TInt err = GetUValueWordSetting(aId, ETypeInt16, value);
   215     if (err != KErrNone)
   216         HCR_TRACE_RETURN(err);        
   217     
   218     aValue = value.iInt16;
   219     return KErrNone;    
   220 #else    
   221     HCR_TRACE_RETURN(KErrGeneral);
   222 #endif // MAKE_DEF_FILE
   223     }
   224     
   225 
   226 EXPORT_C TInt HCR::GetInt(const TSettingId& aId, TInt32& aValue) 
   227     {
   228 #ifndef MAKE_DEF_FILE
   229     HCR_FUNC("HCR::GetInt32");
   230     
   231         UValueWord value;
   232     TInt err = GetUValueWordSetting(aId, ETypeInt32, value);
   233     if (err != KErrNone)
   234         HCR_TRACE_RETURN(err);        
   235     
   236     aValue = value.iInt32;
   237     return KErrNone;    
   238 #else    
   239     HCR_TRACE_RETURN(KErrGeneral);
   240 #endif // MAKE_DEF_FILE
   241     }
   242     
   243     
   244 EXPORT_C TInt HCR::GetInt(const TSettingId& aId, TInt64& aValue) 
   245     {
   246 #ifndef MAKE_DEF_FILE
   247     HCR_FUNC("HCR::GetInt64");
   248     
   249     UValueLarge value;
   250     TInt err = GetUValueLargeSetting64(aId, ETypeInt64, value);
   251     if (err != KErrNone)
   252         HCR_TRACE_RETURN(err);        
   253     
   254     aValue = *(value.iInt64);
   255     return KErrNone;    
   256 #else    
   257     HCR_TRACE_RETURN(KErrGeneral);
   258 #endif // MAKE_DEF_FILE
   259     }
   260     
   261 
   262 EXPORT_C TInt HCR::GetBool(const TSettingId& aId, TBool& aValue) 
   263     {
   264 #ifndef MAKE_DEF_FILE
   265     HCR_FUNC("HCR::GetBool");
   266                  
   267     UValueWord value;
   268     TInt err = GetUValueWordSetting(aId, ETypeBool, value);
   269     if (err != KErrNone)
   270         HCR_TRACE_RETURN(err);        
   271     
   272     aValue = value.iBool;
   273     return KErrNone;    
   274 #else    
   275     HCR_TRACE_RETURN(KErrGeneral);
   276 #endif // MAKE_DEF_FILE
   277     }
   278     
   279 
   280 EXPORT_C TInt HCR::GetUInt(const TSettingId& aId, TUint8& aValue) 
   281     {
   282 #ifndef MAKE_DEF_FILE
   283     HCR_FUNC("HCR::GetUInt8");
   284                  
   285     UValueWord value;
   286     TInt err = GetUValueWordSetting(aId, ETypeUInt8, value);
   287     if (err != KErrNone)
   288         HCR_TRACE_RETURN(err);        
   289     
   290     aValue = value.iUInt8;
   291     return KErrNone;    
   292 #else    
   293     HCR_TRACE_RETURN(KErrGeneral);
   294 #endif // MAKE_DEF_FILE
   295     }
   296     
   297     
   298 EXPORT_C TInt HCR::GetUInt(const TSettingId& aId, TUint16& aValue) 
   299     {
   300 #ifndef MAKE_DEF_FILE
   301     HCR_FUNC("HCR::GetUInt16");
   302     
   303     UValueWord value;
   304     TInt err = GetUValueWordSetting(aId, ETypeUInt16,value);
   305     if (err != KErrNone)
   306         HCR_TRACE_RETURN(err);        
   307     
   308     aValue = value.iUInt16;
   309     return KErrNone;    
   310 #else    
   311     HCR_TRACE_RETURN(KErrGeneral);
   312 #endif // MAKE_DEF_FILE
   313     }
   314     
   315     
   316 EXPORT_C TInt HCR::GetUInt(const TSettingId& aId, TUint32& aValue) 
   317     {
   318 #ifndef MAKE_DEF_FILE
   319     HCR_FUNC("HCR::GetUInt32");
   320     
   321     UValueWord value;
   322     TInt err = GetUValueWordSetting(aId, ETypeUInt32, value);
   323     if (err != KErrNone)
   324         HCR_TRACE_RETURN(err);        
   325     
   326     aValue = value.iUInt32;
   327     return KErrNone;    
   328 #else    
   329     HCR_TRACE_RETURN(KErrGeneral);
   330 #endif // MAKE_DEF_FILE
   331     }
   332     
   333     
   334 EXPORT_C TInt HCR::GetUInt(const TSettingId& aId, TUint64& aValue) 
   335     {
   336 #ifndef MAKE_DEF_FILE
   337     HCR_FUNC("HCR::GetUInt64");
   338     
   339     UValueLarge value;
   340     TInt err = GetUValueLargeSetting64(aId, ETypeUInt64, value);
   341     if (err != KErrNone)
   342         HCR_TRACE_RETURN(err);        
   343     
   344     aValue = *(value.iUInt64);
   345     return KErrNone;    
   346 #else    
   347     HCR_TRACE_RETURN(KErrGeneral);
   348 #endif // MAKE_DEF_FILE
   349     }
   350 
   351     
   352 EXPORT_C TInt HCR::GetLinAddr(const TSettingId& aId, TLinAddr& aValue)
   353     {
   354 #ifndef MAKE_DEF_FILE
   355     HCR_FUNC("HCR::GetLinAddr");
   356     
   357     UValueWord value;
   358     TInt err = GetUValueWordSetting(aId, ETypeLinAddr, value);
   359     if (err != KErrNone)
   360         HCR_TRACE_RETURN(err);        
   361     
   362     aValue = value.iAddress;
   363     return KErrNone;    
   364 #else    
   365     HCR_TRACE_RETURN(KErrGeneral);
   366 #endif // MAKE_DEF_FILE
   367     }
   368         
   369     
   370 EXPORT_C TInt HCR::GetData(const TSettingId& aId, TUint16 aMaxLen, 
   371                                 TUint8* aValue, TUint16& aLen)                             
   372     {
   373 #ifndef MAKE_DEF_FILE
   374     HCR_FUNC("HCR::GetDataTUint8");
   375     
   376     TInt err = GetUValueLargeSettingTUint8(aId, ETypeBinData, aMaxLen, aValue, aLen);
   377     if (err != KErrNone)
   378         HCR_TRACE_RETURN(err);        
   379     
   380     return KErrNone;    
   381 #else    
   382     HCR_TRACE_RETURN(KErrGeneral);
   383 #endif // MAKE_DEF_FILE
   384     }
   385     
   386 
   387 EXPORT_C TInt HCR::GetData(const TSettingId& aId, TDes8& aValue)
   388     {
   389 #ifndef MAKE_DEF_FILE
   390     HCR_FUNC("HCR::GetDataTDes8");
   391     
   392     TInt err = GetUValueLargeSettingTDes8(aId, ETypeBinData, aValue);
   393     if (err != KErrNone)
   394         HCR_TRACE_RETURN(err);  
   395              
   396     return KErrNone;    
   397 #else    
   398     HCR_TRACE_RETURN(KErrGeneral);
   399 #endif // MAKE_DEF_FILE
   400     }
   401     
   402     
   403 EXPORT_C TInt HCR::GetString(const TSettingId& aId, TUint16 aMaxLen, 
   404                                 TText8* aValue, TUint16& aLen)
   405     {
   406 #ifndef MAKE_DEF_FILE
   407     HCR_FUNC("HCR::GetStringTUint8");
   408     
   409     TInt err = GetUValueLargeSettingTUint8(aId, ETypeText8, aMaxLen, aValue, aLen);
   410     if (err != KErrNone)
   411         HCR_TRACE_RETURN(err);        
   412     
   413     return KErrNone;    
   414 #else    
   415     HCR_TRACE_RETURN(KErrGeneral);
   416 #endif // MAKE_DEF_FILE
   417     }
   418     
   419     
   420 EXPORT_C TInt HCR::GetString(const TSettingId& aId, TDes8& aValue)
   421     {
   422 #ifndef MAKE_DEF_FILE
   423     HCR_FUNC("HCR::GetStringTUint8");
   424     
   425     TInt err = GetUValueLargeSettingTDes8(aId, ETypeText8, aValue);
   426     if (err != KErrNone)
   427         HCR_TRACE_RETURN(err);        
   428     
   429     return KErrNone;    
   430 #else    
   431     HCR_TRACE_RETURN(KErrGeneral);
   432 #endif // MAKE_DEF_FILE
   433     }
   434       
   435 EXPORT_C TInt HCR::GetArray(const TSettingId& aId, TUint16 aMaxLen, 
   436                                 TInt32* aValue, TUint16& aLen)
   437     {
   438 #ifndef MAKE_DEF_FILE
   439     HCR_FUNC("HCR::GetArrayTInt32");
   440     
   441     TInt err = GetUValueLargeSettingArray(aId, ETypeArrayInt32, aMaxLen, (TUint32*)aValue, aLen);
   442     if (err != KErrNone)
   443         HCR_TRACE_RETURN(err);        
   444     
   445     return KErrNone;    
   446 #else    
   447     HCR_TRACE_RETURN(KErrGeneral);
   448 #endif // MAKE_DEF_FILE
   449     }
   450 								       
   451 EXPORT_C TInt HCR::GetArray(const TSettingId& aId, TUint16 aMaxLen, 
   452                                 TUint32* aValue, TUint16& aLen)  
   453     {
   454 #ifndef MAKE_DEF_FILE
   455     HCR_FUNC("HCR::GetArrayTUInt32");
   456     
   457     TInt err = GetUValueLargeSettingArray(aId, ETypeArrayUInt32, aMaxLen, aValue, aLen);
   458     if (err != KErrNone)
   459         HCR_TRACE_RETURN(err);        
   460     
   461     return KErrNone;    
   462 #else    
   463     HCR_TRACE_RETURN(KErrGeneral);
   464 #endif // MAKE_DEF_FILE
   465     }
   466 
   467 
   468 // -- MULTIPLE GETS -----------------------------------------------------------
   469   
   470 EXPORT_C TInt HCR::GetWordSettings(TInt aNum, const SSettingId aIds[],
   471         TInt32 aValues[], TSettingType aTypes[], TInt aErrors[])
   472     {
   473 
   474 #ifndef MAKE_DEF_FILE
   475     HCR_FUNC("GetWordSettings");
   476     
   477     if (HCRNotReady)
   478         HCR_TRACE_RETURN(KErrNotReady);
   479     
   480     if(aNum <= 0 || aIds == NULL || aErrors == NULL || aValues == NULL)
   481         HCR_TRACE_RETURN(KErrArgument);
   482     
   483     TInt err = KErrNone;
   484 
   485     //Don't leave while the resources are not fully allocated/deallocated
   486     NKern::ThreadEnterCS();
   487 
   488     err = HCRSingleton->GetWordSettings(aNum, aIds, aValues, aTypes, aErrors);
   489 
   490     //All de-allocations are done, leave a critical section
   491     NKern::ThreadLeaveCS();
   492 
   493     __NK_ASSERT_DEBUG(err >= KErrNone);
   494 
   495     return err;
   496     
   497 #else    
   498     HCR_TRACE_RETURN(KErrGeneral);
   499 #endif // MAKE_DEF_FILE
   500     }
   501 
   502 
   503 // -- SETTING PROPERTIES ------------------------------------------------------
   504 
   505 EXPORT_C TInt HCR::GetTypeAndSize(const TSettingId& aId, TSettingType& aType, 
   506                                         TUint16& aLen) 
   507     {
   508 #ifndef MAKE_DEF_FILE
   509     HCR_FUNC("GetTypeAndSize");
   510     if (HCRNotReady)
   511         HCR_TRACE_RETURN(KErrNotReady);
   512 
   513     TSettingRef sref(0,0);
   514     TInt err = HCRSingleton->FindSettingWithType(aId, aType, sref);
   515 	
   516 	__NK_ASSERT_DEBUG(err == KErrNone || err == KErrNotFound);
   517 
   518 	if(err == KErrNotFound)
   519         {
   520         aLen = 0;
   521         HCR_TRACE_RETURN(KErrNotFound);
   522         }
   523     
   524 	aLen = sref.iRep->GetLength(sref);
   525     return KErrNone;
   526    
   527 #else
   528     HCR_TRACE_RETURN(KErrGeneral);
   529 #endif //MAKE_DEF_FILE
   530     }
   531  
   532 
   533 // -- SETTING SEARCHES --------------------------------------------------------
   534 
   535 EXPORT_C TInt HCR::FindNumSettingsInCategory (TCategoryUid aCatUid)
   536 	{
   537 #ifndef MAKE_DEF_FILE
   538 
   539 	HCR_FUNC("FindNumSettingsInCategory");
   540 
   541 	if (HCRNotReady)
   542 	    HCR_TRACE_RETURN(KErrNotReady);
   543 	
   544 	TInt err = HCRSingleton->FindNumSettingsInCategory(aCatUid);
   545   
   546 	if(err < 0)
   547 	    HCR_TRACE_RETURN(err);
   548 	
   549 	return err;
   550 
   551 #else    
   552 	HCR_TRACE_RETURN(KErrGeneral);
   553 #endif // MAKE_DEF_FILE
   554     }
   555 
   556 EXPORT_C TInt HCR::FindSettings(TCategoryUid aCat, TInt aMaxNum,
   557         TElementId aElIds[], TSettingType aTypes[], TUint16 aLens[])
   558 	{
   559 #ifndef MAKE_DEF_FILE
   560 
   561 	HCR_FUNC("FindSettings without pattern/mask");
   562 	
   563 
   564 	if (HCRNotReady)
   565 	    HCR_TRACE_RETURN(KErrNotReady);
   566 
   567 	if(aMaxNum <= 0 || aElIds == NULL)
   568 	        HCR_TRACE_RETURN(KErrArgument);
   569 	
   570 	TInt err = HCRSingleton->FindSettings(aCat, aMaxNum, aElIds, 
   571 	        aTypes, aLens);
   572     
   573 	if(err < 0)
   574 	    HCR_TRACE_RETURN(err);
   575 	
   576 	return err;
   577 
   578 #else    
   579 	HCR_TRACE_RETURN(KErrGeneral);
   580 #endif // MAKE_DEF_FILE
   581     }
   582 
   583 EXPORT_C TInt HCR::FindSettings(TCategoryUid aCat, 
   584 					TInt aMaxNum, TUint32 aMask, TUint32 aPattern, 
   585                     TElementId aElIds[], TSettingType aTypes[], TUint16 aLens[])
   586 	{
   587 #ifndef MAKE_DEF_FILE
   588 
   589 	HCR_FUNC("FindSettings with pattern/mask");
   590 	
   591 
   592 	if (HCRNotReady)
   593 	    HCR_TRACE_RETURN(KErrNotReady);
   594 
   595 	if(aMaxNum <= 0 || aElIds == NULL)
   596 	    HCR_TRACE_RETURN(KErrArgument);
   597 
   598 	TInt err = KErrNone;
   599 
   600 	//Don't leave while the resources are not fully allocated/deallocated
   601 	NKern::ThreadEnterCS();
   602 	
   603 	err = HCRSingleton->FindSettings(aCat, aMaxNum, aMask, aPattern, 
   604 	       aElIds, aTypes, aLens);
   605 
   606 	//All de-allocations are done, leave a critical section
   607 	NKern::ThreadLeaveCS();
   608 
   609 	if(err < 0)
   610 	    HCR_TRACE_RETURN(err);
   611 
   612 	return err;
   613 	    
   614 #else    
   615 	HCR_TRACE_RETURN(KErrGeneral);
   616 #endif // MAKE_DEF_FILE
   617     }
   618 						
   619 
   620 // -- KERNEL ENTRY POINT ------------------------------------------------------
   621 
   622 
   623 #ifdef MAKE_DEF_FILE
   624 
   625 DECLARE_STANDARD_EXTENSION()
   626 	{
   627 	return KErrNone;
   628 	}
   629 	
   630 #endif // MAKE_DEF_FILE
   631