AGCEventDef.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #ifndef __AGCEventDef_H_
  2. #define __AGCEventDef_H_
  3. /////////////////////////////////////////////////////////////////////////////
  4. // AGCEventDef.h : Declaration of the CAGCEventDef class.
  5. //
  6. /////////////////////////////////////////////////////////////////////////////
  7. // CAGCEventDef
  8. //
  9. class CAGCEventDef
  10. {
  11. // Construction / Destruction
  12. private:
  13. // A static instance is instantiated automatically upon startup
  14. CAGCEventDef();
  15. public:
  16. static void Initialize();
  17. static void Terminate();
  18. // Types
  19. public:
  20. typedef std::vector<BSTR> XParamStrings;
  21. struct XEventDef
  22. {
  23. AGCEventID m_id;
  24. int m_nIndent;
  25. LPCOLESTR m_pszName;
  26. LPCOLESTR m_pszEventDescription; // Use MAKEINTRESOURCE for string ID
  27. LPCOLESTR m_pszFormatDescription; // Use MAKEINTRESOURCE for string ID
  28. WORD m_wSeverity;
  29. bool m_bLogAsNTEvent : 1;
  30. bool m_bLogAsDBEvent : 1;
  31. };
  32. struct XParseData;
  33. typedef HRESULT (__fastcall *XStateProc)(XParseData&);
  34. struct XParseData
  35. {
  36. IAGCEvent* m_pEvent;
  37. IStream* m_pStm;
  38. XParamStrings* m_pParams;
  39. LPCOLESTR m_pszVarBegin;
  40. LPCOLESTR m_pszVarEnd;
  41. LPCOLESTR m_pszInput;
  42. XStateProc m_pfnNextState;
  43. bool m_bEndOfString;
  44. };
  45. protected:
  46. struct XLess :
  47. public std::binary_function<const XEventDef&, const XEventDef&, bool>
  48. {
  49. result_type operator()(first_argument_type a, second_argument_type b) const
  50. {
  51. return a.m_id < b.m_id;
  52. }
  53. };
  54. struct XLessName :
  55. public std::binary_function<const LPCOLESTR&, const LPCOLESTR&, bool>
  56. {
  57. result_type operator()(first_argument_type a, second_argument_type b) const
  58. {
  59. return _wcsicmp(a, b) < 0;
  60. }
  61. };
  62. typedef std::map<LPCOLESTR, AGCEventID, XLessName> XNameMap;
  63. typedef XNameMap::iterator XNameMapIt;
  64. // Attributes
  65. public:
  66. static const XEventDef* begin();
  67. static const XEventDef* end();
  68. static const XEventDef* find(AGCEventID idEvent);
  69. static HRESULT GetEventName (AGCEventID idEvent, BSTR* pbstrOut);
  70. static HRESULT GetEventDescription(AGCEventID idEvent, BSTR* pbstrOut);
  71. static HRESULT GetEventDescription(IAGCEvent* pEvent, BSTR* pbstrOut,
  72. const XEventDef* pDefHint = NULL);
  73. static HRESULT GetEventParameters (IAGCEvent* pEvent, XParamStrings&,
  74. const XEventDef* pDefHint = NULL);
  75. static bool IDFromName(LPCOLESTR pszEventName, AGCEventID& id);
  76. // Implementation
  77. public:
  78. static HRESULT GetString(LPCOLESTR psz, BSTR* pbstrOut);
  79. static HRESULT ExpandFmtString(BSTR bstrFmt, IAGCEvent* pEvent,
  80. BSTR* pbstrOut);
  81. static HRESULT ExpandParams(BSTR bstrFmt, IAGCEvent* pEvent,
  82. XParamStrings& rParams);
  83. protected:
  84. static HRESULT __fastcall ParseState_WriteInput(XParseData& data);
  85. static HRESULT __fastcall ParseState_WriteVar (XParseData& data);
  86. static HRESULT __fastcall ParseState_End (XParseData& data);
  87. static HRESULT __fastcall ParseState_Base (XParseData& data);
  88. static HRESULT __fastcall ParseState_InVar (XParseData& data);
  89. static HRESULT __fastcall ParseState_ProcessVar(XParseData& data);
  90. // Data Members
  91. protected:
  92. const static XEventDef s_EventDefs[];
  93. const static XEventDef* s_EventDefs_end;
  94. #pragma pack(push, 4)
  95. static LONG s_nInitSync;
  96. #pragma pack(pop)
  97. static bool s_bInitialized;
  98. static XNameMap* s_pNameMap;
  99. static CAGCEventDef s_Instance;
  100. };
  101. /////////////////////////////////////////////////////////////////////////////
  102. // Attributes
  103. inline
  104. const CAGCEventDef::XEventDef* CAGCEventDef::begin()
  105. {
  106. return s_EventDefs;
  107. }
  108. inline
  109. const CAGCEventDef::XEventDef* CAGCEventDef::end()
  110. {
  111. return s_EventDefs_end;
  112. }
  113. inline
  114. const CAGCEventDef::XEventDef* CAGCEventDef::find(AGCEventID idEvent)
  115. {
  116. XEventDef value = {idEvent};
  117. const XEventDef* it = std::lower_bound(begin(), end(), value, XLess());
  118. return (it != end() && !XLess()(value, *it)) ? it : end();
  119. }
  120. inline bool CAGCEventDef::IDFromName(LPCOLESTR pszEventName, AGCEventID& id)
  121. {
  122. Initialize();
  123. XNameMapIt it = s_pNameMap->find(pszEventName);
  124. if (s_pNameMap->end() == it)
  125. return false;
  126. id = it->second;
  127. return true;
  128. }
  129. /////////////////////////////////////////////////////////////////////////////
  130. #endif //__AGCEventDef_H_