sl@0: // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // hal\src\hal_main.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: sl@0: _LIT(KLitHal,"HAL"); sl@0: void HalInternal::Panic(HalInternal::THalPanic aPanic) sl@0: { sl@0: User::Panic(KLitHal,aPanic); sl@0: } sl@0: sl@0: void HalInternal::InitialiseData() sl@0: { sl@0: TInt i; sl@0: _LIT_SECURITY_POLICY_PASS(KPassPolicy); sl@0: _LIT_SECURITY_POLICY_C1(KWriteDevDataPolicy, ECapabilityWriteDeviceData); sl@0: sl@0: for (i=0; i=HAL::ENumHalAttributes) sl@0: return KErrNotFound; sl@0: TInt r=RProperty::Get(KUidSystemCategory, KUidHalPropertyKeyBase+aKey, result); sl@0: if (r!=KErrNone) sl@0: { sl@0: InitialiseData(); sl@0: r=RProperty::Get(KUidSystemCategory, KUidHalPropertyKeyBase+aKey, result); sl@0: } sl@0: __ASSERT_ALWAYS(r==KErrNone,Panic(EGetPropFailed)); sl@0: return (result); sl@0: } sl@0: sl@0: TInt HalInternal::WriteWord(TInt aKey, TInt aValue) sl@0: { sl@0: TInt r; sl@0: sl@0: if(aKey>=HAL::ENumHalAttributes) sl@0: return KErrArgument; sl@0: r=RProperty::Set(KUidSystemCategory, KUidHalPropertyKeyBase+aKey, aValue); sl@0: if (r!=KErrNone && r!=KErrPermissionDenied) sl@0: { sl@0: InitialiseData(); sl@0: r=RProperty::Set(KUidSystemCategory, KUidHalPropertyKeyBase+aKey, aValue); sl@0: } sl@0: __ASSERT_ALWAYS(r==KErrNone || r==KErrPermissionDenied,Panic(ESetPropFailed)); sl@0: return r; sl@0: } sl@0: sl@0: sl@0: EXPORT_C TInt HAL::Get(HAL::TAttribute aAttribute, TInt& aValue) sl@0: { sl@0: return HAL::Get(0,aAttribute,aValue); sl@0: } sl@0: sl@0: sl@0: EXPORT_C TInt HAL::Set(HAL::TAttribute aAttribute, TInt aValue) sl@0: { sl@0: return HAL::Set(0,aAttribute,aValue); sl@0: } sl@0: sl@0: sl@0: EXPORT_C TInt HAL::GetAll(TInt& aNumEntries, SEntry*& aData) sl@0: { sl@0: TInt max_devices=1; sl@0: sl@0: HAL::Get(EDisplayNumberOfScreens,max_devices); sl@0: TInt size=max_devices*(TInt)ENumHalAttributes*(TInt)sizeof(SEntry); sl@0: SEntry* pE=(SEntry*)User::Alloc(size); sl@0: if (!pE) sl@0: { sl@0: aNumEntries=0; sl@0: aData=NULL; sl@0: return KErrNoMemory; sl@0: } sl@0: sl@0: TInt device; sl@0: for(device=0;device=0; --i) sl@0: { sl@0: TInt offset = device*(TInt)ENumHalAttributes + i; sl@0: TInt properties=HalInternal::Properties[i]; sl@0: if (properties & HAL::EValid) sl@0: { sl@0: THalImplementation f=HalInternal::Implementation[i]; sl@0: if (f) sl@0: { sl@0: // Initialise the value before getting it, for consistancy sl@0: // when functions take an argument. (-1 is also likely to be sl@0: // an invalid argument and return an error in these cases, which sl@0: // is probably the safest result.) sl@0: pE[offset].iValue = -1; sl@0: r=(*f)(device,i,EFalse,&pE[offset].iValue); sl@0: if (r==KErrNone) sl@0: { sl@0: pE[offset].iProperties=EEntryValid|EEntryDynamic; sl@0: continue; sl@0: } sl@0: // drop through to clear EEntryValid sl@0: } sl@0: else sl@0: { sl@0: //these attributes do not support multiple devices sl@0: if(device==0) sl@0: { sl@0: TInt p; sl@0: if (!(properties & HAL::ESettable)) sl@0: { sl@0: pE[offset].iValue = HalInternal::InitialValue[i]; sl@0: p=EEntryValid; sl@0: } sl@0: else sl@0: { sl@0: r=RProperty::Get(KUidSystemCategory, KUidHalPropertyKeyBase+i, pE[offset].iValue); sl@0: if (r!=KErrNone) sl@0: { sl@0: HalInternal::InitialiseData(); sl@0: r=RProperty::Get(KUidSystemCategory, KUidHalPropertyKeyBase+i, pE[offset].iValue); sl@0: } sl@0: p=(r==KErrNone?EEntryValid:0); sl@0: p|=EEntryDynamic; sl@0: } sl@0: pE[offset].iProperties=p; sl@0: continue; sl@0: } sl@0: // drop through to clear EEntryValid sl@0: } sl@0: } sl@0: pE[offset].iProperties=0; sl@0: pE[offset].iValue=0; sl@0: } sl@0: } sl@0: aNumEntries=max_devices*(TInt)ENumHalAttributes; sl@0: aData=pE; sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: EXPORT_C TInt HAL::Get(TInt aDeviceNumber, HAL::TAttribute aAttribute, TInt& aValue) sl@0: { sl@0: sl@0: if (TUint(aAttribute)>=TUint(ENumHalAttributes)) sl@0: return KErrNotSupported; sl@0: TUint8 properties=HalInternal::Properties[aAttribute]; sl@0: if (!(properties & HAL::EValid)) sl@0: return KErrNotSupported; sl@0: THalImplementation f=HalInternal::Implementation[aAttribute]; sl@0: if (f) sl@0: return (*f)(aDeviceNumber,aAttribute,EFalse,&aValue); sl@0: if (!(properties & HAL::ESettable)) sl@0: { sl@0: aValue=HalInternal::InitialValue[aAttribute]; sl@0: return KErrNone; sl@0: } sl@0: aValue=HalInternal::ReadWord(aAttribute); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: EXPORT_C TInt HAL::Set(TInt aDeviceNumber, HAL::TAttribute aAttribute, TInt aValue) sl@0: { sl@0: sl@0: if (TUint(aAttribute)>=TUint(ENumHalAttributes)) sl@0: return KErrNotSupported; sl@0: sl@0: TUint8 properties=HalInternal::Properties[aAttribute]; sl@0: if (!(properties & HAL::EValid) || !(properties & HAL::ESettable)) sl@0: return KErrNotSupported; sl@0: THalImplementation f=HalInternal::Implementation[aAttribute]; sl@0: if (f) sl@0: return (*f)(aDeviceNumber,aAttribute,ETrue,(TAny*)aValue); sl@0: return HalInternal::WriteWord(aAttribute,aValue); sl@0: } sl@0: