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.

254 lines
10 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. PCH_ResourceDMA.CPP
  5. Abstract:
  6. WBEM provider class implementation for PCH_ResourceDMA class
  7. Revision History:
  8. Ghim-Sim Chua (gschua) 04/27/99
  9. - Created
  10. ********************************************************************/
  11. #include "pchealth.h"
  12. #include "PCH_ResourceDMA.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_RESOURCEDMA
  22. CPCH_ResourceDMA MyPCH_ResourceDMASet (PROVIDER_NAME_PCH_RESOURCEDMA, PCH_NAMESPACE) ;
  23. // Property names
  24. //===============
  25. const static WCHAR* pCategory = L"Category" ;
  26. const static WCHAR* pTimeStamp = L"TimeStamp" ;
  27. const static WCHAR* pChange = L"Change" ;
  28. const static WCHAR* pChannel = L"Channel" ;
  29. const static WCHAR* pMask = L"Mask" ;
  30. const static WCHAR* pName = L"Name" ;
  31. /*****************************************************************************
  32. *
  33. * FUNCTION : CPCH_ResourceDMA::EnumerateInstances
  34. *
  35. * DESCRIPTION : Returns all the instances of this class.
  36. *
  37. * INPUTS : A pointer to the MethodContext for communication with WinMgmt.
  38. * A long that contains the flags described in
  39. * IWbemServices::CreateInstanceEnumAsync. Note that the following
  40. * flags are handled by (and filtered out by) WinMgmt:
  41. * WBEM_FLAG_DEEP
  42. * WBEM_FLAG_SHALLOW
  43. * WBEM_FLAG_RETURN_IMMEDIATELY
  44. * WBEM_FLAG_FORWARD_ONLY
  45. * WBEM_FLAG_BIDIRECTIONAL
  46. *
  47. * RETURNS : WBEM_S_NO_ERROR if successful
  48. *
  49. * COMMENTS : TO DO: All instances on the machine should be returned here.
  50. * If there are no instances, return WBEM_S_NO_ERROR.
  51. * It is not an error to have no instances.
  52. *
  53. *****************************************************************************/
  54. HRESULT CPCH_ResourceDMA::EnumerateInstances(
  55. MethodContext* pMethodContext,
  56. long lFlags
  57. )
  58. {
  59. TraceFunctEnter("CPCH_ResourceDMA::EnumerateInstances");
  60. HRESULT hRes = WBEM_S_NO_ERROR;
  61. REFPTRCOLLECTION_POSITION posList;
  62. // Instances
  63. CComPtr<IEnumWbemClassObject> pWin32AllocatedResourceEnumInst;
  64. // Objects
  65. IWbemClassObjectPtr pWin32AllocatedResourceObj;
  66. // Variants
  67. CComVariant varAntecedent;
  68. CComVariant varDependent;
  69. CComVariant varPNPEntity;
  70. CComVariant varDMANumber;
  71. // Query Strings
  72. CComBSTR bstrWin32AllocatedResourceQuery = L"Select Antecedent, Dependent FROM win32_Allocatedresource";
  73. // Return Values;
  74. ULONG ulWin32AllocatedResourceRetVal = 0;
  75. // Integers
  76. int i;
  77. int nDMALen;
  78. int nIter;
  79. // Pattern Strings
  80. LPCSTR strDMAPattern = "Win32_DMAChannel.DMAChannel=";
  81. LPCSTR strPNPEntityPattern = "Win32_PnPEntity.DeviceID=";
  82. // Chars
  83. LPSTR strSource;
  84. LPSTR pDest;
  85. BOOL fValidInt;
  86. CComBSTR bstrPropertyAntecedent=L"Antecedent";
  87. CComBSTR bstrPropertyDependent=L"Dependent";
  88. // Enumerate the instances of Win32_PNPAllocatedResource
  89. hRes = ExecWQLQuery(&pWin32AllocatedResourceEnumInst, bstrWin32AllocatedResourceQuery);
  90. if (FAILED(hRes))
  91. {
  92. // Cannot get any properties.
  93. goto END;
  94. }
  95. // Query Succeeded
  96. while(WBEM_S_NO_ERROR == pWin32AllocatedResourceEnumInst->Next(WBEM_INFINITE, 1, &pWin32AllocatedResourceObj, &ulWin32AllocatedResourceRetVal))
  97. {
  98. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  99. // DMA Value //
  100. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  101. // Get the Antecedent Value
  102. hRes = pWin32AllocatedResourceObj->Get(bstrPropertyAntecedent, 0, &varAntecedent, NULL, NULL);
  103. if (FAILED(hRes))
  104. {
  105. // Could not get the antecedent
  106. ErrorTrace(TRACE_ID, "GetVariant on Win32_AllocatedResource:Antecedent Field failed.");
  107. }
  108. else
  109. {
  110. // Got the Antecedent. Search its value to see if it is a IRQ Resource.
  111. // varAntecedent set to antecedent. Copy this to bstrResult
  112. varAntecedent.ChangeType(VT_BSTR, NULL);
  113. {
  114. USES_CONVERSION;
  115. strSource = OLE2A(varAntecedent.bstrVal);
  116. }
  117. // Check if it is DMA Resource by comparing with the known pattern of DMA Resource.
  118. pDest = strstr(strSource,strDMAPattern);
  119. if(pDest != NULL)
  120. {
  121. // This is DMA Resource instance
  122. // Can get the DMA ChannelNumber
  123. // Advance the pointer to the end of the pattern so the pointer is
  124. // positioned at DMA Channel Number
  125. pDest += lstrlen(strDMAPattern);
  126. // First verify that the given string is a valid integer.
  127. nDMALen = lstrlen(pDest);
  128. fValidInt = TRUE;
  129. for(nIter = 0; nIter <nDMALen; nIter++)
  130. {
  131. if (_istdigit(pDest[nIter]) == 0)
  132. {
  133. fValidInt = FALSE;
  134. break;
  135. }
  136. }
  137. if(fValidInt)
  138. {
  139. // Convert the DMA Channel Number that you get as string to a long
  140. varDMANumber = atol(pDest);
  141. // Create a new instance of PCH_ResourceDMA Class based on the passed-in MethodContext
  142. CInstancePtr pPCHResourceDMAInstance(CreateNewInstance(pMethodContext), false);
  143. // Created a New Instance of PCH_ResourceDMA Successfully.
  144. // Set the DMA Channel Number as a variant
  145. hRes = pPCHResourceDMAInstance->SetVariant(pChannel, varDMANumber);
  146. if (FAILED(hRes))
  147. {
  148. ErrorTrace(TRACE_ID, "SetVariant on PCH_ResourceDMA.Channel Failed!");
  149. // Proceed Anyway
  150. }
  151. // Copy the following properties from win32_AllocatedResource class Instance
  152. // TO PCH_ResourceDMA class Instance.
  153. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  154. // Name //
  155. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  156. // CopyProperty(pWin32AllocatedResourceObj, L"Dependent", pPCHResourceDMAInstance, pName);
  157. // Get the Dependent Value
  158. hRes = pWin32AllocatedResourceObj->Get(bstrPropertyDependent, 0, &varDependent, NULL, NULL);
  159. if (FAILED(hRes))
  160. {
  161. // Could not get the Dependent
  162. ErrorTrace(TRACE_ID, "GetVariant on Win32_AllocatedResource:Dependent Field failed.");
  163. }
  164. else
  165. {
  166. // Got the Dependent. Search its value to point to PNPEntity.
  167. // varDependent set to Dependent. Copy this to bstrResult
  168. varDependent.ChangeType(VT_BSTR, NULL);
  169. {
  170. USES_CONVERSION;
  171. strSource = OLE2A(varDependent.bstrVal);
  172. }
  173. // Search for Win32_PNPEntity Pattern.
  174. pDest = strstr(strSource,strPNPEntityPattern);
  175. if(pDest)
  176. {
  177. // Advance the pointer to point to the PNPEntity Name
  178. pDest += lstrlen(strPNPEntityPattern);
  179. // Copy the PNPEntity Name.....
  180. varPNPEntity = pDest;
  181. // Set the Name
  182. hRes = pPCHResourceDMAInstance->SetVariant(pName, varPNPEntity);
  183. if (FAILED(hRes))
  184. {
  185. ErrorTrace(TRACE_ID, "SetVariant on win32_AllocatedResource.IRQ Number Failed!");
  186. // Proceed Anyway
  187. }
  188. }
  189. }
  190. // All the properties in pPCHResourceDMAInstance are set
  191. hRes = pPCHResourceDMAInstance->Commit();
  192. if (FAILED(hRes))
  193. {
  194. // Cannot commit the Instance
  195. ErrorTrace(TRACE_ID, "Commit on Instance failed.");
  196. } // end of if FAILED(hRes)
  197. }
  198. } // end of if pDest != NULL
  199. else
  200. {
  201. // This is not DMA Resource
  202. } // end of else pDest != NULL
  203. } // end of else got the antecedent
  204. } //end of Allocated Resource Instances.
  205. END:
  206. TraceFunctLeave();
  207. return hRes ;
  208. }