00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __UT_ErrorManager_h__
00024 #define __UT_ErrorManager_h__
00025
00026 #include "UT_API.h"
00027 #include "UT_Error.h"
00028 #include "UT_PtrArray.h"
00029 #include <fstream.h>
00030
00031 typedef UT_PtrArray<UT_Error *> UT_ErrorList;
00032
00033 class UT_API UT_ErrorManager
00034 {
00035 enum {
00036 FLAG_ERRORS_READ = 0x01,
00037 FLAG_SCAN_NEEDED = 0x02,
00038 FLAG_DISABLED = 0x04,
00039 FLAG_DEADLOCK = 0x08,
00040 };
00041
00042 public:
00043 UT_ErrorManager();
00044 ~UT_ErrorManager();
00045
00046 UT_ErrorSeverity addMessage (const char *type, int code, const char *msg=0);
00047 UT_ErrorSeverity addPrompt (const char *type, int code, const char *msg=0);
00048 UT_ErrorSeverity addWarning (const char *type, int code, const char *msg=0);
00049 UT_ErrorSeverity addError (const char *type, int code, const char *msg=0);
00050 UT_ErrorSeverity addFatal (const char *type, int code, const char *msg=0);
00051 UT_ErrorSeverity systemError(const char *msg=0);
00052 UT_ErrorSeverity commonWarning(UT_CommonErrorCode what, const char *msg=0);
00053 UT_ErrorSeverity commonError(UT_CommonErrorCode what, const char *msg=0);
00054
00055 UT_ErrorSeverity addDeadlockError();
00056
00057 UT_ErrorSeverity addGeneric(const char *type, int code, const char *msg,
00058 UT_ErrorSeverity sev);
00059
00060 void clearAndDestroyErrors();
00061
00062 int getNumErrors() const { return myList.entries(); }
00063
00064 int stealErrors(UT_ErrorManager &victim,
00065 int rangestart = 0, int rangeend = -1,
00066 UT_ErrorSeverity severity = UT_ERROR_NONE,
00067 bool borrow_only = false);
00068
00069 int removeError(int index);
00070 int findError(const char *type, int code) const;
00071
00072
00073
00074 int getErrorMessages(UT_String &messages,
00075 UT_ErrorSeverity severity = UT_ERROR_NONE,
00076 int headerflag=1);
00077
00078
00079
00080 UT_ErrorSeverity getSeverity()
00081 {
00082 if( getNeedScan() )
00083 computeSeverity();
00084 return mySeverity;
00085 }
00086
00087
00088 UT_ErrorSeverity getErrorState() { return getSeverity(); }
00089
00090 void pruneDuplicates();
00091
00092 bool isDisabled() const
00093 {
00094 return ((myFlags & FLAG_DISABLED) != 0);
00095 }
00096 void setDisabled(bool f)
00097 {
00098 if (f)
00099 myFlags |= FLAG_DISABLED;
00100 else
00101 myFlags &= ~FLAG_DISABLED;
00102 }
00103
00104 UT_ErrorSeverity updateSeverity(UT_ErrorSeverity sev)
00105 {
00106 if (sev > mySeverity)
00107 mySeverity = sev;
00108 return mySeverity;
00109 }
00110
00111 bool hasDeadlockError() const
00112 {
00113 return ((myFlags & FLAG_DEADLOCK) != 0);
00114 }
00115
00116 protected:
00117 void setReadFlag(int state);
00118 int getReadFlag() const
00119 {
00120 return (myFlags & FLAG_ERRORS_READ) != 0;
00121 }
00122
00123 void setNeedScan(int state);
00124 int getNeedScan() const
00125 {
00126 return (myFlags & FLAG_SCAN_NEEDED) != 0;
00127 }
00128
00129 void setDeadlockError(bool onoff)
00130 {
00131 if (onoff)
00132 myFlags |= FLAG_DEADLOCK;
00133 else
00134 myFlags &= ~FLAG_DEADLOCK;
00135 }
00136
00137 private:
00138
00139 static const int MAX_ERRORS_KEPT = 40;
00140 static const int MAX_ERRORS_STEAL = 400;
00141
00142 UT_ErrorSeverity append(UT_Error *error,
00143 int max_errors = MAX_ERRORS_KEPT,
00144 bool log = true);
00145
00146 void computeSeverity();
00147
00148 UT_ErrorList myList;
00149 UT_ErrorSeverity mySeverity;
00150 char myFlags;
00151 };
00152
00153 UT_API UT_ErrorManager *UTgetErrorManager();
00154 UT_API UT_ErrorManager *UTgetErrorManager(int thraed);
00155 UT_API void UTpushErrorManager();
00156 UT_API void UTpushErrorManager(int thread);
00157 UT_API void UTpopErrorManager();
00158 UT_API void UTpopErrorManager(int thread);
00159
00160 UT_API UT_ErrorSeverity UTaddWarning(const char *type, int code,
00161 const char *msg=0);
00162 UT_API UT_ErrorSeverity UTaddPrompt(const char *type, int code,
00163 const char *msg=0);
00164 UT_API UT_ErrorSeverity UTaddMessage(const char *type, int code,
00165 const char *msg=0);
00166 UT_API UT_ErrorSeverity UTaddError (const char *type, int code,
00167 const char *msg=0);
00168 UT_API UT_ErrorSeverity UTaddFatal (const char *type, int code,
00169 const char *msg=0);
00170 UT_API UT_ErrorSeverity UTaddSystemError(const char *msg=0);
00171 UT_API UT_ErrorSeverity UTaddCommonWarning(UT_CommonErrorCode what,
00172 const char *msg=0);
00173 UT_API UT_ErrorSeverity UTaddCommonError(UT_CommonErrorCode what,
00174 const char *msg=0);
00175 UT_API UT_ErrorSeverity UTaddDeadlockError();
00176
00177 UT_API int UTfindError(const char *type, int code);
00178
00179 UT_API UT_ErrorSeverity UTgetErrorSeverity();
00180
00181 UT_API int UTcheckOutStream(ostream &os, const char *m, const char *path=0);
00182 #endif