Update contrib.
1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // hal\src\hal_main.cpp
18 #include <kernel/hal_int.h>
21 void HalInternal::Panic(HalInternal::THalPanic aPanic)
23 User::Panic(KLitHal,aPanic);
26 void HalInternal::InitialiseData()
29 _LIT_SECURITY_POLICY_PASS(KPassPolicy);
30 _LIT_SECURITY_POLICY_C1(KWriteDevDataPolicy, ECapabilityWriteDeviceData);
32 for (i=0; i<HAL::ENumHalAttributes; i++) // for every attribute,
34 if (Properties[i]&HAL::EValid && !Implementation[i] && (Properties[i] & HAL::ESettable))
35 // if it's implemented, not a constant and not a user function
37 TInt r = RProperty::Define(KUidSystemCategory, KUidHalPropertyKeyBase+i, RProperty::EInt,
38 KPassPolicy, KWriteDevDataPolicy);
39 __ASSERT_ALWAYS(r==KErrNone || r==KErrAlreadyExists,Panic(EInitialAllocFailed1));
40 if (r==KErrAlreadyExists)
43 // This will panic if the first instance of the DLL to start does not have WriteDeviceData
44 // capability. Again, there isn't anything we can do about this. It shouldn't ever happen.
45 r = RProperty::Set(KUidSystemCategory, KUidHalPropertyKeyBase+i, InitialValue[i]);
46 __ASSERT_ALWAYS(r==KErrNone,Panic(EInitialAllocFailed2));
51 TInt HalInternal::ReadWord(TInt aKey)
55 // This is a slow way of doing it, but it is light on memory as it doesn't
56 // need an offset array.
58 if(aKey>=HAL::ENumHalAttributes)
60 TInt r=RProperty::Get(KUidSystemCategory, KUidHalPropertyKeyBase+aKey, result);
64 r=RProperty::Get(KUidSystemCategory, KUidHalPropertyKeyBase+aKey, result);
66 __ASSERT_ALWAYS(r==KErrNone,Panic(EGetPropFailed));
70 TInt HalInternal::WriteWord(TInt aKey, TInt aValue)
74 if(aKey>=HAL::ENumHalAttributes)
76 r=RProperty::Set(KUidSystemCategory, KUidHalPropertyKeyBase+aKey, aValue);
77 if (r!=KErrNone && r!=KErrPermissionDenied)
80 r=RProperty::Set(KUidSystemCategory, KUidHalPropertyKeyBase+aKey, aValue);
82 __ASSERT_ALWAYS(r==KErrNone || r==KErrPermissionDenied,Panic(ESetPropFailed));
87 EXPORT_C TInt HAL::Get(HAL::TAttribute aAttribute, TInt& aValue)
89 return HAL::Get(0,aAttribute,aValue);
93 EXPORT_C TInt HAL::Set(HAL::TAttribute aAttribute, TInt aValue)
95 return HAL::Set(0,aAttribute,aValue);
99 EXPORT_C TInt HAL::GetAll(TInt& aNumEntries, SEntry*& aData)
103 HAL::Get(EDisplayNumberOfScreens,max_devices);
104 TInt size=max_devices*(TInt)ENumHalAttributes*(TInt)sizeof(SEntry);
105 SEntry* pE=(SEntry*)User::Alloc(size);
114 for(device=0;device<max_devices;device++)
117 TInt i=ENumHalAttributes-1;
120 TInt offset = device*(TInt)ENumHalAttributes + i;
121 TInt properties=HalInternal::Properties[i];
122 if (properties & HAL::EValid)
124 THalImplementation f=HalInternal::Implementation[i];
127 // Initialise the value before getting it, for consistancy
128 // when functions take an argument. (-1 is also likely to be
129 // an invalid argument and return an error in these cases, which
130 // is probably the safest result.)
131 pE[offset].iValue = -1;
132 r=(*f)(device,i,EFalse,&pE[offset].iValue);
135 pE[offset].iProperties=EEntryValid|EEntryDynamic;
138 // drop through to clear EEntryValid
142 //these attributes do not support multiple devices
146 if (!(properties & HAL::ESettable))
148 pE[offset].iValue = HalInternal::InitialValue[i];
153 r=RProperty::Get(KUidSystemCategory, KUidHalPropertyKeyBase+i, pE[offset].iValue);
156 HalInternal::InitialiseData();
157 r=RProperty::Get(KUidSystemCategory, KUidHalPropertyKeyBase+i, pE[offset].iValue);
159 p=(r==KErrNone?EEntryValid:0);
162 pE[offset].iProperties=p;
165 // drop through to clear EEntryValid
168 pE[offset].iProperties=0;
172 aNumEntries=max_devices*(TInt)ENumHalAttributes;
179 EXPORT_C TInt HAL::Get(TInt aDeviceNumber, HAL::TAttribute aAttribute, TInt& aValue)
182 if (TUint(aAttribute)>=TUint(ENumHalAttributes))
183 return KErrNotSupported;
184 TUint8 properties=HalInternal::Properties[aAttribute];
185 if (!(properties & HAL::EValid))
186 return KErrNotSupported;
187 THalImplementation f=HalInternal::Implementation[aAttribute];
189 return (*f)(aDeviceNumber,aAttribute,EFalse,&aValue);
190 if (!(properties & HAL::ESettable))
192 aValue=HalInternal::InitialValue[aAttribute];
195 aValue=HalInternal::ReadWord(aAttribute);
200 EXPORT_C TInt HAL::Set(TInt aDeviceNumber, HAL::TAttribute aAttribute, TInt aValue)
203 if (TUint(aAttribute)>=TUint(ENumHalAttributes))
204 return KErrNotSupported;
206 TUint8 properties=HalInternal::Properties[aAttribute];
207 if (!(properties & HAL::EValid) || !(properties & HAL::ESettable))
208 return KErrNotSupported;
209 THalImplementation f=HalInternal::Implementation[aAttribute];
211 return (*f)(aDeviceNumber,aAttribute,ETrue,(TAny*)aValue);
212 return HalInternal::WriteWord(aAttribute,aValue);