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.

215 lines
8.6 KiB

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