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.

185 lines
4.9 KiB

  1. /*++
  2. Copyright (C) 1999-2001 Microsoft Corporation
  3. Module Name:
  4. ADAPPERF.H
  5. Abstract:
  6. History:
  7. --*/
  8. // Use this guy to build a map of index to display name from a localized
  9. // Name Database At this time, it just brute forces a class and a flex
  10. // array, but could be modified to use an STL map just as easily.
  11. #ifndef __ADAPPERF_H__
  12. #define __ADAPPERF_H__
  13. #include <wbemcomn.h>
  14. #include "adapelem.h"
  15. #include "ntreg.h"
  16. #include "perfthrd.h"
  17. #include "perflibschema.h"
  18. // Registry definitions
  19. // ====================
  20. #define ADAP_PERFLIB_STATUS_KEY L"WbemAdapStatus"
  21. #define ADAP_PERFLIB_SIGNATURE L"WbemAdapFileSignature"
  22. #define ADAP_PERFLIB_SIZE L"WbemAdapFileSize"
  23. #define ADAP_PERFLIB_TIME L"WbemAdapFileTime"
  24. #define KNOWN_SERVICES L"KnownSvcs"
  25. #define ADAP_TIMESTAMP_FULL L"LastFullDredgeTimestamp"
  26. #define ADAP_PERFLIB_LASTCHANCE 3L
  27. #define ADAP_PERFLIB_BOOBOO 2L
  28. #define ADAP_PERFLIB_PROCESSING 1L
  29. #define ADAP_PERFLIB_OK 0L
  30. #define ADAP_PERFLIB_CORRUPT -1L
  31. // Run time definitions
  32. // ====================
  33. #define ADAP_PERFLIB_IS_OK 0x0000L
  34. #define ADAP_PERFLIB_IS_CORRUPT 0x0001L
  35. #define ADAP_PERFLIB_IS_INACTIVE 0x0002L
  36. #define ADAP_PERFLIB_FAILED 0x0004L
  37. #define ADAP_PERFLIB_PREVIOUSLY_PROCESSED 0x0008L
  38. #define ADAP_PERFLIB_IS_LOADED 0x0010L
  39. #define ADAP_PERFLIB_IS_UNAVAILABLE ADAP_PERFLIB_IS_CORRUPT | ADAP_PERFLIB_IS_INACTIVE // | ADAP_PERFLIB_IS_UNLOADED
  40. // others
  41. // the library has NO FirstCounter/LastCounter key
  42. #define EX_STATUS_UNLOADED 0
  43. // the library has al least FirstCounter/LastCounter key
  44. #define EX_STATUS_LOADABLE 1
  45. // the library has a Collect Function that fails
  46. #define EX_STATUS_COLLECTFAIL 2
  47. typedef struct tagCheckLibStruct {
  48. BYTE Signature[16];
  49. FILETIME FileTime;
  50. DWORD FileSize;
  51. } CheckLibStruct;
  52. class CAdapSafeBuffer
  53. {
  54. HANDLE m_hPerfLibHeap; // A handle to the private heap for the data block
  55. CHAR* m_pGuardBytes;
  56. DWORD m_dwGuardSize;
  57. BYTE* m_pRawBuffer;
  58. BYTE* m_pSafeBuffer;
  59. DWORD m_dwSafeBufferSize;
  60. BYTE* m_pCurrentPtr;
  61. DWORD m_dwDataBlobSize;
  62. DWORD m_dwNumObjects;
  63. HRESULT ValidateSafePointer( BYTE* pPtr );
  64. WString m_wstrServiceName;
  65. public:
  66. CAdapSafeBuffer( WString wstrServiceName );
  67. virtual ~CAdapSafeBuffer();
  68. HRESULT SetSize( DWORD dwNumBytes );
  69. HRESULT Validate(BOOL * pSentToEventLog);
  70. HRESULT CopyData( BYTE** ppData, DWORD* pdwNumBytes, DWORD* pdwNumObjects );
  71. void** GetSafeBufferPtrPtr() { m_pCurrentPtr = m_pSafeBuffer; return (void**) &m_pCurrentPtr; }
  72. DWORD* GetDataBlobSizePtr() { m_dwDataBlobSize = m_dwSafeBufferSize; return &m_dwDataBlobSize; }
  73. DWORD* GetNumObjTypesPtr() {m_dwNumObjects = 0; return &m_dwNumObjects; }
  74. };
  75. class CPerfThread;
  76. class CPerfLibSchema;
  77. class CAdapPerfLib : public CAdapElement
  78. {
  79. private:
  80. CPerfThread* m_pPerfThread;
  81. BOOL m_EventLogCalled;
  82. BOOL m_CollectOK;
  83. WString m_wstrServiceName; // The service name of the perflib
  84. WCHAR* m_pwcsLibrary; // The file name of the perflib
  85. WCHAR* m_pwcsOpenProc; // The name of the perflib's open function
  86. WCHAR* m_pwcsCollectProc; // The name of the perflib's collect function
  87. WCHAR* m_pwcsCloseProc; // The name of the perflib's close function
  88. PM_OPEN_PROC* m_pfnOpenProc; // The function pointer to the perflib's open function
  89. PM_COLLECT_PROC* m_pfnCollectProc; // The function pointer to the perflib's collect function
  90. PM_CLOSE_PROC* m_pfnCloseProc; // The function pointer to the perflib's close function
  91. HANDLE m_hPLMutex; // Used for serializing the calls to open/collect/close
  92. HRESULT m_dwStatus; // The status of the perflib
  93. BOOL m_fOK;
  94. BOOL m_fOpen; // Flags whether the perflib's open function has been called
  95. HINSTANCE m_hLib; // The handle to the perflib
  96. HRESULT Load(void);
  97. protected:
  98. HRESULT InitializeEntryPoints(CNTRegistry & reg,WString & wszRegPath);
  99. HRESULT BeginProcessingStatus();
  100. HRESULT EndProcessingStatus();
  101. HRESULT GetFileSignature( CheckLibStruct * pCheckLib );
  102. HRESULT SetFileSignature();
  103. HRESULT CheckFileSignature();
  104. HRESULT VerifyLoaded();
  105. public:
  106. CAdapPerfLib( LPCWSTR pwcsServiceName, DWORD * pLoadStatus );
  107. ~CAdapPerfLib();
  108. HRESULT _Open( void );
  109. HRESULT _Close( void );
  110. HRESULT _GetPerfBlock( PERF_OBJECT_TYPE** ppData, DWORD* pdwBytes, DWORD* pdwNumObjTypes, BOOL fCostly );
  111. HRESULT Initialize();
  112. HRESULT Close();
  113. HRESULT Cleanup();
  114. BOOL IsOK( void )
  115. {
  116. return m_fOK;
  117. }
  118. LPCWSTR GetServiceName( void )
  119. {
  120. return m_wstrServiceName;
  121. }
  122. LPCWSTR GetLibraryName( void )
  123. {
  124. return m_pwcsLibrary;
  125. }
  126. HRESULT GetBlob( PERF_OBJECT_TYPE** ppPerfBlock, DWORD* pdwNumBytes, DWORD* pdwNumObjects, BOOL fCostly );
  127. HRESULT SetStatus( DWORD dwStatus );
  128. HRESULT ClearStatus( DWORD dwStatus );
  129. BOOL CheckStatus( DWORD dwStatus );
  130. BOOL IsCollectOK( void ){ return m_CollectOK; };
  131. BOOL GetEventLogCalled(){ return m_EventLogCalled; };
  132. void SetEventLogCalled(BOOL bVal){ m_EventLogCalled = bVal; };
  133. };
  134. #endif