Source code of Windows XP (NT5)
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.

558 lines
13 KiB

  1. #ifndef __CNODE_H__
  2. #define __CNODE_H__
  3. /*++
  4. Copyright (C) 1997-1999 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. BOOL operator ==(CDevice& OtherDevice);
  141. CDevice* GetChild()
  142. {
  143. return m_pChild;
  144. }
  145. CDevice* GetParent()
  146. {
  147. return m_pParent;
  148. }
  149. CDevice* GetSibling()
  150. {
  151. return m_pSibling;
  152. }
  153. void SetChild(CDevice* pDevice)
  154. {
  155. m_pChild = pDevice;
  156. }
  157. void SetParent(CDevice* pDevice)
  158. {
  159. m_pParent = pDevice;
  160. }
  161. void SetSibling(CDevice* pDevice)
  162. {
  163. m_pSibling = pDevice;
  164. }
  165. CClass* GetClass()
  166. {
  167. return m_pClass;
  168. }
  169. virtual DEVNODE GetDevNode()
  170. {
  171. return m_DevData.DevInst;
  172. }
  173. LPCTSTR GetDeviceID() const
  174. {
  175. return (m_strDeviceID.IsEmpty()) ? NULL : (LPCTSTR)m_strDeviceID;
  176. }
  177. void SetClass(CClass* pClass)
  178. {
  179. m_pClass = pClass;
  180. }
  181. BOOL IsHidden();
  182. BOOL IsPhantom();
  183. BOOL NoShowInDM();
  184. BOOL IsPCMCIA();
  185. BOOL IsPCIDevice();
  186. BOOL IsPnpDevice();
  187. BOOL IsBiosDevice();
  188. BOOL GetMFG(TCHAR* pBuffer, DWORD Size, DWORD* pRequiredSize)
  189. {
  190. return m_pMachine->DiGetDeviceMFGString(&m_DevData, pBuffer, Size, pRequiredSize);
  191. }
  192. virtual CItemIdentifier* CreateIdentifier();
  193. CDevice* FindMFParent();
  194. HICON LoadClassIcon();
  195. BOOL GetStatus(DWORD* pStatus, DWORD* pProblem);
  196. BOOL GetCapabilities(DWORD* pCapabilities);
  197. BOOL GetPowerCapabilities(DWORD* pCapabilities);
  198. BOOL IsRAW();
  199. BOOL IsUninstallable();
  200. BOOL IsDisableable();
  201. BOOL IsDisabled();
  202. BOOL IsStateDisabled();
  203. BOOL IsStarted();
  204. BOOL IsMFChild();
  205. BOOL IsSpecialMFChild();
  206. BOOL HasProblem();
  207. BOOL NeedsRestart();
  208. BOOL GetConfigFlags(DWORD* pFlags);
  209. BOOL GetConfigSpecificConfigFlags(DWORD* pCSStatus);
  210. BOOL GetKnownLogConf(LOG_CONF* plc, DWORD* plcType);
  211. BOOL HasResources();
  212. void GetMFGString(String& strMFG);
  213. void GetProviderString(String& strMFG);
  214. void GetDriverDateString(String& strMFG);
  215. void GetDriverVersionString(String& strMFG);
  216. LPCTSTR GetClassDisplayName();
  217. void ClassGuid(GUID& ClassGuid)
  218. {
  219. ASSERT(m_pClass);
  220. ClassGuid = *m_pClass;
  221. }
  222. BOOL NoChangeUsage();
  223. CDriver* CreateDriver();
  224. BOOL HasDrivers();
  225. DWORD EnableDisableDevice(HWND hDlg, BOOL Enabling);
  226. void PropertyChanged();
  227. CPropSheetData m_psd;
  228. BOOL m_bLaunchTroubleShooter;
  229. private:
  230. CDevice(const CDevice& DeviceSrc);
  231. CDevice& operator=(const CDevice& DeviceSrc);
  232. CDevice* m_pParent;
  233. CDevice* m_pSibling;
  234. CDevice* m_pChild;
  235. String m_strDeviceID;
  236. SP_DEVINFO_DATA m_DevData;
  237. CClass* m_pClass;
  238. };
  239. class CComputer : public CDevice
  240. {
  241. public:
  242. CComputer(CMachine* pMachine, DEVNODE dnRoot);
  243. virtual DEVNODE GetDevNode()
  244. {
  245. return m_dnRoot;
  246. }
  247. virtual CItemIdentifier* CreateIdentifier();
  248. private:
  249. DEVNODE m_dnRoot;
  250. CComputer(const CComputer& ComputerSrc);
  251. CComputer& operator=(const CComputer& ComputerSrc);
  252. };
  253. class CResource : public CResultItem
  254. {
  255. public:
  256. CResource(CDevice* pDevice, RESOURCEID ResType, DWORDLONG dlBase, DWORDLONG dlLen,
  257. BOOL Forced, BOOL Free = FALSE);
  258. BOOL IsForced()
  259. {
  260. return m_Forced;
  261. }
  262. void GetValue(DWORDLONG* pdlBase, DWORDLONG* pdlLen) const
  263. {
  264. ASSERT(pdlBase && pdlLen);
  265. *pdlBase = m_dlBase;
  266. *pdlLen = m_dlLen;
  267. }
  268. virtual CItemIdentifier* CreateIdentifier();
  269. void GetRangeString(String& strRange);
  270. LPCTSTR GetViewName()
  271. {
  272. return (LPCTSTR)m_strViewName;
  273. }
  274. CDevice* GetDevice()
  275. {
  276. return m_pDevice;
  277. }
  278. CResource* GetChild()
  279. {
  280. return m_pChild;
  281. }
  282. CResource* GetSibling()
  283. {
  284. return m_pSibling;
  285. }
  286. CResource* GetParent()
  287. {
  288. return m_pParent;
  289. }
  290. void SetChild(CResource* pRes)
  291. {
  292. m_pChild = pRes;
  293. }
  294. void SetParent(CResource* pRes)
  295. {
  296. m_pParent = pRes;
  297. }
  298. void SetSibling(CResource* pRes)
  299. {
  300. m_pSibling = pRes;
  301. }
  302. BOOL operator <=(const CResource& resSrc);
  303. BOOL SameRange(const CResource& resSrc);
  304. BOOL EnclosedBy(const CResource& resSrc);
  305. RESOURCEID ResType()
  306. {
  307. return m_ResType;
  308. }
  309. CDevice* m_pDevice; // BUGBUG - this should not be public
  310. private:
  311. CResource(const CResource& resSrc);
  312. CResource& operator=(const CResource& resSrc);
  313. RESOURCEID m_ResType;
  314. DWORDLONG m_dlBase;
  315. DWORDLONG m_dlEnd;
  316. DWORDLONG m_dlLen;
  317. BOOL m_Forced;
  318. CResource* m_pChild;
  319. CResource* m_pSibling;
  320. CResource* m_pParent;
  321. // COOKIE_TYPE m_CookieType;
  322. BOOL m_Allocated;
  323. String m_strViewName;
  324. };
  325. #define pIRQResData(pData) ((IRQ_RESOURCE*)pData)
  326. #define pDMAResData(pData) ((DMA_RESOURCE*)pData)
  327. #define pMemResData(pData) ((MEM_RESOURCE*)pData)
  328. #define pIOResData(pData) ((IO_RESOURCE*)pData)
  329. class CResourceType : public CResultItem
  330. {
  331. public:
  332. CResourceType(CMachine* pMachine, RESOURCEID ResType);
  333. virtual CItemIdentifier* CreateIdentifier();
  334. CResource* GetChild()
  335. {
  336. return m_pChild;
  337. }
  338. CResourceType* GetSibling()
  339. {
  340. return m_pSibling;
  341. }
  342. CComputer* GetParent()
  343. {
  344. return m_pParent;
  345. }
  346. void SetChild(CResource* pRes)
  347. {
  348. m_pChild = pRes;
  349. }
  350. void SetParent(CComputer* pComp)
  351. {
  352. m_pParent = pComp;
  353. }
  354. void SetSibling(CResourceType* pResT)
  355. {
  356. m_pSibling = pResT;
  357. }
  358. RESOURCEID GetResType()
  359. {
  360. return m_ResType;
  361. }
  362. private:
  363. CResourceType(const CResourceType& resSrc);
  364. CResourceType& operator=(const CResourceType& resSrc);
  365. RESOURCEID m_ResType;
  366. CResource* m_pChild;
  367. CResourceType* m_pSibling;
  368. CComputer* m_pParent;
  369. };
  370. class CResourceList
  371. {
  372. public:
  373. CResourceList(CDevice* pDevice, RESOURCEID ResType,
  374. ULONG LogConfType = ALLOC_LOG_CONF, ULONG AltLogConfType = BOOT_LOG_CONF);
  375. CResourceList(CMachine* pMachine, RESOURCEID ResType,
  376. ULONG LogConfType = ALLOC_LOG_CONF, ULONG AltLogConfType = BOOT_LOG_CONF);
  377. ~CResourceList();
  378. int GetCount()
  379. {
  380. return m_listRes.GetCount();
  381. }
  382. BOOL GetFirst(CResource** ppRes, PVOID& pContext);
  383. BOOL GetNext(CResource** ppRes, PVOID& Context);
  384. BOOL CreateResourceTree(CResource** ppRoot);
  385. static BOOL ExtractResourceValue(RESOURCEID ResType, PVOID pData,
  386. DWORDLONG* pdlBase, DWORDLONG* pdlLen);
  387. private:
  388. BOOL InsertResourceToTree(CResource* pRes, CResource* pResRoot, BOOL ForcedInsert);
  389. CResourceList(const CResourceList& Src);
  390. CResourceList& operator=(const CResourceList& Src);
  391. void CreateSubtreeResourceList(CDevice* pDeviceStart, RESOURCEID ResType,
  392. ULONG LogConfType, ULONG AltLogConfType);
  393. CList<CResource*, CResource*> m_listRes;
  394. void InsertResourceToList(CResource* pRes);
  395. #define pIRQResData(pData) ((IRQ_RESOURCE*)pData)
  396. #define pDMAResData(pData) ((DMA_RESOURCE*)pData)
  397. #define pMemResData(pData) ((MEM_RESOURCE*)pData)
  398. #define pIOResData(pData) ((IO_RESOURCE*)pData)
  399. };
  400. class CItemIdentifier
  401. {
  402. public:
  403. CItemIdentifier()
  404. {}
  405. virtual ~CItemIdentifier()
  406. {}
  407. virtual BOOL operator==(CCookie& Cookie) = 0;
  408. };
  409. class CClassIdentifier : public CItemIdentifier
  410. {
  411. public:
  412. CClassIdentifier(CClass& Class)
  413. {
  414. m_Guid = (GUID&)Class;
  415. }
  416. virtual BOOL operator==(CCookie& Cookie)
  417. {
  418. return COOKIE_TYPE_RESULTITEM_CLASS == Cookie.GetType() &&
  419. IsEqualGUID(m_Guid, *((CClass*)Cookie.GetResultItem()));
  420. }
  421. private:
  422. GUID m_Guid;
  423. };
  424. class CDeviceIdentifier : public CItemIdentifier
  425. {
  426. public:
  427. CDeviceIdentifier(CDevice& Device)
  428. {
  429. ASSERT(Device.GetDeviceID());
  430. m_strDeviceId = Device.GetDeviceID();
  431. }
  432. virtual BOOL operator==(CCookie& Cookie)
  433. {
  434. return COOKIE_TYPE_RESULTITEM_DEVICE == Cookie.GetType() &&
  435. !lstrcmpi(m_strDeviceId, ((CDevice*)Cookie.GetResultItem())->GetDeviceID());
  436. }
  437. private:
  438. String m_strDeviceId;
  439. };
  440. class CResourceIdentifier : public CItemIdentifier
  441. {
  442. public:
  443. CResourceIdentifier(CResource& Res)
  444. {
  445. m_CookieType = CookieType(Res.ResType());
  446. m_strDisplayName = Res.GetDisplayName();
  447. }
  448. virtual BOOL operator==(CCookie& Cookie)
  449. {
  450. return m_CookieType == Cookie.GetType() &&
  451. !lstrcmpi((LPCTSTR)m_strDisplayName, Cookie.GetResultItem()->GetDisplayName());
  452. }
  453. private:
  454. COOKIE_TYPE m_CookieType;
  455. String m_strDisplayName;
  456. };
  457. class CResourceTypeIdentifier : public CItemIdentifier
  458. {
  459. public:
  460. CResourceTypeIdentifier(CResourceType& ResType)
  461. {
  462. m_ResType = ResType.GetResType();
  463. }
  464. virtual BOOL operator==(CCookie& Cookie)
  465. {
  466. return COOKIE_TYPE_RESULTITEM_RESTYPE == Cookie.GetType() &&
  467. m_ResType == ((CResourceType*)Cookie.GetResultItem())->GetResType();
  468. }
  469. private:
  470. RESOURCEID m_ResType;
  471. };
  472. class CComputerIdentifier : public CItemIdentifier
  473. {
  474. public:
  475. CComputerIdentifier(CComputer& Computer)
  476. {
  477. ASSERT(Computer.GetDisplayName());
  478. m_strName = Computer.GetDisplayName();
  479. }
  480. virtual BOOL operator==(CCookie& Cookie)
  481. {
  482. return COOKIE_TYPE_RESULTITEM_COMPUTER == Cookie.GetType() &&
  483. !lstrcmpi((LPCTSTR)m_strName, Cookie.GetResultItem()->GetDisplayName());
  484. }
  485. private:
  486. String m_strName;
  487. };
  488. #endif // __CNODE_H__