00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #if !defined(AFX_ERRORHANDLER_H__B886D5A4_FD2D_4CB8_8459_7311CBE31B77__INCLUDED_)
00037 #define AFX_ERRORHANDLER_H__B886D5A4_FD2D_4CB8_8459_7311CBE31B77__INCLUDED_
00038
00039 #if _MSC_VER > 1000
00040 #pragma once
00041 #endif // _MSC_VER > 1000
00042
00043 #include "KomodiaSettings.h"
00044
00045 #include <string>
00046 #include <map>
00047
00048 KOMODIA_NAMESPACE_START
00049
00050 class CErrorHandler
00051 {
00052 public:
00053
00054 class CErrorLog
00055 {
00056 friend class CErrorHandler;
00057 public:
00058
00059
00060 void SetAutoFlush(BOOL bFlush);
00061 BOOL GetAutoFlush()const;
00062
00063
00064 CErrorLog& operator=(const CErrorLog& rLog);
00065
00066
00067 CErrorLog();
00068 CErrorLog(const CErrorLog& rLog);
00069 virtual ~CErrorLog();
00070 protected:
00071
00072 virtual void WriteError(const std::string& rError)=0;
00073
00074
00075 virtual void WriteMessage(const std::string& rMessage)=0;
00076 private:
00077
00078 BOOL m_bAutoFlush;
00079 };
00080 public:
00081
00082
00083
00084
00085 static CErrorHandler* GetSecondaryLog();
00086
00087
00088 static CErrorHandler* GetThirdLog();
00089
00090
00091 static void ClearStaticLogs();
00092
00093
00094 static std::string GetCurrentDateTime();
00095
00096
00097 static std::string ErrorCodeToString(DWORD dwErrorCode);
00098
00099
00100 static void RegisterError(DWORD dwErrorCode,
00101 const std::string& rDescription);
00102
00103
00104 void SetLocalLog(CErrorLog* pLog,
00105 bool bWriteToMain=false);
00106
00107
00108 static void SetLog(CErrorLog* pLog);
00109
00110
00111 void WriteError(const std::string& rClass,
00112 const std::string& rMethod,
00113 const std::string& rError)const;
00114
00115
00116 static void WriteStaticError(const std::string& rClass,
00117 const std::string& rMethod,
00118 const std::string& rError);
00119
00120
00121 void WriteMessage(const std::string& rClass,
00122 const std::string& rMethod,
00123 const std::string& rMessage)const;
00124
00125
00126 static void WriteStaticMessage(const std::string& rClass,
00127 const std::string& rMethod,
00128 const std::string& rMessage);
00129
00130
00131 static std::string FormatData(const std::string& rClass,
00132 const std::string& rMethod,
00133 const std::string& rMsgOrError,
00134 bool bError=true);
00135
00136
00137 CErrorHandler();
00138 CErrorHandler(const CErrorHandler& rHandler);
00139 virtual ~CErrorHandler();
00140 protected:
00141
00142 const std::string& GetClassName()const;
00143
00144
00145 void WriteMessage(const std::string& rMethod,
00146 const std::string& rMessage)const;
00147
00148
00149
00150 static void ReportStaticError(const std::string& rClass,
00151 const std::string& rMethod);
00152
00153
00154 static void ReportStaticError(const std::string& rClass,
00155 const std::string& rMethod,
00156 const std::string& rMessage);
00157
00158
00159 static void ReportStaticError(const std::string& rClass,
00160 const std::string& rMethod,
00161 const std::string& rMessage,
00162 DWORD dwAdditionalData);
00163
00164
00165 static void ReportStaticErrorOS(const std::string& rClass,
00166 const std::string& rMethod,
00167 const std::string& rMessage);
00168
00169
00170 virtual void ReportError(const std::string& rMethod)const;
00171
00172
00173 virtual void ReportError(const std::string& rMethod,
00174 const std::string& rMessage)const;
00175
00176
00177 virtual void ReportError(const std::string& rMethod,
00178 const std::string& rMessage,
00179 DWORD dwAdditionalData)const;
00180
00181
00182 virtual void ReportError(const std::string& rMethod,
00183 const std::string& rMessage,
00184 const std::string& rAdditionalData)const;
00185
00186
00187 virtual void ReportError(const std::string& rMethod,
00188 int iErrorCode)const;
00189
00190
00191 virtual void ReportError(const std::string& rMethod,
00192 const std::string& rMessage,
00193 int iErrorCode)const;
00194
00195
00196 virtual void ReportErrorOS(const std::string& rMethod,
00197 const std::string& rMessage)const;
00198
00199
00200 void SetName(const std::string& rName)const;
00201 private:
00202
00203 CErrorLog* GetLog()const;
00204
00205
00206 static CErrorLog* m_pLog;
00207
00208
00209 static CErrorHandler* m_pSecondLevelLog;
00210
00211
00212 static CErrorHandler* m_pThirdLevelLog;
00213
00214
00215 CErrorLog* m_pLocalLog;
00216
00217
00218 bool m_bWriteToMain;
00219
00220
00221 mutable std::string m_sClassName;
00222 private:
00223
00224 class CErrorsRepository
00225 {
00226 public:
00227
00228 typedef std::map<DWORD,std::string> ErrorMap;
00229 public:
00230
00231 ErrorMap& GetErrorsMap();
00232
00233
00234 static CErrorsRepository& GetInstance();
00235 private:
00236
00237 ErrorMap m_aErrorMap;
00238 };
00239 };
00240
00241 KOMODIA_NAMESPACE_END
00242
00243 #endif // !defined(AFX_ERRORHANDLER_H__B886D5A4_FD2D_4CB8_8459_7311CBE31B77__INCLUDED_)