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.

118 lines
2.7 KiB

  1. // ReportEvent.h
  2. // This module contains helpers for the WMIReportEvent function.
  3. #pragma once
  4. #include "NCObjApi.h"
  5. #include <wstlallc.h>
  6. #include <map>
  7. class CReportParams
  8. {
  9. public:
  10. CReportParams(LPCWSTR szName, LPCWSTR szFormat)
  11. {
  12. m_szName = szName;
  13. m_szFormat = szFormat;
  14. }
  15. bool operator < (const CReportParams& other) const
  16. {
  17. return m_szName < other.m_szName && m_szFormat < other.m_szFormat;
  18. }
  19. bool operator == (const CReportParams& other) const
  20. {
  21. return m_szName == other.m_szName && m_szFormat == other.m_szFormat;
  22. }
  23. bool IsEquivalent(const CReportParams& other) const
  24. {
  25. // The format string is case-senstive due to printf format characters.
  26. return !_wcsicmp(m_szName, other.m_szName) &&
  27. !wcscmp(m_szFormat, other.m_szFormat);
  28. }
  29. protected:
  30. LPCWSTR m_szName;
  31. LPCWSTR m_szFormat;
  32. };
  33. class CReportItem
  34. {
  35. public:
  36. CReportItem( )
  37. : m_szName( NULL ),
  38. m_szFormat( NULL ),
  39. m_hEvent( NULL )
  40. {
  41. }
  42. ~CReportItem()
  43. {
  44. if (m_szName)
  45. free(m_szName);
  46. if (m_szFormat)
  47. free(m_szFormat);
  48. if (m_hEvent)
  49. WmiDestroyObject(m_hEvent);
  50. }
  51. BOOL Initialize( LPCWSTR szName, LPCWSTR szFormat, HANDLE hEvent )
  52. {
  53. if ( szName && szFormat && hEvent )
  54. {
  55. m_szName = _wcsdup(szName);
  56. if ( NULL == m_szName )
  57. {
  58. return FALSE;
  59. }
  60. m_szFormat = _wcsdup(szFormat);
  61. if ( NULL == m_szFormat )
  62. {
  63. return FALSE;
  64. }
  65. m_hEvent = hEvent;
  66. return TRUE;
  67. }
  68. return FALSE;
  69. }
  70. HANDLE GetEvent() { return m_hEvent; }
  71. protected:
  72. LPWSTR m_szName;
  73. LPWSTR m_szFormat;
  74. HANDLE m_hEvent;
  75. };
  76. class CReportEventMap : protected std::map< CReportParams,
  77. CReportItem*,
  78. std::less< CReportParams >,
  79. wbem_allocator< CReportItem* > >
  80. {
  81. public:
  82. ~CReportEventMap();
  83. HANDLE GetEvent(
  84. HANDLE hConnection,
  85. LPCWSTR szName,
  86. LPCWSTR szFormat);
  87. HANDLE CreateEvent(
  88. HANDLE hConnection,
  89. LPCWSTR szName,
  90. DWORD dwFlags,
  91. LPCWSTR szFormat);
  92. protected:
  93. typedef CReportEventMap::iterator CReportEventMapIterator;
  94. static CIMTYPE PrintfTypeToCimType(LPCWSTR szType);
  95. };