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  FLAG_NOLOG = 0x10
35  };
36 
37 public:
39  ~UT_ErrorManager();
40 
41  UT_ErrorSeverity addMessage (const char *type, int code, const char *msg=0,
42  const UT_SourceLocation *loc=0);
43  UT_ErrorSeverity addPrompt (const char *type, int code, const char *msg=0,
44  const UT_SourceLocation *loc=0);
45  UT_ErrorSeverity addWarning (const char *type, int code, const char *msg=0,
46  const UT_SourceLocation *loc=0);
47  UT_ErrorSeverity addError (const char *type, int code, const char *msg=0,
48  const UT_SourceLocation *loc=0);
49  UT_ErrorSeverity addFatal (const char *type, int code, const char *msg=0,
50  const UT_SourceLocation *loc=0);
51 
52  UT_ErrorSeverity sopAddMessage (int code, const char *msg=0,
53  const UT_SourceLocation *loc=0)
54  { return addMessage("SOP", code, msg, loc); }
55  UT_ErrorSeverity sopAddPrompt (int code, const char *msg=0,
56  const UT_SourceLocation *loc=0)
57  { return addPrompt("SOP", code, msg, loc); }
58  UT_ErrorSeverity sopAddWarning (int code, const char *msg=0,
59  const UT_SourceLocation *loc=0)
60  { return addWarning("SOP", code, msg, loc); }
61  UT_ErrorSeverity sopAddError (int code, const char *msg=0,
62  const UT_SourceLocation *loc=0)
63  { return addError("SOP", code, msg, loc); }
64  UT_ErrorSeverity sopAddFatal (int code, const char *msg=0,
65  const UT_SourceLocation *loc=0)
66  { return addFatal("SOP", code, msg, loc); }
67 
68  UT_ErrorSeverity systemError(const char *msg=0);
69  UT_ErrorSeverity systemWarning(const char *msg=0);
70 
71  UT_ErrorSeverity commonWarning(UT_CommonErrorCode what, const char *msg=0);
72  UT_ErrorSeverity commonError(UT_CommonErrorCode what, const char *msg=0);
73  UT_ErrorSeverity commonMessage(UT_CommonErrorCode what, const char *msg=0);
74 
75  UT_ErrorSeverity addDeadlockError();
76 
77  UT_ErrorSeverity addGeneric(const char *type, int code, const char *msg,
78  UT_ErrorSeverity sev,
79  const UT_SourceLocation *loc=0);
80 
81  UT_ErrorSeverity addGeneric(UT_Error *error);
82 
83  void clearAndDestroyErrors();
84 
85  bool isEmpty() const { return myList.entries() <= 0; }
86  int getNumErrors() const { return myList.entries(); }
87  const UT_Error &getError(int index) const { return *myList(index); }
88 
89  int stealErrors(UT_ErrorManager &victim,
90  int rangestart = 0, int rangeend = -1,
92  bool borrow_only = false);
93 
94  int removeError(int index);
95  int findError(const char *type, int code) const;
96 
97 // passing in a severity of NONE will return all errors
98 //
99  int getErrorMessages(UT_String &messages,
101  bool use_headers = true);
102 
103 // Returns the worst error state
104 //
106  {
107  if( getNeedScan() )
108  computeSeverity();
109  return mySeverity;
110  }
111 
112 
113  // Clamp all errors to the maximum severity specified and recompute
114  // severity
115  void clampSeverity(UT_ErrorSeverity severity);
116 
117 // This is for backward compatibility: use "getSeverity" !!!
118  UT_ErrorSeverity getErrorState() { return getSeverity(); }
119 
120  void pruneDuplicates();
121 
122  bool isDisabled() const
123  {
124  return ((myFlags & FLAG_DISABLED) != 0);
125  }
126  void setDisabled(bool f)
127  {
128  if (f)
129  myFlags |= FLAG_DISABLED;
130  else
131  myFlags &= ~FLAG_DISABLED;
132  }
133  bool isLogging() const
134  {
135  return (myFlags & FLAG_NOLOG) == 0;
136  }
137  // In some rare cases we want to be able to add errors to the manager but
138  // not log them.
139  void setErrorLogging(bool f)
140  {
141  if (!f)
142  myFlags |= FLAG_NOLOG;
143  else
144  myFlags &= ~FLAG_NOLOG;
145  }
146 
148  {
149  if (sev > mySeverity)
150  mySeverity = sev;
151  return mySeverity;
152  }
153 
154  // You typically do not need to call this method unless
155  // you want to restore the error severity back to a
156  // level that matches the errors recorded in the log.
158  {
159  setNeedScan(true);
160  computeSeverity();
161  }
162 
163  bool hasDeadlockError() const
164  {
165  return ((myFlags & FLAG_DEADLOCK) != 0);
166  }
167 
168  int64 getMemoryUsage(bool inclusive) const
169  {
170  int64 mem = inclusive ? sizeof(*this) : 0;
171  mem += myList.getMemoryUsage(false);
172  for (exint i = 0; i < myList.entries(); ++i)
173  mem += myList(i)->getMemoryUsage(true);
174  return mem;
175  }
176 
177  /// Returns a timestamp that is incremented every time an
178  /// error of ABORT or higher is logged.
179  static int getErrorManagerTimestamp();
180 
181  class Scope;
182 
183  UT_ErrorList::const_iterator begin() const { return myList.begin(); }
184  UT_ErrorList::const_iterator end() const { return myList.end(); }
185 protected:
186  void setReadFlag(bool state);
187  bool getReadFlag() const
188  {
189  return (myFlags & FLAG_ERRORS_READ) != 0;
190  }
191 
192  void setNeedScan(bool needscan);
193  bool getNeedScan() const
194  {
195  return (myFlags & FLAG_SCAN_NEEDED) != 0;
196  }
197 
198  void setDeadlockError(bool onoff)
199  {
200  if (onoff)
201  myFlags |= FLAG_DEADLOCK;
202  else
203  myFlags &= ~FLAG_DEADLOCK;
204  }
205 private:
206 
207  static const int MAX_ERRORS_KEPT = 40; // Max when doing regular add
208  static const int MAX_ERRORS_STEAL = 400; // Max errors when stealing
209 
210  UT_ErrorSeverity append(UT_Error *error,
211  int max_errors = MAX_ERRORS_KEPT,
212  bool log = true);
213 
214  void computeSeverity();
215 
216  UT_ErrorList myList;
217  UT_ErrorSeverity mySeverity;
218  char myFlags;
219 };
220 
221 /// A global error manager scope
223 {
224 public:
225  struct DelayTag {};
226  static DelayTag Delay;
227 
228  /// Push empty error manager
229  /// @{
230  Scope();
231  explicit Scope(int thread);
232  /// @}
233 
234  /// Push given error manager, must live beyond current scope. This renders
235  /// all accessors on this class unusable.
236  Scope(UT_ErrorManager &errors);
237 
238  /// Construct scope which has not begun yet. Call begin() to start.
240  : myThread(-1) {}
241 
242  /// Ends error scope if needed
243  ~Scope() { end(); }
244 
245  UT_ErrorManager &getErrorManager() { return myErrorManager; }
246  int getThread() const { return myThread; }
247 
248  UT_ErrorSeverity getSeverity() { return myErrorManager.getSeverity(); }
249 
250  /// Disable error accumulation for this scope, note however that the status
251  /// will be maintained.
252  void setDisabled(bool f)
253  { myErrorManager.setDisabled(f); }
254 
255  /// Get error messages
257  UT_String &messages,
259  bool use_headers = true)
260  {
261  return myErrorManager.getErrorMessages(
262  messages, severity, use_headers);
263  }
264 
265  /// Manually begin the scope. Subsequent calls will do nothing until end()
266  /// is called.
267  /// @{
268  void begin();
269  void begin(int thread);
270  /// @}
271 
272  /// Manually end the scope. Subsequent calls will do nothing.
273  void end();
274 
275 private:
276  UT_ErrorManager myErrorManager;
277  int myThread;
278 };
279 
280 /// Alias UT_AutoErrorManager as UT_ErrorManager::Scope
282 
283 
286 
290 UT_API void UTpushErrorManager(int thread);
294 UT_API void UTpopErrorManager(int thread);
295 
297  const char *msg=0,
298  const UT_SourceLocation *loc=0);
299 UT_API UT_ErrorSeverity UTaddPrompt(const char *type, int code,
300  const char *msg=0,
301  const UT_SourceLocation *loc=0);
302 UT_API UT_ErrorSeverity UTaddMessage(const char *type, int code,
303  const char *msg=0,
304  const UT_SourceLocation *loc=0);
305 UT_API UT_ErrorSeverity UTaddError (const char *type, int code,
306  const char *msg=0,
307  const UT_SourceLocation *loc=0);
308 UT_API UT_ErrorSeverity UTaddFatal (const char *type, int code,
309  const char *msg=0,
310  const UT_SourceLocation *loc=0);
313  const char *msg=0);
315  const char *msg=0);
317 
318 /// Add a generic error message to the global error manager.
320  const char *type, int code,
321  const char *msg = 0,
322  const UT_SourceLocation *loc = 0);
324 
325 UT_API int UTfindError(const char *type, int code);
326 
328 
329 #include <ostream>
330 UT_API int UTcheckOutStream(std::ostream &os, const char *m, const char *path=0);
331 class UT_OStream;
332 UT_API int UTcheckOutStream(UT_OStream &os, const char *m, const char *path=0);
333 
334 #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
int64 exint
Definition: SYS_Types.h:125
UT_ErrorSeverity
Definition: UT_Error.h:25
UT_API UT_ErrorManager * UTgetErrorManager()
#define UT_API
Definition: UT_API.h:13
void setErrorLogging(bool f)
const GLdouble * m
Definition: glew.h:9124
UT_ErrorList::const_iterator end() const
UT_ErrorManager & getErrorManager()
UT_API UT_ErrorSeverity UTaddMessage(const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0)
bool getNeedScan() const
void setDeadlockError(bool onoff)
UT_API UT_ErrorSeverity UTaddSystemError(const char *msg=0)
void setDisabled(bool f)
UT_API UT_ErrorSeverity UTgetErrorSeverity()
bool getReadFlag() const
#define SYS_DEPRECATED_REPLACE(__V__, __R__)
static DelayTag Delay
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)
UT_ErrorList::const_iterator begin() const
GLuint GLuint end
Definition: glew.h:1253
bool isLogging() const
long long int64
Definition: SYS_Types.h:116
*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
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.
base_iterator< const UT_Error *, true > const_iterator
Definition: UT_Array.h:789
UT_API UT_ErrorSeverity UTaddDeadlockError()
UT_API UT_ErrorSeverity UTaddCommonWarning(UT_CommonErrorCode what, const char *msg=0)
#define const
Definition: zconf.h:214
bool isEmpty() 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()