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.

193 lines
7.4 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. PCH_ResourceIRQ.CPP
  5. Abstract:
  6. WBEM provider class implementation for PCH_ResourceIRQ class
  7. Revision History:
  8. Ghim-Sim Chua (gschua) 04/27/99
  9. - Created
  10. ********************************************************************/
  11. #include "pchealth.h"
  12. #include "PCH_ResourceIRQ.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_RESOURCEIRQ
  22. CPCH_ResourceIRQ MyPCH_ResourceIRQSet (PROVIDER_NAME_PCH_RESOURCEIRQ, 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* pMask = L"Mask" ;
  29. const static WCHAR* pName = L"Name" ;
  30. const static WCHAR* pValue = L"Value" ;
  31. /*****************************************************************************
  32. *
  33. * FUNCTION : CPCH_ResourceIRQ::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_ResourceIRQ::EnumerateInstances(
  55. MethodContext* pMethodContext,
  56. long lFlags
  57. )
  58. {
  59. TraceFunctEnter("CPCH_ResourceIRQ::EnumerateInstances");
  60. CConfigManager cfgManager;
  61. CDeviceCollection deviceList;
  62. HRESULT hRes = WBEM_S_NO_ERROR;
  63. //
  64. // Get the date and time
  65. //
  66. SYSTEMTIME stUTCTime;
  67. GetSystemTime(&stUTCTime);
  68. // get the device list
  69. if (cfgManager.GetDeviceList(deviceList))
  70. {
  71. REFPTR_POSITION pos;
  72. // Initialize device enumerator
  73. if (deviceList.BeginEnum(pos))
  74. {
  75. CConfigMgrDevice* pDevice = NULL;
  76. try
  77. {
  78. // Walk the list of devices
  79. while ((NULL != (pDevice = deviceList.GetNext(pos))))
  80. {
  81. CIRQCollection irqList;
  82. try
  83. {
  84. // Get DMAChannel list for this device
  85. if (pDevice->GetIRQResources(irqList))
  86. {
  87. REFPTR_POSITION pos2;
  88. // Initialize DMA enumerator
  89. if (irqList.BeginEnum(pos2))
  90. {
  91. CIRQDescriptor *pIRQ = NULL;
  92. // Walk the list of DMA
  93. while (( NULL != (pIRQ = irqList.GetNext(pos2))))
  94. {
  95. try
  96. {
  97. // Create a new instance based on the passed-in MethodContext
  98. CInstancePtr pInstance(CreateNewInstance(pMethodContext), false);
  99. CHString chstrVar;
  100. CComVariant varValue;
  101. // Timestamp
  102. if (!pInstance->SetDateTime(pTimeStamp, WBEMTime(stUTCTime)))
  103. ErrorTrace(TRACE_ID, "SetDateTime on Timestamp Field failed.");
  104. // Snapshot
  105. if (!pInstance->SetCHString(pChange, L"Snapshot"))
  106. ErrorTrace(TRACE_ID, "SetCHString on Change Field failed.");
  107. // Name
  108. if (pDevice->GetDeviceID(chstrVar))
  109. if (!pInstance->SetCHString(pName, chstrVar))
  110. ErrorTrace(TRACE_ID, "SetCHString on Name field failed.");
  111. // Category
  112. if (pDevice->GetClass(chstrVar))
  113. if (!pInstance->SetCHString(pCategory, chstrVar))
  114. ErrorTrace(TRACE_ID, "SetCHString on Category field failed.");
  115. // Value
  116. varValue = (long)pIRQ->GetInterrupt();
  117. if (!pInstance->SetVariant(pValue, varValue))
  118. ErrorTrace(TRACE_ID, "SetVariant on Value field failed.");
  119. // Mask
  120. varValue = (long)pIRQ->GetFlags();
  121. if (!pInstance->SetVariant(pMask, varValue))
  122. ErrorTrace(TRACE_ID, "SetVariant on Mask field failed.");
  123. // Commit this
  124. hRes = pInstance->Commit();
  125. if (FAILED(hRes))
  126. ErrorTrace(TRACE_ID, "Commit on Instance failed.");
  127. }
  128. catch (...)
  129. {
  130. pIRQ->Release();
  131. throw;
  132. }
  133. // release the DMA object
  134. pIRQ->Release();
  135. }
  136. }
  137. }
  138. }
  139. catch (...)
  140. {
  141. pDevice->Release();
  142. irqList.EndEnum();
  143. throw;
  144. }
  145. // GetNext() AddRefs
  146. pDevice->Release();
  147. // Always call EndEnum(). For all Beginnings, there must be an End
  148. irqList.EndEnum();
  149. }
  150. }
  151. catch (...)
  152. {
  153. deviceList.EndEnum();
  154. throw;
  155. }
  156. // Always call EndEnum(). For all Beginnings, there must be an End
  157. deviceList.EndEnum();
  158. }
  159. }
  160. TraceFunctLeave();
  161. return hRes ;
  162. }