os/boardsupport/haitest/bspsvs/suite/hal/src/T_HALData.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.
     1 /*
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:
    15 *
    16 */
    17 
    18 #include "T_HALData.h"
    19 
    20 /*@{*/
    21 _LIT(KDeviceId,								"deviceid");
    22 _LIT(KHalEValue,							"halEValue");
    23 _LIT(KValue,								"value");
    24 _LIT(KExpected,								"expected");
    25 
    26 _LIT(KCmdSet,								"Set");
    27 _LIT(KCmdGet,								"Get");
    28 
    29 _LIT(KLogEnumNotFound,						"Enum '%S' not found");
    30 _LIT(KLogError,								"Error=%d");
    31 _LIT(KLogMissingParameter,					"Missing parameter '%S'");
    32 _LIT(KLogActualValue,						"Actual Value '%d' 0x%x");
    33 /*@}*/
    34 
    35 //////////////////////////////////////////////////////////////////////
    36 // Construction/Destruction
    37 //////////////////////////////////////////////////////////////////////
    38 
    39 CT_HALData::CT_HALData(const THalTableLookup* aTable)
    40 :	CDataWrapperBase()
    41 ,	iTable(aTable)
    42 ,	iValue(-1)
    43 	{
    44 	}
    45 
    46 CT_HALData::~CT_HALData()
    47 /**
    48  * Public destructor
    49  */
    50 	{
    51 	}
    52 
    53 TAny* CT_HALData::GetObject()
    54 /**
    55  * Return a pointer to the object that the data wraps
    56  *
    57  * @return	pointer to the object that the data wraps
    58  */
    59 	{
    60 	return NULL;
    61 	}
    62 
    63 const CT_HALData::THalTableLookup* CT_HALData::LookUp(const TDesC& aValue)
    64 	{
    65 	const THalTableLookup*	ret=NULL;
    66 	TInt					index=0;
    67 	while ( (iTable[index].iHalFunctionSetPrepare!=NULL) &&
    68 			(iTable[index].iHalFunctionGetValidation!=NULL) && (ret==NULL) )
    69 		{
    70 		if ( iTable[index].iHalString==aValue )
    71 			{
    72 			ret=&iTable[index];
    73 			}
    74 		else
    75 			{
    76 			++index;
    77 			}
    78 		}
    79 	return ret;
    80 	}
    81 
    82 TBool CT_HALData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
    83 /**
    84  * Process a command read from the ini file
    85  *
    86  * @param aCommand			The command to process
    87  * @param aSection			The section in the ini containing data for the command
    88  * @param aAsyncErrorIndex	Command index for async calls to return errors to
    89  *
    90  * @return					ETrue if the command is processed
    91  *
    92  * @leave					System wide error
    93  */
    94 	{
    95 	TBool	ret=ETrue;
    96 	TInt	err=KErrNone;
    97 
    98 	if ( aCommand==KCmdSet )
    99 		{
   100 		err=DoCmdSet(aSection);
   101 		}
   102 	else if ( aCommand==KCmdGet)
   103 		{
   104 		err=DoCmdGet(aSection);
   105 		}
   106 	else
   107 		{
   108 		ret=CDataWrapperBase::DoCommandL(aCommand, aSection, aAsyncErrorIndex);
   109 		}
   110 
   111 	if ( err!=KErrNone )
   112 		{
   113 		ERR_PRINTF2(KLogError, err);
   114 		SetError(err);
   115 		}
   116 
   117 	return ret;
   118 	}
   119 
   120 TInt CT_HALData::DoCmdSet(const TDesC& aSection)
   121 	{
   122 	TInt	err=KErrNone;
   123 
   124 	//	Do we have a device id
   125 	TInt	deviceId=0;
   126 	TBool	hasDeviceId=GetIntFromConfig(aSection, KDeviceId(), deviceId);
   127 
   128 	//	Get the HAL variable to set
   129 	TPtrC	enumString;
   130 	if ( GetStringFromConfig(aSection, KHalEValue(), enumString) )
   131 		{
   132 		const THalTableLookup*	entry=LookUp(enumString);
   133 
   134 		if ( entry==NULL )
   135 			{
   136 			//	HAL variable not valid
   137 			ERR_PRINTF2(KLogEnumNotFound, &enumString);
   138 			SetBlockResult(EFail);
   139 			}
   140 		else
   141 			{
   142 			TInt	value=0;
   143 			//	Read data from ini file for the value to set
   144 			if ( entry->iHalFunctionSetPrepare(this, aSection, value) )
   145 				{
   146 				//	Set the value
   147 				if ( hasDeviceId )
   148 					{
   149 					err=HAL::Set(deviceId, entry->iHalAttribute, value);
   150 					}
   151 				else
   152 					{
   153 					err=HAL::Set(entry->iHalAttribute, value);
   154 					}
   155 
   156 				if ( err==KErrNone )
   157 					{
   158 					//	Set was successful so store it locally
   159 					entry->iHalFunctionStore(this, value);
   160 					}
   161 				}
   162 			}
   163 		}
   164 	else
   165 		{
   166 		ERR_PRINTF2(KLogMissingParameter, &KHalEValue());
   167 		SetBlockResult(EFail);
   168 		}
   169 
   170 	return err;
   171 	}
   172 
   173 TInt CT_HALData::DoCmdGet(const TDesC& aSection)
   174 	{
   175 	TInt	err=KErrNone;
   176 
   177 	//	Do we have a device id
   178 	TInt	deviceId=0;
   179 	TBool	hasDeviceId=GetIntFromConfig(aSection, KDeviceId(), deviceId);
   180 
   181 	//	Get the HAL variable to set
   182 	TPtrC	enumString;
   183 	if ( GetStringFromConfig(aSection, KHalEValue(), enumString) )
   184 		{
   185 		const THalTableLookup*	entry=LookUp(enumString);
   186 
   187 		if ( entry==NULL )
   188 			{
   189 			//	HAL variable not valid
   190 			ERR_PRINTF2(KLogEnumNotFound, &enumString);
   191 			SetBlockResult(EFail);
   192 			}
   193 		else
   194 			{
   195 			//	HAL::Get testing works within a range (needed if we request the full palette)
   196 			//	Get the range of values to get
   197 			TInt	valueStart=0;
   198 			TInt	valueEnd=0;
   199 			if ( entry->iHalFunctionGetPrepare(this, aSection, valueStart, valueEnd) )
   200 				{
   201 				for ( iValue=valueStart; (iValue<=valueEnd) && (err==KErrNone); ++iValue )
   202 					{
   203 					//	Get the value
   204 					TInt	value=iValue;
   205 					if ( hasDeviceId )
   206 						{
   207 						err=HAL::Get(deviceId, entry->iHalAttribute, value);
   208 						}
   209 					else
   210 						{
   211 						err=HAL::Get(entry->iHalAttribute, value);
   212 						}
   213 
   214 					if ( err==KErrNone )
   215 						{
   216 						//	Get was successful validate the returned value and store it locally
   217 						INFO_PRINTF3(KLogActualValue, value, value);
   218 						entry->iHalFunctionGetValidation(this, aSection, value, entry->iHalForceValidation);
   219 						entry->iHalFunctionStore(this, value);
   220 						}
   221 					}
   222 				}
   223 			}
   224 		}
   225 	else
   226 		{
   227 		ERR_PRINTF2(KLogMissingParameter, &KHalEValue());
   228 		SetBlockResult(EFail);
   229 		}
   230 
   231 	return err;
   232 	}
   233 
   234 //	Prepare the value we are setting as a TInt
   235 TBool CT_HALData::SetPrepareInt(CDataWrapperBase* aThis, const TDesC& aSection, TInt& aValue)
   236 	{
   237 	TBool	ret=aThis->GetIntFromConfig(aSection, KValue(), aValue);
   238 	if ( !ret )
   239 		{
   240 		aThis->ERR_PRINTF2(KLogMissingParameter, &KValue());
   241 		aThis->SetBlockResult(EFail);
   242 		}
   243 
   244 	return ret;
   245 	}
   246 
   247 //	Prepare the value we are setting as a TUint
   248 TBool CT_HALData::SetPrepareUint(CDataWrapperBase* aThis, const TDesC& aSection, TInt& aValue)
   249 	{
   250 	TUint	uint=aValue;
   251 	TBool	ret=aThis->GetUintFromConfig(aSection, KValue(), uint);
   252 	if ( !ret )
   253 		{
   254 		aThis->ERR_PRINTF2(KLogMissingParameter, &KValue());
   255 		aThis->SetBlockResult(EFail);
   256 		}
   257 
   258 	aValue=uint;
   259 	return ret;
   260 	}
   261 
   262 //	Validate the returned value from a HAL::Get as a TBool
   263 void CT_HALData::GetValidationBool(CDataWrapperBase* aThis, const TDesC& aSection, TInt aValue, TBool aForceValidation)
   264 	{
   265 	TBool	expectedValue;
   266 	TBool	ret=aThis->GetBoolFromConfig(aSection, KExpected(), expectedValue);
   267 	if ( !ret )
   268 		{
   269 		if ( aForceValidation )
   270 			{
   271 			aThis->ERR_PRINTF2(KLogMissingParameter, &KExpected());
   272 			aThis->SetBlockResult(EFail);
   273 			}
   274 		}
   275 	else
   276 		{
   277 		if ( aValue!=expectedValue )
   278 			{
   279 			aThis->SetBlockResult(EFail);
   280 			aThis->ERR_PRINTF3(_L("Retrived Value(%d) != expectedValue(%d)"), aValue, expectedValue);
   281 			}
   282 		}
   283 	}
   284 
   285 //	Validate the returned value from a HAL::Get as a TInt
   286 void CT_HALData::GetValidationInt(CDataWrapperBase* aThis, const TDesC& aSection, TInt aValue, TBool aForceValidation)
   287 	{
   288 	TInt	expectedValue;
   289 	TBool	ret=aThis->GetIntFromConfig(aSection, KExpected(), expectedValue);
   290 	if ( !ret )
   291 		{
   292 		if ( aForceValidation )
   293 			{
   294 			aThis->ERR_PRINTF2(KLogMissingParameter, &KExpected());
   295 			aThis->SetBlockResult(EFail);
   296 			}
   297 		}
   298 	else
   299 		{
   300 		if ( aValue!=expectedValue )
   301 			{
   302 			aThis->SetBlockResult(EFail);
   303 			aThis->ERR_PRINTF3(_L("Retrived Value(%d) != expectedValue(%d)"), aValue, expectedValue);
   304 			}
   305 		}
   306 	}
   307 
   308 //	Validate the returned value from a HAL::Get as a TUint
   309 void CT_HALData::GetValidationUint(CDataWrapperBase* aThis, const TDesC& aSection, TInt aValue, TBool aForceValidation)
   310 	{
   311 	TUint	expectedValue;
   312 	TBool	ret=aThis->GetUintFromConfig(aSection, KExpected(), expectedValue);
   313 	if ( !ret )
   314 		{
   315 		if ( aForceValidation )
   316 			{
   317 			aThis->ERR_PRINTF2(KLogMissingParameter, &KExpected());
   318 			aThis->SetBlockResult(EFail);
   319 			}
   320 		}
   321 	else
   322 		{
   323 		if ( (TUint)aValue!=expectedValue )
   324 			{
   325 			aThis->SetBlockResult(EFail);
   326 			aThis->ERR_PRINTF3(_L("Retrived Value(%d) != expectedValue(%d)"), aValue, expectedValue);
   327 			}
   328 		}
   329 	}