Leaked source code of windows server 2003
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.

83 lines
2.2 KiB

  1. /*
  2. *
  3. * NOTES:
  4. *
  5. * REVISIONS:
  6. * ker02DEC92: Initial breakout of sensor classes into indiv files
  7. * ker04DEC92: Added Validate Function
  8. * dma10Nov97: Added virtual destructor for ReplaceBatterySensor class.
  9. * dma06Feb98: Added register/unregister for BATTERY_REPLACEMENT_CONDITION
  10. * tjg25Feb98: Added update method to handle problems with 2G replace
  11. * battery notifications
  12. */
  13. #define INCL_BASE
  14. #define INCL_DOS
  15. #define INCL_NOPM
  16. #include "cdefine.h"
  17. extern "C" {
  18. #if (C_OS & C_OS2)
  19. #include <os2.h>
  20. #endif
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <malloc.h>
  24. #include <string.h>
  25. }
  26. #include "replbatt.h"
  27. #include "comctrl.h"
  28. #include "event.h"
  29. #include "device.h"
  30. ReplaceBatterySensor :: ReplaceBatterySensor(PDevice aParent, PCommController aCommController)
  31. : StateSensor(aParent, aCommController, BATTERY_REPLACEMENT_CONDITION)
  32. {
  33. storeState(BATTERY_DOESNT_NEED_REPLACING);
  34. theCommController->RegisterEvent(BATTERY_REPLACEMENT_CONDITION, this);
  35. }
  36. ReplaceBatterySensor :: ~ReplaceBatterySensor()
  37. {
  38. theCommController->UnregisterEvent(BATTERY_REPLACEMENT_CONDITION, this);
  39. }
  40. INT ReplaceBatterySensor :: Update(PEvent anEvent)
  41. {
  42. INT err = ErrNO_ERROR;
  43. INT event_code = anEvent->GetCode();
  44. PCHAR event_value = anEvent->GetValue();
  45. // Ensure that the new value is different from the cached value
  46. if (err = Validate(event_code, event_value) == ErrNO_ERROR) {
  47. // If battery needs replacing ....
  48. if (atoi(event_value) == BATTERY_NEEDS_REPLACING) {
  49. CHAR buffer[16] = {NULL};
  50. theDevice->Get(LIGHTS_TEST, buffer);
  51. // ... and UPS is NOT doing a lights test
  52. if (atoi(buffer) != LIGHTS_TEST_IN_PROGRESS) {
  53. // store the new value in the cache and tell the world
  54. storeValue(event_value);
  55. UpdateObj::Update(anEvent);
  56. }
  57. }
  58. // If battery doesn't need replacing, store the new value in
  59. // the cache and tell the world
  60. else if (atoi(event_value) == BATTERY_DOESNT_NEED_REPLACING) {
  61. storeValue(event_value);
  62. UpdateObj::Update(anEvent);
  63. }
  64. }
  65. return err;
  66. }