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.

113 lines
2.9 KiB

  1. /*
  2. *
  3. * REVISIONS:
  4. * ker25NOV92 Initial OS/2 Revision
  5. * pcy11Dec92: New defines for lite sensor stuff used
  6. * cad23Jun93: Fixed on/off events
  7. * cad07Oct93: Plugging Memory Leaks
  8. * cad11Nov93: Making sure all timers are cancelled on destruction
  9. * pcy08Apr94: Trim size, use static iterators, dead code removal
  10. * pcy13Apr94: Use automatic variables decrease dynamic mem allocation
  11. */
  12. #define INCL_BASE
  13. #define INCL_DOS
  14. #define INCL_NOPM
  15. #include "cdefine.h"
  16. extern "C" {
  17. #if (C_OS & C_OS2)
  18. #include <os2.h>
  19. #endif
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <malloc.h>
  23. #include <string.h>
  24. }
  25. #include "litesnsr.h"
  26. #include "comctrl.h"
  27. #include "dispatch.h"
  28. #include "timerman.h"
  29. //Constructor
  30. LightsTestSensor :: LightsTestSensor(PDevice aParent,
  31. PCommController aCommController)
  32. : StateSensor(aParent,aCommController,LIGHTS_TEST,AREAD_WRITE),
  33. theTimerId(0)
  34. {
  35. storeState(NO_LIGHTS_TEST_IN_PROGRESS);
  36. }
  37. LightsTestSensor::~LightsTestSensor()
  38. {
  39. if (theTimerId) {
  40. _theTimerManager->CancelTimer(theTimerId);
  41. theTimerId = 0;
  42. }
  43. }
  44. INT LightsTestSensor::Set(const PCHAR aValue)
  45. {
  46. if( atoi(aValue) == LIGHTS_TEST )
  47. {
  48. CHAR buffer[16] = {NULL};
  49. _itoa(LIGHTS_TEST_IN_PROGRESS, buffer, 10);
  50. INT the_return=Sensor::Set(buffer);
  51. //Tell the CommController that we're doing a lights test
  52. theCommController->Set(theSensorCode, aValue);
  53. Event the_event(LIGHTS_TEST, LIGHTS_TEST_IN_PROGRESS);
  54. Update(&the_event);
  55. if (theTimerId) {
  56. _theTimerManager->CancelTimer(theTimerId);
  57. theTimerId = 0;
  58. }
  59. Event done_event(LIGHTS_TEST, NO_LIGHTS_TEST_IN_PROGRESS);
  60. theTimerId = _theTimerManager->SetTheTimer((ULONG)LIGHTS_TEST_SECONDS,
  61. &done_event, this);
  62. return the_return;
  63. }
  64. else
  65. return ErrINVALID_VALUE;
  66. }
  67. INT LightsTestSensor::Update(PEvent anEvent)
  68. {
  69. INT the_temp_code;
  70. PCHAR the_temp_value;
  71. INT the_int_value;
  72. the_temp_code=anEvent->GetCode();
  73. the_temp_value=anEvent->GetValue();
  74. the_int_value=atoi(the_temp_value);
  75. if( (the_temp_code == LIGHTS_TEST) && (the_int_value == NO_LIGHTS_TEST_IN_PROGRESS)) {
  76. Set(the_temp_value);
  77. theTimerId = 0;
  78. }
  79. return UpdateObj::Update(anEvent);
  80. }
  81. #if 0
  82. *** Removed for size concerns. This is really a redundant feature since
  83. *** protocol generates these events
  84. INT LightsTestSensor::Validate(INT aCode, const PCHAR aValue)
  85. {
  86. INT the_temp_value=atoi(aValue);
  87. if( (aCode == LIGHTS_TEST) && (
  88. (the_temp_value == LIGHTS_TEST_IN_PROGRESS)||(the_temp_value == NO_LIGHTS_TEST_IN_PROGRESS)))
  89. return ErrNO_ERROR;
  90. else
  91. return ErrINVALID_VALUE;
  92. }
  93. #endif