Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
4.9 KiB

  1. /*
  2. * REVISIONS:
  3. * pcy11Dec92: Added apc.h, string.h, itemcode.h, and _theConfigManager
  4. * ane11Dec92: Added os/2 include files
  5. * hw12Dec92: Added ConfigItemList structure and BuildItemCodes routine
  6. * pcy17Dec92: Implemented Get's using a Code
  7. * pcy17Dec92: Chnaged some defines in ItemCode list
  8. * ane22Dec92: Added local bindery address constant
  9. * ane23Dec92: Changed defaults for Lan Manager settings
  10. * pcy27Dec92: Added some sensor codes
  11. * ane05Jan93: Added slave codes
  12. * rct01Jan93: Corrected some problems searching, cleaned things up
  13. * ane18Jan93: Added roll percentage defaults
  14. * rct26Jan93: Added Remove() methods
  15. * rct09Feb93: Split out cfg items array (stdcfg.cxx)
  16. * pcy18Feb93: Cast NULL's to appropriate types
  17. * ajr11Mar93: Set default pwrchute_dir to /usr/lib/powerchute for unix
  18. * tje12Mar93: Removed strDEFAULT_PWRCHUTE_DIR references
  19. * tje13Mar93: Made ConfigManager abstract and added IniConfigManager class
  20. * pcy09Sep93: Set object status to indicate ini file create failure
  21. * rct03Mar94: fixed Get() for NoDefault case
  22. * cad04Mar94: added remove and rename for components
  23. * ajr09Mar94: Fixed logical check for ErrNO_ERORR and ErrDEFAULT_VALUE_USED
  24. * pcy08Apr94: Trim size, use static iterators, dead code removal
  25. * ajr28Apr94: Now striping trailing white spaces in the Get....
  26. * mwh07Jun94: port for NCR
  27. * pav02Jul96: Added Add to handle lists (i.e. - SmartScheduling)
  28. * ntf22Aug97: Changed Component::GetItemValue to be more robust.
  29. * awm02Oct97: Added a check to see whether the global _theConfigManager already existed before
  30. * setting it equal to the config manager being created. This is to support multiple
  31. * config managers within the application
  32. * Took out a line which set the global "_theConfigManager" to NULL in the destructor
  33. * of the IniConfigManager. This will have to be done manually when the config manager
  34. * is destroyed in the main application.
  35. * mholly06Oct98 : Discontinue use of a cache
  36. */
  37. #include "cdefine.h"
  38. extern "C" {
  39. #include <stdio.h>
  40. #include <stdlib.h>
  41. #include <string.h>
  42. #include <malloc.h>
  43. }
  44. #include "apc.h"
  45. #include "cfgmgr.h"
  46. #include "err.h"
  47. #include "isa.h"
  48. PConfigManager _theConfigManager = (PConfigManager)NULL;
  49. extern struct _ConfigItemList_T ConfigItemList[];
  50. /********************************************************************
  51. *
  52. * ConfigManager methods
  53. *
  54. ********************************************************************/
  55. //-------------------------------------------------------------------
  56. // Constructor
  57. ConfigManager::ConfigManager()
  58. {
  59. }
  60. /********************************************************************
  61. *
  62. * IniConfigManager methods
  63. *
  64. ********************************************************************/
  65. //-------------------------------------------------------------------
  66. // Constructor
  67. IniConfigManager::IniConfigManager()
  68. : ConfigManager()
  69. {
  70. // If there is no configuration manager currently,
  71. // then set the global this one. Any others created
  72. // subsequently will not have the global handle
  73. if (!_theConfigManager) {
  74. _theConfigManager = this;
  75. }
  76. }
  77. //-------------------------------------------------------------------
  78. // Destructor
  79. IniConfigManager::~IniConfigManager()
  80. {
  81. }
  82. //-------------------------------------------------------------------
  83. // Private member to return an item code given the component/item pair
  84. _ConfigItemList_T * IniConfigManager::getItemCode(INT aCode)
  85. {
  86. INT index = 0;
  87. while (ConfigItemList[index].code != aCode) {
  88. if (ConfigItemList[index].code == LAST_ENTRY) {
  89. return NULL;
  90. }
  91. index++;
  92. }
  93. return &ConfigItemList[index];
  94. }
  95. _ConfigItemList_T * IniConfigManager::getItemCode(PCHAR aComponent, PCHAR anItem)
  96. {
  97. INT index = 0;
  98. while ((_strcmpi(ConfigItemList[index].componentName, aComponent) != 0) ||
  99. (_strcmpi(ConfigItemList[index].itemName, anItem) != 0)) {
  100. if (ConfigItemList[index].code == LAST_ENTRY) {
  101. return NULL;
  102. }
  103. index++;
  104. }
  105. return &ConfigItemList[index];
  106. }
  107. //-------------------------------------------------------------------
  108. INT IniConfigManager::Get(INT itemCode, PCHAR aValue)
  109. {
  110. INT err = ErrNO_ERROR;
  111. _ConfigItemList_T * search = getItemCode(itemCode);
  112. if (!search) {
  113. strcpy(aValue, "NoDefault");
  114. err = ErrINVALID_ITEM_CODE;
  115. }
  116. else {
  117. strcpy(aValue, search->defaultValue);
  118. }
  119. return err;
  120. }
  121. //-------------------------------------------------------------------
  122. //-------------------------------------------------------------------
  123. INT IniConfigManager::GetListValue(PCHAR aComponent, PCHAR anItem, PCHAR aValue)
  124. {
  125. INT err = ErrNO_ERROR;
  126. _ConfigItemList_T * search = getItemCode(aComponent, anItem);
  127. if (search) {
  128. strcpy(aValue, search->defaultValue);
  129. }
  130. return err;
  131. }