Update contrib.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
18 #include "T_HALData.h"
21 _LIT(KDeviceId, "deviceid");
22 _LIT(KHalEValue, "halEValue");
23 _LIT(KValue, "value");
24 _LIT(KExpected, "expected");
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");
35 //////////////////////////////////////////////////////////////////////
36 // Construction/Destruction
37 //////////////////////////////////////////////////////////////////////
39 CT_HALData::CT_HALData(const THalTableLookup* aTable)
46 CT_HALData::~CT_HALData()
53 TAny* CT_HALData::GetObject()
55 * Return a pointer to the object that the data wraps
57 * @return pointer to the object that the data wraps
63 const CT_HALData::THalTableLookup* CT_HALData::LookUp(const TDesC& aValue)
65 const THalTableLookup* ret=NULL;
67 while ( (iTable[index].iHalFunctionSetPrepare!=NULL) &&
68 (iTable[index].iHalFunctionGetValidation!=NULL) && (ret==NULL) )
70 if ( iTable[index].iHalString==aValue )
82 TBool CT_HALData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
84 * Process a command read from the ini file
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
90 * @return ETrue if the command is processed
92 * @leave System wide error
98 if ( aCommand==KCmdSet )
100 err=DoCmdSet(aSection);
102 else if ( aCommand==KCmdGet)
104 err=DoCmdGet(aSection);
108 ret=CDataWrapperBase::DoCommandL(aCommand, aSection, aAsyncErrorIndex);
113 ERR_PRINTF2(KLogError, err);
120 TInt CT_HALData::DoCmdSet(const TDesC& aSection)
124 // Do we have a device id
126 TBool hasDeviceId=GetIntFromConfig(aSection, KDeviceId(), deviceId);
128 // Get the HAL variable to set
130 if ( GetStringFromConfig(aSection, KHalEValue(), enumString) )
132 const THalTableLookup* entry=LookUp(enumString);
136 // HAL variable not valid
137 ERR_PRINTF2(KLogEnumNotFound, &enumString);
138 SetBlockResult(EFail);
143 // Read data from ini file for the value to set
144 if ( entry->iHalFunctionSetPrepare(this, aSection, value) )
149 err=HAL::Set(deviceId, entry->iHalAttribute, value);
153 err=HAL::Set(entry->iHalAttribute, value);
158 // Set was successful so store it locally
159 entry->iHalFunctionStore(this, value);
166 ERR_PRINTF2(KLogMissingParameter, &KHalEValue());
167 SetBlockResult(EFail);
173 TInt CT_HALData::DoCmdGet(const TDesC& aSection)
177 // Do we have a device id
179 TBool hasDeviceId=GetIntFromConfig(aSection, KDeviceId(), deviceId);
181 // Get the HAL variable to set
183 if ( GetStringFromConfig(aSection, KHalEValue(), enumString) )
185 const THalTableLookup* entry=LookUp(enumString);
189 // HAL variable not valid
190 ERR_PRINTF2(KLogEnumNotFound, &enumString);
191 SetBlockResult(EFail);
195 // HAL::Get testing works within a range (needed if we request the full palette)
196 // Get the range of values to get
199 if ( entry->iHalFunctionGetPrepare(this, aSection, valueStart, valueEnd) )
201 for ( iValue=valueStart; (iValue<=valueEnd) && (err==KErrNone); ++iValue )
207 err=HAL::Get(deviceId, entry->iHalAttribute, value);
211 err=HAL::Get(entry->iHalAttribute, value);
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);
227 ERR_PRINTF2(KLogMissingParameter, &KHalEValue());
228 SetBlockResult(EFail);
234 // Prepare the value we are setting as a TInt
235 TBool CT_HALData::SetPrepareInt(CDataWrapperBase* aThis, const TDesC& aSection, TInt& aValue)
237 TBool ret=aThis->GetIntFromConfig(aSection, KValue(), aValue);
240 aThis->ERR_PRINTF2(KLogMissingParameter, &KValue());
241 aThis->SetBlockResult(EFail);
247 // Prepare the value we are setting as a TUint
248 TBool CT_HALData::SetPrepareUint(CDataWrapperBase* aThis, const TDesC& aSection, TInt& aValue)
251 TBool ret=aThis->GetUintFromConfig(aSection, KValue(), uint);
254 aThis->ERR_PRINTF2(KLogMissingParameter, &KValue());
255 aThis->SetBlockResult(EFail);
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)
266 TBool ret=aThis->GetBoolFromConfig(aSection, KExpected(), expectedValue);
269 if ( aForceValidation )
271 aThis->ERR_PRINTF2(KLogMissingParameter, &KExpected());
272 aThis->SetBlockResult(EFail);
277 if ( aValue!=expectedValue )
279 aThis->SetBlockResult(EFail);
280 aThis->ERR_PRINTF3(_L("Retrived Value(%d) != expectedValue(%d)"), aValue, expectedValue);
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)
289 TBool ret=aThis->GetIntFromConfig(aSection, KExpected(), expectedValue);
292 if ( aForceValidation )
294 aThis->ERR_PRINTF2(KLogMissingParameter, &KExpected());
295 aThis->SetBlockResult(EFail);
300 if ( aValue!=expectedValue )
302 aThis->SetBlockResult(EFail);
303 aThis->ERR_PRINTF3(_L("Retrived Value(%d) != expectedValue(%d)"), aValue, expectedValue);
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)
312 TBool ret=aThis->GetUintFromConfig(aSection, KExpected(), expectedValue);
315 if ( aForceValidation )
317 aThis->ERR_PRINTF2(KLogMissingParameter, &KExpected());
318 aThis->SetBlockResult(EFail);
323 if ( (TUint)aValue!=expectedValue )
325 aThis->SetBlockResult(EFail);
326 aThis->ERR_PRINTF3(_L("Retrived Value(%d) != expectedValue(%d)"), aValue, expectedValue);