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  UT_ErrorSeverity commonMessage(UT_CommonErrorCode what, const char *msg=0);
73 
74  UT_ErrorSeverity addDeadlockError();
75 
76  UT_ErrorSeverity addGeneric(const char *type, int code, const char *msg,
77  UT_ErrorSeverity sev,
78  const UT_SourceLocation *loc=0);
79 
80  UT_ErrorSeverity addGeneric(UT_Error *error);
81 
82  void clearAndDestroyErrors();
83 
84  int getNumErrors() const { return myList.entries(); }
85  const UT_Error &getError(int index) const { return *myList(index); }
86 
87  int stealErrors(UT_ErrorManager &victim,
88  int rangestart = 0, int rangeend = -1,
90  bool borrow_only = false);
91 
92  int removeError(int index);
93  int findError(const char *type, int code) const;
94 
95 // passing in a severity of NONE will return all errors
96 //
97  int getErrorMessages(UT_String &messages,
99  bool use_headers = true);
100 
101 // Returns the worst error state
102 //
104  {
105  if( getNeedScan() )
106  computeSeverity();
107  return mySeverity;
108  }
109 
110 // This is for backward compatibility: use "getSeverity" !!!
111  UT_ErrorSeverity getErrorState() { return getSeverity(); }
112 
113  void pruneDuplicates();
114 
115  bool isDisabled() const
116  {
117  return ((myFlags & FLAG_DISABLED) != 0);
118  }
119  void setDisabled(bool f)
120  {
121  if (f)
122  myFlags |= FLAG_DISABLED;
123  else
124  myFlags &= ~FLAG_DISABLED;
125  }
126 
128  {
129  if (sev > mySeverity)
130  mySeverity = sev;
131  return mySeverity;
132  }
133 
134  // You typically do not need to call this method unless
135  // you want to restore the error severity back to a
136  // level that matches the errors recorded in the log.
138  {
139  setNeedScan(1);
140  computeSeverity();
141  }
142 
143  bool hasDeadlockError() const
144  {
145  return ((myFlags & FLAG_DEADLOCK) != 0);
146  }
147 
148  int64 getMemoryUsage(bool inclusive) const
149  {
150  int64 mem = inclusive ? sizeof(*this) : 0;
151  mem += myList.getMemoryUsage(false);
152  for (exint i = 0; i < myList.entries(); ++i)
153  mem += myList(i)->getMemoryUsage(true);
154  return mem;
155  }
156 
157  /// Returns a timestamp that is incremented every time an
158  /// error of ABORT or higher is logged.
159  static int getErrorManagerTimestamp();
160 
161  class Scope;
162 
163 protected:
164  void setReadFlag(int state);
165  int getReadFlag() const
166  {
167  return (myFlags & FLAG_ERRORS_READ) != 0;
168  }
169 
170  void setNeedScan(int state);
171  int getNeedScan() const
172  {
173  return (myFlags & FLAG_SCAN_NEEDED) != 0;
174  }
175 
176  void setDeadlockError(bool onoff)
177  {
178  if (onoff)
179  myFlags |= FLAG_DEADLOCK;
180  else
181  myFlags &= ~FLAG_DEADLOCK;
182  }
183 private:
184 
185  static const int MAX_ERRORS_KEPT = 40; // Max when doing regular add
186  static const int MAX_ERRORS_STEAL = 400; // Max errors when stealing
187 
188  UT_ErrorSeverity append(UT_Error *error,
189  int max_errors = MAX_ERRORS_KEPT,
190  bool log = true);
191 
192  void computeSeverity();
193 
194  UT_ErrorList myList;
195  UT_ErrorSeverity mySeverity;
196  char myFlags;
197 };
198 
199 /// A global error manager scope
201 {
202 public:
203  struct DelayTag {};
204  static DelayTag Delay;
205 
206  /// Push empty error manager
207  /// @{
208  Scope();
209  explicit Scope(int thread);
210  /// @}
211 
212  /// Push given error manager, must live beyond current scope. This renders
213  /// all accessors on this class unusable.
214  Scope(UT_ErrorManager &errors);
215 
216  /// Construct scope which has not begun yet. Call begin() to start.
218  : myThread(-1) {}
219 
220  /// Ends error scope if needed
221  ~Scope() { end(); }
222 
223  UT_ErrorManager &getErrorManager() { return myErrorManager; }
224  int getThread() const { return myThread; }
225 
226  UT_ErrorSeverity getSeverity() { return myErrorManager.getSeverity(); }
227 
228  /// Disable error accumulation for this scope, note however that the status
229  /// will be maintained.
230  void setDisabled(bool f)
231  { myErrorManager.setDisabled(f); }
232 
233  /// Get error messages
235  UT_String &messages,
237  bool use_headers = true)
238  {
239  return myErrorManager.getErrorMessages(
240  messages, severity, use_headers);
241  }
242 
243  /// Manually begin the scope. Subsequent calls will do nothing until end()
244  /// is called.
245  /// @{
246  void begin();
247  void begin(int thread);
248  /// @}
249 
250  /// Manually end the scope. Subsequent calls will do nothing.
251  void end();
252 
253 private:
254  UT_ErrorManager myErrorManager;
255  int myThread;
256 };
257 
258 /// Alias UT_AutoErrorManager as UT_ErrorManager::Scope
260 
261 
264 
268 UT_API void UTpushErrorManager(int thread);
272 UT_API void UTpopErrorManager(int thread);
273 
275  const char *msg=0,
276  const UT_SourceLocation *loc=0);
277 UT_API UT_ErrorSeverity UTaddPrompt(const char *type, int code,
278  const char *msg=0,
279  const UT_SourceLocation *loc=0);
280 UT_API UT_ErrorSeverity UTaddMessage(const char *type, int code,
281  const char *msg=0,
282  const UT_SourceLocation *loc=0);
283 UT_API UT_ErrorSeverity UTaddError (const char *type, int code,
284  const char *msg=0,
285  const UT_SourceLocation *loc=0);
286 UT_API UT_ErrorSeverity UTaddFatal (const char *type, int code,
287  const char *msg=0,
288  const UT_SourceLocation *loc=0);
291  const char *msg=0);
293  const char *msg=0);
295 
296 /// Add a generic error message to the global error manager.
298  const char *type, int code,
299  const char *msg = 0,
300  const UT_SourceLocation *loc = 0);
301 
302 UT_API int UTfindError(const char *type, int code);
303 
305 
306 #include <ostream>
307 UT_API int UTcheckOutStream(std::ostream &os, const char *m, const char *path=0);
308 class UT_OStream;
309 UT_API int UTcheckOutStream(UT_OStream &os, const char *m, const char *path=0);
310 
311 #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()
FMT_CONSTEXPR auto begin(const C &c) -> decltype(c.begin())
Definition: format.h:251
GLuint index
Definition: glew.h:1814
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)
GLenum severity
Definition: glew.h:2579
UT_ErrorSeverity
Definition: UT_Error.h:25
UT_API UT_ErrorManager * UTgetErrorManager()
#define UT_API
Definition: UT_API.h:13
const GLdouble * m
Definition: glew.h:9124
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)
void setDisabled(bool f)
UT_API UT_ErrorSeverity UTgetErrorSeverity()
#define SYS_DEPRECATED_REPLACE(__V__, __R__)
static DelayTag Delay
long long int64
Definition: SYS_Types.h:111
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)
GLclampf f
Definition: glew.h:3499
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:120
GLuint GLuint end
Definition: glew.h:1253
*Note that the tasks the is the thread number *for the or if it s being executed by a non pool thread(this *can happen in cases where the whole pool is occupied and the calling *thread contributes to running the work load).**Thread pool.Have fun
int getReadFlag() const
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
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)
GLsizei const GLchar *const * path
Definition: glew.h:6461
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
T log(const T &v)
Definition: simd.h:7432
UT_API int UTfindError(const char *type, int code)
UT_API UT_ErrorSeverity UTaddWarning(const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0)
A global error manager scope.
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()