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.

247 lines
6.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: statmon.cxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 3-20-96 srikants Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <pch.cxx>
  18. #pragma hdrstop
  19. #include <ciregkey.hxx>
  20. #include <statmon.hxx>
  21. #include <cievtmsg.h>
  22. #include <eventlog.hxx>
  23. #include <pathpars.hxx>
  24. //+---------------------------------------------------------------------------
  25. //
  26. // Member: CCiStatusMonitor::ReportInitFailure
  27. //
  28. // Synopsis:
  29. //
  30. // Arguments: [status] -
  31. //
  32. // Returns:
  33. //
  34. // Modifies:
  35. //
  36. // History: 3-20-96 srikants Created
  37. //
  38. // Notes:
  39. //
  40. //----------------------------------------------------------------------------
  41. void CCiStatusMonitor::ReportInitFailure()
  42. {
  43. Win4Assert( STATUS_SUCCESS != _status );
  44. if ( CI_CORRUPT_DATABASE == _status || CI_CORRUPT_CATALOG == _status )
  45. {
  46. LogEvent( eCorrupt, _status );
  47. }
  48. else
  49. {
  50. LogEvent( eInitFailed, _status );
  51. }
  52. _fDontLog = TRUE;
  53. }
  54. //+---------------------------------------------------------------------------
  55. //
  56. // Member: CCiStatusMonitor::ReportFailure
  57. //
  58. // Synopsis:
  59. //
  60. // Arguments: [status] -
  61. //
  62. // Returns:
  63. //
  64. // Modifies:
  65. //
  66. // History: 3-20-96 srikants Created
  67. //
  68. // Notes:
  69. //
  70. //----------------------------------------------------------------------------
  71. void CCiStatusMonitor::ReportFailure( NTSTATUS status )
  72. {
  73. if ( !_fDontLog )
  74. {
  75. if ( CI_CORRUPT_DATABASE == status || CI_CORRUPT_CATALOG == status )
  76. {
  77. LogEvent( eCorrupt, status );
  78. }
  79. else
  80. {
  81. LogEvent( eCiError, status );
  82. }
  83. _fDontLog = TRUE;
  84. }
  85. }
  86. //+---------------------------------------------------------------------------
  87. //
  88. // Member: CCiStatusMonitor::LogEvent
  89. //
  90. // Synopsis:
  91. //
  92. // Arguments: [type] -
  93. // [status] -
  94. //
  95. // Returns:
  96. //
  97. // Modifies:
  98. //
  99. // History: 3-20-96 srikants Created
  100. //
  101. // Notes:
  102. //
  103. //----------------------------------------------------------------------------
  104. void CCiStatusMonitor::LogEvent( EMessageType type, DWORD status, ULONG val )
  105. {
  106. TRY
  107. {
  108. USHORT nParams = 1;
  109. DWORD msgId;
  110. USHORT usLevel = EVENTLOG_WARNING_TYPE;
  111. switch ( type )
  112. {
  113. case eCorrupt:
  114. usLevel = EVENTLOG_ERROR_TYPE;
  115. msgId = MSG_CI_CORRUPT_INDEX_DOWNLEVEL;
  116. break;
  117. case eCIStarted:
  118. usLevel = EVENTLOG_INFORMATION_TYPE;
  119. msgId = MSG_CI_STARTED;
  120. break;
  121. case eInitFailed:
  122. usLevel = EVENTLOG_ERROR_TYPE;
  123. msgId = MSG_CI_INIT_INDEX_DOWNLEVEL_FAILED;
  124. nParams = 2;
  125. break;
  126. case eCiRemoved:
  127. usLevel = EVENTLOG_ERROR_TYPE;
  128. msgId = MSG_CI_CORRUPT_INDEX_DOWNLEVEL_REMOVED;
  129. break;
  130. case eCiError:
  131. usLevel = EVENTLOG_ERROR_TYPE;
  132. msgId = MSG_CI_INDEX_DOWNLEVEL_ERROR;
  133. nParams = 2;
  134. break;
  135. case ePropStoreRecoveryStart:
  136. usLevel = EVENTLOG_INFORMATION_TYPE;
  137. msgId = MSG_CI_PROPSTORE_RECOVERY_START;
  138. break;
  139. case ePropStoreRecoveryEnd:
  140. usLevel = EVENTLOG_INFORMATION_TYPE;
  141. msgId = MSG_CI_PROPSTORE_RECOVERY_COMPLETED;
  142. break;
  143. case ePropStoreError:
  144. usLevel = EVENTLOG_ERROR_TYPE;
  145. msgId = MSG_CI_PROPSTORE_INCONSISTENT;
  146. break;
  147. case ePropStoreRecoveryError:
  148. msgId = MSG_CI_PROPSTORE_RECOVERY_INCONSISTENT;
  149. nParams = 2;
  150. break;
  151. default:
  152. ciDebugOut(( DEB_IERROR, "Unknown message type. %d\n", type ));
  153. return;
  154. }
  155. CEventLog eventLog( NULL, wcsCiEventSource );
  156. CEventItem item( usLevel,
  157. CI_SERVICE_CATEGORY,
  158. msgId,
  159. nParams );
  160. switch (msgId)
  161. {
  162. case MSG_CI_CORRUPT_INDEX_DOWNLEVEL:
  163. case MSG_CI_CORRUPT_INDEX_DOWNLEVEL_REMOVED:
  164. case MSG_CI_PROPSTORE_INCONSISTENT:
  165. case MSG_CI_PROPSTORE_RECOVERY_START:
  166. case MSG_CI_PROPSTORE_RECOVERY_COMPLETED:
  167. case MSG_CI_STARTED:
  168. item.AddArg( _wcsCatDir );
  169. break;
  170. case MSG_CI_INIT_INDEX_DOWNLEVEL_FAILED:
  171. item.AddArg( _wcsCatDir );
  172. item.AddArg( status );
  173. break;
  174. case MSG_CI_INDEX_DOWNLEVEL_ERROR:
  175. item.AddArg( status );
  176. item.AddArg( _wcsCatDir );
  177. break;
  178. case MSG_CI_PROPSTORE_RECOVERY_INCONSISTENT:
  179. item.AddArg( val );
  180. item.AddArg( _wcsCatDir );
  181. break;
  182. default:
  183. Win4Assert( !"Impossible case stmt" );
  184. break;
  185. }
  186. eventLog.ReportEvent( item );
  187. }
  188. CATCH( CException,e )
  189. {
  190. ciDebugOut(( DEB_ERROR, "Exception 0x%X while writing to event log\n",
  191. e.GetErrorCode() ));
  192. }
  193. END_CATCH
  194. }
  195. void CCiStatusMonitor::ReportPathTooLong( WCHAR const * pwszPath )
  196. {
  197. TRY
  198. {
  199. CEventLog eventLog( NULL, wcsCiEventSource );
  200. CEventItem item( EVENTLOG_ERROR_TYPE,
  201. CI_SERVICE_CATEGORY,
  202. MSG_CI_PATH_TOO_LONG,
  203. 1 );
  204. item.AddArg( pwszPath );
  205. eventLog.ReportEvent( item );
  206. }
  207. CATCH( CException,e )
  208. {
  209. ciDebugOut(( DEB_ERROR, "Exception 0x%X while writing to event log\n",
  210. e.GetErrorCode() ));
  211. }
  212. END_CATCH
  213. }