HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 #include <SYS/SYS_Deprecated.h>
23 
24 
26 
28 {
29  enum {
30  FLAG_ERRORS_READ = 0x01,
31  FLAG_SCAN_NEEDED = 0x02,
32  FLAG_DISABLED = 0x04,
33  FLAG_DEADLOCK = 0x08,
34  };
35 
36 public:
38  ~UT_ErrorManager();
39 
40  UT_ErrorSeverity addMessage (const char *type, int code, const char *msg=0,
41  const UT_SourceLocation *loc=0);
42  UT_ErrorSeverity addPrompt (const char *type, int code, const char *msg=0,
43  const UT_SourceLocation *loc=0);
44  UT_ErrorSeverity addWarning (const char *type, int code, const char *msg=0,
45  const UT_SourceLocation *loc=0);
46  UT_ErrorSeverity addError (const char *type, int code, const char *msg=0,
47  const UT_SourceLocation *loc=0);
48  UT_ErrorSeverity addFatal (const char *type, int code, const char *msg=0,
49  const UT_SourceLocation *loc=0);
50 
51  UT_ErrorSeverity sopAddMessage (int code, const char *msg=0,
52  const UT_SourceLocation *loc=0)
53  { return addMessage("SOP", code, msg, loc); }
54  UT_ErrorSeverity sopAddPrompt (int code, const char *msg=0,
55  const UT_SourceLocation *loc=0)
56  { return addPrompt("SOP", code, msg, loc); }
57  UT_ErrorSeverity sopAddWarning (int code, const char *msg=0,
58  const UT_SourceLocation *loc=0)
59  { return addWarning("SOP", code, msg, loc); }
60  UT_ErrorSeverity sopAddError (int code, const char *msg=0,
61  const UT_SourceLocation *loc=0)
62  { return addError("SOP", code, msg, loc); }
63  UT_ErrorSeverity sopAddFatal (int code, const char *msg=0,
64  const UT_SourceLocation *loc=0)
65  { return addFatal("SOP", code, msg, loc); }
66 
67  UT_ErrorSeverity systemError(const char *msg=0);
68  UT_ErrorSeverity systemWarning(const char *msg=0);
69 
70  UT_ErrorSeverity commonWarning(UT_CommonErrorCode what, const char *msg=0);
71  UT_ErrorSeverity commonError(UT_CommonErrorCode what, const char *msg=0);
72 
73  UT_ErrorSeverity addDeadlockError();
74 
75  UT_ErrorSeverity addGeneric(const char *type, int code, const char *msg,
76  UT_ErrorSeverity sev,
77  const UT_SourceLocation *loc=0);
78 
79  UT_ErrorSeverity addGeneric(UT_Error *error);
80 
81  void clearAndDestroyErrors();
82 
83  int getNumErrors() const { return myList.entries(); }
84  const UT_Error &getError(int index) const { return *myList(index); }
85 
86  int stealErrors(UT_ErrorManager &victim,
87  int rangestart = 0, int rangeend = -1,
89  bool borrow_only = false);
90 
91  int removeError(int index);
92  int findError(const char *type, int code) const;
93 
94 // passing in a severity of NONE will return all errors
95 //
96  int getErrorMessages(UT_String &messages,
98  bool use_headers = true);
99 
100 // Returns the worst error state
101 //
103  {
104  if( getNeedScan() )
105  computeSeverity();
106  return mySeverity;
107  }
108 
109 // This is for backward compatibility: use "getSeverity" !!!
110  UT_ErrorSeverity getErrorState() { return getSeverity(); }
111 
112  void pruneDuplicates();
113 
114  bool isDisabled() const
115  {
116  return ((myFlags & FLAG_DISABLED) != 0);
117  }
118  void setDisabled(bool f)
119  {
120  if (f)
121  myFlags |= FLAG_DISABLED;
122  else
123  myFlags &= ~FLAG_DISABLED;
124  }
125 
127  {
128  if (sev > mySeverity)
129  mySeverity = sev;
130  return mySeverity;
131  }
132 
133  // You typically do not need to call this method unless
134  // you want to restore the error severity back to a
135  // level that matches the errors recorded in the log.
137  {
138  setNeedScan(1);
139  computeSeverity();
140  }
141 
142  bool hasDeadlockError() const
143  {
144  return ((myFlags & FLAG_DEADLOCK) != 0);
145  }
146 
147  int64 getMemoryUsage(bool inclusive) const
148  {
149  int64 mem = inclusive ? sizeof(*this) : 0;
150  mem += myList.getMemoryUsage(false);
151  for (exint i = 0; i < myList.entries(); ++i)
152  mem += myList(i)->getMemoryUsage(true);
153  return mem;
154  }
155 
156  class Scope;
157 
158 protected:
159  void setReadFlag(int state);
160  int getReadFlag() const
161  {
162  return (myFlags & FLAG_ERRORS_READ) != 0;
163  }
164 
165  void setNeedScan(int state);
166  int getNeedScan() const
167  {
168  return (myFlags & FLAG_SCAN_NEEDED) != 0;
169  }
170 
171  void setDeadlockError(bool onoff)
172  {
173  if (onoff)
174  myFlags |= FLAG_DEADLOCK;
175  else
176  myFlags &= ~FLAG_DEADLOCK;
177  }
178 private:
179 
180  static const int MAX_ERRORS_KEPT = 40; // Max when doing regular add
181  static const int MAX_ERRORS_STEAL = 400; // Max errors when stealing
182 
183  UT_ErrorSeverity append(UT_Error *error,
184  int max_errors = MAX_ERRORS_KEPT,
185  bool log = true);
186 
187  void computeSeverity();
188 
189  UT_ErrorList myList;
190  UT_ErrorSeverity mySeverity;
191  char myFlags;
192 };
193 
194 /// A global error manager scope
196 {
197 public:
198  struct DelayTag {};
199  static DelayTag Delay;
200 
201  /// Push empty error manager
202  /// @{
203  Scope();
204  explicit Scope(int thread);
205  /// @}
206 
207  /// Push given error manager, must live beyond current scope. This renders
208  /// all accessors on this class unusable.
209  Scope(UT_ErrorManager &errors);
210 
211  /// Construct scope which has not begun yet. Call begin() to start.
213  : myThread(-1) {}
214 
215  /// Ends error scope if needed
216  ~Scope() { end(); }
217 
218  UT_ErrorManager &getErrorManager() { return myErrorManager; }
219  int getThread() const { return myThread; }
220 
221  UT_ErrorSeverity getSeverity() { return myErrorManager.getSeverity(); }
222 
223  /// Disable error accumulation for this scope, note however that the status
224  /// will be maintained.
225  void setDisabled(bool f)
226  { myErrorManager.setDisabled(f); }
227 
228  /// Get error messages
230  UT_String &messages,
232  bool use_headers = true)
233  {
234  return myErrorManager.getErrorMessages(
235  messages, severity, use_headers);
236  }
237 
238  /// Manually begin the scope. Subsequent calls will do nothing until end()
239  /// is called.
240  /// @{
241  void begin();
242  void begin(int thread);
243  /// @}
244 
245  /// Manually end the scope. Subsequent calls will do nothing.
246  void end();
247 
248 private:
249  UT_ErrorManager myErrorManager;
250  int myThread;
251 };
252 
253 /// Alias UT_AutoErrorManager as UT_ErrorManager::Scope
255 
256 
259 
263 UT_API void UTpushErrorManager(int thread);
267 UT_API void UTpopErrorManager(int thread);
268 
270  const char *msg=0,
271  const UT_SourceLocation *loc=0);
272 UT_API UT_ErrorSeverity UTaddPrompt(const char *type, int code,
273  const char *msg=0,
274  const UT_SourceLocation *loc=0);
275 UT_API UT_ErrorSeverity UTaddMessage(const char *type, int code,
276  const char *msg=0,
277  const UT_SourceLocation *loc=0);
278 UT_API UT_ErrorSeverity UTaddError (const char *type, int code,
279  const char *msg=0,
280  const UT_SourceLocation *loc=0);
281 UT_API UT_ErrorSeverity UTaddFatal (const char *type, int code,
282  const char *msg=0,
283  const UT_SourceLocation *loc=0);
286  const char *msg=0);
288  const char *msg=0);
290 
291 /// Add a generic error message to the global error manager.
293  const char *type, int code,
294  const char *msg = 0,
295  const UT_SourceLocation *loc = 0);
296 
297 UT_API int UTfindError(const char *type, int code);
298 
300 
301 #include <ostream>
302 UT_API int UTcheckOutStream(std::ostream &os, const char *m, const char *path=0);
303 class UT_OStream;
304 UT_API int UTcheckOutStream(UT_OStream &os, const char *m, const char *path=0);
305 
306 #endif
const UT_Error & getError(int index) const
UT_ErrorSeverity getSeverity()
int getErrorMessages(UT_String &messages, UT_ErrorSeverity severity=UT_ERROR_NONE, bool use_headers=true)
Get error messages.
UT_API void UTpopErrorManager()
UT_ErrorSeverity sopAddMessage(int code, const char *msg=0, const UT_SourceLocation *loc=0)
Scope(DelayTag)
Construct scope which has not begun yet. Call begin() to start.
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:13
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()
#define SYS_DEPRECATED_REPLACE(__V__, __R__)
SYS_API double log(double x)
Definition: SYS_FPUMath.h:87
static DelayTag Delay
long long int64
Definition: SYS_Types.h:107
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:116
GLuint GLuint end
Definition: glcorearb.h:474
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)
#define const
Definition: zconf.h:214
int getNeedScan() const
UT_ErrorManager::Scope UT_AutoErrorManager
Alias UT_AutoErrorManager as UT_ErrorManager::Scope.
~Scope()
Ends error scope if needed.
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()