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.

393 lines
18 KiB

  1. /*******************************************************************************
  2. *
  3. * Copyright 1999 American Power Conversion, All Rights Reserved
  4. *
  5. * TITLE: UPSREG.H
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: SteveT
  10. *
  11. * DATE: 07 June, 1999
  12. *
  13. ********************************************************************************/
  14. // This file contains declarations that support accessing
  15. // registry data passed between the UPS service and the
  16. // UPS UI.
  17. #ifndef _UPSREG_H_
  18. #define _UPSREG_H_
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. LONG getStringValue(struct _reg_entry *aRegEntry, LPTSTR aBuffer, size_t aBufferLen);
  23. LONG getDwordValue(struct _reg_entry *aRegEntry, LPDWORD aValue);
  24. /*
  25. * Public Config function declarations
  26. */
  27. LONG GetUPSConfigVendor(LPTSTR aBuffer, size_t aBufferLen);
  28. LONG GetUPSConfigModel(LPTSTR aBuffer, size_t aBufferLen);
  29. LONG GetUPSConfigPort(LPTSTR aBuffer, size_t aBufferLen);
  30. LONG GetUPSConfigOptions( LPDWORD aValue);
  31. LONG GetUPSConfigShutdownWait( LPDWORD aValue);
  32. LONG GetUPSConfigFirstMessageDelay( LPDWORD aValue);
  33. LONG GetUPSConfigMessageInterval( LPDWORD aValue);
  34. LONG GetUPSConfigServiceDLL(LPTSTR aBuffer, size_t aBufferLen);
  35. LONG GetUPSConfigNotifyEnable( LPDWORD aValue);
  36. LONG GetUPSConfigShutdownOnBatteryEnable( LPDWORD aValue);
  37. LONG GetUPSConfigShutdownOnBatteryWait( LPDWORD aValue);
  38. LONG GetUPSConfigRunTaskEnable( LPDWORD aValue);
  39. LONG GetUPSConfigTaskName(LPTSTR aBuffer, size_t aBufferLen);
  40. LONG GetUPSConfigTurnOffEnable( LPDWORD aValue);
  41. LONG GetUPSConfigAPCLinkURL(LPTSTR aBuffer, size_t aBufferLen);
  42. LONG GetUPSConfigUpgrade( LPDWORD aValue);
  43. LONG GetUPSConfigCustomOptions( LPDWORD aValue);
  44. LONG GetUPSConfigCriticalPowerAction( LPDWORD aValue);
  45. LONG GetUPSConfigTurnOffWait( LPDWORD aValue);
  46. LONG GetUPSConfigImagePath(LPTSTR aBuffer, size_t aBufferLen);
  47. LONG GetUPSConfigObjectName(LPTSTR aBuffer, size_t aBufferLen);
  48. LONG GetUPSConfigShowUPSTab( LPDWORD aValue);
  49. LONG GetUPSConfigErrorControl( LPDWORD aValue);
  50. LONG GetUPSConfigStart( LPDWORD aValue);
  51. LONG GetUPSConfigType( LPDWORD aValue);
  52. LONG SetUPSConfigVendor( LPCTSTR aBuffer);
  53. LONG SetUPSConfigModel( LPCTSTR aBuffer);
  54. LONG SetUPSConfigPort( LPCTSTR aBuffer);
  55. LONG SetUPSConfigOptions( DWORD aValue);
  56. LONG SetUPSConfigShutdownWait( DWORD aValue);
  57. LONG SetUPSConfigFirstMessageDelay( DWORD aValue);
  58. LONG SetUPSConfigMessageInterval( DWORD aValue);
  59. LONG SetUPSConfigServiceDLL( LPCTSTR aBuffer);
  60. LONG SetUPSConfigNotifyEnable( DWORD aValue);
  61. LONG SetUPSConfigShutdownOnBatteryEnable( DWORD aValue);
  62. LONG SetUPSConfigShutdownOnBatteryWait( DWORD aValue);
  63. LONG SetUPSConfigRunTaskEnable( DWORD aValue);
  64. LONG SetUPSConfigTaskName( LPCTSTR aBuffer);
  65. LONG SetUPSConfigTurnOffEnable( DWORD aValue);
  66. LONG SetUPSConfigAPCLinkURL( LPCTSTR aBuffer);
  67. LONG SetUPSConfigUpgrade( DWORD aValue);
  68. LONG SetUPSConfigCustomOptions( DWORD aValue);
  69. LONG SetUPSConfigCriticalPowerAction( DWORD aValue);
  70. LONG SetUPSConfigTurnOffWait( DWORD aValue);
  71. LONG SetUPSConfigImagePath( LPCTSTR aBuffer);
  72. LONG SetUPSConfigObjectName( LPCTSTR aBuffer);
  73. LONG SetUPSConfigShowUPSTab( DWORD aValue);
  74. LONG SetUPSConfigErrorControl( DWORD aValue);
  75. LONG SetUPSConfigStart( DWORD aValue);
  76. LONG SetUPSConfigType( DWORD aValue);
  77. /*
  78. * Public Status function declarations
  79. */
  80. LONG GetUPSStatusSerialNum(LPTSTR aBuffer, size_t aBufferLen);
  81. LONG GetUPSStatusFirmRev(LPTSTR aBuffer, size_t aBufferLen);
  82. LONG GetUPSStatusUtilityStatus( LPDWORD aValue);
  83. LONG GetUPSStatusRuntime( LPDWORD aValue);
  84. LONG GetUPSStatusBatteryStatus( LPDWORD aValue);
  85. LONG GetUPSStatusCommStatus( LPDWORD aValue);
  86. LONG GetUPSStatusBatteryCapacity( LPDWORD aValue);
  87. LONG SetUPSStatusSerialNum( LPCTSTR aBuffer);
  88. LONG SetUPSStatusFirmRev( LPCTSTR aBuffer);
  89. LONG SetUPSStatusUtilityStatus( DWORD aValue);
  90. LONG SetUPSStatusRuntime( DWORD aValue);
  91. LONG SetUPSStatusBatteryStatus( DWORD aValue);
  92. LONG SetUPSStatusCommStatus( DWORD aValue);
  93. LONG SetUPSStatusBatteryCapacity( DWORD aValue);
  94. /*
  95. * Public Reg Entry function declarations
  96. */
  97. void InitUPSConfigBlock();
  98. void InitUPSStatusBlock();
  99. void RestoreUPSConfigBlock();
  100. void RestoreUPSStatusBlock();
  101. void SaveUPSConfigBlock(BOOL forceAll);
  102. void SaveUPSStatusBlock(BOOL forceAll);
  103. void FreeUPSConfigBlock();
  104. void FreeUPSStatusBlock();
  105. /*
  106. * Reg entry path string declarations
  107. */
  108. #define UPS_DEFAULT_ROOT _T("SYSTEM\\CurrentControlSet\\Services\\UPS")
  109. #define UPS_STATUS_ROOT _T("SYSTEM\\CurrentControlSet\\Services\\UPS\\Status")
  110. #define UPS_CONFIG_ROOT _T("SYSTEM\\CurrentControlSet\\Services\\UPS\\Config")
  111. #define UPS_SERVICE_ROOT _T("SYSTEM\\CurrentControlSet\\Services\\UPS\\ServiceProviders")
  112. #define UPS_PORT_ROOT _T("HARDWARE\\DEVICEMAP\\SERIALCOMM")
  113. #define UPS_UTILITYPOWER_UNKNOWN 0
  114. #define UPS_UTILITYPOWER_ON 1
  115. #define UPS_UTILITYPOWER_OFF 2
  116. #define UPS_BATTERYSTATUS_UNKNOWN 0
  117. #define UPS_BATTERYSTATUS_GOOD 1
  118. #define UPS_BATTERYSTATUS_REPLACE 2
  119. #define UPS_COMMSTATUS_UNKNOWN 0
  120. #define UPS_COMMSTATUS_OK 1
  121. #define UPS_COMMSTATUS_LOST 2
  122. // Defines the values for the 'Options' bitmask registry key
  123. #define UPS_INSTALLED 0x00000001
  124. #define UPS_POWERFAILSIGNAL 0x00000002
  125. #define UPS_LOWBATTERYSIGNAL 0x00000004
  126. #define UPS_SHUTOFFSIGNAL 0x00000008
  127. #define UPS_POSSIGONPOWERFAIL 0x00000010
  128. #define UPS_POSSIGONLOWBATTERY 0x00000020
  129. #define UPS_POSSIGSHUTOFF 0x00000040
  130. #define UPS_RUNCMDFILE 0x00000080
  131. #define UPS_DEFAULT_SIGMASK 0x0000007f
  132. #define DEFAULT_CONFIG_IMAGEPATH TEXT("%SystemRoot%\\System32\\ups.exe")
  133. // Min / Max / Default values for FirstMessageDelay (seconds)
  134. #define WAITSECONDSFIRSTVAL 0
  135. #define WAITSECONDSLASTVAL 120
  136. #define WAITSECONDSDEFAULT 5
  137. // Min / Max / Default values for MessageInterval (seconds)
  138. #define REPEATSECONDSFIRSTVAL 5
  139. #define REPEATSECONDSLASTVAL 300
  140. #define REPEATSECONDSDEFAULT 120
  141. // Min / Max / Default values for ShutdownOnBatteryWait (minutes)
  142. #define SHUTDOWNTIMERMINUTESFIRSTVAL 2
  143. #define SHUTDOWNTIMERMINUTESLASTVAL 720
  144. #define SHUTDOWNTIMERMINUTESDEFAULT 2
  145. // Shutdown behavior values
  146. #define UPS_SHUTDOWN_SHUTDOWN 0
  147. #define UPS_SHUTDOWN_HIBERNATE 1
  148. /** ServiceProvider structure. The structure defines the entries in the
  149. * ServiceProviders registry key.
  150. */
  151. typedef struct {
  152. LPTSTR theVendorKey; // Vendor registry subkey
  153. LPTSTR theModelName; // UPS model name
  154. LPTSTR theValue; // UPS value data
  155. } ServiceProviderStructure;
  156. /**
  157. * InitializeRegistry
  158. *
  159. * Description:
  160. * This function initiates the registry for the UPS service and the
  161. * configuration application. When called, this function examines
  162. * the registry to determine if it needs to be initalized. If the key
  163. * HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\UPS\Config\ServiceProviderDLL
  164. * is present, the registry is assumed to be initialized and no initialization
  165. * is done. If the key is not present the following Keys are updated:
  166. * Status
  167. * Config
  168. * ServiceProviders
  169. *
  170. * The values for the ServiceProviders key is supplied in the regdefs.h
  171. * header file.
  172. *
  173. * Parameters:
  174. * none
  175. *
  176. * Returns:
  177. * TRUE if able to open registry keys with write access.
  178. */
  179. BOOL InitializeRegistry();
  180. ///////////////
  181. // upsdefines.h
  182. #ifndef _ASSERT
  183. #define _ASSERT(x)
  184. #endif
  185. #define DIMENSION_OF(array) (sizeof(array)/sizeof(array[0]))
  186. //This value is used in most of the text buffers in various places throughout
  187. //the application.
  188. #define MAX_MESSAGE_LENGTH 1024
  189. //The following three strings are the registry value names where all
  190. //the UPS data is stored. These values are used in the RegField array
  191. //in datacces.c
  192. #define UPS_KEY_NAME TEXT("SYSTEM\\CurrentControlSet\\Services\\UPS")
  193. #define STATUS_KEY_NAME TEXT("SYSTEM\\CurrentControlSet\\Services\\UPS\\Status")
  194. #define CONFIG_KEY_NAME TEXT("SYSTEM\\CurrentControlSet\\Services\\UPS\\Config")
  195. //The following values are used in the DialogAssociations arrays in updatdlg.c
  196. //and upsinfo.c
  197. #define RESOURCE_FIXED 0
  198. #define RESOURCE_INCREMENT 1
  199. #define REG_ANY_DWORD_TYPE (REG_DWORD | REG_DWORD_BIG_ENDIAN | REG_DWORD_LITTLE_ENDIAN)
  200. //This is a helper macro to help form a DialogAssociations array members.
  201. #define MAKE_ARRAY(stub, insertID, indexID, stringType, indexMax, regAccessType, shallowAccessPtr, regEntryPtr)\
  202. { eREG_##stub, IDC_##stub##_LHS, IDC_##stub, insertID, indexID, stringType, indexMax, regAccessType, shallowAccessPtr, regEntryPtr }
  203. //The following are all the registry values supported by the application.
  204. //The amount and values to these enums correspond to the size of the array
  205. //g_upsRegFields
  206. typedef enum _tUPSDataItemID { eREG_VENDOR_NAME = 0,
  207. eREG_MODEL_TYPE,
  208. eREG_SERIAL_NUMBER,
  209. eREG_FIRMWARE_REVISION,
  210. eREG_POWER_SOURCE,
  211. eREG_RUNTIME_REMAINING,
  212. eREG_BATTERY_CAPACITY,
  213. eREG_BATTERY_STATUS,
  214. eREG_UPS_OPTIONS,
  215. eREG_SERVICE_PROVIDER_DLL,
  216. eREG_SHUTDOWN_ON_BATTERY_ENABLE,
  217. eREG_SHUTDOWN_ON_BATTERY_WAIT,
  218. eREG_TURN_UPS_OFF_ENABLE,
  219. eREG_APC_LINKURL,
  220. eREG_UPGRADE_ENABLE,
  221. eREG_COMM_STATUS,
  222. eREG_PORT } tUPSDataItemID;
  223. //This enum is used in DialogAssociations below. This defines the
  224. //type of registry query to perform when reading registry values.
  225. //There are only two options, to perform a deep get, that is, go
  226. //right to the registry every time, re-reading it from the registry, or to
  227. //use the regfunc buffer value (shallow get).
  228. typedef enum _tRegAccessType { eDeepGet = 0,
  229. eShallowGet } tRegAccessType;
  230. //This struct links the registry field and the dialog controls.
  231. typedef struct _DialogAssociations {
  232. const tUPSDataItemID theFieldTypeID; //the eREG_... id. This is used to read the
  233. //registry data.
  234. DWORD theStaticFieldID; //A control id (usually for a static control). This
  235. //is the left-hand side control. For example, in the
  236. //on-screen text "Model Type: Back-UPS Pro" there are
  237. //actually two controls the left-hand side (LHS) is
  238. //"Model Type:" and the right-hand side is "Back-UPS Pro".
  239. //These controls are separated as the LHS's behavior is
  240. //different to the RHS when no data is present.
  241. DWORD theDisplayControlID; //A control id (usually an edit field or a static)
  242. DWORD theResourceInsertID; //The id of the string resource to insert the value into
  243. //If the registry value is a DWORD then
  244. //the insertion point should be %n!lu!, if
  245. //it's a string then the insertion point can be just %n
  246. DWORD theResourceIndexID; //This is only relevant if theResourceStringType is
  247. //of type RESOURCE_INCREMENT. This identifies the id
  248. //of the string when the value read for this item is 0,
  249. //it is assumed that the other string values are stored
  250. //consequtively in the string table following this value.
  251. //For an example see below.
  252. DWORD theResourceStringType; //This can be RESOURCE_FIXED or RESOURCE_INCREMENT.
  253. //RESOURCE_FIXED means that the value needs no special
  254. //handling. Simple insert the value into the string
  255. //identified by theResourceInsertID. If it's equal to
  256. //RESOURCE_INCREMENT then the string inserted is determined
  257. //by reading the value from the registry (say it's equal
  258. //to 1). The theResourceIndexID indentifies the id of the
  259. //string resource corresponding to a value. A value of 1
  260. //gives up the string with id theResourceIndexID + 1. This
  261. //string is loaded and inserted into the string identified
  262. //by theResourceInsertID.
  263. DWORD theResourceIndexMax; //This is only relevant if theResourceStringType is
  264. //of type RESOURCE_INCREMENT. This identifies the maximum
  265. //index value that is support for this increment type. This
  266. //is to protect from unsupported registry value causing the
  267. //"theResourceIndexID + value" addition going beyond the
  268. //range of supported string resource values.
  269. tRegAccessType theRegAccessType; //This define whether the access to the registry value
  270. //should use a "shallow" or "deep" get. See help on
  271. //tUPSDataItemID above.
  272. void * theShallowAccessFunctionPtr; //This point to the regfuncs function to use when performing
  273. //a shallow get. This parameter is only required if
  274. //theRegAccessType is set to eShallowGet, otherwise it can
  275. //be 0.
  276. struct _reg_entry * theRegEntryPtr; //This is the _reg_entry * parameter passed to the regfuncs
  277. //function (theShallowAccessFunctionPtr member) when
  278. //performing a shallow get. This parameter is only required if
  279. //theRegAccessType is set to eShallowGet, otherwise it can
  280. //be 0.
  281. } DialogAssociations;
  282. /*
  283. The following example helps to explain more the members of the DialogAssociations struct.
  284. Say we have an instance of this struct as follows:
  285. DialogAssociations da = { eREG_POWER_SOURCE,
  286. IDC_POWER_SOURCE_LHS,
  287. IDC_POWER_SOURCE,
  288. IDS_STRING,
  289. IDS_UTILITYPOWER_UNKNOWN,
  290. RESOURCE_INCREMENT,
  291. 2,
  292. eDeepGet,
  293. 0,
  294. 0 };
  295. This describes a registry field called eREG_POWER_SOURCE. If we look at
  296. tUPSDataItemID above we see that eREG_POWER_SOURCE has a value of 4. If
  297. we then look at g_upsRegFields in datacces.c we that the RegField at index
  298. 4 has the following data:
  299. { HKEY_LOCAL_MACHINE, STATUS_KEY_NAME, TEXT("UtilityPowerStatus"), REG_DWORD },
  300. The DoUpdateInfo function, for example, takes this information when updating
  301. the onscreen data in the main UPS page. The function gets the RegField
  302. information, as above. It then looks to see if it needs to do a deep get (read
  303. directly from the registry), or a shallow get (take data from the current
  304. values stored in the regfuncs buffers. If the registry item theValueType is
  305. one of the string type then the string value is copied into the resource
  306. string identified by theResourceInsertID. In this case theValueType is
  307. REG_DWORD. In this case the DWORD is read from the registry directly. Its
  308. value (say it had a value of 1) is then added to IDS_UTILITYPOWER_UNKNOWN
  309. giving a value which corresponds to IDS_UTILITYPOWER_ON. The string
  310. IDS_UTILITYPOWER_ON is then loaded and used as a parameter value when
  311. loaded the parameterized string resource identified by the
  312. theResourceInsertID string id. This string (which should include the inserted
  313. text) is then displayed in the control identified by theDisplayControlID.
  314. */
  315. //this struct describes a registy field item
  316. typedef struct _RegField {
  317. HKEY theRootKey; //Handle to an existing registry key.
  318. LPCTSTR theKeyName; //The name of the subkey relative to the above handle.
  319. LPCTSTR theValueName; //The name of the registry value.
  320. DWORD theValueType; //The type of the value.
  321. } RegField;
  322. ///////////////////////////////////////////////////////////////////////////////
  323. RegField * GetRegField (DWORD index);
  324. // upsdata.h
  325. //Note that the order and numbering of the enums in tUPSDataItemID is linked to
  326. //the contents of the array of RegFields defined in datacces.h.
  327. //Do not change these value without due care and attention. It's OK to change
  328. //it as long as the array of RegFields is updated to match.
  329. DWORD ReadRegistryValueData (HKEY aRootKey,
  330. LPCTSTR aKeyName,
  331. LPCTSTR aValueName,
  332. DWORD aAllowedTypes,
  333. DWORD * aTypePtr,
  334. LPTSTR aReturnBuffer,
  335. DWORD * aBufferSizePtr);
  336. BOOL GetUPSDataItemDWORD (const tUPSDataItemID aDataItemID, DWORD * aReturnValuePtr);
  337. BOOL GetUPSDataItemString (const tUPSDataItemID aDataItemID, LPTSTR aBufferPtr, DWORD * pSizeOfBufferPtr);
  338. #ifdef __cplusplus
  339. }
  340. #endif
  341. #endif