author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 23:56:21 +0300 | |
branch | RCL_3 |
changeset 45 | 9e2d4f7f5028 |
parent 28 | 5b5d147c7838 |
permissions | -rw-r--r-- |
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1 |
// Copyright (c) 1999-2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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]; |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
122 |
// Exclusion of the EDisplayMemoryHandle attribute is a work around |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
123 |
// to avoid the handle and resources related to it from being |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
124 |
// allocated. Callers of this API (halsettings - to save modifiable |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
125 |
// atrributes) need to avoid this resource overhead. Clients of |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
126 |
// this attribute need to use HAL::Get() directly. |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
127 |
// HAL should not be used for handle opening and this |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
128 |
// attribute should be replaced with a better API. |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
129 |
if ((properties & HAL::EValid) && (i != EDisplayMemoryHandle)) |
0 | 130 |
{ |
131 |
THalImplementation f=HalInternal::Implementation[i]; |
|
132 |
if (f) |
|
133 |
{ |
|
134 |
// Initialise the value before getting it, for consistancy |
|
135 |
// when functions take an argument. (-1 is also likely to be |
|
136 |
// an invalid argument and return an error in these cases, which |
|
137 |
// is probably the safest result.) |
|
138 |
pE[offset].iValue = -1; |
|
139 |
r=(*f)(device,i,EFalse,&pE[offset].iValue); |
|
140 |
if (r==KErrNone) |
|
141 |
{ |
|
142 |
pE[offset].iProperties=EEntryValid|EEntryDynamic; |
|
143 |
continue; |
|
144 |
} |
|
145 |
// drop through to clear EEntryValid |
|
146 |
} |
|
147 |
else |
|
148 |
{ |
|
149 |
//these attributes do not support multiple devices |
|
150 |
if(device==0) |
|
151 |
{ |
|
152 |
TInt p; |
|
153 |
if (!(properties & HAL::ESettable)) |
|
154 |
{ |
|
155 |
pE[offset].iValue = HalInternal::InitialValue[i]; |
|
156 |
p=EEntryValid; |
|
157 |
} |
|
158 |
else |
|
159 |
{ |
|
160 |
r=RProperty::Get(KUidSystemCategory, KUidHalPropertyKeyBase+i, pE[offset].iValue); |
|
161 |
if (r!=KErrNone) |
|
162 |
{ |
|
163 |
HalInternal::InitialiseData(); |
|
164 |
r=RProperty::Get(KUidSystemCategory, KUidHalPropertyKeyBase+i, pE[offset].iValue); |
|
165 |
} |
|
166 |
p=(r==KErrNone?EEntryValid:0); |
|
167 |
p|=EEntryDynamic; |
|
168 |
} |
|
169 |
pE[offset].iProperties=p; |
|
170 |
continue; |
|
171 |
} |
|
172 |
// drop through to clear EEntryValid |
|
173 |
} |
|
174 |
} |
|
175 |
pE[offset].iProperties=0; |
|
176 |
pE[offset].iValue=0; |
|
177 |
} |
|
178 |
} |
|
179 |
aNumEntries=max_devices*(TInt)ENumHalAttributes; |
|
180 |
aData=pE; |
|
181 |
||
182 |
return KErrNone; |
|
183 |
} |
|
184 |
||
185 |
||
186 |
EXPORT_C TInt HAL::Get(TInt aDeviceNumber, HAL::TAttribute aAttribute, TInt& aValue) |
|
187 |
{ |
|
188 |
||
189 |
if (TUint(aAttribute)>=TUint(ENumHalAttributes)) |
|
190 |
return KErrNotSupported; |
|
191 |
TUint8 properties=HalInternal::Properties[aAttribute]; |
|
192 |
if (!(properties & HAL::EValid)) |
|
193 |
return KErrNotSupported; |
|
194 |
THalImplementation f=HalInternal::Implementation[aAttribute]; |
|
195 |
if (f) |
|
196 |
return (*f)(aDeviceNumber,aAttribute,EFalse,&aValue); |
|
197 |
if (!(properties & HAL::ESettable)) |
|
198 |
{ |
|
199 |
aValue=HalInternal::InitialValue[aAttribute]; |
|
200 |
return KErrNone; |
|
201 |
} |
|
202 |
aValue=HalInternal::ReadWord(aAttribute); |
|
203 |
return KErrNone; |
|
204 |
} |
|
205 |
||
206 |
||
207 |
EXPORT_C TInt HAL::Set(TInt aDeviceNumber, HAL::TAttribute aAttribute, TInt aValue) |
|
208 |
{ |
|
209 |
||
210 |
if (TUint(aAttribute)>=TUint(ENumHalAttributes)) |
|
211 |
return KErrNotSupported; |
|
212 |
||
213 |
TUint8 properties=HalInternal::Properties[aAttribute]; |
|
214 |
if (!(properties & HAL::EValid) || !(properties & HAL::ESettable)) |
|
215 |
return KErrNotSupported; |
|
216 |
THalImplementation f=HalInternal::Implementation[aAttribute]; |
|
217 |
if (f) |
|
218 |
return (*f)(aDeviceNumber,aAttribute,ETrue,(TAny*)aValue); |
|
219 |
return HalInternal::WriteWord(aAttribute,aValue); |
|
220 |
} |
|
221 |