1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/halservices/hal/src/hal_main.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,214 @@
1.4 +// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// hal\src\hal_main.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <kernel/hal_int.h>
1.22 +
1.23 +_LIT(KLitHal,"HAL");
1.24 +void HalInternal::Panic(HalInternal::THalPanic aPanic)
1.25 + {
1.26 + User::Panic(KLitHal,aPanic);
1.27 + }
1.28 +
1.29 +void HalInternal::InitialiseData()
1.30 + {
1.31 + TInt i;
1.32 + _LIT_SECURITY_POLICY_PASS(KPassPolicy);
1.33 + _LIT_SECURITY_POLICY_C1(KWriteDevDataPolicy, ECapabilityWriteDeviceData);
1.34 +
1.35 + for (i=0; i<HAL::ENumHalAttributes; i++) // for every attribute,
1.36 + {
1.37 + if (Properties[i]&HAL::EValid && !Implementation[i] && (Properties[i] & HAL::ESettable))
1.38 + // if it's implemented, not a constant and not a user function
1.39 + {
1.40 + TInt r = RProperty::Define(KUidSystemCategory, KUidHalPropertyKeyBase+i, RProperty::EInt,
1.41 + KPassPolicy, KWriteDevDataPolicy);
1.42 + __ASSERT_ALWAYS(r==KErrNone || r==KErrAlreadyExists,Panic(EInitialAllocFailed1));
1.43 + if (r==KErrAlreadyExists)
1.44 + break;
1.45 +
1.46 + // This will panic if the first instance of the DLL to start does not have WriteDeviceData
1.47 + // capability. Again, there isn't anything we can do about this. It shouldn't ever happen.
1.48 + r = RProperty::Set(KUidSystemCategory, KUidHalPropertyKeyBase+i, InitialValue[i]);
1.49 + __ASSERT_ALWAYS(r==KErrNone,Panic(EInitialAllocFailed2));
1.50 + }
1.51 + }
1.52 + }
1.53 +
1.54 +TInt HalInternal::ReadWord(TInt aKey)
1.55 + {
1.56 + TInt result;
1.57 +
1.58 + // This is a slow way of doing it, but it is light on memory as it doesn't
1.59 + // need an offset array.
1.60 +
1.61 + if(aKey>=HAL::ENumHalAttributes)
1.62 + return KErrNotFound;
1.63 + TInt r=RProperty::Get(KUidSystemCategory, KUidHalPropertyKeyBase+aKey, result);
1.64 + if (r!=KErrNone)
1.65 + {
1.66 + InitialiseData();
1.67 + r=RProperty::Get(KUidSystemCategory, KUidHalPropertyKeyBase+aKey, result);
1.68 + }
1.69 + __ASSERT_ALWAYS(r==KErrNone,Panic(EGetPropFailed));
1.70 + return (result);
1.71 + }
1.72 +
1.73 +TInt HalInternal::WriteWord(TInt aKey, TInt aValue)
1.74 + {
1.75 + TInt r;
1.76 +
1.77 + if(aKey>=HAL::ENumHalAttributes)
1.78 + return KErrArgument;
1.79 + r=RProperty::Set(KUidSystemCategory, KUidHalPropertyKeyBase+aKey, aValue);
1.80 + if (r!=KErrNone && r!=KErrPermissionDenied)
1.81 + {
1.82 + InitialiseData();
1.83 + r=RProperty::Set(KUidSystemCategory, KUidHalPropertyKeyBase+aKey, aValue);
1.84 + }
1.85 + __ASSERT_ALWAYS(r==KErrNone || r==KErrPermissionDenied,Panic(ESetPropFailed));
1.86 + return r;
1.87 + }
1.88 +
1.89 +
1.90 +EXPORT_C TInt HAL::Get(HAL::TAttribute aAttribute, TInt& aValue)
1.91 + {
1.92 + return HAL::Get(0,aAttribute,aValue);
1.93 + }
1.94 +
1.95 +
1.96 +EXPORT_C TInt HAL::Set(HAL::TAttribute aAttribute, TInt aValue)
1.97 + {
1.98 + return HAL::Set(0,aAttribute,aValue);
1.99 + }
1.100 +
1.101 +
1.102 +EXPORT_C TInt HAL::GetAll(TInt& aNumEntries, SEntry*& aData)
1.103 + {
1.104 + TInt max_devices=1;
1.105 +
1.106 + HAL::Get(EDisplayNumberOfScreens,max_devices);
1.107 + TInt size=max_devices*(TInt)ENumHalAttributes*(TInt)sizeof(SEntry);
1.108 + SEntry* pE=(SEntry*)User::Alloc(size);
1.109 + if (!pE)
1.110 + {
1.111 + aNumEntries=0;
1.112 + aData=NULL;
1.113 + return KErrNoMemory;
1.114 + }
1.115 +
1.116 + TInt device;
1.117 + for(device=0;device<max_devices;device++)
1.118 + {
1.119 + TInt r;
1.120 + TInt i=ENumHalAttributes-1;
1.121 + for (; i>=0; --i)
1.122 + {
1.123 + TInt offset = device*(TInt)ENumHalAttributes + i;
1.124 + TInt properties=HalInternal::Properties[i];
1.125 + if (properties & HAL::EValid)
1.126 + {
1.127 + THalImplementation f=HalInternal::Implementation[i];
1.128 + if (f)
1.129 + {
1.130 + // Initialise the value before getting it, for consistancy
1.131 + // when functions take an argument. (-1 is also likely to be
1.132 + // an invalid argument and return an error in these cases, which
1.133 + // is probably the safest result.)
1.134 + pE[offset].iValue = -1;
1.135 + r=(*f)(device,i,EFalse,&pE[offset].iValue);
1.136 + if (r==KErrNone)
1.137 + {
1.138 + pE[offset].iProperties=EEntryValid|EEntryDynamic;
1.139 + continue;
1.140 + }
1.141 + // drop through to clear EEntryValid
1.142 + }
1.143 + else
1.144 + {
1.145 + //these attributes do not support multiple devices
1.146 + if(device==0)
1.147 + {
1.148 + TInt p;
1.149 + if (!(properties & HAL::ESettable))
1.150 + {
1.151 + pE[offset].iValue = HalInternal::InitialValue[i];
1.152 + p=EEntryValid;
1.153 + }
1.154 + else
1.155 + {
1.156 + r=RProperty::Get(KUidSystemCategory, KUidHalPropertyKeyBase+i, pE[offset].iValue);
1.157 + if (r!=KErrNone)
1.158 + {
1.159 + HalInternal::InitialiseData();
1.160 + r=RProperty::Get(KUidSystemCategory, KUidHalPropertyKeyBase+i, pE[offset].iValue);
1.161 + }
1.162 + p=(r==KErrNone?EEntryValid:0);
1.163 + p|=EEntryDynamic;
1.164 + }
1.165 + pE[offset].iProperties=p;
1.166 + continue;
1.167 + }
1.168 + // drop through to clear EEntryValid
1.169 + }
1.170 + }
1.171 + pE[offset].iProperties=0;
1.172 + pE[offset].iValue=0;
1.173 + }
1.174 + }
1.175 + aNumEntries=max_devices*(TInt)ENumHalAttributes;
1.176 + aData=pE;
1.177 +
1.178 + return KErrNone;
1.179 + }
1.180 +
1.181 +
1.182 +EXPORT_C TInt HAL::Get(TInt aDeviceNumber, HAL::TAttribute aAttribute, TInt& aValue)
1.183 + {
1.184 +
1.185 + if (TUint(aAttribute)>=TUint(ENumHalAttributes))
1.186 + return KErrNotSupported;
1.187 + TUint8 properties=HalInternal::Properties[aAttribute];
1.188 + if (!(properties & HAL::EValid))
1.189 + return KErrNotSupported;
1.190 + THalImplementation f=HalInternal::Implementation[aAttribute];
1.191 + if (f)
1.192 + return (*f)(aDeviceNumber,aAttribute,EFalse,&aValue);
1.193 + if (!(properties & HAL::ESettable))
1.194 + {
1.195 + aValue=HalInternal::InitialValue[aAttribute];
1.196 + return KErrNone;
1.197 + }
1.198 + aValue=HalInternal::ReadWord(aAttribute);
1.199 + return KErrNone;
1.200 + }
1.201 +
1.202 +
1.203 +EXPORT_C TInt HAL::Set(TInt aDeviceNumber, HAL::TAttribute aAttribute, TInt aValue)
1.204 + {
1.205 +
1.206 + if (TUint(aAttribute)>=TUint(ENumHalAttributes))
1.207 + return KErrNotSupported;
1.208 +
1.209 + TUint8 properties=HalInternal::Properties[aAttribute];
1.210 + if (!(properties & HAL::EValid) || !(properties & HAL::ESettable))
1.211 + return KErrNotSupported;
1.212 + THalImplementation f=HalInternal::Implementation[aAttribute];
1.213 + if (f)
1.214 + return (*f)(aDeviceNumber,aAttribute,ETrue,(TAny*)aValue);
1.215 + return HalInternal::WriteWord(aAttribute,aValue);
1.216 + }
1.217 +