|
1 // ltkhal.cpp |
|
2 // |
|
3 // Copyright (c) 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "Eclipse Public License v1.0" |
|
6 // which accompanies this distribution, and is available |
|
7 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // |
|
9 // Initial Contributors: |
|
10 // Accenture - Initial contribution |
|
11 // |
|
12 #include <fshell/ltkhal.h> |
|
13 #include <fshell/descriptorutils.h> |
|
14 #include <HAL.h> |
|
15 |
|
16 LtkUtils::CHalAttribute::CHalAttribute(TInt aAttribute, TInt aDeviceNumber, TInt aValue, TInt aError, const TDesC& aAttributeName, HBufC* aDescription) |
|
17 : iAttribute(aAttribute), iDeviceNumber(aDeviceNumber), iValue(aValue), iError(aError), iAttributeName(aAttributeName), iDescription(aDescription) |
|
18 { |
|
19 } |
|
20 |
|
21 EXPORT_C LtkUtils::CHalAttribute::~CHalAttribute() |
|
22 { |
|
23 delete iDescription; |
|
24 } |
|
25 |
|
26 const LtkUtils::SLitC KHalNames[] = |
|
27 { |
|
28 DESC("EManufacturer"), |
|
29 DESC("EManufacturerHardwareRev"), |
|
30 DESC("EManufacturerSoftwareRev"), |
|
31 DESC("EManufacturerSoftwareBuild"), |
|
32 DESC("EModel"), |
|
33 DESC("EMachineUid"), |
|
34 DESC("EDeviceFamily"), |
|
35 DESC("EDeviceFamilyRev"), |
|
36 DESC("ECPU"), |
|
37 DESC("ECPUArch"), |
|
38 DESC("ECPUABI"), |
|
39 DESC("ECPUSpeed"), |
|
40 DESC("ESystemStartupReason"), |
|
41 DESC("ESystemException"), |
|
42 DESC("ESystemTickPeriod"), |
|
43 DESC("EMemoryRAM"), |
|
44 DESC("EMemoryRAMFree"), |
|
45 DESC("EMemoryROM"), |
|
46 DESC("EMemoryPageSize"), |
|
47 DESC("EPowerGood"), |
|
48 DESC("EPowerBatteryStatus"), |
|
49 DESC("EPowerBackup"), |
|
50 DESC("EPowerBackupStatus"), |
|
51 DESC("EPowerExternal"), |
|
52 DESC("EKeyboard"), |
|
53 DESC("EKeyboardDeviceKeys"), |
|
54 DESC("EKeyboardAppKeys"), |
|
55 DESC("EKeyboardClick"), |
|
56 DESC("EKeyboardClickState"), |
|
57 DESC("EKeyboardClickVolume"), |
|
58 DESC("EKeyboardClickVolumeMax"), |
|
59 DESC("EDisplayXPixels"), |
|
60 DESC("EDisplayYPixels"), |
|
61 DESC("EDisplayXTwips"), |
|
62 DESC("EDisplayYTwips"), |
|
63 DESC("EDisplayColors"), |
|
64 DESC("EDisplayState"), |
|
65 DESC("EDisplayContrast"), |
|
66 DESC("EDisplayContrastMax"), |
|
67 DESC("EBacklight"), |
|
68 DESC("EBacklightState"), |
|
69 DESC("EPen"), |
|
70 DESC("EPenX"), |
|
71 DESC("EPenY"), |
|
72 DESC("EPenDisplayOn"), |
|
73 DESC("EPenClick"), |
|
74 DESC("EPenClickState"), |
|
75 DESC("EPenClickVolume"), |
|
76 DESC("EPenClickVolumeMax"), |
|
77 DESC("EMouse"), |
|
78 DESC("EMouseX"), |
|
79 DESC("EMouseY"), |
|
80 DESC("EMouseState"), |
|
81 DESC("EMouseSpeed"), |
|
82 DESC("EMouseAcceleration"), |
|
83 DESC("EMouseButtons"), |
|
84 DESC("EMouseButtonState"), |
|
85 DESC("ECaseState"), |
|
86 DESC("ECaseSwitch"), |
|
87 DESC("ECaseSwitchDisplayOn"), |
|
88 DESC("ECaseSwitchDisplayOff"), |
|
89 DESC("ELEDs"), |
|
90 DESC("ELEDmask"), |
|
91 DESC("EIntegratedPhone"), |
|
92 DESC("EDisplayBrightness"), |
|
93 DESC("EDisplayBrightnessMax"), |
|
94 DESC("EKeyboardBacklightState"), |
|
95 DESC("EAccessoryPower"), |
|
96 DESC("ELanguageIndex"), |
|
97 DESC("EKeyboardIndex"), |
|
98 DESC("EMaxRAMDriveSize"), |
|
99 DESC("EKeyboardState"), |
|
100 DESC("ESystemDrive"), |
|
101 DESC("EPenState"), |
|
102 DESC("EDisplayIsMono"), |
|
103 DESC("EDisplayIsPalettized"), |
|
104 DESC("EDisplayBitsPerPixel"), |
|
105 DESC("EDisplayNumModes"), |
|
106 DESC("EDisplayMemoryAddress"), |
|
107 DESC("EDisplayOffsetToFirstPixel"), |
|
108 DESC("EDisplayOffsetBetweenLines"), |
|
109 DESC("EDisplayPaletteEntry"), |
|
110 DESC("EDisplayIsPixelOrderRGB"), |
|
111 DESC("EDisplayIsPixelOrderLandscape"), |
|
112 DESC("EDisplayMode"), |
|
113 DESC("ESwitches"), |
|
114 DESC("EDebugPort"), |
|
115 DESC("ELocaleLoaded"), |
|
116 DESC("EClipboardDrive"), |
|
117 DESC("ECustomRestart"), |
|
118 DESC("ECustomRestartReason"), |
|
119 DESC("EDisplayNumberOfScreens"), |
|
120 DESC("ENanoTickPeriod"), |
|
121 DESC("EFastCounterFrequency"), |
|
122 DESC("EFastCounterCountsUp"), |
|
123 DESC("EPointer3D"), |
|
124 DESC("EPointer3DZ/EPointer3DMaxProximity"), |
|
125 DESC("EPointer3DThetaSupported"), |
|
126 DESC("EPointer3DPhiSupported"), |
|
127 DESC("EPointer3DRotationSupported"), |
|
128 DESC("EPointer3DPressureSupported"), |
|
129 DESC("EHardwareFloatingPoint"), |
|
130 DESC("ETimeNonSecureOffset"), |
|
131 DESC("EPersistStartupModeKernel"), |
|
132 DESC("EMaximumCustomRestartReasons"), |
|
133 DESC("EMaximumRestartStartupModes"), |
|
134 DESC("ECustomResourceDrive"), |
|
135 DESC("EPointer3DProximityStep"), |
|
136 DESC("EPointerMaxPointers"), |
|
137 DESC("EPointerNumberOfPointers"), |
|
138 DESC("EPointer3DMaxPressure"), |
|
139 DESC("EPointer3DPressureStep"), |
|
140 DESC("EPointer3DEnterHighPressureThreshold"), |
|
141 DESC("EPointer3DExitHighPressureThreshold"), |
|
142 DESC("EPointer3DEnterCloseProximityThreshold"), |
|
143 DESC("EPointer3DExitCloseProximityThreshold"), |
|
144 DESC("EDisplayMemoryHandle"), |
|
145 DESC("ESerialNumber"), |
|
146 DESC("ECpuProfilingDefaultInterruptBase"), |
|
147 }; |
|
148 const TInt KNumHalNames = sizeof(KHalNames) / sizeof(LtkUtils::SLitC); |
|
149 |
|
150 const TDesC* Stringify(TInt aHalAttribute, TInt aValue) |
|
151 { |
|
152 _LIT(KManufacturerEricsson, "Ericsson"); |
|
153 _LIT(KManufacturerMotorola, "Motorola"); |
|
154 _LIT(KManufacturerNokia, "Nokia"); |
|
155 _LIT(KManufacturerPanasonic, "Panasonic"); |
|
156 _LIT(KManufacturerPsion, "Psion"); |
|
157 _LIT(KManufacturerIntel, "Intel"); |
|
158 _LIT(KManufacturerCogent, "Cogent"); |
|
159 _LIT(KManufacturerCirrus, "Cirrus"); |
|
160 _LIT(KManufacturerLinkup, "Linkup"); |
|
161 _LIT(KCpuArm, "ARM"); |
|
162 _LIT(KCpuMCore, "MCore"); |
|
163 _LIT(KCpuX86, "x86"); |
|
164 _LIT(KCpuAbiArm4, "ARM4"); |
|
165 _LIT(KCpuAbiThumb, "THUMB"); |
|
166 _LIT(KCpuAbiArmI, "ARMI"); |
|
167 _LIT(KCpuAbiMCore, "MCore"); |
|
168 _LIT(KCpuAbiMsvc, "MSVC"); |
|
169 _LIT(KCpuAbiArm5T, "ARM5T"); |
|
170 _LIT(KCpuAbiX86, "x86"); |
|
171 _LIT(KStartupReasonCold, "Cold"); |
|
172 _LIT(KStartupReasonWarm, "Warm"); |
|
173 _LIT(KStartupReasonFault, "Fault"); |
|
174 _LIT(KUp, "Up"); |
|
175 _LIT(KDown, "Down"); |
|
176 |
|
177 switch (aHalAttribute) |
|
178 { |
|
179 case HALData::EManufacturer: |
|
180 switch (aValue) |
|
181 { |
|
182 case HALData::EManufacturer_Ericsson: |
|
183 return &KManufacturerEricsson; |
|
184 case HALData::EManufacturer_Motorola: |
|
185 return &KManufacturerMotorola; |
|
186 case HALData::EManufacturer_Nokia: |
|
187 return &KManufacturerNokia; |
|
188 case HALData::EManufacturer_Panasonic: |
|
189 return &KManufacturerPanasonic; |
|
190 case HALData::EManufacturer_Psion: |
|
191 return &KManufacturerPsion; |
|
192 case HALData::EManufacturer_Intel: |
|
193 return &KManufacturerIntel; |
|
194 case HALData::EManufacturer_Cogent: |
|
195 return &KManufacturerCogent; |
|
196 case HALData::EManufacturer_Cirrus: |
|
197 return &KManufacturerCirrus; |
|
198 case HALData::EManufacturer_Linkup: |
|
199 return &KManufacturerLinkup; |
|
200 default: |
|
201 break; |
|
202 } |
|
203 break; |
|
204 case HALData::ECPU: |
|
205 switch (aValue) |
|
206 { |
|
207 case HALData::ECPU_ARM: |
|
208 return &KCpuArm; |
|
209 case HALData::ECPU_MCORE: |
|
210 return &KCpuMCore; |
|
211 case HALData::ECPU_X86: |
|
212 return &KCpuX86; |
|
213 default: |
|
214 break; |
|
215 } |
|
216 break; |
|
217 case HALData::ECPUABI: |
|
218 switch (aValue) |
|
219 { |
|
220 case HALData::ECPUABI_ARM4: |
|
221 return &KCpuAbiArm4; |
|
222 case HALData::ECPUABI_ARMI: |
|
223 return &KCpuAbiMCore; |
|
224 case HALData::ECPUABI_THUMB: |
|
225 return &KCpuAbiThumb; |
|
226 case HALData::ECPUABI_MCORE: |
|
227 return &KCpuAbiArmI; |
|
228 case HALData::ECPUABI_MSVC: |
|
229 return &KCpuAbiMsvc; |
|
230 case HALData::ECPUABI_ARM5T: |
|
231 return &KCpuAbiArm5T; |
|
232 case HALData::ECPUABI_X86: |
|
233 return &KCpuAbiX86; |
|
234 default: |
|
235 break; |
|
236 } |
|
237 break; |
|
238 case HALData::ESystemStartupReason: |
|
239 switch (aValue) |
|
240 { |
|
241 case HALData::ESystemStartupReason_Cold: |
|
242 return &KStartupReasonCold; |
|
243 case HALData::ESystemStartupReason_Warm: |
|
244 return &KStartupReasonWarm; |
|
245 case HALData::ESystemStartupReason_Fault: |
|
246 return &KStartupReasonFault; |
|
247 default: |
|
248 break; |
|
249 } |
|
250 break; |
|
251 case HALData::EFastCounterCountsUp: |
|
252 if (aValue) |
|
253 { |
|
254 return &KUp; |
|
255 } |
|
256 else |
|
257 { |
|
258 return &KDown; |
|
259 } |
|
260 default: |
|
261 break; |
|
262 } |
|
263 |
|
264 return NULL; |
|
265 } |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 EXPORT_C void LtkUtils::GetHalInfoL(RPointerArray<CHalAttribute>& aAttributes) |
|
271 { |
|
272 // Use GetAll to find out how many attributes we have |
|
273 aAttributes.ResetAndDestroy(); |
|
274 HAL::SEntry* ents = NULL; |
|
275 TInt numEntries = 0; |
|
276 User::LeaveIfError(HAL::GetAll(numEntries, ents)); |
|
277 delete ents; |
|
278 |
|
279 for (TInt i = 0; i < numEntries; i++) |
|
280 { |
|
281 // Now re-get them individually so we can get the error field |
|
282 CHalAttribute* attrib = GetHalInfoL(i); |
|
283 CleanupStack::PushL(attrib); |
|
284 aAttributes.AppendL(attrib); |
|
285 CleanupStack::Pop(attrib); |
|
286 } |
|
287 } |
|
288 |
|
289 EXPORT_C LtkUtils::CHalAttribute* LtkUtils::GetHalInfoL(TInt aAttribute) |
|
290 { |
|
291 return GetHalInfoL(0, aAttribute); |
|
292 } |
|
293 |
|
294 EXPORT_C LtkUtils::CHalAttribute* LtkUtils::GetHalInfoL(TInt aDeviceNumber, TInt aAttribute) |
|
295 { |
|
296 TInt val = 0; |
|
297 TInt err = HAL::Get((HALData::TAttribute)aAttribute, val); |
|
298 CHalAttribute* attrib = NULL; |
|
299 if (err == KErrNone) |
|
300 { |
|
301 attrib = GetHalInfoForValueL(aDeviceNumber, aAttribute, val); |
|
302 } |
|
303 else |
|
304 { |
|
305 const TDesC& attribName = aAttribute >= KNumHalNames ? KNullDesC() : KHalNames[aAttribute]; |
|
306 RLtkBuf buf; |
|
307 buf.AppendFormatL(_L("HAL::Get() returned error %d"), err); |
|
308 HBufC* bufc = buf.ToHBuf(); |
|
309 CleanupStack::PushL(bufc); |
|
310 attrib = new(ELeave) CHalAttribute(aAttribute, aDeviceNumber, val, err, attribName, bufc); |
|
311 CleanupStack::Pop(bufc); |
|
312 } |
|
313 return attrib; |
|
314 } |
|
315 |
|
316 EXPORT_C LtkUtils::CHalAttribute* LtkUtils::GetHalInfoForValueL(TInt aDeviceNumber, TInt aAttribute, TInt aValue) |
|
317 { |
|
318 const TDesC& attribName = aAttribute >= KNumHalNames ? KNullDesC() : KHalNames[aAttribute]; |
|
319 RLtkBuf buf; |
|
320 CleanupClosePushL(buf); |
|
321 const TDesC* string = Stringify(aAttribute, aValue); |
|
322 if (string) buf.AppendL(*string); |
|
323 else |
|
324 { |
|
325 if ((aAttribute == HAL::ESystemDrive || aAttribute == HAL::EClipboardDrive) && aValue == -1) |
|
326 { |
|
327 // Emulator returns -1 for system drive... |
|
328 buf.AppendL(_L("Unknown")); |
|
329 } |
|
330 } |
|
331 if (buf.Length()) |
|
332 { |
|
333 buf.AppendFormatL(_L(" (%d/0x%08x)"), aValue, aValue); |
|
334 } |
|
335 else |
|
336 { |
|
337 buf.AppendFormatL(_L("%d (0x%08x)"), aValue, aValue); |
|
338 } |
|
339 |
|
340 CHalAttribute* attrib = new(ELeave) CHalAttribute(aAttribute, aDeviceNumber, aValue, KErrNone, attribName, buf.GetHBuf()); |
|
341 CleanupStack::Pop(&buf); // attrib now owns its HBufC* |
|
342 return attrib; |
|
343 } |