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