Source code of Windows XP (NT5)
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.

199 lines
4.1 KiB

  1. // HMSystemStatus.cpp: implementation of the CHMSystemStatus class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "snapin.h"
  6. #include "HMSystemStatus.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. IMPLEMENT_DYNCREATE(CHMSystemStatus,CHMEvent)
  13. //////////////////////////////////////////////////////////////////////
  14. // Construction/Destruction
  15. //////////////////////////////////////////////////////////////////////
  16. CHMSystemStatus::CHMSystemStatus()
  17. {
  18. m_iNumberWarnings = 0; // Number of Rules currently in critical state
  19. m_iNumberCriticals = 0;// Number of Rules currently in warning state
  20. m_iState = 2; // The state we are in - rollup from all Microsoft_HMDataGroups.
  21. }
  22. CHMSystemStatus::~CHMSystemStatus()
  23. {
  24. for( int i = 0; i < m_DGStatus.GetSize(); i++ )
  25. {
  26. delete m_DGStatus[i];
  27. }
  28. m_DGStatus.RemoveAll();
  29. for( i = 0; i < m_RolledUpRuleStatus.GetSize(); i++ )
  30. {
  31. if( GfxCheckObjPtr(m_RolledUpRuleStatus[i],CHMEvent) )
  32. {
  33. delete m_RolledUpRuleStatus[i];
  34. }
  35. }
  36. m_RolledUpRuleStatus.RemoveAll();
  37. Destroy();
  38. }
  39. //////////////////////////////////////////////////////////////////////
  40. // Create
  41. //////////////////////////////////////////////////////////////////////
  42. HRESULT CHMSystemStatus::Create(const CString& sMachineName)
  43. {
  44. HRESULT hr = CWbemClassObject::Create(sMachineName);
  45. if( !CHECKHRESULT(hr) )
  46. {
  47. return hr;
  48. }
  49. // create the enumerator for Microsoft_HMSystemStatus object instances
  50. BSTR bsClass = SysAllocString(_T("Microsoft_HMSystemStatus"));
  51. hr = CreateEnumerator(bsClass);
  52. SysFreeString(bsClass);
  53. if( !CHECKHRESULT(hr) )
  54. {
  55. return hr;
  56. }
  57. return hr;
  58. }
  59. HRESULT CHMSystemStatus::Create(IWbemClassObject* pObject)
  60. {
  61. HRESULT hr = CWbemClassObject::Create(pObject);
  62. if( !CHECKHRESULT(hr) )
  63. {
  64. return hr;
  65. }
  66. return hr;
  67. }
  68. //////////////////////////////////////////////////////////////////////
  69. // Enumeration Operations
  70. //////////////////////////////////////////////////////////////////////
  71. HRESULT CHMSystemStatus::EnumerateObjects(ULONG& uReturned)
  72. {
  73. // call GetNextObject to proceed to the next object instance
  74. HRESULT hr = GetNextObject(uReturned);
  75. if( FAILED(hr) || uReturned != 1 )
  76. {
  77. // no more instances
  78. return hr;
  79. }
  80. ASSERT(m_pIWbemClassObject);
  81. if( m_pIWbemClassObject == NULL )
  82. {
  83. ASSERT(0);
  84. return S_FALSE;
  85. }
  86. // process the properties of this object
  87. hr = GetAllProperties();
  88. return hr;
  89. }
  90. //////////////////////////////////////////////////////////////////////
  91. // Property Retrieval Operations
  92. //////////////////////////////////////////////////////////////////////
  93. HRESULT CHMSystemStatus::GetAllProperties()
  94. {
  95. ASSERT(m_pIWbemClassObject);
  96. if( m_pIWbemClassObject == NULL )
  97. {
  98. ASSERT(FALSE);
  99. return S_FALSE;
  100. }
  101. HRESULT hr = S_OK;
  102. // Name
  103. hr = GetLocaleStringProperty(IDS_STRING_MOF_NAME,m_sName);
  104. // NumberNormals
  105. hr = GetProperty(IDS_STRING_MOF_NUMBERNORMALS,m_iNumberNormals);
  106. // NumberWarnings
  107. hr = GetProperty(IDS_STRING_MOF_NUMBERWARNINGS,m_iNumberWarnings);
  108. // NumberCriticals
  109. hr = GetProperty(IDS_STRING_MOF_NUMBERCRITICALS,m_iNumberCriticals);
  110. // State
  111. hr = GetProperty(IDS_STRING_MOF_STATE,m_iState);
  112. // DataGroups
  113. hr = GetProperty(IDS_STRING_MOF_DATAGROUPS,m_DataGroups);
  114. long lLower = 0L;
  115. long lUpper = -1L;
  116. if( hr != S_FALSE )
  117. {
  118. m_DataGroups.GetLBound(1L,&lLower);
  119. m_DataGroups.GetUBound(1L,&lUpper);
  120. }
  121. for( long i = lLower; i <= lUpper; i++ )
  122. {
  123. IWbemClassObject* pIWBCO = NULL;
  124. m_DataGroups.GetElement(&i,&pIWBCO);
  125. CHMDataGroupStatus* pDGS = new CHMDataGroupStatus;
  126. pDGS->SetParent(this);
  127. pDGS->m_sSystemName = m_sSystemName;
  128. pDGS->Create(pIWBCO);
  129. pDGS->GetAllProperties();
  130. m_DGStatus.Add(pDGS);
  131. }
  132. return hr;
  133. }
  134. void CHMSystemStatus::RemoveStatusEvent(CHMEvent* pEvent)
  135. {
  136. for( int i = 0; i < m_RolledUpRuleStatus.GetSize(); i++ )
  137. {
  138. if( pEvent == m_RolledUpRuleStatus[i] )
  139. {
  140. m_RolledUpRuleStatus.RemoveAt(i);
  141. break;
  142. }
  143. }
  144. for( i = 0; i < m_DGStatus.GetSize(); i++ )
  145. {
  146. m_DGStatus[i]->RemoveStatusEvent(pEvent);
  147. }
  148. }