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.

128 lines
2.6 KiB

  1. // HMDataElementStatistics.cpp: implementation of the CHMDataElementStatistics class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "snapin.h"
  6. #include "HMDataElementStatistics.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. IMPLEMENT_DYNCREATE(CHMDataElementStatistics,CHMEvent)
  13. //////////////////////////////////////////////////////////////////////
  14. // Construction/Destruction
  15. //////////////////////////////////////////////////////////////////////
  16. CHMDataElementStatistics::CHMDataElementStatistics()
  17. {
  18. }
  19. CHMDataElementStatistics::~CHMDataElementStatistics()
  20. {
  21. for( int i = 0; i < m_PropStats.GetSize(); i++ )
  22. {
  23. delete m_PropStats[i];
  24. }
  25. m_PropStats.RemoveAll();
  26. Destroy();
  27. }
  28. //////////////////////////////////////////////////////////////////////
  29. // Create
  30. //////////////////////////////////////////////////////////////////////
  31. HRESULT CHMDataElementStatistics::Create(const CString& sMachineName)
  32. {
  33. HRESULT hr = CHMEvent::Create(sMachineName);
  34. if( !CHECKHRESULT(hr) )
  35. {
  36. return hr;
  37. }
  38. return hr;
  39. }
  40. HRESULT CHMDataElementStatistics::Create(IWbemClassObject* pObject)
  41. {
  42. HRESULT hr = CHMEvent::Create(pObject);
  43. if( !CHECKHRESULT(hr) )
  44. {
  45. return hr;
  46. }
  47. return hr;
  48. }
  49. //////////////////////////////////////////////////////////////////////
  50. // Property Retrieval Operations
  51. //////////////////////////////////////////////////////////////////////
  52. HRESULT CHMDataElementStatistics::GetAllProperties()
  53. {
  54. ASSERT(m_pIWbemClassObject);
  55. if( m_pIWbemClassObject == NULL )
  56. {
  57. ASSERT(FALSE);
  58. return S_FALSE;
  59. }
  60. HRESULT hr = S_OK;
  61. // Unique identifier
  62. hr = GetProperty(IDS_STRING_MOF_GUID,m_sGUID);
  63. m_sGUID.TrimLeft(_T("{"));
  64. m_sGUID.TrimRight(_T("}"));
  65. // DTime
  66. CTime time;
  67. hr = GetProperty(IDS_STRING_MOF_DTIME,time);
  68. time.GetAsSystemTime(m_st);
  69. CString sTime;
  70. int iLen = GetTimeFormat(LOCALE_USER_DEFAULT,0L,&m_st,NULL,NULL,0);
  71. iLen = GetTimeFormat(LOCALE_USER_DEFAULT,0L,&m_st,NULL,sTime.GetBuffer(iLen+(sizeof(TCHAR)*1)),iLen);
  72. sTime.ReleaseBuffer();
  73. m_sDateTime = sTime;
  74. // Statistics
  75. hr = GetProperty(IDS_STRING_MOF_STATISTICS,m_Statistics);
  76. long lLower = 0L;
  77. long lUpper = -1L;
  78. if( hr != S_FALSE )
  79. {
  80. m_Statistics.GetLBound(1L,&lLower);
  81. m_Statistics.GetUBound(1L,&lUpper);
  82. }
  83. for( long i = lLower; i <= lUpper; i++ )
  84. {
  85. IWbemClassObject* pIWBCO = NULL;
  86. m_Statistics.GetElement(&i,&pIWBCO);
  87. CHMPropertyStatus* pPS = new CHMPropertyStatus;
  88. pPS->Create(pIWBCO);
  89. pPS->GetAllProperties();
  90. m_PropStats.Add(pPS);
  91. pPS->Destroy();
  92. }
  93. m_Statistics.Destroy();
  94. m_Statistics.Detach();
  95. return hr;
  96. }