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.

217 lines
8.8 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. PCH_ResourceMemRange.CPP
  5. Abstract:
  6. WBEM provider class implementation for PCH_ResourceMemRange class
  7. Revision History:
  8. Ghim-Sim Chua (gschua) 04/27/99
  9. - Created
  10. ********************************************************************/
  11. #include "pchealth.h"
  12. #include "PCH_ResourceMemRange.h"
  13. #include "confgmgr.h"
  14. /////////////////////////////////////////////////////////////////////////////
  15. // tracing stuff
  16. #ifdef THIS_FILE
  17. #undef THIS_FILE
  18. #endif
  19. static char __szTraceSourceFile[] = __FILE__;
  20. #define THIS_FILE __szTraceSourceFile
  21. #define TRACE_ID DCID_RESOURCEMEMRANGE
  22. CPCH_ResourceMemRange MyPCH_ResourceMemRangeSet (PROVIDER_NAME_PCH_RESOURCEMEMRANGE, PCH_NAMESPACE) ;
  23. // Property names
  24. //===============
  25. const static WCHAR* pBase = L"Base" ;
  26. const static WCHAR* pCategory = L"Category" ;
  27. const static WCHAR* pTimeStamp = L"TimeStamp" ;
  28. const static WCHAR* pChange = L"Change" ;
  29. const static WCHAR* pEnd = L"End" ;
  30. const static WCHAR* pMax = L"Max" ;
  31. const static WCHAR* pMin = L"Min" ;
  32. const static WCHAR* pName = L"Name" ;
  33. /*****************************************************************************
  34. *
  35. * FUNCTION : CPCH_ResourceMemRange::EnumerateInstances
  36. *
  37. * DESCRIPTION : Returns all the instances of this class.
  38. *
  39. * INPUTS : A pointer to the MethodContext for communication with WinMgmt.
  40. * A long that contains the flags described in
  41. * IWbemServices::CreateInstanceEnumAsync. Note that the following
  42. * flags are handled by (and filtered out by) WinMgmt:
  43. * WBEM_FLAG_DEEP
  44. * WBEM_FLAG_SHALLOW
  45. * WBEM_FLAG_RETURN_IMMEDIATELY
  46. * WBEM_FLAG_FORWARD_ONLY
  47. * WBEM_FLAG_BIDIRECTIONAL
  48. *
  49. * RETURNS : WBEM_S_NO_ERROR if successful
  50. *
  51. * COMMENTS : TO DO: All instances on the machine should be returned here.
  52. * If there are no instances, return WBEM_S_NO_ERROR.
  53. * It is not an error to have no instances.
  54. *
  55. *****************************************************************************/
  56. HRESULT CPCH_ResourceMemRange::EnumerateInstances(
  57. MethodContext* pMethodContext,
  58. long lFlags
  59. )
  60. {
  61. TraceFunctEnter("CPCH_ResourceIRQ::EnumerateInstances");
  62. CConfigManager cfgManager;
  63. CDeviceCollection deviceList;
  64. HRESULT hRes = WBEM_S_NO_ERROR;
  65. //
  66. // Get the date and time
  67. //
  68. SYSTEMTIME stUTCTime;
  69. GetSystemTime(&stUTCTime);
  70. // get the device list
  71. if (cfgManager.GetDeviceList(deviceList))
  72. {
  73. REFPTR_POSITION pos;
  74. // Initialize device enumerator
  75. if (deviceList.BeginEnum(pos))
  76. {
  77. CConfigMgrDevice* pDevice = NULL;
  78. try
  79. {
  80. // Walk the list of devices
  81. while ((NULL != (pDevice = deviceList.GetNext(pos))))
  82. {
  83. CDeviceMemoryCollection memList;
  84. try
  85. {
  86. // Get DMAChannel list for this device
  87. if (pDevice->GetDeviceMemoryResources(memList))
  88. {
  89. REFPTR_POSITION pos2;
  90. // Initialize DMA enumerator
  91. if (memList.BeginEnum(pos2))
  92. {
  93. CDeviceMemoryDescriptor *pMem = NULL;
  94. // Walk the list of DMA
  95. while (( NULL != (pMem = memList.GetNext(pos2))))
  96. {
  97. try
  98. {
  99. // Create a new instance based on the passed-in MethodContext
  100. CInstancePtr pInstance(CreateNewInstance(pMethodContext), false);
  101. CHString chstrVar;
  102. CComVariant varValue;
  103. TCHAR strTemp[64];
  104. // Timestamp
  105. if (!pInstance->SetDateTime(pTimeStamp, WBEMTime(stUTCTime)))
  106. ErrorTrace(TRACE_ID, "SetDateTime on Timestamp Field failed.");
  107. // Snapshot
  108. if (!pInstance->SetCHString(pChange, L"Snapshot"))
  109. ErrorTrace(TRACE_ID, "SetCHString on Change Field failed.");
  110. // Name
  111. if (pDevice->GetDeviceID(chstrVar))
  112. if (!pInstance->SetCHString(pName, chstrVar))
  113. ErrorTrace(TRACE_ID, "SetCHString on Name field failed.");
  114. // Category
  115. if (pDevice->GetClass(chstrVar))
  116. if (!pInstance->SetCHString(pCategory, chstrVar))
  117. ErrorTrace(TRACE_ID, "SetCHString on Category field failed.");
  118. // Base
  119. _stprintf(strTemp, "x%I64X", pMem->GetBaseAddress());
  120. varValue = strTemp;
  121. if (!pInstance->SetVariant(pBase, varValue))
  122. ErrorTrace(TRACE_ID, "SetVariant on Base field failed.");
  123. // End
  124. _stprintf(strTemp, "x%I64X", pMem->GetEndAddress());
  125. varValue = strTemp;
  126. if (!pInstance->SetVariant(pEnd, varValue))
  127. ErrorTrace(TRACE_ID, "SetVariant on End field failed.");
  128. /*
  129. // Alias
  130. varValue = (long)pMem->GetAlias();
  131. if (!pInstance->SetVariant(pAlias, varValue))
  132. ErrorTrace(TRACE_ID, "SetVariant on Alias field failed.");
  133. // Decode
  134. varValue = (long)pMem->GetDecode();
  135. if (!pInstance->SetVariant(pDecode, varValue))
  136. ErrorTrace(TRACE_ID, "SetVariant on Decode field failed.");
  137. */
  138. // Commit this
  139. hRes = pInstance->Commit();
  140. if (FAILED(hRes))
  141. ErrorTrace(TRACE_ID, "Commit on Instance failed.");
  142. }
  143. catch (...)
  144. {
  145. pMem->Release();
  146. throw;
  147. }
  148. // release the DMA object
  149. pMem->Release();
  150. }
  151. }
  152. }
  153. }
  154. catch (...)
  155. {
  156. pDevice->Release();
  157. memList.EndEnum();
  158. throw;
  159. }
  160. // GetNext() AddRefs
  161. pDevice->Release();
  162. // Always call EndEnum(). For all Beginnings, there must be an End
  163. memList.EndEnum();
  164. }
  165. }
  166. catch (...)
  167. {
  168. deviceList.EndEnum();
  169. throw;
  170. }
  171. // Always call EndEnum(). For all Beginnings, there must be an End
  172. deviceList.EndEnum();
  173. }
  174. }
  175. TraceFunctLeave();
  176. return hRes ;
  177. // pInstance->SetVariant(pBase, <Property Value>);
  178. // pInstance->SetVariant(pCategory, <Property Value>);
  179. // pInstance->SetVariant(pTimeStamp, <Property Value>);
  180. // pInstance->SetVariant(pChange, <Property Value>);
  181. // pInstance->SetVariant(pEnd, <Property Value>);
  182. // pInstance->SetVariant(pMax, <Property Value>);
  183. // pInstance->SetVariant(pMin, <Property Value>);
  184. // pInstance->SetVariant(pName, <Property Value>);
  185. }