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.

267 lines
12 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. HRESULT hRes = WBEM_S_NO_ERROR;
  63. REFPTRCOLLECTION_POSITION posList;
  64. // Instances
  65. CComPtr<IEnumWbemClassObject> pDeviceMemAddressEnumInst;
  66. CComPtr<IEnumWbemClassObject> pWin32AllocatedResourceEnumInst;
  67. // Objects
  68. IWbemClassObjectPtr pWin32AllocatedResourceObj;
  69. IWbemClassObjectPtr pDeviceMemAddressObj;
  70. // Variants
  71. CComVariant varAntecedent;
  72. CComVariant varDependent;
  73. CComVariant varStartingAddress;
  74. CComVariant varPNPEntity;
  75. // Query Strings
  76. CComBSTR bstrWin32AllocatedResourceQuery = L"Select Antecedent, Dependent FROM win32_Allocatedresource";
  77. CComBSTR bstrDeviceMemAddressQuery = L"Select StartingAddress, EndingAddress FROM Win32_DeviceMemoryAddress WHERE StartingAddress = ";
  78. CComBSTR bstrDeviceMemAddressQueryString;
  79. // Return Values;
  80. ULONG ulWin32AllocatedResourceRetVal = 0;
  81. ULONG ulDeviceMemAddressRetVal = 0;
  82. // Integers
  83. int i;
  84. int nStAddren;
  85. int nIter;
  86. // Pattern Strings
  87. LPCSTR strDeviceMemAddressPattern = "Win32_DeviceMemoryAddress.StartingAddress=";
  88. LPCSTR strPNPEntityPattern = "Win32_PnPEntity.DeviceID=";
  89. // Chars
  90. LPSTR strSource;
  91. LPSTR pDest;
  92. BOOL fValidInt;
  93. CComBSTR bstrPropertyAntecedent=L"Antecedent";
  94. CComBSTR bstrPropertyDependent=L"Dependent";
  95. // Enumerate the instances of Win32_PNPAllocatedResource
  96. hRes = ExecWQLQuery(&pWin32AllocatedResourceEnumInst, bstrWin32AllocatedResourceQuery);
  97. if (FAILED(hRes))
  98. {
  99. // Cannot get any properties.
  100. goto END;
  101. }
  102. // Query Succeeded
  103. while(WBEM_S_NO_ERROR == pWin32AllocatedResourceEnumInst->Next(WBEM_INFINITE, 1, &pWin32AllocatedResourceObj, &ulWin32AllocatedResourceRetVal))
  104. {
  105. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  106. // Starting Address //
  107. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  108. // Get the Antecedent Value
  109. hRes = pWin32AllocatedResourceObj->Get(bstrPropertyAntecedent, 0, &varAntecedent, NULL, NULL);
  110. if (FAILED(hRes))
  111. {
  112. // Could not get the antecedent
  113. ErrorTrace(TRACE_ID, "GetVariant on Win32_AllocatedResource:Antecedent Field failed.");
  114. }
  115. else
  116. {
  117. // Got the Antecedent. Search its value to see if it is a DeviceMemAddress.
  118. // varAntecedent set to antecedent. Copy this to bstrResult
  119. varAntecedent.ChangeType(VT_BSTR, NULL);
  120. {
  121. USES_CONVERSION;
  122. strSource = OLE2A(varAntecedent.bstrVal);
  123. }
  124. // Check if it is DeviceMemoryAddress by comparing with the known pattern of DeviceMemoryAddress.
  125. pDest = strstr(strSource,strDeviceMemAddressPattern);
  126. if(pDest != NULL)
  127. {
  128. // This is DeviceMemoryAddress Resource instance
  129. // Can get the Device Memory Starting Address
  130. // Advance the pointer to the end of the pattern so the pointer is
  131. // positioned at Starting Address
  132. pDest += lstrlen(strDeviceMemAddressPattern);
  133. // Formulate the Query String
  134. bstrDeviceMemAddressQueryString = bstrDeviceMemAddressQuery;
  135. bstrDeviceMemAddressQueryString.Append(pDest);
  136. // At this point the WQL Query can be used to get the win32_DeviceMemoryAddress Instance.
  137. // Added the following line because you need to clear the CComPtr before you query the second time.
  138. pDeviceMemAddressEnumInst = NULL;
  139. hRes = ExecWQLQuery(&pDeviceMemAddressEnumInst, bstrDeviceMemAddressQueryString);
  140. if (SUCCEEDED(hRes))
  141. {
  142. // Query Succeeded. Get the Instance Object
  143. if(WBEM_S_NO_ERROR == pDeviceMemAddressEnumInst->Next(WBEM_INFINITE, 1, &pDeviceMemAddressObj, &ulDeviceMemAddressRetVal))
  144. {
  145. // Create a new instance of PCH_ResourceMemRange Class based on the passed-in MethodContext
  146. CInstancePtr pPCHResourceMemRangeInstance(CreateNewInstance(pMethodContext), false);
  147. // Created a New Instance of PCH_ResourceMemRange Successfully.
  148. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  149. // StartingAddress //
  150. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  151. CopyProperty(pDeviceMemAddressObj, L"StartingAddress", pPCHResourceMemRangeInstance, pBase);
  152. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  153. // EndingAddress //
  154. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  155. CopyProperty(pDeviceMemAddressObj, L"EndingAddress", pPCHResourceMemRangeInstance, pEnd);
  156. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  157. // Name //
  158. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  159. // CopyProperty(pWin32AllocatedResourceObj, L"Dependent", pPCHResourceMemRangeInstance, pName);
  160. // Get the Dependent Value
  161. hRes = pWin32AllocatedResourceObj->Get(bstrPropertyDependent, 0, &varDependent, NULL, NULL);
  162. if (FAILED(hRes))
  163. {
  164. // Could not get the Dependent
  165. ErrorTrace(TRACE_ID, "GetVariant on Win32_AllocatedResource:Dependent Field failed.");
  166. }
  167. else
  168. {
  169. // Got the Dependent. Search its value to point to PNPEntity.
  170. // varDependent set to Dependent. Copy this to bstrResult
  171. varDependent.ChangeType(VT_BSTR, NULL);
  172. {
  173. USES_CONVERSION;
  174. strSource = OLE2A(varDependent.bstrVal);
  175. }
  176. // Search for Win32_PNPEntity Pattern.
  177. pDest = strstr(strSource,strPNPEntityPattern);
  178. if(pDest)
  179. {
  180. // Advance the pointer to point to the PNPEntity Name
  181. pDest += lstrlen(strPNPEntityPattern);
  182. // Copy the PNPEntity Name.....
  183. varPNPEntity = pDest;
  184. // Set the Name
  185. hRes = pPCHResourceMemRangeInstance->SetVariant(pName, varPNPEntity);
  186. if (FAILED(hRes))
  187. {
  188. ErrorTrace(TRACE_ID, "SetVariant on win32_AllocatedResource.IRQ Number Failed!");
  189. // Proceed Anyway
  190. }
  191. }
  192. }
  193. // All the properties in pPCHResourceMemRange are set
  194. hRes = pPCHResourceMemRangeInstance->Commit();
  195. if (FAILED(hRes))
  196. {
  197. // Cannot commit the Instance
  198. ErrorTrace(TRACE_ID, "Commit on Instance failed.");
  199. } // end of if FAILED(hRes)
  200. }
  201. } // end of Query Succeeded.
  202. } // end of if pDest != NULL
  203. } // end of else got the antecedent
  204. } //end of Allocated Resource Instances.
  205. END:
  206. TraceFunctLeave();
  207. return hRes ;
  208. // pInstance->SetVariant(pBase, <Property Value>);
  209. // pInstance->SetVariant(pCategory, <Property Value>);
  210. // pInstance->SetVariant(pTimeStamp, <Property Value>);
  211. // pInstance->SetVariant(pChange, <Property Value>);
  212. // pInstance->SetVariant(pEnd, <Property Value>);
  213. // pInstance->SetVariant(pMax, <Property Value>);
  214. // pInstance->SetVariant(pMin, <Property Value>);
  215. // pInstance->SetVariant(pName, <Property Value>);
  216. }