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.

210 lines
4.0 KiB

  1. /* Copyright 1999 American Power Conversion, All Rights Reserverd
  2. *
  3. * Description:
  4. * DLL entry points for the APC UpsMiniDriver interface
  5. * Creates a single instance of an ApcMiniDriver class
  6. * and forwards all requests to this object
  7. *
  8. * Revision History:
  9. * mholly 14Apr1999 Created
  10. *
  11. */
  12. #include "cdefine.h"
  13. #include <windows.h>
  14. #include "apcups.h"
  15. #include "apcdrvr.h"
  16. //
  17. // _theDriver
  18. //
  19. // Each process that attaches to this DLL will
  20. // get its own copy of _theDriver. _theDriver
  21. // is an instance of the class ApcMiniDriver.
  22. // The ApcMiniDriver class provides support for
  23. // APC "smart" signalling UPS systems
  24. //
  25. ApcMiniDriver _theDriver;
  26. /**
  27. * DllMain
  28. *
  29. * Description:
  30. * This method is called when the DLL is loaded
  31. * We do not make use of this method
  32. *
  33. * Parameters:
  34. * not used
  35. * Returns:
  36. * TRUE
  37. *
  38. */
  39. BOOL APIENTRY DllMain( HANDLE hModule,
  40. DWORD ul_reason_for_call,
  41. LPVOID lpReserved
  42. )
  43. {
  44. switch (ul_reason_for_call)
  45. {
  46. case DLL_PROCESS_ATTACH:
  47. case DLL_THREAD_ATTACH:
  48. case DLL_THREAD_DETACH:
  49. case DLL_PROCESS_DETACH:
  50. break;
  51. }
  52. return TRUE;
  53. }
  54. /**
  55. * UPSInit
  56. *
  57. * Description:
  58. * Must be the first method called in the interface -
  59. * forwards call to ApcMiniDriver::UPSInit
  60. *
  61. * Parameters:
  62. * aCommPort: comm port that the UPS is connected
  63. *
  64. * Returns:
  65. * UPS_INITOK: successful initialization
  66. * UPS_INITUNKNOWNERROR: failed initialization
  67. *
  68. */
  69. DWORD UPSInit()
  70. {
  71. return _theDriver.UPSInit();
  72. }
  73. /**
  74. * UPSStop
  75. *
  76. * Description:
  77. * stops monitoring of the UPS - the only valid
  78. * interface after a call to UPSStop is UPSInit
  79. *
  80. * Parameters:
  81. * None
  82. *
  83. * Returns:
  84. * None
  85. *
  86. */
  87. void UPSStop(void)
  88. {
  89. _theDriver.UPSStop();
  90. }
  91. /**
  92. * UPSWaitForStateChange
  93. *
  94. * Description:
  95. * Blocks until the state of the UPS differs
  96. * from the value passed in via aState or
  97. * anInterval milliseconds has expired. If
  98. * anInterval has a value of INFINITE this
  99. * function will never timeout
  100. *
  101. * Parameters:
  102. * aState: defines the state to wait for a change from,
  103. * possible values:
  104. * UPS_ONLINE
  105. * UPS_ONBATTERY
  106. * UPS_LOWBATTERY
  107. * UPS_NOCOMM
  108. *
  109. * anInterval: timeout in milliseconds, or INFINITE for
  110. * no timeout interval
  111. *
  112. * Returns:
  113. * None
  114. *
  115. */
  116. void UPSWaitForStateChange(DWORD aState, DWORD anInterval)
  117. {
  118. _theDriver.UPSWaitForStateChange(aState, anInterval);
  119. }
  120. /**
  121. * UPSGetState
  122. *
  123. * Description:
  124. * returns the current state of the UPS
  125. *
  126. * Parameters:
  127. * None
  128. *
  129. * Returns:
  130. * possible values:
  131. * UPS_ONLINE
  132. * UPS_ONBATTERY
  133. * UPS_LOWBATTERY
  134. * UPS_NOCOMM
  135. *
  136. */
  137. DWORD UPSGetState(void)
  138. {
  139. return _theDriver.UPSGetState();
  140. }
  141. /**
  142. * UPSCancelWait
  143. *
  144. * Description:
  145. * interrupts pending calls to UPSWaitForStateChange
  146. * without regard to timout or state change
  147. *
  148. * Parameters:
  149. * None
  150. *
  151. * Returns:
  152. * None
  153. *
  154. */
  155. void UPSCancelWait(void)
  156. {
  157. _theDriver.UPSCancelWait();
  158. }
  159. /**
  160. * UPSTurnOff
  161. *
  162. * Description:
  163. * Attempts to turn off the outlets on the UPS
  164. * after the specified delay. This method querries the
  165. * UPS for the allowed shutdown delays and sets the
  166. * delay to one of the following:
  167. * 1. aTurnOffDelay if it exactly matches one of the allowed values
  168. * 2. the next highest value after aTurnOffDelay, if one exists
  169. * 3. the highest allowed value, if aTurnOffDelay is larger than all of
  170. * the allowed values.
  171. * If no allowed values are returned, the Shutdown Delay will not be set.
  172. * Next the UPS is instructed to sleep until power is restored.
  173. *
  174. * Parameters:
  175. * aTurnOffDelay: the minimum amount of time to wait before
  176. * turning off the outlets on the UPS
  177. *
  178. * Returns:
  179. * None
  180. *
  181. */
  182. void UPSTurnOff(DWORD aTurnOffDelay)
  183. {
  184. _theDriver.UPSTurnOff(aTurnOffDelay);
  185. }