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.

256 lines
7.3 KiB

  1. //=============================================================================
  2. // Contains the refresh function for the resource categories.
  3. //=============================================================================
  4. #include "stdafx.h"
  5. #include "category.h"
  6. #include "dataset.h"
  7. #include "wmiabstraction.h"
  8. #include "resourcemap.h"
  9. //
  10. // The compiler doesn't like this perfectly correct code:
  11. //
  12. // (dwIndex >= RESOURCE_DMA && dwIndex <= RESOURCE_MEM)
  13. //
  14. #pragma warning(disable:4296) // expression is always true/false
  15. //-----------------------------------------------------------------------------
  16. // The resource refreshing function handles all of the categories under the
  17. // resource subtree. It makes heavy use of the CResourceMap class to cache
  18. // values and speed up subsequent resource queries.
  19. //-----------------------------------------------------------------------------
  20. HRESULT ResourceCategories(CWMIHelper * pWMI, DWORD dwIndex, volatile BOOL * pfCancel, CPtrList * aColValues, int iColCount, void ** ppCache)
  21. {
  22. ASSERT(pWMI == NULL || aColValues);
  23. HRESULT hr = S_OK;
  24. if (ppCache)
  25. {
  26. if (pWMI && *ppCache == NULL)
  27. {
  28. *ppCache = (void *) new CResourceMap;
  29. if (*ppCache)
  30. {
  31. hr = ((CResourceMap *) *ppCache)->Initialize(pWMI);
  32. if (FAILED(hr))
  33. {
  34. delete ((CResourceMap *) *ppCache);
  35. *ppCache = (void *) NULL;
  36. }
  37. }
  38. }
  39. else if (pWMI == NULL && *ppCache)
  40. {
  41. delete ((CResourceMap *) *ppCache);
  42. return S_OK;
  43. }
  44. }
  45. CResourceMap * pResourceMap = (CResourceMap *) *ppCache;
  46. // This is a nice way to cache to resource map for multiple functions, but it's
  47. // a monumental pain when we remote to a different machine:
  48. //
  49. // CResourceMap * pResourceMap = gResourceMap.GetResourceMap(pWMI);
  50. // if (pResourceMap == NULL)
  51. // return hr;
  52. // Based on the index, we'll (probably) want to enumerate a resource category.
  53. if (dwIndex >= RESOURCE_DMA && dwIndex <= RESOURCE_MEM)
  54. {
  55. CString strClass;
  56. switch (dwIndex)
  57. {
  58. case RESOURCE_DMA:
  59. strClass = _T("Win32_DMAChannel");
  60. break;
  61. case RESOURCE_IRQ:
  62. strClass = _T("Win32_IRQResource");
  63. break;
  64. case RESOURCE_IO:
  65. strClass = _T("Win32_PortResource");
  66. break;
  67. case RESOURCE_MEM:
  68. strClass = _T("Win32_DeviceMemoryAddress");
  69. break;
  70. }
  71. CWMIObjectCollection * pCollection = NULL;
  72. hr = pWMI->Enumerate(strClass, &pCollection);
  73. if (SUCCEEDED(hr))
  74. {
  75. CWMIObject * pObject = NULL;
  76. CWMIObject * pDeviceObject = NULL;
  77. CString strDevicePath, strPath;
  78. CStringList * pDeviceList;
  79. while (S_OK == pCollection->GetNext(&pObject))
  80. {
  81. DWORD dwCaption = 0;
  82. switch (dwIndex)
  83. {
  84. case RESOURCE_DMA:
  85. pObject->GetValueDWORD(_T("DMAChannel"), &dwCaption);
  86. break;
  87. case RESOURCE_IRQ:
  88. pObject->GetValueDWORD(_T("IRQNumber"), &dwCaption);
  89. break;
  90. case RESOURCE_IO:
  91. pObject->GetValueDWORD(_T("StartingAddress"), &dwCaption);
  92. break;
  93. case RESOURCE_MEM:
  94. pObject->GetValueDWORD(_T("StartingAddress"), &dwCaption);
  95. break;
  96. }
  97. // Get the path for this resource (strip off machine stuff).
  98. strPath = pObject->GetString(_T("__PATH"));
  99. int i = strPath.Find(_T(":"));
  100. if (i != -1)
  101. strPath = strPath.Right(strPath.GetLength() - i - 1);
  102. // Look up the list of devices assigned to this resource.
  103. pDeviceList = pResourceMap->Lookup(strPath);
  104. if (pDeviceList)
  105. {
  106. for (POSITION pos = pDeviceList->GetHeadPosition(); pos != NULL;)
  107. {
  108. strDevicePath = pDeviceList->GetNext(pos);
  109. if (SUCCEEDED(pWMI->GetObject(strDevicePath, &pDeviceObject)))
  110. {
  111. pWMI->AppendCell(aColValues[1], pDeviceObject->GetString(_T("Caption")), 0);
  112. delete pDeviceObject;
  113. pDeviceObject = NULL;
  114. }
  115. else
  116. pWMI->AppendCell(aColValues[1], _T(""), 0);
  117. pWMI->AppendCell(aColValues[0], pObject->GetString(_T("Caption")), dwCaption);
  118. pWMI->AppendCell(aColValues[2], pObject->GetString(_T("Status")), 0);
  119. }
  120. }
  121. }
  122. delete pObject;
  123. delete pCollection;
  124. }
  125. }
  126. else if (dwIndex == RESOURCE_CONFLICTS && pResourceMap && !pResourceMap->m_map.IsEmpty())
  127. {
  128. // Scan through each element of the map.
  129. CString strKey;
  130. CStringList * plistStrings;
  131. CString strResourcePath;
  132. CString strDevicePath;
  133. CWMIObject * pResourceObject;
  134. CWMIObject * pDeviceObject;
  135. for (POSITION pos = pResourceMap->m_map.GetStartPosition(); pos != NULL;)
  136. {
  137. pResourceMap->m_map.GetNextAssoc(pos, strKey, (CObject*&) plistStrings);
  138. if (plistStrings)
  139. {
  140. // Check to see if there are more than one items associated with this one.
  141. if (plistStrings->GetCount() > 1)
  142. {
  143. // Then figure out if this is for a resource class. Just look for the
  144. // class name in the key.
  145. BOOL fResource = FALSE;
  146. if (strKey.Find(_T("Win32_IRQResource")) != -1)
  147. fResource = TRUE;
  148. else if (strKey.Find(_T("Win32_PortResource")) != -1)
  149. fResource = TRUE;
  150. else if (strKey.Find(_T("Win32_DMAChannel")) != -1)
  151. fResource = TRUE;
  152. else if (strKey.Find(_T("Win32_DeviceMemoryAddress")) != -1)
  153. fResource = TRUE;
  154. if (fResource)
  155. {
  156. CString strItem, strValue;
  157. // Get the name of this shared resource.
  158. strResourcePath = strKey;
  159. pResourceObject = NULL;
  160. hr = pWMI->GetObject(strResourcePath, &pResourceObject);
  161. if (SUCCEEDED(hr))
  162. {
  163. strItem.Empty();
  164. if (strKey.Find(_T("Win32_PortResource")) != -1)
  165. {
  166. strItem.LoadString(IDS_IOPORT);
  167. strItem += CString(_T(" "));
  168. }
  169. else if (strKey.Find(_T("Win32_DeviceMemoryAddress")) != -1)
  170. {
  171. strItem.LoadString(IDS_MEMORYADDRESS);
  172. strItem += CString(_T(" "));
  173. }
  174. CString strTemp;
  175. pResourceObject->GetValueString(_T("Caption"), &strTemp);
  176. if (!strTemp.IsEmpty())
  177. strItem += strTemp;
  178. delete pResourceObject;
  179. }
  180. for (POSITION pos = plistStrings->GetHeadPosition(); pos != NULL;)
  181. {
  182. strDevicePath = plistStrings->GetNext(pos);
  183. pDeviceObject = NULL;
  184. hr = pWMI->GetObject(strDevicePath, &pDeviceObject);
  185. if (SUCCEEDED(hr))
  186. {
  187. if (SUCCEEDED(pDeviceObject->GetValueString(_T("Caption"), &strValue)))
  188. {
  189. pWMI->AppendCell(aColValues[0], strItem, 0);
  190. pWMI->AppendCell(aColValues[1], strValue, 0);
  191. }
  192. delete pDeviceObject;
  193. }
  194. }
  195. pWMI->AppendBlankLine(aColValues, iColCount, FALSE);
  196. }
  197. }
  198. }
  199. }
  200. }
  201. else if (dwIndex == RESOURCE_FORCED)
  202. {
  203. CWMIObjectCollection * pCollection = NULL;
  204. hr = pWMI->Enumerate(_T("Win32_PnPEntity"), &pCollection, _T("Caption, PNPDeviceID, ConfigManagerUserConfig"));
  205. if (SUCCEEDED(hr))
  206. {
  207. CWMIObject * pObject = NULL;
  208. while (S_OK == pCollection->GetNext(&pObject))
  209. {
  210. DWORD dwUserConfig;
  211. if (SUCCEEDED(pObject->GetValueDWORD(_T("ConfigManagerUserConfig"), &dwUserConfig)))
  212. {
  213. if (dwUserConfig)
  214. {
  215. pWMI->AppendCell(aColValues[0], pObject->GetString(_T("Caption")), 0);
  216. pWMI->AppendCell(aColValues[1], pObject->GetString(_T("PNPDeviceID")), 0);
  217. }
  218. }
  219. }
  220. delete pObject;
  221. delete pCollection;
  222. }
  223. }
  224. return hr;
  225. }