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.

283 lines
6.1 KiB

  1. // SSRLog.h : Declaration of the CSSRLog
  2. #pragma once
  3. #include "resource.h" // main symbols
  4. #include "SSRTE.h"
  5. #include "wbemcli.h"
  6. /////////////////////////////////////////////////////////////////////////////
  7. // CSSRLog
  8. class ATL_NO_VTABLE CSsrLog :
  9. public CComObjectRootEx<CComSingleThreadModel>,
  10. public CComCoClass<CSsrLog, &CLSID_SsrLog>,
  11. public IDispatchImpl<ISsrLog, &IID_ISsrLog, &LIBID_SSRLib>
  12. {
  13. protected:
  14. CSsrLog();
  15. virtual ~CSsrLog();
  16. //
  17. // we don't want anyone (include self) to be able to do an assignment
  18. // or invoking copy constructor.
  19. //
  20. CSsrLog (const CSsrLog& );
  21. void operator = (const CSsrLog& );
  22. public:
  23. DECLARE_REGISTRY_RESOURCEID(IDR_SSRTENGINE)
  24. DECLARE_NOT_AGGREGATABLE(CSsrLog)
  25. DECLARE_PROTECT_FINAL_CONSTRUCT()
  26. BEGIN_COM_MAP(CSsrLog)
  27. COM_INTERFACE_ENTRY(ISsrLog)
  28. COM_INTERFACE_ENTRY(IDispatch)
  29. END_COM_MAP()
  30. // ISsrLog
  31. public:
  32. STDMETHOD(LogString) (
  33. IN BSTR bstrLogRecord
  34. )
  35. {
  36. return PrivateLogString(bstrLogRecord);
  37. }
  38. STDMETHOD(LogResult) (
  39. IN BSTR bstrSrc,
  40. IN LONG lErrorCode,
  41. IN LONG lErrorCodeType
  42. );
  43. STDMETHOD(get_LogFilePath) (
  44. OUT BSTR * pbstrLogFilePath
  45. );
  46. STDMETHOD(put_LogFile) (
  47. IN BSTR bstrLogFile
  48. );
  49. HRESULT PrivateLogString (
  50. IN LPCWSTR pwszLogRecord
  51. );
  52. HRESULT
  53. GetErrorText (
  54. IN LONG lErrorCode,
  55. IN LONG lCodeType,
  56. OUT BSTR * pbstrErrorText
  57. );
  58. private:
  59. HRESULT CreateLogFilePath ();
  60. HRESULT
  61. GetWbemErrorText (
  62. HRESULT hrCode,
  63. BSTR * pbstrErrText
  64. );
  65. CComPtr<IWbemStatusCodeText> m_srpStatusCodeText;
  66. CComBSTR m_bstrLogFilePath;
  67. CComBSTR m_bstrLogFile;
  68. };
  69. const LONG FBLog_Log = 0x01000000;
  70. //
  71. // these are for logging only, not for feedback. Please see SSR_FB_ALL_MASK
  72. //
  73. const LONG FBLog_Stack = 0x10000000; // for call stack only
  74. const LONG FBLog_Verbose = 0x20000000; // intended for verbose logging only
  75. const LONG FBLog_VerboseMask = 0xF0000000;
  76. //
  77. // helper class to do feedback and logging. We will only have one object
  78. // instance of this class.
  79. //
  80. class CFBLogMgr
  81. {
  82. protected:
  83. //
  84. // we don't want anyone (include self) to be able to do an assignment
  85. // or invoking copy constructor.
  86. //
  87. CFBLogMgr (const CFBLogMgr& );
  88. void operator = (const CFBLogMgr& );
  89. public:
  90. CFBLogMgr();
  91. ~CFBLogMgr();
  92. HRESULT SetFeedbackSink (
  93. IN VARIANT varSink
  94. );
  95. //
  96. // We will release the feedback object once the action
  97. // is completed instead of holding on to the object for
  98. // future use.
  99. //
  100. void TerminateFeedback();
  101. //
  102. // This will cause the logging header to be modified
  103. //
  104. void SetMemberAction (
  105. IN LPCWSTR pwszMember,
  106. IN LPCWSTR pwszAction
  107. );
  108. //
  109. // This will do both logging and feedback.
  110. //
  111. void LogFeedback (
  112. IN LONG lSsrFbLogMsg,
  113. IN DWORD dwErrorCode,
  114. IN LPCWSTR pwszObjDetail,
  115. IN ULONG uCauseResID
  116. );
  117. //
  118. // This will do both logging and feedback.
  119. //
  120. void LogFeedback (
  121. IN LONG lSsrFbLogMsg,
  122. IN LPCWSTR pwszError,
  123. IN LPCWSTR pwszObjDetail,
  124. IN ULONG uCauseResID
  125. );
  126. //
  127. // This only does logging, no feedback. The error code will
  128. // be used to lookup the error text (assuming this is not WBEM error)
  129. //
  130. void LogError (
  131. IN DWORD dwErrorCode,
  132. IN LPCWSTR pwszMember,
  133. IN LPCWSTR pwszExtraInfo
  134. );
  135. //
  136. // will return the ISsrLog object this helper class uses
  137. //
  138. HRESULT GetLogObject (
  139. OUT VARIANT * pvarVal
  140. );
  141. //
  142. // will just log the text to the log file
  143. //
  144. void LogString (
  145. IN LPCWSTR pwszText
  146. )
  147. {
  148. if (m_pLog != NULL)
  149. {
  150. m_pLog->PrivateLogString(pwszText);
  151. }
  152. }
  153. //
  154. // will just log the text (using resource id) with pwszDetail
  155. // inserted into the text (if not NULL)
  156. //
  157. void LogString (
  158. IN DWORD dwResID,
  159. IN LPCWSTR pwszDetail
  160. );
  161. //
  162. // entire process will take these many steps
  163. //
  164. void SetTotalSteps (
  165. IN DWORD dwTotal
  166. );
  167. //
  168. // progress has moved forward these many steps
  169. //
  170. void Steps (
  171. IN DWORD dwSteps
  172. );
  173. //
  174. // Since this is an internal class, we don't intend to create multiple
  175. // instance of this class. This mutex is thus a single instance
  176. //
  177. HANDLE m_hLogMutex;
  178. private:
  179. bool NeedLog (
  180. IN LONG lFbMsg
  181. )const
  182. {
  183. return ( m_pLog != NULL &&
  184. ( (lFbMsg & FBLog_Log) ||
  185. ( (lFbMsg & FBLog_VerboseMask) && m_bVerbose)
  186. )
  187. );
  188. }
  189. bool NeedFeedback (
  190. IN LONG lFbMsg
  191. )const
  192. {
  193. return ( (lFbMsg & SSR_FB_ALL_MASK) && (m_srpFeedback != NULL) );
  194. }
  195. HRESULT GetLogString (
  196. IN ULONG uCauseResID,
  197. IN LPCWSTR pwszText,
  198. IN LPCWSTR pwszObjDetail,
  199. IN LONG lSsrFbMsg,
  200. OUT BSTR * pbstrLogStr
  201. )const;
  202. HRESULT
  203. GetLogString (
  204. IN ULONG uCauseResID,
  205. IN DWORD dwErrorCode,
  206. IN LPCWSTR pwszObjDetail,
  207. IN LONG lSsrFbMsg,
  208. OUT BSTR * pbstrLogStr
  209. )const;
  210. CComObject<CSsrLog> * m_pLog;
  211. CComPtr<ISsrFeedbackSink> m_srpFeedback;
  212. DWORD m_dwRemainSteps;
  213. bool m_bVerbose;
  214. CComBSTR m_bstrVerboseHeading;
  215. };