1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/boardsupport/haitest/bspsvs/suite/hal/src/T_HALData.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,329 @@
1.4 +/*
1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +#include "T_HALData.h"
1.22 +
1.23 +/*@{*/
1.24 +_LIT(KDeviceId, "deviceid");
1.25 +_LIT(KHalEValue, "halEValue");
1.26 +_LIT(KValue, "value");
1.27 +_LIT(KExpected, "expected");
1.28 +
1.29 +_LIT(KCmdSet, "Set");
1.30 +_LIT(KCmdGet, "Get");
1.31 +
1.32 +_LIT(KLogEnumNotFound, "Enum '%S' not found");
1.33 +_LIT(KLogError, "Error=%d");
1.34 +_LIT(KLogMissingParameter, "Missing parameter '%S'");
1.35 +_LIT(KLogActualValue, "Actual Value '%d' 0x%x");
1.36 +/*@}*/
1.37 +
1.38 +//////////////////////////////////////////////////////////////////////
1.39 +// Construction/Destruction
1.40 +//////////////////////////////////////////////////////////////////////
1.41 +
1.42 +CT_HALData::CT_HALData(const THalTableLookup* aTable)
1.43 +: CDataWrapperBase()
1.44 +, iTable(aTable)
1.45 +, iValue(-1)
1.46 + {
1.47 + }
1.48 +
1.49 +CT_HALData::~CT_HALData()
1.50 +/**
1.51 + * Public destructor
1.52 + */
1.53 + {
1.54 + }
1.55 +
1.56 +TAny* CT_HALData::GetObject()
1.57 +/**
1.58 + * Return a pointer to the object that the data wraps
1.59 + *
1.60 + * @return pointer to the object that the data wraps
1.61 + */
1.62 + {
1.63 + return NULL;
1.64 + }
1.65 +
1.66 +const CT_HALData::THalTableLookup* CT_HALData::LookUp(const TDesC& aValue)
1.67 + {
1.68 + const THalTableLookup* ret=NULL;
1.69 + TInt index=0;
1.70 + while ( (iTable[index].iHalFunctionSetPrepare!=NULL) &&
1.71 + (iTable[index].iHalFunctionGetValidation!=NULL) && (ret==NULL) )
1.72 + {
1.73 + if ( iTable[index].iHalString==aValue )
1.74 + {
1.75 + ret=&iTable[index];
1.76 + }
1.77 + else
1.78 + {
1.79 + ++index;
1.80 + }
1.81 + }
1.82 + return ret;
1.83 + }
1.84 +
1.85 +TBool CT_HALData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
1.86 +/**
1.87 + * Process a command read from the ini file
1.88 + *
1.89 + * @param aCommand The command to process
1.90 + * @param aSection The section in the ini containing data for the command
1.91 + * @param aAsyncErrorIndex Command index for async calls to return errors to
1.92 + *
1.93 + * @return ETrue if the command is processed
1.94 + *
1.95 + * @leave System wide error
1.96 + */
1.97 + {
1.98 + TBool ret=ETrue;
1.99 + TInt err=KErrNone;
1.100 +
1.101 + if ( aCommand==KCmdSet )
1.102 + {
1.103 + err=DoCmdSet(aSection);
1.104 + }
1.105 + else if ( aCommand==KCmdGet)
1.106 + {
1.107 + err=DoCmdGet(aSection);
1.108 + }
1.109 + else
1.110 + {
1.111 + ret=CDataWrapperBase::DoCommandL(aCommand, aSection, aAsyncErrorIndex);
1.112 + }
1.113 +
1.114 + if ( err!=KErrNone )
1.115 + {
1.116 + ERR_PRINTF2(KLogError, err);
1.117 + SetError(err);
1.118 + }
1.119 +
1.120 + return ret;
1.121 + }
1.122 +
1.123 +TInt CT_HALData::DoCmdSet(const TDesC& aSection)
1.124 + {
1.125 + TInt err=KErrNone;
1.126 +
1.127 + // Do we have a device id
1.128 + TInt deviceId=0;
1.129 + TBool hasDeviceId=GetIntFromConfig(aSection, KDeviceId(), deviceId);
1.130 +
1.131 + // Get the HAL variable to set
1.132 + TPtrC enumString;
1.133 + if ( GetStringFromConfig(aSection, KHalEValue(), enumString) )
1.134 + {
1.135 + const THalTableLookup* entry=LookUp(enumString);
1.136 +
1.137 + if ( entry==NULL )
1.138 + {
1.139 + // HAL variable not valid
1.140 + ERR_PRINTF2(KLogEnumNotFound, &enumString);
1.141 + SetBlockResult(EFail);
1.142 + }
1.143 + else
1.144 + {
1.145 + TInt value=0;
1.146 + // Read data from ini file for the value to set
1.147 + if ( entry->iHalFunctionSetPrepare(this, aSection, value) )
1.148 + {
1.149 + // Set the value
1.150 + if ( hasDeviceId )
1.151 + {
1.152 + err=HAL::Set(deviceId, entry->iHalAttribute, value);
1.153 + }
1.154 + else
1.155 + {
1.156 + err=HAL::Set(entry->iHalAttribute, value);
1.157 + }
1.158 +
1.159 + if ( err==KErrNone )
1.160 + {
1.161 + // Set was successful so store it locally
1.162 + entry->iHalFunctionStore(this, value);
1.163 + }
1.164 + }
1.165 + }
1.166 + }
1.167 + else
1.168 + {
1.169 + ERR_PRINTF2(KLogMissingParameter, &KHalEValue());
1.170 + SetBlockResult(EFail);
1.171 + }
1.172 +
1.173 + return err;
1.174 + }
1.175 +
1.176 +TInt CT_HALData::DoCmdGet(const TDesC& aSection)
1.177 + {
1.178 + TInt err=KErrNone;
1.179 +
1.180 + // Do we have a device id
1.181 + TInt deviceId=0;
1.182 + TBool hasDeviceId=GetIntFromConfig(aSection, KDeviceId(), deviceId);
1.183 +
1.184 + // Get the HAL variable to set
1.185 + TPtrC enumString;
1.186 + if ( GetStringFromConfig(aSection, KHalEValue(), enumString) )
1.187 + {
1.188 + const THalTableLookup* entry=LookUp(enumString);
1.189 +
1.190 + if ( entry==NULL )
1.191 + {
1.192 + // HAL variable not valid
1.193 + ERR_PRINTF2(KLogEnumNotFound, &enumString);
1.194 + SetBlockResult(EFail);
1.195 + }
1.196 + else
1.197 + {
1.198 + // HAL::Get testing works within a range (needed if we request the full palette)
1.199 + // Get the range of values to get
1.200 + TInt valueStart=0;
1.201 + TInt valueEnd=0;
1.202 + if ( entry->iHalFunctionGetPrepare(this, aSection, valueStart, valueEnd) )
1.203 + {
1.204 + for ( iValue=valueStart; (iValue<=valueEnd) && (err==KErrNone); ++iValue )
1.205 + {
1.206 + // Get the value
1.207 + TInt value=iValue;
1.208 + if ( hasDeviceId )
1.209 + {
1.210 + err=HAL::Get(deviceId, entry->iHalAttribute, value);
1.211 + }
1.212 + else
1.213 + {
1.214 + err=HAL::Get(entry->iHalAttribute, value);
1.215 + }
1.216 +
1.217 + if ( err==KErrNone )
1.218 + {
1.219 + // Get was successful validate the returned value and store it locally
1.220 + INFO_PRINTF3(KLogActualValue, value, value);
1.221 + entry->iHalFunctionGetValidation(this, aSection, value, entry->iHalForceValidation);
1.222 + entry->iHalFunctionStore(this, value);
1.223 + }
1.224 + }
1.225 + }
1.226 + }
1.227 + }
1.228 + else
1.229 + {
1.230 + ERR_PRINTF2(KLogMissingParameter, &KHalEValue());
1.231 + SetBlockResult(EFail);
1.232 + }
1.233 +
1.234 + return err;
1.235 + }
1.236 +
1.237 +// Prepare the value we are setting as a TInt
1.238 +TBool CT_HALData::SetPrepareInt(CDataWrapperBase* aThis, const TDesC& aSection, TInt& aValue)
1.239 + {
1.240 + TBool ret=aThis->GetIntFromConfig(aSection, KValue(), aValue);
1.241 + if ( !ret )
1.242 + {
1.243 + aThis->ERR_PRINTF2(KLogMissingParameter, &KValue());
1.244 + aThis->SetBlockResult(EFail);
1.245 + }
1.246 +
1.247 + return ret;
1.248 + }
1.249 +
1.250 +// Prepare the value we are setting as a TUint
1.251 +TBool CT_HALData::SetPrepareUint(CDataWrapperBase* aThis, const TDesC& aSection, TInt& aValue)
1.252 + {
1.253 + TUint uint=aValue;
1.254 + TBool ret=aThis->GetUintFromConfig(aSection, KValue(), uint);
1.255 + if ( !ret )
1.256 + {
1.257 + aThis->ERR_PRINTF2(KLogMissingParameter, &KValue());
1.258 + aThis->SetBlockResult(EFail);
1.259 + }
1.260 +
1.261 + aValue=uint;
1.262 + return ret;
1.263 + }
1.264 +
1.265 +// Validate the returned value from a HAL::Get as a TBool
1.266 +void CT_HALData::GetValidationBool(CDataWrapperBase* aThis, const TDesC& aSection, TInt aValue, TBool aForceValidation)
1.267 + {
1.268 + TBool expectedValue;
1.269 + TBool ret=aThis->GetBoolFromConfig(aSection, KExpected(), expectedValue);
1.270 + if ( !ret )
1.271 + {
1.272 + if ( aForceValidation )
1.273 + {
1.274 + aThis->ERR_PRINTF2(KLogMissingParameter, &KExpected());
1.275 + aThis->SetBlockResult(EFail);
1.276 + }
1.277 + }
1.278 + else
1.279 + {
1.280 + if ( aValue!=expectedValue )
1.281 + {
1.282 + aThis->SetBlockResult(EFail);
1.283 + aThis->ERR_PRINTF3(_L("Retrived Value(%d) != expectedValue(%d)"), aValue, expectedValue);
1.284 + }
1.285 + }
1.286 + }
1.287 +
1.288 +// Validate the returned value from a HAL::Get as a TInt
1.289 +void CT_HALData::GetValidationInt(CDataWrapperBase* aThis, const TDesC& aSection, TInt aValue, TBool aForceValidation)
1.290 + {
1.291 + TInt expectedValue;
1.292 + TBool ret=aThis->GetIntFromConfig(aSection, KExpected(), expectedValue);
1.293 + if ( !ret )
1.294 + {
1.295 + if ( aForceValidation )
1.296 + {
1.297 + aThis->ERR_PRINTF2(KLogMissingParameter, &KExpected());
1.298 + aThis->SetBlockResult(EFail);
1.299 + }
1.300 + }
1.301 + else
1.302 + {
1.303 + if ( aValue!=expectedValue )
1.304 + {
1.305 + aThis->SetBlockResult(EFail);
1.306 + aThis->ERR_PRINTF3(_L("Retrived Value(%d) != expectedValue(%d)"), aValue, expectedValue);
1.307 + }
1.308 + }
1.309 + }
1.310 +
1.311 +// Validate the returned value from a HAL::Get as a TUint
1.312 +void CT_HALData::GetValidationUint(CDataWrapperBase* aThis, const TDesC& aSection, TInt aValue, TBool aForceValidation)
1.313 + {
1.314 + TUint expectedValue;
1.315 + TBool ret=aThis->GetUintFromConfig(aSection, KExpected(), expectedValue);
1.316 + if ( !ret )
1.317 + {
1.318 + if ( aForceValidation )
1.319 + {
1.320 + aThis->ERR_PRINTF2(KLogMissingParameter, &KExpected());
1.321 + aThis->SetBlockResult(EFail);
1.322 + }
1.323 + }
1.324 + else
1.325 + {
1.326 + if ( (TUint)aValue!=expectedValue )
1.327 + {
1.328 + aThis->SetBlockResult(EFail);
1.329 + aThis->ERR_PRINTF3(_L("Retrived Value(%d) != expectedValue(%d)"), aValue, expectedValue);
1.330 + }
1.331 + }
1.332 + }