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.

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