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 static std::string GetCurrentDateTime();
00083
00084
00085 static std::string ErrorCodeToString(DWORD dwErrorCode);
00086
00087
00088 static void RegisterError(DWORD dwErrorCode,
00089 const std::string& rDescription);
00090
00091
00092 void SetLocalLog(CErrorLog* pLog);
00093
00094
00095 static void SetLog(CErrorLog* pLog);
00096
00097
00098 void WriteError(const std::string& rClass,
00099 const std::string& rMethod,
00100 const std::string& rError)const;
00101
00102
00103 static void WriteStaticError(const std::string& rClass,
00104 const std::string& rMethod,
00105 const std::string& rError);
00106
00107
00108 void WriteMessage(const std::string& rClass,
00109 const std::string& rMethod,
00110 const std::string& rMessage)const;
00111
00112
00113 static std::string FormatData(const std::string& rClass,
00114 const std::string& rMethod,
00115 const std::string& rMsgOrError,
00116 bool bError=true);
00117
00118
00119 CErrorHandler();
00120 CErrorHandler(const CErrorHandler& rHandler);
00121 virtual ~CErrorHandler();
00122 protected:
00123
00124 const std::string& GetClassName()const;
00125
00126
00127
00128 static void ReportStaticError(const std::string& rClass,
00129 const std::string& rMethod);
00130
00131
00132 static void ReportStaticError(const std::string& rClass,
00133 const std::string& rMethod,
00134 const std::string& rMessage);
00135
00136
00137 static void ReportStaticError(const std::string& rClass,
00138 const std::string& rMethod,
00139 const std::string& rMessage,
00140 DWORD dwAdditionalData);
00141
00142
00143 static void ReportStaticErrorOS(const std::string& rClass,
00144 const std::string& rMethod,
00145 const std::string& rMessage);
00146
00147
00148 virtual void ReportError(const std::string& rMethod)const;
00149
00150
00151 virtual void ReportError(const std::string& rMethod,
00152 const std::string& rMessage)const;
00153
00154
00155 virtual void ReportError(const std::string& rMethod,
00156 const std::string& rMessage,
00157 DWORD dwAdditionalData)const;
00158
00159
00160 virtual void ReportError(const std::string& rMethod,
00161 const std::string& rMessage,
00162 const std::string& rAdditionalData)const;
00163
00164
00165 virtual void ReportError(const std::string& rMethod,
00166 int iErrorCode)const;
00167
00168
00169 virtual void ReportError(const std::string& rMethod,
00170 const std::string& rMessage,
00171 int iErrorCode)const;
00172
00173
00174 virtual void ReportErrorOS(const std::string& rMethod,
00175 const std::string& rMessage)const;
00176
00177
00178 void SetName(const std::string& rName)const;
00179 private:
00180
00181 CErrorLog* GetLog()const;
00182
00183
00184 static CErrorLog* m_pLog;
00185
00186
00187 CErrorLog* m_pLocalLog;
00188
00189
00190 mutable std::string m_sClassName;
00191 private:
00192
00193 class CErrorsRepository
00194 {
00195 public:
00196
00197 typedef std::map<DWORD,std::string> ErrorMap;
00198 public:
00199
00200 ErrorMap& GetErrorsMap();
00201
00202
00203 static CErrorsRepository& GetInstance();
00204 private:
00205
00206 ErrorMap m_aErrorMap;
00207 };
00208 };
00209
00210 KOMODIA_NAMESPACE_END
00211
00212 #endif // !defined(AFX_ERRORHANDLER_H__B886D5A4_FD2D_4CB8_8459_7311CBE31B77__INCLUDED_)