HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_ErrorManager.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_ErrorManager.h (Utility library)
7  *
8  * COMMENTS:
9  * This class implements an error manager which will
10  * manage a list of error messages.
11  * NOTE: It assumes ownership of the errors that it is givin.
12  *
13  */
14 
15 #ifndef __UT_ErrorManager_h__
16 #define __UT_ErrorManager_h__
17 
18 #include "UT_API.h"
19 #include "UT_Error.h"
20 #include "UT_NonCopyable.h"
21 #include "UT_ValArray.h"
22 
23 
25 
27 {
28  enum {
29  FLAG_ERRORS_READ = 0x01,
30  FLAG_SCAN_NEEDED = 0x02,
31  FLAG_DISABLED = 0x04,
32  FLAG_DEADLOCK = 0x08,
33  };
34 
35 public:
37  ~UT_ErrorManager();
38 
39  UT_ErrorSeverity addMessage (const char *type, int code, const char *msg=0,
40  const UT_SourceLocation *loc=0);
41  UT_ErrorSeverity addPrompt (const char *type, int code, const char *msg=0,
42  const UT_SourceLocation *loc=0);
43  UT_ErrorSeverity addWarning (const char *type, int code, const char *msg=0,
44  const UT_SourceLocation *loc=0);
45  UT_ErrorSeverity addError (const char *type, int code, const char *msg=0,
46  const UT_SourceLocation *loc=0);
47  UT_ErrorSeverity addFatal (const char *type, int code, const char *msg=0,
48  const UT_SourceLocation *loc=0);
49 
50  UT_ErrorSeverity sopAddMessage (int code, const char *msg=0,
51  const UT_SourceLocation *loc=0)
52  { return addMessage("SOP", code, msg, loc); }
53  UT_ErrorSeverity sopAddPrompt (int code, const char *msg=0,
54  const UT_SourceLocation *loc=0)
55  { return addPrompt("SOP", code, msg, loc); }
56  UT_ErrorSeverity sopAddWarning (int code, const char *msg=0,
57  const UT_SourceLocation *loc=0)
58  { return addWarning("SOP", code, msg, loc); }
59  UT_ErrorSeverity sopAddError (int code, const char *msg=0,
60  const UT_SourceLocation *loc=0)
61  { return addError("SOP", code, msg, loc); }
62  UT_ErrorSeverity sopAddFatal (int code, const char *msg=0,
63  const UT_SourceLocation *loc=0)
64  { return addFatal("SOP", code, msg, loc); }
65 
66  UT_ErrorSeverity systemError(const char *msg=0);
67  UT_ErrorSeverity systemWarning(const char *msg=0);
68 
69  UT_ErrorSeverity commonWarning(UT_CommonErrorCode what, const char *msg=0);
70  UT_ErrorSeverity commonError(UT_CommonErrorCode what, const char *msg=0);
71 
72  UT_ErrorSeverity addDeadlockError();
73 
74  UT_ErrorSeverity addGeneric(const char *type, int code, const char *msg,
75  UT_ErrorSeverity sev,
76  const UT_SourceLocation *loc=0);
77 
78  UT_ErrorSeverity addGeneric(UT_Error *error);
79 
80  void clearAndDestroyErrors();
81 
82  int getNumErrors() const { return myList.entries(); }
83  const UT_Error &getError(int index) const { return *myList(index); }
84 
85  int stealErrors(UT_ErrorManager &victim,
86  int rangestart = 0, int rangeend = -1,
88  bool borrow_only = false);
89 
90  int removeError(int index);
91  int findError(const char *type, int code) const;
92 
93 // passing in a severity of NONE will return all errors
94 //
95  int getErrorMessages(UT_String &messages,
97  int headerflag=1);
98 
99 // Returns the worst error state
100 //
102  {
103  if( getNeedScan() )
104  computeSeverity();
105  return mySeverity;
106  }
107 
108 // This is for backward compatibility: use "getSeverity" !!!
109  UT_ErrorSeverity getErrorState() { return getSeverity(); }
110 
111  void pruneDuplicates();
112 
113  bool isDisabled() const
114  {
115  return ((myFlags & FLAG_DISABLED) != 0);
116  }
117  void setDisabled(bool f)
118  {
119  if (f)
120  myFlags |= FLAG_DISABLED;
121  else
122  myFlags &= ~FLAG_DISABLED;
123  }
124 
126  {
127  if (sev > mySeverity)
128  mySeverity = sev;
129  return mySeverity;
130  }
131 
132  // You typically do not need to call this method unless
133  // you want to restore the error severity back to a
134  // level that matches the errors recorded in the log.
136  {
137  setNeedScan(1);
138  computeSeverity();
139  }
140 
141  bool hasDeadlockError() const
142  {
143  return ((myFlags & FLAG_DEADLOCK) != 0);
144  }
145 
146  int64 getMemoryUsage(bool inclusive) const
147  {
148  int64 mem = inclusive ? sizeof(*this) : 0;
149  mem += myList.getMemoryUsage(false);
150  for (exint i = 0; i < myList.entries(); ++i)
151  mem += myList(i)->getMemoryUsage(true);
152  return mem;
153  }
154 
155  class Scope;
156 
157 protected:
158  void setReadFlag(int state);
159  int getReadFlag() const
160  {
161  return (myFlags & FLAG_ERRORS_READ) != 0;
162  }
163 
164  void setNeedScan(int state);
165  int getNeedScan() const
166  {
167  return (myFlags & FLAG_SCAN_NEEDED) != 0;
168  }
169 
170  void setDeadlockError(bool onoff)
171  {
172  if (onoff)
173  myFlags |= FLAG_DEADLOCK;
174  else
175  myFlags &= ~FLAG_DEADLOCK;
176  }
177 private:
178 
179  static const int MAX_ERRORS_KEPT = 40; // Max when doing regular add
180  static const int MAX_ERRORS_STEAL = 400; // Max errors when stealing
181 
182  UT_ErrorSeverity append(UT_Error *error,
183  int max_errors = MAX_ERRORS_KEPT,
184  bool log = true);
185 
186  void computeSeverity();
187 
188  UT_ErrorList myList;
189  UT_ErrorSeverity mySeverity;
190  char myFlags;
191 };
192 
193 /// A global error manager scope
195 {
196 public:
197  Scope();
198  Scope(UT_ErrorManager &errors);
199  explicit Scope(int thread);
200  ~Scope();
201 
202  UT_ErrorManager &getErrorManager() { return myErrorManager; }
203  int getThread() const { return myThread; }
204 
205  UT_ErrorSeverity getSeverity() { return myErrorManager.getSeverity(); }
206 
207 private:
208  UT_ErrorManager myErrorManager;
209  int myThread;
210 };
211 
212 
216 UT_API void UTpushErrorManager(int thread);
218 UT_API void UTpopErrorManager(int thread);
219 
220 UT_API UT_ErrorSeverity UTaddWarning(const char *type, int code,
221  const char *msg=0,
222  const UT_SourceLocation *loc=0);
223 UT_API UT_ErrorSeverity UTaddPrompt(const char *type, int code,
224  const char *msg=0,
225  const UT_SourceLocation *loc=0);
226 UT_API UT_ErrorSeverity UTaddMessage(const char *type, int code,
227  const char *msg=0,
228  const UT_SourceLocation *loc=0);
229 UT_API UT_ErrorSeverity UTaddError (const char *type, int code,
230  const char *msg=0,
231  const UT_SourceLocation *loc=0);
232 UT_API UT_ErrorSeverity UTaddFatal (const char *type, int code,
233  const char *msg=0,
234  const UT_SourceLocation *loc=0);
235 UT_API UT_ErrorSeverity UTaddSystemError(const char *msg=0);
237  const char *msg=0);
239  const char *msg=0);
241 
242 /// Add a generic error message to the global error manager.
244  const char *type, int code,
245  const char *msg = 0,
246  const UT_SourceLocation *loc = 0);
247 
248 UT_API int UTfindError(const char *type, int code);
249 
251 
252 #include <ostream>
253 UT_API int UTcheckOutStream(std::ostream &os, const char *m, const char *path=0);
254 class UT_OStream;
255 UT_API int UTcheckOutStream(UT_OStream &os, const char *m, const char *path=0);
256 
257 #endif
const UT_Error & getError(int index) const
UT_ErrorSeverity getSeverity()
UT_API void UTpopErrorManager()
UT_ErrorSeverity sopAddMessage(int code, const char *msg=0, const UT_SourceLocation *loc=0)
UT_API UT_ErrorSeverity UTaddFatal(const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0)
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
UT_ErrorSeverity
Definition: UT_Error.h:25
UT_API UT_ErrorManager * UTgetErrorManager()
#define UT_API
Definition: UT_API.h:12
UT_ErrorManager & getErrorManager()
UT_API UT_ErrorSeverity UTaddMessage(const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0)
void setDeadlockError(bool onoff)
UT_API UT_ErrorSeverity UTaddSystemError(const char *msg=0)
png_uint_32 i
Definition: png.h:2877
void setDisabled(bool f)
UT_API UT_ErrorSeverity UTgetErrorSeverity()
SYS_API double log(double x)
long long int64
Definition: SYS_Types.h:100
GLfloat f
Definition: glcorearb.h:1925
UT_ErrorSeverity updateSeverity(UT_ErrorSeverity sev)
bool hasDeadlockError() const
int getThread() const
UT_API int UTcheckOutStream(std::ostream &os, const char *m, const char *path=0)
UT_API UT_ErrorSeverity UTaddPrompt(const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0)
int64 exint
Definition: SYS_Types.h:109
GLenum GLenum severity
Definition: glcorearb.h:2538
int getReadFlag() const
UT_ErrorSeverity sopAddWarning(int code, const char *msg=0, const UT_SourceLocation *loc=0)
bool isDisabled() const
UT_API UT_ErrorSeverity UTaddCommonError(UT_CommonErrorCode what, const char *msg=0)
UT_CommonErrorCode
Definition: UT_Error.h:42
UT_ErrorSeverity sopAddError(int code, const char *msg=0, const UT_SourceLocation *loc=0)
int64 getMemoryUsage(bool inclusive) const
UT_API int UTfindError(const char *type, int code)
GLuint index
Definition: glcorearb.h:785
UT_API UT_ErrorSeverity UTaddWarning(const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0)
A global error manager scope.
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
UT_API UT_ErrorSeverity UTaddDeadlockError()
UT_API UT_ErrorSeverity UTaddCommonWarning(UT_CommonErrorCode what, const char *msg=0)
int getNeedScan() const
UT_API UT_ErrorSeverity UTaddGeneric(UT_ErrorSeverity sev, const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0)
Add a generic error message to the global error manager.
UT_ValArray< UT_Error * > UT_ErrorList
UT_API void UTpushErrorManager()
int getNumErrors() const
UT_ErrorSeverity sopAddFatal(int code, const char *msg=0, const UT_SourceLocation *loc=0)
UT_API UT_ErrorSeverity UTaddError(const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0)
UT_ErrorSeverity sopAddPrompt(int code, const char *msg=0, const UT_SourceLocation *loc=0)
UT_ErrorSeverity getErrorState()