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.

252 lines
6.5 KiB

  1. /******************************************************************
  2. devnode.h
  3. Generic class for tracking CM32 Devnodes
  4. first created (as such) by jeffth
  5. Revision history
  6. 3-99 jeffth created
  7. *******************************************************************/
  8. #ifndef _INCLUDE_DEVNODE_H_
  9. #define _INCLUDE_DEVNODE_H_
  10. /*******************************************************************
  11. INCLUDES
  12. *******************************************************************/
  13. #include <windows.h>
  14. //#include <stl.h>
  15. #include <cfgmgr32.h>
  16. #include <alclass.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. // if we are ever compliled against win9x version of cfgmgr32.h
  20. #ifndef CM_DISABLE_UI_NOT_OK
  21. #define CM_DISABLE_UI_NOT_OK (0x00000004)
  22. #endif
  23. /*******************************************************************
  24. DEFINES
  25. *******************************************************************/
  26. // UNICODE conversions
  27. #ifdef UNICODE
  28. #define sprintf swprintf
  29. #define strstr wcsstr
  30. #define strlen wcslen
  31. #define strcmp wcscmp
  32. #define _strupr _wcsupr
  33. #define strcpy wcscpy
  34. #define _strlwr _wcslwr
  35. #define strncpy wcsncpy
  36. #define atoi _wtoi
  37. #define strchr wcschr
  38. #define _fullpath _wfullpath
  39. #define system _wsystem
  40. #endif
  41. #define CAN_DISABLE_BITS (DN_DISABLEABLE)
  42. #define IGNORE_ME_BITS (DN_STOP_FREE_RES | DN_NEED_TO_ENUM | DN_ARM_WAKEUP)
  43. // I had to copy this from ntioapi.h
  44. // did not want to , but if i included all of teh goo that ntioapi.h wanted me to include,
  45. // would break everyting else
  46. //
  47. // Define the I/O bus interface types.
  48. //
  49. typedef enum _INTERFACE_TYPE {
  50. InterfaceTypeUndefined = -1,
  51. Internal,
  52. Isa,
  53. Eisa,
  54. MicroChannel,
  55. TurboChannel,
  56. PCIBus,
  57. VMEBus,
  58. NuBus,
  59. PCMCIABus,
  60. CBus,
  61. MPIBus,
  62. MPSABus,
  63. ProcessorInternal,
  64. InternalPowerBus,
  65. PNPISABus,
  66. PNPBus,
  67. MaximumInterfaceType
  68. }INTERFACE_TYPE, *PINTERFACE_TYPE;
  69. #define BADHANDLE(x) ((x == 0 ) || ((HANDLE)x == INVALID_HANDLE_VALUE))
  70. #define BUFFSIZE 1024
  71. /*******************************************************************
  72. CLASSES and STRUCTS
  73. *******************************************************************/
  74. class DevnodeClass : public AutoListClass
  75. {
  76. public:
  77. DevnodeClass(void);
  78. DevnodeClass(DEVNODE hDevnode, DEVNODE hParent = NULL);
  79. ~DevnodeClass(void);
  80. virtual BOOL SetHandle(DEVNODE hDevnode, DEVNODE hParent = NULL);
  81. // Disable funcions
  82. CONFIGRET Remove(ULONG uFlags = CM_REMOVE_UI_NOT_OK);
  83. CONFIGRET Refresh(ULONG uFlags = CM_REENUMERATE_SYNCHRONOUS);
  84. CONFIGRET Enable(ULONG uFlags = CM_SETUP_DEVNODE_READY); // enables the devnode, returns CM_ERROR code
  85. CONFIGRET Disable(ULONG uFlags = (CM_DISABLE_POLITE | CM_DISABLE_UI_NOT_OK)); // disables the devnode, returns CM_ERROR code
  86. CONFIGRET GetProblemCode(ULONG *Status = NULL, ULONG *Problem = NULL);
  87. // getrelations
  88. CONFIGRET GetChild (DEVNODE *pChildDevnode);
  89. CONFIGRET GetParent (DEVNODE *pParentDevnode);
  90. CONFIGRET GetSibling (DEVNODE *pSiblingDevnode);
  91. int operator==(const DevnodeClass &OtherDevnode);
  92. // refresh devnode funcitons
  93. CONFIGRET GetDeviceInformation (void); // gets information about the devnode
  94. CONFIGRET FindDevnode(void);
  95. // acessor funcitons
  96. ULONG ProblemCode(void) {return ulProblemCode;};
  97. ULONG StatusCode(void) {return ulStatus;};
  98. TCHAR *DeviceName(void) {return pszDescription;};
  99. TCHAR *DeviceClass(void) {return pszClass;};
  100. TCHAR *HardwareID(void) {return pHardwareID;};
  101. TCHAR *CompatID(void) {return pCompatID;};
  102. BOOL GetMark(void) {return bDNHasMark;};
  103. TCHAR *DeviceID(void) {return pDeviceID;};
  104. void SetMark(BOOL bMark = TRUE) {bDNHasMark = bMark;};
  105. void SetPass(BOOL bPass = TRUE) {bDidPass = bPass;};
  106. DEVNODE Devnode(void) {return hDevnode;};
  107. DEVNODE Parent(void) {return hParent;};
  108. BOOL BCanTest(void) {return bCanTest;};
  109. TCHAR *GUID(void) {return pszGUID;};
  110. TCHAR *Location(void) {return pszLocation;};
  111. TCHAR *PDO(void) {return pszPDO;};
  112. TCHAR *MFG(void) {return pszMFG;};
  113. TCHAR *FriendlyName(void) {return pszFriendlyName;};
  114. INTERFACE_TYPE BusType(void) {return InterfaceBusType;};
  115. protected:
  116. TCHAR * pDeviceID;
  117. TCHAR * pHardwareID;
  118. TCHAR * pCompatID;
  119. DEVNODE hDevnode;
  120. DEVNODE hParent;
  121. TCHAR * pszDescription;
  122. TCHAR * pszFriendlyName;
  123. ULONG ulProblemCode;
  124. ULONG ulStatus;
  125. TCHAR * pszClass;
  126. TCHAR * pszGUID;
  127. TCHAR * pszLocation;
  128. BOOL bDNHasMark;
  129. BOOL bCanDisable;
  130. BOOL bCanTest;
  131. BOOL bDidPass;
  132. TCHAR * pszPDO;
  133. TCHAR * pszMFG;
  134. INTERFACE_TYPE InterfaceBusType;
  135. private:
  136. };
  137. /*******************************************************************
  138. GLOBALS
  139. *******************************************************************/
  140. /*******************************************************************
  141. PROTOTYPES
  142. *******************************************************************/
  143. ULONG ReadRegKeyInformationSZ (HKEY RootKey, TCHAR *KeyName, TCHAR **Value);
  144. // from the new disabler classes
  145. // error string reporting
  146. TCHAR * CM_ErrToStr(ULONG);
  147. TCHAR * DN_ErrStr(ULONG *);
  148. TCHAR * CM_ProbToStr(ULONG ErrorCode);
  149. ULONG EnumerateTree_Devnode(void);
  150. template <class T>
  151. BOOL Enumerate_WalkTree_Template( T type, DEVNODE hDevnode, DEVNODE hParent)
  152. {
  153. CONFIGRET retval;
  154. T *pNewDevice;
  155. DEVNODE hSib;
  156. pNewDevice = new T(hDevnode, hParent);
  157. retval = pNewDevice->GetChild(&hSib);
  158. if ( !retval )
  159. {
  160. Enumerate_WalkTree_Template(type, hSib, hDevnode);
  161. }
  162. retval = pNewDevice->GetSibling(&hSib);
  163. if ( !retval )
  164. {
  165. Enumerate_WalkTree_Template(type, hSib, hParent);
  166. }
  167. return (retval);
  168. }
  169. template <class T>
  170. ULONG EnumerateTree_Template(T type)
  171. {
  172. DEVNODE hDevnode;
  173. CM_Locate_DevNode(&hDevnode, NULL, CM_LOCATE_DEVNODE_NORMAL);
  174. Enumerate_WalkTree_Template(type, hDevnode, NULL);
  175. return (DevnodeClass::ALCCount());
  176. }
  177. #endif //_INCLUDE_DEVNODE_H_
  178. // cause compiler demands this anyway