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.

531 lines
12 KiB

  1. #ifndef __CNODE_H__
  2. #define __CNODE_H__
  3. /*++
  4. Copyright (C) Microsoft Corporation
  5. Module Name:
  6. cnode.h
  7. Abstract:
  8. header file for cnode.cpp
  9. Author:
  10. William Hsieh (williamh) created
  11. Revision History:
  12. --*/
  13. class CResultItem;
  14. class CResultComputer;
  15. class CResultClass;
  16. class CResultDevice;
  17. class CDriverList;
  18. class CDriver;
  19. class CHwProfile;
  20. class CMachine;
  21. class CItemIdentifier;
  22. class CDeviceIdentifier;
  23. class CClassIdentifier;
  24. class CComputerIdentifier;
  25. class CResourceIdentifier;
  26. class CResourceTypeIdentifier;
  27. #define ALL_LOG_CONF BOOT_LOG_CONF + ALLOC_LOG_CONF + FORCED_LOG_CONF
  28. inline
  29. COOKIE_TYPE CookieType(RESOURCEID ResType)
  30. {
  31. if (ResType_Mem == ResType)
  32. {
  33. return COOKIE_TYPE_RESULTITEM_RESOURCE_MEMORY;
  34. }
  35. else if (ResType_IO == ResType)
  36. {
  37. return COOKIE_TYPE_RESULTITEM_RESOURCE_IO;
  38. }
  39. else if (ResType_DMA == ResType)
  40. {
  41. return COOKIE_TYPE_RESULTITEM_RESOURCE_DMA;
  42. }
  43. else if (ResType_IRQ == ResType)
  44. {
  45. return COOKIE_TYPE_RESULTITEM_RESOURCE_IRQ;
  46. }
  47. else
  48. {
  49. ASSERT(FALSE);
  50. return COOKIE_TYPE_UNKNOWN;
  51. }
  52. }
  53. ///
  54. /// class to represent a result pane item
  55. ///
  56. class CResultItem
  57. {
  58. public:
  59. CResultItem() : m_pMachine(NULL)
  60. {}
  61. virtual ~CResultItem() {};
  62. LPCTSTR GetDisplayName() const
  63. {
  64. return (LPCTSTR)m_strDisplayName;
  65. }
  66. int GetImageIndex()
  67. {
  68. return m_iImage;
  69. }
  70. virtual CItemIdentifier* CreateIdentifier() = 0;
  71. CMachine* m_pMachine;
  72. protected:
  73. int m_iImage;
  74. String m_strDisplayName;
  75. };
  76. class CClass : public CResultItem
  77. {
  78. public:
  79. CClass(CMachine* pMachine, LPGUID pGuid);
  80. virtual ~CClass();
  81. BOOL GetFirstDevice(CDevice** ppDevice, PVOID& pContext);
  82. BOOL GetNextDevice(CDevice** ppDevice, PVOID& Context);
  83. operator GUID&()
  84. {
  85. return m_Guid;
  86. }
  87. operator LPGUID()
  88. {
  89. return &m_Guid;
  90. }
  91. BOOL operator ==(const CClass& OtherClass)
  92. {
  93. return IsEqualGUID(m_Guid, (GUID&)OtherClass);
  94. }
  95. CDevInfoList* GetDevInfoList(HWND hwndParent = NULL);
  96. HICON LoadIcon();
  97. void AddDevice(CDevice* pDevice);
  98. int GetNumberOfDevices(BOOL Hidden = FALSE)
  99. {
  100. return Hidden ? m_TotalDevices :
  101. m_TotalDevices - m_TotalHiddenDevices;
  102. }
  103. BOOL NoDisplay()
  104. {
  105. return m_NoDisplay;
  106. }
  107. virtual CItemIdentifier* CreateIdentifier();
  108. void PropertyChanged();
  109. CPropSheetData m_psd;
  110. private:
  111. CClass(const CClass& ClassSrc);
  112. CClass& operator=(const CClass& ClassSrc);
  113. GUID m_Guid;
  114. CList<CDevice*, CDevice*> m_listDevice;
  115. BOOL m_NoDisplay;
  116. POSITION m_pos;
  117. CDevInfoList* m_pDevInfoList;
  118. int m_TotalDevices;
  119. int m_TotalHiddenDevices;
  120. };
  121. class CDevice : public CResultItem
  122. {
  123. public:
  124. CDevice() : m_pClass(NULL), m_pSibling(NULL), m_pChild(NULL),
  125. m_pParent(NULL), m_bLaunchTroubleShooter(FALSE)
  126. {}
  127. CDevice(CMachine* pMachine, CClass* pClass, PSP_DEVINFO_DATA pDevData);
  128. operator SP_DEVINFO_DATA&()
  129. {
  130. return m_DevData;
  131. }
  132. operator PSP_DEVINFO_DATA()
  133. {
  134. return &m_DevData;
  135. }
  136. BOOL operator ==(LPCTSTR DeviceID)
  137. {
  138. return (0 == m_strDeviceID.CompareNoCase(DeviceID));
  139. }
  140. CDevice* GetChild()
  141. {
  142. return m_pChild;
  143. }
  144. CDevice* GetParent()
  145. {
  146. return m_pParent;
  147. }
  148. CDevice* GetSibling()
  149. {
  150. return m_pSibling;
  151. }
  152. void SetChild(CDevice* pDevice)
  153. {
  154. m_pChild = pDevice;
  155. }
  156. void SetParent(CDevice* pDevice)
  157. {
  158. m_pParent = pDevice;
  159. }
  160. void SetSibling(CDevice* pDevice)
  161. {
  162. m_pSibling = pDevice;
  163. }
  164. CClass* GetClass()
  165. {
  166. return m_pClass;
  167. }
  168. virtual DEVNODE GetDevNode()
  169. {
  170. return m_DevData.DevInst;
  171. }
  172. LPCTSTR GetDeviceID() const
  173. {
  174. return (m_strDeviceID.IsEmpty()) ? NULL : (LPCTSTR)m_strDeviceID;
  175. }
  176. BOOL IsHidden();
  177. BOOL IsPhantom();
  178. BOOL NoShowInDM();
  179. BOOL IsPCIDevice();
  180. virtual CItemIdentifier* CreateIdentifier();
  181. HICON LoadClassIcon();
  182. BOOL GetStatus(DWORD* pStatus, DWORD* pProblem);
  183. BOOL GetCapabilities(DWORD* pCapabilities);
  184. BOOL GetPowerCapabilities(DWORD* pCapabilities);
  185. BOOL IsRAW();
  186. BOOL IsUninstallable();
  187. BOOL IsDisableable();
  188. BOOL IsDisabled();
  189. BOOL IsStateDisabled();
  190. BOOL IsStarted();
  191. BOOL HasProblem();
  192. BOOL NeedsRestart();
  193. BOOL GetConfigFlags(DWORD* pFlags);
  194. BOOL GetConfigSpecificConfigFlags(DWORD* pCSStatus);
  195. BOOL GetKnownLogConf(LOG_CONF* plc, DWORD* plcType);
  196. BOOL HasResources();
  197. void GetMFGString(String& strMFG);
  198. void GetProviderString(String& strMFG);
  199. void GetDriverDateString(String& strMFG);
  200. void GetDriverVersionString(String& strMFG);
  201. LPCTSTR GetClassDisplayName();
  202. void ClassGuid(GUID& ClassGuid)
  203. {
  204. ASSERT(m_pClass);
  205. ClassGuid = *m_pClass;
  206. }
  207. BOOL NoChangeUsage();
  208. CDriver* CreateDriver();
  209. DWORD EnableDisableDevice(HWND hDlg, BOOL Enabling);
  210. void PropertyChanged();
  211. CPropSheetData m_psd;
  212. BOOL m_bLaunchTroubleShooter;
  213. private:
  214. CDevice(const CDevice& DeviceSrc);
  215. CDevice& operator=(const CDevice& DeviceSrc);
  216. CDevice* m_pParent;
  217. CDevice* m_pSibling;
  218. CDevice* m_pChild;
  219. String m_strDeviceID;
  220. SP_DEVINFO_DATA m_DevData;
  221. CClass* m_pClass;
  222. };
  223. class CComputer : public CDevice
  224. {
  225. public:
  226. CComputer(CMachine* pMachine, DEVNODE dnRoot);
  227. virtual DEVNODE GetDevNode()
  228. {
  229. return m_dnRoot;
  230. }
  231. virtual CItemIdentifier* CreateIdentifier();
  232. private:
  233. DEVNODE m_dnRoot;
  234. CComputer(const CComputer& ComputerSrc);
  235. CComputer& operator=(const CComputer& ComputerSrc);
  236. };
  237. class CResource : public CResultItem
  238. {
  239. public:
  240. CResource(CDevice* pDevice, RESOURCEID ResType, DWORDLONG dlBase, DWORDLONG dlLen,
  241. BOOL Forced, BOOL Free = FALSE);
  242. BOOL IsForced()
  243. {
  244. return m_Forced;
  245. }
  246. void GetValue(DWORDLONG* pdlBase, DWORDLONG* pdlLen) const
  247. {
  248. ASSERT(pdlBase && pdlLen);
  249. *pdlBase = m_dlBase;
  250. *pdlLen = m_dlLen;
  251. }
  252. virtual CItemIdentifier* CreateIdentifier();
  253. LPCTSTR GetViewName()
  254. {
  255. return (LPCTSTR)m_strViewName;
  256. }
  257. CDevice* GetDevice()
  258. {
  259. return m_pDevice;
  260. }
  261. CResource* GetChild()
  262. {
  263. return m_pChild;
  264. }
  265. CResource* GetSibling()
  266. {
  267. return m_pSibling;
  268. }
  269. CResource* GetParent()
  270. {
  271. return m_pParent;
  272. }
  273. void SetChild(CResource* pRes)
  274. {
  275. m_pChild = pRes;
  276. }
  277. void SetParent(CResource* pRes)
  278. {
  279. m_pParent = pRes;
  280. }
  281. void SetSibling(CResource* pRes)
  282. {
  283. m_pSibling = pRes;
  284. }
  285. BOOL operator <=(const CResource& resSrc);
  286. BOOL EnclosedBy(const CResource& resSrc);
  287. RESOURCEID ResType()
  288. {
  289. return m_ResType;
  290. }
  291. CDevice* m_pDevice;
  292. private:
  293. CResource(const CResource& resSrc);
  294. CResource& operator=(const CResource& resSrc);
  295. RESOURCEID m_ResType;
  296. DWORDLONG m_dlBase;
  297. DWORDLONG m_dlEnd;
  298. DWORDLONG m_dlLen;
  299. BOOL m_Forced;
  300. CResource* m_pChild;
  301. CResource* m_pSibling;
  302. CResource* m_pParent;
  303. BOOL m_Allocated;
  304. String m_strViewName;
  305. };
  306. #define pIRQResData(pData) ((IRQ_RESOURCE*)pData)
  307. #define pDMAResData(pData) ((DMA_RESOURCE*)pData)
  308. #define pMemResData(pData) ((MEM_RESOURCE*)pData)
  309. #define pIOResData(pData) ((IO_RESOURCE*)pData)
  310. class CResourceType : public CResultItem
  311. {
  312. public:
  313. CResourceType(CMachine* pMachine, RESOURCEID ResType);
  314. virtual CItemIdentifier* CreateIdentifier();
  315. CResource* GetChild()
  316. {
  317. return m_pChild;
  318. }
  319. CResourceType* GetSibling()
  320. {
  321. return m_pSibling;
  322. }
  323. CComputer* GetParent()
  324. {
  325. return m_pParent;
  326. }
  327. void SetChild(CResource* pRes)
  328. {
  329. m_pChild = pRes;
  330. }
  331. void SetParent(CComputer* pComp)
  332. {
  333. m_pParent = pComp;
  334. }
  335. void SetSibling(CResourceType* pResT)
  336. {
  337. m_pSibling = pResT;
  338. }
  339. RESOURCEID GetResType()
  340. {
  341. return m_ResType;
  342. }
  343. private:
  344. CResourceType(const CResourceType& resSrc);
  345. CResourceType& operator=(const CResourceType& resSrc);
  346. RESOURCEID m_ResType;
  347. CResource* m_pChild;
  348. CResourceType* m_pSibling;
  349. CComputer* m_pParent;
  350. };
  351. class CResourceList
  352. {
  353. public:
  354. CResourceList(CDevice* pDevice, RESOURCEID ResType,
  355. ULONG LogConfType = ALLOC_LOG_CONF, ULONG AltLogConfType = BOOT_LOG_CONF);
  356. CResourceList(CMachine* pMachine, RESOURCEID ResType,
  357. ULONG LogConfType = ALLOC_LOG_CONF, ULONG AltLogConfType = BOOT_LOG_CONF);
  358. ~CResourceList();
  359. int GetCount()
  360. {
  361. return m_listRes.GetCount();
  362. }
  363. BOOL GetFirst(CResource** ppRes, PVOID& pContext);
  364. BOOL GetNext(CResource** ppRes, PVOID& Context);
  365. BOOL CreateResourceTree(CResource** ppRoot);
  366. static BOOL ExtractResourceValue(RESOURCEID ResType, PVOID pData,
  367. DWORDLONG* pdlBase, DWORDLONG* pdlLen);
  368. private:
  369. BOOL InsertResourceToTree(CResource* pRes, CResource* pResRoot, BOOL ForcedInsert);
  370. CResourceList(const CResourceList& Src);
  371. CResourceList& operator=(const CResourceList& Src);
  372. void CreateSubtreeResourceList(CDevice* pDeviceStart, RESOURCEID ResType,
  373. ULONG LogConfType, ULONG AltLogConfType);
  374. CList<CResource*, CResource*> m_listRes;
  375. void InsertResourceToList(CResource* pRes);
  376. };
  377. class CItemIdentifier
  378. {
  379. public:
  380. CItemIdentifier()
  381. {}
  382. virtual ~CItemIdentifier()
  383. {}
  384. virtual BOOL operator==(CCookie& Cookie) = 0;
  385. };
  386. class CClassIdentifier : public CItemIdentifier
  387. {
  388. public:
  389. CClassIdentifier(CClass& Class)
  390. {
  391. m_Guid = (GUID&)Class;
  392. }
  393. virtual BOOL operator==(CCookie& Cookie)
  394. {
  395. return COOKIE_TYPE_RESULTITEM_CLASS == Cookie.GetType() &&
  396. IsEqualGUID(m_Guid, *((CClass*)Cookie.GetResultItem()));
  397. }
  398. private:
  399. GUID m_Guid;
  400. };
  401. class CDeviceIdentifier : public CItemIdentifier
  402. {
  403. public:
  404. CDeviceIdentifier(CDevice& Device)
  405. {
  406. ASSERT(Device.GetDeviceID());
  407. m_strDeviceId = Device.GetDeviceID();
  408. }
  409. virtual BOOL operator==(CCookie& Cookie)
  410. {
  411. return COOKIE_TYPE_RESULTITEM_DEVICE == Cookie.GetType() &&
  412. !lstrcmpi(m_strDeviceId, ((CDevice*)Cookie.GetResultItem())->GetDeviceID());
  413. }
  414. private:
  415. String m_strDeviceId;
  416. };
  417. class CResourceIdentifier : public CItemIdentifier
  418. {
  419. public:
  420. CResourceIdentifier(CResource& Res)
  421. {
  422. m_CookieType = CookieType(Res.ResType());
  423. m_strDisplayName = Res.GetDisplayName();
  424. }
  425. virtual BOOL operator==(CCookie& Cookie)
  426. {
  427. return m_CookieType == Cookie.GetType() &&
  428. !lstrcmpi((LPCTSTR)m_strDisplayName, Cookie.GetResultItem()->GetDisplayName());
  429. }
  430. private:
  431. COOKIE_TYPE m_CookieType;
  432. String m_strDisplayName;
  433. };
  434. class CResourceTypeIdentifier : public CItemIdentifier
  435. {
  436. public:
  437. CResourceTypeIdentifier(CResourceType& ResType)
  438. {
  439. m_ResType = ResType.GetResType();
  440. }
  441. virtual BOOL operator==(CCookie& Cookie)
  442. {
  443. return COOKIE_TYPE_RESULTITEM_RESTYPE == Cookie.GetType() &&
  444. m_ResType == ((CResourceType*)Cookie.GetResultItem())->GetResType();
  445. }
  446. private:
  447. RESOURCEID m_ResType;
  448. };
  449. class CComputerIdentifier : public CItemIdentifier
  450. {
  451. public:
  452. CComputerIdentifier(CComputer& Computer)
  453. {
  454. ASSERT(Computer.GetDisplayName());
  455. m_strName = Computer.GetDisplayName();
  456. }
  457. virtual BOOL operator==(CCookie& Cookie)
  458. {
  459. return COOKIE_TYPE_RESULTITEM_COMPUTER == Cookie.GetType() &&
  460. !lstrcmpi((LPCTSTR)m_strName, Cookie.GetResultItem()->GetDisplayName());
  461. }
  462. private:
  463. String m_strName;
  464. };
  465. #endif // __CNODE_H__