|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // hal\src\hal_main.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <kernel/hal_int.h> |
|
19 |
|
20 _LIT(KLitHal,"HAL"); |
|
21 void HalInternal::Panic(HalInternal::THalPanic aPanic) |
|
22 { |
|
23 User::Panic(KLitHal,aPanic); |
|
24 } |
|
25 |
|
26 void HalInternal::InitialiseData() |
|
27 { |
|
28 TInt i; |
|
29 _LIT_SECURITY_POLICY_PASS(KPassPolicy); |
|
30 _LIT_SECURITY_POLICY_C1(KWriteDevDataPolicy, ECapabilityWriteDeviceData); |
|
31 |
|
32 for (i=0; i<HAL::ENumHalAttributes; i++) // for every attribute, |
|
33 { |
|
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 |
|
36 { |
|
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) |
|
41 break; |
|
42 |
|
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)); |
|
47 } |
|
48 } |
|
49 } |
|
50 |
|
51 TInt HalInternal::ReadWord(TInt aKey) |
|
52 { |
|
53 TInt result; |
|
54 |
|
55 // This is a slow way of doing it, but it is light on memory as it doesn't |
|
56 // need an offset array. |
|
57 |
|
58 if(aKey>=HAL::ENumHalAttributes) |
|
59 return KErrNotFound; |
|
60 TInt r=RProperty::Get(KUidSystemCategory, KUidHalPropertyKeyBase+aKey, result); |
|
61 if (r!=KErrNone) |
|
62 { |
|
63 InitialiseData(); |
|
64 r=RProperty::Get(KUidSystemCategory, KUidHalPropertyKeyBase+aKey, result); |
|
65 } |
|
66 __ASSERT_ALWAYS(r==KErrNone,Panic(EGetPropFailed)); |
|
67 return (result); |
|
68 } |
|
69 |
|
70 TInt HalInternal::WriteWord(TInt aKey, TInt aValue) |
|
71 { |
|
72 TInt r; |
|
73 |
|
74 if(aKey>=HAL::ENumHalAttributes) |
|
75 return KErrArgument; |
|
76 r=RProperty::Set(KUidSystemCategory, KUidHalPropertyKeyBase+aKey, aValue); |
|
77 if (r!=KErrNone && r!=KErrPermissionDenied) |
|
78 { |
|
79 InitialiseData(); |
|
80 r=RProperty::Set(KUidSystemCategory, KUidHalPropertyKeyBase+aKey, aValue); |
|
81 } |
|
82 __ASSERT_ALWAYS(r==KErrNone || r==KErrPermissionDenied,Panic(ESetPropFailed)); |
|
83 return r; |
|
84 } |
|
85 |
|
86 |
|
87 EXPORT_C TInt HAL::Get(HAL::TAttribute aAttribute, TInt& aValue) |
|
88 { |
|
89 return HAL::Get(0,aAttribute,aValue); |
|
90 } |
|
91 |
|
92 |
|
93 EXPORT_C TInt HAL::Set(HAL::TAttribute aAttribute, TInt aValue) |
|
94 { |
|
95 return HAL::Set(0,aAttribute,aValue); |
|
96 } |
|
97 |
|
98 |
|
99 EXPORT_C TInt HAL::GetAll(TInt& aNumEntries, SEntry*& aData) |
|
100 { |
|
101 TInt max_devices=1; |
|
102 |
|
103 HAL::Get(EDisplayNumberOfScreens,max_devices); |
|
104 TInt size=max_devices*(TInt)ENumHalAttributes*(TInt)sizeof(SEntry); |
|
105 SEntry* pE=(SEntry*)User::Alloc(size); |
|
106 if (!pE) |
|
107 { |
|
108 aNumEntries=0; |
|
109 aData=NULL; |
|
110 return KErrNoMemory; |
|
111 } |
|
112 |
|
113 TInt device; |
|
114 for(device=0;device<max_devices;device++) |
|
115 { |
|
116 TInt r; |
|
117 TInt i=ENumHalAttributes-1; |
|
118 for (; i>=0; --i) |
|
119 { |
|
120 TInt offset = device*(TInt)ENumHalAttributes + i; |
|
121 TInt properties=HalInternal::Properties[i]; |
|
122 if (properties & HAL::EValid) |
|
123 { |
|
124 THalImplementation f=HalInternal::Implementation[i]; |
|
125 if (f) |
|
126 { |
|
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); |
|
133 if (r==KErrNone) |
|
134 { |
|
135 pE[offset].iProperties=EEntryValid|EEntryDynamic; |
|
136 continue; |
|
137 } |
|
138 // drop through to clear EEntryValid |
|
139 } |
|
140 else |
|
141 { |
|
142 //these attributes do not support multiple devices |
|
143 if(device==0) |
|
144 { |
|
145 TInt p; |
|
146 if (!(properties & HAL::ESettable)) |
|
147 { |
|
148 pE[offset].iValue = HalInternal::InitialValue[i]; |
|
149 p=EEntryValid; |
|
150 } |
|
151 else |
|
152 { |
|
153 r=RProperty::Get(KUidSystemCategory, KUidHalPropertyKeyBase+i, pE[offset].iValue); |
|
154 if (r!=KErrNone) |
|
155 { |
|
156 HalInternal::InitialiseData(); |
|
157 r=RProperty::Get(KUidSystemCategory, KUidHalPropertyKeyBase+i, pE[offset].iValue); |
|
158 } |
|
159 p=(r==KErrNone?EEntryValid:0); |
|
160 p|=EEntryDynamic; |
|
161 } |
|
162 pE[offset].iProperties=p; |
|
163 continue; |
|
164 } |
|
165 // drop through to clear EEntryValid |
|
166 } |
|
167 } |
|
168 pE[offset].iProperties=0; |
|
169 pE[offset].iValue=0; |
|
170 } |
|
171 } |
|
172 aNumEntries=max_devices*(TInt)ENumHalAttributes; |
|
173 aData=pE; |
|
174 |
|
175 return KErrNone; |
|
176 } |
|
177 |
|
178 |
|
179 EXPORT_C TInt HAL::Get(TInt aDeviceNumber, HAL::TAttribute aAttribute, TInt& aValue) |
|
180 { |
|
181 |
|
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]; |
|
188 if (f) |
|
189 return (*f)(aDeviceNumber,aAttribute,EFalse,&aValue); |
|
190 if (!(properties & HAL::ESettable)) |
|
191 { |
|
192 aValue=HalInternal::InitialValue[aAttribute]; |
|
193 return KErrNone; |
|
194 } |
|
195 aValue=HalInternal::ReadWord(aAttribute); |
|
196 return KErrNone; |
|
197 } |
|
198 |
|
199 |
|
200 EXPORT_C TInt HAL::Set(TInt aDeviceNumber, HAL::TAttribute aAttribute, TInt aValue) |
|
201 { |
|
202 |
|
203 if (TUint(aAttribute)>=TUint(ENumHalAttributes)) |
|
204 return KErrNotSupported; |
|
205 |
|
206 TUint8 properties=HalInternal::Properties[aAttribute]; |
|
207 if (!(properties & HAL::EValid) || !(properties & HAL::ESettable)) |
|
208 return KErrNotSupported; |
|
209 THalImplementation f=HalInternal::Implementation[aAttribute]; |
|
210 if (f) |
|
211 return (*f)(aDeviceNumber,aAttribute,ETrue,(TAny*)aValue); |
|
212 return HalInternal::WriteWord(aAttribute,aValue); |
|
213 } |
|
214 |