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.

181 lines
3.9 KiB

  1. /*
  2. *
  3. * NOTES:
  4. *
  5. * REVISIONS:
  6. * ker04DEC92 Initial OS/2 Revision
  7. * pcy26Jan93: Superclassed EepromChoiceSensor w/ EepromSensor
  8. * pcy26Jan93: Handle Dip switch events
  9. * rct15Jun93: Added error code for getAllowedValues()
  10. * cad04Mar94: fix for access problem
  11. * dml13Oct95: fixed assignment in logical expression (needed ==)
  12. * cgm12Apr96: Add destructor with unregister
  13. * inf20Mar97: Loaded error string from resource file
  14. * mholly22Oct98 : recognize ErrITEM_NOT_FOUND as a valid error from
  15. * theConfigManager->Get in the getAllowedValues method
  16. */
  17. extern "C" {
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #include <malloc.h>
  21. #include <string.h>
  22. }
  23. #include "eeprom.h"
  24. #include "cfgmgr.h"
  25. #include "event.h"
  26. #include "device.h"
  27. //Constructor
  28. EepromSensor::EepromSensor(PDevice aParent, PCommController aCommController,
  29. INT aSensorCode, ACCESSTYPE anACCESSTYPE)
  30. : Sensor(aParent,aCommController, aSensorCode, anACCESSTYPE)
  31. {
  32. theCommController->RegisterEvent(EEPROM_CHANGED, this);
  33. }
  34. EepromSensor::~EepromSensor()
  35. {
  36. theCommController->UnregisterEvent(EEPROM_CHANGED, this);
  37. }
  38. INT EepromSensor::Update(PEvent anEvent)
  39. {
  40. INT val;
  41. switch(anEvent->GetCode()) {
  42. case EEPROM_CHANGED:
  43. //
  44. //
  45. DeepGet();
  46. break;
  47. case DIP_SWITCH_POSITION:
  48. //
  49. // If the dip swicthes change, reget the valu from the UPS
  50. // and if not all zeros, we cant change the settings so we
  51. // set our access to read only. This probably shouldn't be
  52. // here since it ties UPS implementation to the values of the
  53. // Dip switches. Oh well.
  54. //
  55. DeepGet();
  56. val = (atoi(anEvent->GetValue()) == 0) ? AREAD_WRITE : AREAD_ONLY;
  57. SetEepromAccess(val);
  58. break;
  59. default:
  60. Sensor::Update(anEvent);
  61. break;
  62. }
  63. return ErrNO_ERROR;
  64. }
  65. INT EepromSensor::Set(const PCHAR aValue)
  66. {
  67. return Sensor::Set(aValue);
  68. }
  69. VOID EepromSensor::SetEepromAccess(INT anAccessCode)
  70. {
  71. readOnly = (ACCESSTYPE)anAccessCode;
  72. }
  73. INT EepromSensor::setInitialValue()
  74. {
  75. return ErrNO_ERROR;
  76. }
  77. EepromChoiceSensor:: EepromChoiceSensor(PDevice aParent, PCommController aCommController,
  78. INT aSensorCode, ACCESSTYPE anACCESSTYPE)
  79. :EepromSensor(aParent,aCommController, aSensorCode, anACCESSTYPE)
  80. {
  81. //Set the Values
  82. theAllowedValues = (PCHAR)NULL;
  83. }
  84. EepromChoiceSensor::~EepromChoiceSensor() {
  85. free(theAllowedValues);
  86. }
  87. INT EepromChoiceSensor::Validate(INT aCode, const PCHAR aValue)
  88. {
  89. INT err = ErrNO_ERROR;
  90. if(aCode!=theSensorCode)
  91. err = ErrINVALID_CODE;
  92. if(theAllowedValues != (PCHAR)NULL) {
  93. if(strstr(theAllowedValues, aValue))
  94. err = ErrNO_ERROR;
  95. else
  96. err = ErrINVALID_VALUE;
  97. }
  98. else {
  99. err = ErrINVALID_VALUE;
  100. }
  101. return err;
  102. }
  103. INT EepromChoiceSensor::Get(INT aCode, PCHAR aValue)
  104. {
  105. INT err = ErrNO_ERROR;
  106. switch(aCode)
  107. {
  108. case ALLOWED_VALUES:
  109. getCurrentAllowedValues(aValue);
  110. break;
  111. default:
  112. err = Sensor::Get(aCode, aValue);
  113. break;
  114. }
  115. return err;
  116. }
  117. INT EepromChoiceSensor::getAllowedValues()
  118. {
  119. CHAR value[128];
  120. CHAR allowedValue[128] = "";
  121. INT cCode = _theConfigManager->GetListValue(lookupSensorName(IsA()),
  122. "AllowedValues", value);
  123. theDevice->GetAllowedValue(theSensorCode, allowedValue);
  124. if (strlen(allowedValue))
  125. {
  126. theAllowedValues = _strdup(allowedValue);
  127. return ErrNO_ERROR;
  128. }
  129. else
  130. {
  131. theAllowedValues = _strdup(value);
  132. return cCode;
  133. }
  134. }
  135. VOID EepromChoiceSensor::getCurrentAllowedValues(PCHAR aValue)
  136. {
  137. if (theAllowedValues)
  138. {
  139. strcpy(aValue, theAllowedValues);
  140. }
  141. else
  142. {
  143. strcpy(aValue, "");
  144. }
  145. }