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.

130 lines
2.9 KiB

  1. ////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2000, Microsoft Corporation.
  4. //
  5. // All rights reserved.
  6. //
  7. // Module Name:
  8. //
  9. // WMI_perf.cpp
  10. //
  11. // Abstract:
  12. //
  13. // Defines common helpers for conversion
  14. // Works with table structure for objects ( init, refresh )
  15. //
  16. // History:
  17. //
  18. // initial a-marius
  19. //
  20. ////////////////////////////////////////////////////////////////////////////////////
  21. #include "precomp.h"
  22. #include "WMI_perf_data.h"
  23. // debuging features
  24. #ifndef _INC_CRTDBG
  25. #include <crtdbg.h>
  26. #endif _INC_CRTDBG
  27. // new stores file/line info
  28. #ifdef _DEBUG
  29. #ifndef NEW
  30. #define NEW new( _NORMAL_BLOCK, __FILE__, __LINE__ )
  31. #define new NEW
  32. #endif NEW
  33. #endif _DEBUG
  34. #include "wmi_perf_struct.h"
  35. #include <pshpack8.h>
  36. #pragma pack ( push, 8 )
  37. ////////////////////////////////////////////////////////////////////////////////////
  38. // Initialize WINDOWS PERFORMANCE table struct from internal structure
  39. ////////////////////////////////////////////////////////////////////////////////////
  40. HRESULT WmiPerformanceData::InitializeTable ( void )
  41. {
  42. try
  43. {
  44. m_dwDataTable = ( m_dwCount * ObjectSize ) +
  45. SizeSize +
  46. CountSize +
  47. RealSize;
  48. if ( ( m_pDataTable = (BYTE*) malloc ( m_dwDataTable ) ) != NULL )
  49. {
  50. __SetValue ( m_pDataTable, m_dwDataTable, offsetSize );
  51. __SetValue ( m_pDataTable, m_dwCount, offsetCount );
  52. __SetValue ( m_pDataTable, 0, offsetRealSize );
  53. for ( DWORD dw = 0; dw < m_dwCount; dw++ )
  54. {
  55. __SetValue ( m_pDataTable, dw, offsetObject + ( dw * ( ObjectSize ) + offIndex ) );
  56. __SetValue ( m_pDataTable, m_Ord2Ind[dw], offsetObject + ( dw * ( ObjectSize ) + offCounter ) );
  57. __SetValue ( m_pDataTable, 0, offsetObject + ( dw * ( ObjectSize ) + offOffset ) );
  58. __SetValue ( m_pDataTable, 0, offsetObject + ( dw * ( ObjectSize ) + offValidity ) );
  59. }
  60. }
  61. }
  62. catch ( ... )
  63. {
  64. return E_UNEXPECTED;
  65. }
  66. return S_OK;
  67. }
  68. HRESULT WmiPerformanceData::RefreshTable ( void )
  69. {
  70. DWORD offset = 0;
  71. DWORD realsize = 0;
  72. DWORD realcount = 0;
  73. for ( DWORD dw = 0; dw < m_dwCount; dw++ )
  74. {
  75. if ( __GetValue ( m_pDataTable,
  76. offsetObject + ( dw * ( ObjectSize ) + offValidity )
  77. )
  78. == ( DWORD ) -1
  79. )
  80. {
  81. __SetValue ( m_pDataTable,
  82. ( DWORD ) -1,
  83. offsetObject + ( dw * ( ObjectSize ) + offOffset )
  84. );
  85. }
  86. else
  87. {
  88. __SetValue ( m_pDataTable,
  89. realsize,
  90. offsetObject + ( dw * ( ObjectSize ) + offOffset )
  91. );
  92. if ( data.Read ( &offset, sizeof ( DWORD ), NULL, realsize ) == TRUE )
  93. {
  94. realsize += offset;
  95. realcount++;
  96. }
  97. }
  98. }
  99. // set num of objects
  100. __SetValue ( m_pDataTable,
  101. m_dwCount,
  102. offsetCount
  103. );
  104. // set real size
  105. __SetValue ( m_pDataTable,
  106. realsize,
  107. offsetRealSize
  108. );
  109. return S_OK;
  110. }
  111. #pragma pack ( pop )
  112. #include <poppack.h>