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.

149 lines
4.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: K K L O G . H
  7. //
  8. // Contents: Error logging for NetCfg components
  9. //
  10. // Notes:
  11. //
  12. // Author: kumarp 14 April 97 (09:22:00 pm)
  13. //
  14. // Notes:
  15. //----------------------------------------------------------------------------
  16. enum ENetCfgComponentType;
  17. // ----------------------------------------------------------------------
  18. // Class CLog
  19. //
  20. // Inheritance:
  21. // none
  22. //
  23. // Purpose:
  24. // Provides a way to log errors/warnings to
  25. // - NT EventLog
  26. // - NT SetupLog (setuperr.log / setupact.log)
  27. //
  28. // This class hides much of complexity of the EventLog API. In addition
  29. // the user of this class does not have to first check whether a EventSource
  30. // has been created in the registry. This class will create one if not found.
  31. // Also, it is not necessary to call (De)RegisterEventSource for each report.
  32. //
  33. // Messages are logged to SetupLog only during system install/upgrade
  34. // Message are always logged to the EventLog
  35. //
  36. // This class provides function interface that is closer to EventLog API
  37. // than to the SetupLog API. The EventLog parameter values are mapped to
  38. // corresponding SetupLog parameters using some helper functions.
  39. // See nclog.cpp for details.
  40. //
  41. // The members of this class do not return an error, because this itself is the
  42. // error reporting mechanism. However, the class has several Trace* functions.
  43. //
  44. // Hungarian: cl
  45. // ----------------------------------------------------------------------
  46. class CLog
  47. {
  48. public:
  49. CLog(ENetCfgComponentType nccType);
  50. ~CLog();
  51. void Initialize(IN ENetCfgComponentType nccType);
  52. void SetCategory(IN ENetCfgComponentType nccType) { m_nccType = nccType; }
  53. //Event Reporting functions
  54. void ReportEvent(IN WORD wType, IN DWORD dwEventID,
  55. IN WORD wNumStrings=0, IN PCWSTR* ppszStrings=NULL,
  56. IN DWORD dwBinaryDataNumBytes=0,
  57. IN PVOID pvBinaryData=NULL) const;
  58. void ReportEvent(IN WORD wType, IN DWORD dwEventID,
  59. IN WORD wNumStrings, ...) const;
  60. void ReportEvent(IN WORD wType, IN DWORD dwEventID,
  61. IN WORD wNumStrings, va_list arglist) const;
  62. void ReportError(DWORD dwEventID);
  63. void ReportWarning(DWORD dwEventID);
  64. private:
  65. static BOOL m_fNetSetupMode; // TRUE only during NT install/upgrade
  66. // this must be set by some external logic
  67. static PCWSTR m_pszEventSource;// EventLog source name
  68. BOOL m_fInitialized; // TRUE only if correctly initialized
  69. ENetCfgComponentType m_nccType; // Component category
  70. };
  71. inline void CLog::ReportError(DWORD dwEventID)
  72. {
  73. ReportEvent(EVENTLOG_ERROR_TYPE, dwEventID);
  74. }
  75. inline void CLog::ReportWarning(DWORD dwEventID)
  76. {
  77. ReportEvent(EVENTLOG_WARNING_TYPE, dwEventID);
  78. }
  79. // ----------------------------------------------------------------------
  80. // The wType parameter of ReportEvent can take any on of the following values
  81. //
  82. // - EVENTLOG_SUCCESS
  83. // - EVENTLOG_ERROR_TYPE
  84. // - EVENTLOG_WARNING_TYPE
  85. // - EVENTLOG_INFORMATION_TYPE
  86. // - EVENTLOG_AUDIT_SUCCESS
  87. // - EVENTLOG_AUDIT_FAILURE
  88. // ----------------------------------------------------------------------
  89. // Components categories. This decides which event-message-file to use
  90. // ----------------------------------------------------------------------
  91. enum ENetCfgComponentType
  92. {
  93. nccUnknown = 0,
  94. nccError,
  95. nccNetcfgBase,
  96. nccNWClientCfg,
  97. nccRasCli,
  98. nccRasSrv,
  99. nccRasRtr,
  100. nccRasNdisWan,
  101. nccRasPptp,
  102. nccNCPA,
  103. nccCompInst,
  104. nccMSCliCfg,
  105. nccSrvrCfg,
  106. nccNetUpgrade,
  107. nccNetSetup,
  108. nccDAFile,
  109. nccTcpip,
  110. nccAtmArps,
  111. nccAtmUni,
  112. nccLast
  113. };
  114. // ----------------------------------------------------------------------
  115. // These functions should normally be used by components that require
  116. // event reporting for different sub-components using different categories.
  117. //
  118. // For those components that report events only for a single component,
  119. // should probably create a global instance of CLog only once
  120. // and report thru that instance.
  121. // ----------------------------------------------------------------------
  122. void NcReportEvent(IN ENetCfgComponentType nccType,
  123. IN WORD wType, IN DWORD dwEventID,
  124. IN WORD wNumStrings, IN PCWSTR* ppszStrings,
  125. IN DWORD dwBinaryDataNumBytes,
  126. IN PVOID pvBinaryData);
  127. void NcReportEvent(IN ENetCfgComponentType nccType,
  128. IN WORD wType, IN DWORD dwEventID,
  129. IN WORD wNumStrings, ...);
  130. // ----------------------------------------------------------------------