Update contrib.
1 // Copyright (c) 2008-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 // Hardware Configuration Respoitory Platform Independent Layer (PIL)
17 // -- INCLUDES ----------------------------------------------------------------
20 #include <nkern/nkern.h>
21 #include <kernel/kernel.h>
23 #ifdef HCRTEST_NO_EXPORT
28 #endif // HCRTEST_NO_EXPORT
30 #include <drivers/hcr.h>
31 #include "hcr_debug.h"
35 // -- FUNCTIONS ---------------------------------------------------------------
41 LOCAL_C TInt GetUValueWordSetting (const TSettingId& aId,
42 TSettingType aType, UValueWord& aValue)
44 HCR_FUNC("GetUValueWordSetting");
47 HCR_TRACE_RETURN(KErrNotReady);
49 __NK_ASSERT_DEBUG((aType & KMaskWordTypes) != 0);
51 TSettingRef sref(0,0);
53 err = HCRSingleton->FindSetting(aId, aType, sref);
55 HCR_TRACE_RETURN(err);
57 err = sref.iRep->GetValue(sref, aValue);
58 __NK_ASSERT_DEBUG(err == KErrNone);
63 LOCAL_C TInt GetUValueLargeSetting64 (const TSettingId& aId,
64 TSettingType aType, UValueLarge& aValue)
66 HCR_FUNC("GetUValueLargeSetting64");
69 HCR_TRACE_RETURN(KErrNotReady);
71 __NK_ASSERT_DEBUG(aType == ETypeInt64 || aType == ETypeUInt64);
73 TSettingRef sref(0,0);
75 err = HCRSingleton->FindSetting(aId, aType, sref);
77 HCR_TRACE_RETURN(err);
79 err = sref.iRep->GetLargeValue(sref, aValue);
80 __NK_ASSERT_DEBUG(err == KErrNone);
86 LOCAL_C TInt GetUValueLargeSettingTDes8 (const TSettingId& aId,
87 TSettingType aType, TDes8& aValue)
89 HCR_FUNC("GetUValueLargeSettingTDes8");
92 HCR_TRACE_RETURN(KErrNotReady);
94 __NK_ASSERT_DEBUG(aType == ETypeBinData || aType == ETypeText8);
96 TSettingRef sref(0,0);
98 err = HCRSingleton->FindSetting(aId, aType, sref);
100 HCR_TRACE_RETURN(err);
103 err = sref.iRep->GetLargeValue(sref, value);
104 __NK_ASSERT_DEBUG(err == KErrNone);
106 TInt len = sref.iRep->GetLength(sref);
107 if (len > aValue.MaxSize())
108 HCR_TRACE_RETURN(KErrTooBig);
110 if (aType == ETypeBinData)
111 aValue.Copy(value.iData, len);
113 aValue.Copy(value.iString8, len);
118 LOCAL_C TInt GetUValueLargeSettingTUint8 (const TSettingId& aId, TSettingType aType,
119 TUint16 aMaxLen, TUint8* aValue, TUint16& aLen)
121 HCR_FUNC("GetUValueLargeSettingTUint8");
124 HCR_TRACE_RETURN(KErrNotReady);
126 __NK_ASSERT_DEBUG(aType == ETypeBinData || aType == ETypeText8);
128 TSettingRef sref(0,0);
130 err = HCRSingleton->FindSetting(aId, aType, sref);
132 HCR_TRACE_RETURN(err);
135 err = sref.iRep->GetLargeValue(sref, value);
136 __NK_ASSERT_DEBUG(err == KErrNone);
138 aLen = sref.iRep->GetLength(sref);
140 HCR_TRACE_RETURN(KErrTooBig);
142 if (aType == ETypeBinData)
143 memcpy (aValue, value.iData, aLen);
145 memcpy (aValue, value.iString8, aLen);
150 LOCAL_C TInt GetUValueLargeSettingArray (const TSettingId& aId, TSettingType aType,
151 TUint16 aMaxLen, TUint32* aValue, TUint16& aLen)
153 HCR_FUNC("GetUValueLargeSettingArray");
156 HCR_TRACE_RETURN(KErrNotReady);
158 __NK_ASSERT_DEBUG(aType == ETypeArrayInt32 || aType == ETypeArrayUInt32);
160 TSettingRef sref(0,0);
162 err = HCRSingleton->FindSetting(aId, aType, sref);
164 HCR_TRACE_RETURN(err);
167 err = sref.iRep->GetLargeValue(sref, value);
168 __NK_ASSERT_DEBUG(err == KErrNone);
170 aLen = sref.iRep->GetLength(sref);
172 HCR_TRACE_RETURN(KErrTooBig);
174 if (aType == ETypeArrayInt32)
175 memcpy (aValue, value.iArrayInt32, aLen);
177 memcpy (aValue, value.iArrayUInt32, aLen);
184 #endif // MAKE_DEF_FILE
187 // -- SETTING GET -------------------------------------------------------------
190 EXPORT_C TInt HCR::GetInt(const TSettingId& aId, TInt8& aValue)
192 #ifndef MAKE_DEF_FILE
193 HCR_FUNC("HCR::GetInt8");
196 TInt err = GetUValueWordSetting(aId, ETypeInt8, value);
198 HCR_TRACE_RETURN(err);
200 aValue = value.iInt8;
203 HCR_TRACE_RETURN(KErrGeneral);
204 #endif // MAKE_DEF_FILE
208 EXPORT_C TInt HCR::GetInt(const TSettingId& aId, TInt16& aValue)
210 #ifndef MAKE_DEF_FILE
211 HCR_FUNC("HCR::GetInt16");
214 TInt err = GetUValueWordSetting(aId, ETypeInt16, value);
216 HCR_TRACE_RETURN(err);
218 aValue = value.iInt16;
221 HCR_TRACE_RETURN(KErrGeneral);
222 #endif // MAKE_DEF_FILE
226 EXPORT_C TInt HCR::GetInt(const TSettingId& aId, TInt32& aValue)
228 #ifndef MAKE_DEF_FILE
229 HCR_FUNC("HCR::GetInt32");
232 TInt err = GetUValueWordSetting(aId, ETypeInt32, value);
234 HCR_TRACE_RETURN(err);
236 aValue = value.iInt32;
239 HCR_TRACE_RETURN(KErrGeneral);
240 #endif // MAKE_DEF_FILE
244 EXPORT_C TInt HCR::GetInt(const TSettingId& aId, TInt64& aValue)
246 #ifndef MAKE_DEF_FILE
247 HCR_FUNC("HCR::GetInt64");
250 TInt err = GetUValueLargeSetting64(aId, ETypeInt64, value);
252 HCR_TRACE_RETURN(err);
254 aValue = *(value.iInt64);
257 HCR_TRACE_RETURN(KErrGeneral);
258 #endif // MAKE_DEF_FILE
262 EXPORT_C TInt HCR::GetBool(const TSettingId& aId, TBool& aValue)
264 #ifndef MAKE_DEF_FILE
265 HCR_FUNC("HCR::GetBool");
268 TInt err = GetUValueWordSetting(aId, ETypeBool, value);
270 HCR_TRACE_RETURN(err);
272 aValue = value.iBool;
275 HCR_TRACE_RETURN(KErrGeneral);
276 #endif // MAKE_DEF_FILE
280 EXPORT_C TInt HCR::GetUInt(const TSettingId& aId, TUint8& aValue)
282 #ifndef MAKE_DEF_FILE
283 HCR_FUNC("HCR::GetUInt8");
286 TInt err = GetUValueWordSetting(aId, ETypeUInt8, value);
288 HCR_TRACE_RETURN(err);
290 aValue = value.iUInt8;
293 HCR_TRACE_RETURN(KErrGeneral);
294 #endif // MAKE_DEF_FILE
298 EXPORT_C TInt HCR::GetUInt(const TSettingId& aId, TUint16& aValue)
300 #ifndef MAKE_DEF_FILE
301 HCR_FUNC("HCR::GetUInt16");
304 TInt err = GetUValueWordSetting(aId, ETypeUInt16,value);
306 HCR_TRACE_RETURN(err);
308 aValue = value.iUInt16;
311 HCR_TRACE_RETURN(KErrGeneral);
312 #endif // MAKE_DEF_FILE
316 EXPORT_C TInt HCR::GetUInt(const TSettingId& aId, TUint32& aValue)
318 #ifndef MAKE_DEF_FILE
319 HCR_FUNC("HCR::GetUInt32");
322 TInt err = GetUValueWordSetting(aId, ETypeUInt32, value);
324 HCR_TRACE_RETURN(err);
326 aValue = value.iUInt32;
329 HCR_TRACE_RETURN(KErrGeneral);
330 #endif // MAKE_DEF_FILE
334 EXPORT_C TInt HCR::GetUInt(const TSettingId& aId, TUint64& aValue)
336 #ifndef MAKE_DEF_FILE
337 HCR_FUNC("HCR::GetUInt64");
340 TInt err = GetUValueLargeSetting64(aId, ETypeUInt64, value);
342 HCR_TRACE_RETURN(err);
344 aValue = *(value.iUInt64);
347 HCR_TRACE_RETURN(KErrGeneral);
348 #endif // MAKE_DEF_FILE
352 EXPORT_C TInt HCR::GetLinAddr(const TSettingId& aId, TLinAddr& aValue)
354 #ifndef MAKE_DEF_FILE
355 HCR_FUNC("HCR::GetLinAddr");
358 TInt err = GetUValueWordSetting(aId, ETypeLinAddr, value);
360 HCR_TRACE_RETURN(err);
362 aValue = value.iAddress;
365 HCR_TRACE_RETURN(KErrGeneral);
366 #endif // MAKE_DEF_FILE
370 EXPORT_C TInt HCR::GetData(const TSettingId& aId, TUint16 aMaxLen,
371 TUint8* aValue, TUint16& aLen)
373 #ifndef MAKE_DEF_FILE
374 HCR_FUNC("HCR::GetDataTUint8");
376 TInt err = GetUValueLargeSettingTUint8(aId, ETypeBinData, aMaxLen, aValue, aLen);
378 HCR_TRACE_RETURN(err);
382 HCR_TRACE_RETURN(KErrGeneral);
383 #endif // MAKE_DEF_FILE
387 EXPORT_C TInt HCR::GetData(const TSettingId& aId, TDes8& aValue)
389 #ifndef MAKE_DEF_FILE
390 HCR_FUNC("HCR::GetDataTDes8");
392 TInt err = GetUValueLargeSettingTDes8(aId, ETypeBinData, aValue);
394 HCR_TRACE_RETURN(err);
398 HCR_TRACE_RETURN(KErrGeneral);
399 #endif // MAKE_DEF_FILE
403 EXPORT_C TInt HCR::GetString(const TSettingId& aId, TUint16 aMaxLen,
404 TText8* aValue, TUint16& aLen)
406 #ifndef MAKE_DEF_FILE
407 HCR_FUNC("HCR::GetStringTUint8");
409 TInt err = GetUValueLargeSettingTUint8(aId, ETypeText8, aMaxLen, aValue, aLen);
411 HCR_TRACE_RETURN(err);
415 HCR_TRACE_RETURN(KErrGeneral);
416 #endif // MAKE_DEF_FILE
420 EXPORT_C TInt HCR::GetString(const TSettingId& aId, TDes8& aValue)
422 #ifndef MAKE_DEF_FILE
423 HCR_FUNC("HCR::GetStringTUint8");
425 TInt err = GetUValueLargeSettingTDes8(aId, ETypeText8, aValue);
427 HCR_TRACE_RETURN(err);
431 HCR_TRACE_RETURN(KErrGeneral);
432 #endif // MAKE_DEF_FILE
435 EXPORT_C TInt HCR::GetArray(const TSettingId& aId, TUint16 aMaxLen,
436 TInt32* aValue, TUint16& aLen)
438 #ifndef MAKE_DEF_FILE
439 HCR_FUNC("HCR::GetArrayTInt32");
441 TInt err = GetUValueLargeSettingArray(aId, ETypeArrayInt32, aMaxLen, (TUint32*)aValue, aLen);
443 HCR_TRACE_RETURN(err);
447 HCR_TRACE_RETURN(KErrGeneral);
448 #endif // MAKE_DEF_FILE
451 EXPORT_C TInt HCR::GetArray(const TSettingId& aId, TUint16 aMaxLen,
452 TUint32* aValue, TUint16& aLen)
454 #ifndef MAKE_DEF_FILE
455 HCR_FUNC("HCR::GetArrayTUInt32");
457 TInt err = GetUValueLargeSettingArray(aId, ETypeArrayUInt32, aMaxLen, aValue, aLen);
459 HCR_TRACE_RETURN(err);
463 HCR_TRACE_RETURN(KErrGeneral);
464 #endif // MAKE_DEF_FILE
468 // -- MULTIPLE GETS -----------------------------------------------------------
470 EXPORT_C TInt HCR::GetWordSettings(TInt aNum, const SSettingId aIds[],
471 TInt32 aValues[], TSettingType aTypes[], TInt aErrors[])
474 #ifndef MAKE_DEF_FILE
475 HCR_FUNC("GetWordSettings");
478 HCR_TRACE_RETURN(KErrNotReady);
480 if(aNum <= 0 || aIds == NULL || aErrors == NULL || aValues == NULL)
481 HCR_TRACE_RETURN(KErrArgument);
485 //Don't leave while the resources are not fully allocated/deallocated
486 NKern::ThreadEnterCS();
488 err = HCRSingleton->GetWordSettings(aNum, aIds, aValues, aTypes, aErrors);
490 //All de-allocations are done, leave a critical section
491 NKern::ThreadLeaveCS();
493 __NK_ASSERT_DEBUG(err >= KErrNone);
498 HCR_TRACE_RETURN(KErrGeneral);
499 #endif // MAKE_DEF_FILE
503 // -- SETTING PROPERTIES ------------------------------------------------------
505 EXPORT_C TInt HCR::GetTypeAndSize(const TSettingId& aId, TSettingType& aType,
508 #ifndef MAKE_DEF_FILE
509 HCR_FUNC("GetTypeAndSize");
511 HCR_TRACE_RETURN(KErrNotReady);
513 TSettingRef sref(0,0);
514 TInt err = HCRSingleton->FindSettingWithType(aId, aType, sref);
516 __NK_ASSERT_DEBUG(err == KErrNone || err == KErrNotFound);
518 if(err == KErrNotFound)
521 HCR_TRACE_RETURN(KErrNotFound);
524 aLen = sref.iRep->GetLength(sref);
528 HCR_TRACE_RETURN(KErrGeneral);
529 #endif //MAKE_DEF_FILE
533 // -- SETTING SEARCHES --------------------------------------------------------
535 EXPORT_C TInt HCR::FindNumSettingsInCategory (TCategoryUid aCatUid)
537 #ifndef MAKE_DEF_FILE
539 HCR_FUNC("FindNumSettingsInCategory");
542 HCR_TRACE_RETURN(KErrNotReady);
544 TInt err = HCRSingleton->FindNumSettingsInCategory(aCatUid);
547 HCR_TRACE_RETURN(err);
552 HCR_TRACE_RETURN(KErrGeneral);
553 #endif // MAKE_DEF_FILE
556 EXPORT_C TInt HCR::FindSettings(TCategoryUid aCat, TInt aMaxNum,
557 TElementId aElIds[], TSettingType aTypes[], TUint16 aLens[])
559 #ifndef MAKE_DEF_FILE
561 HCR_FUNC("FindSettings without pattern/mask");
565 HCR_TRACE_RETURN(KErrNotReady);
567 if(aMaxNum <= 0 || aElIds == NULL)
568 HCR_TRACE_RETURN(KErrArgument);
570 TInt err = HCRSingleton->FindSettings(aCat, aMaxNum, aElIds,
574 HCR_TRACE_RETURN(err);
579 HCR_TRACE_RETURN(KErrGeneral);
580 #endif // MAKE_DEF_FILE
583 EXPORT_C TInt HCR::FindSettings(TCategoryUid aCat,
584 TInt aMaxNum, TUint32 aMask, TUint32 aPattern,
585 TElementId aElIds[], TSettingType aTypes[], TUint16 aLens[])
587 #ifndef MAKE_DEF_FILE
589 HCR_FUNC("FindSettings with pattern/mask");
593 HCR_TRACE_RETURN(KErrNotReady);
595 if(aMaxNum <= 0 || aElIds == NULL)
596 HCR_TRACE_RETURN(KErrArgument);
600 //Don't leave while the resources are not fully allocated/deallocated
601 NKern::ThreadEnterCS();
603 err = HCRSingleton->FindSettings(aCat, aMaxNum, aMask, aPattern,
604 aElIds, aTypes, aLens);
606 //All de-allocations are done, leave a critical section
607 NKern::ThreadLeaveCS();
610 HCR_TRACE_RETURN(err);
615 HCR_TRACE_RETURN(KErrGeneral);
616 #endif // MAKE_DEF_FILE
620 // -- KERNEL ENTRY POINT ------------------------------------------------------
625 DECLARE_STANDARD_EXTENSION()
630 #endif // MAKE_DEF_FILE