Changeset 336 for cpp/frams/errmgr/errmanager.h
- Timestamp:
- 03/12/15 04:19:45 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/errmgr/errmanager.h
r286 r336 15 15 class ErrorManager 16 16 { 17 friend class ErrorHandlerBase; 18 SListTempl<ErrorHandlerBase*> handlers; 19 void send(int level,const char *o,const char *m,const char *bl,int w); 20 public: 21 int find(ErrorHandlerBase *r) {return handlers.find(r);} 22 int add(ErrorHandlerBase *r); 23 void remove(int i); 24 void remove(ErrorHandlerBase *r); 25 void removeAll(); 26 void send(const char *o,const char *m,const char *bl,int w) 27 {send(handlers.size()-1,o,m,bl,w);} 28 ~ErrorManager() {removeAll();} 17 friend class ErrorHandlerBase; 18 SListTempl<ErrorHandlerBase*> handlers; 19 void send(int level, const char *o, const char *m, const char *bl, int w); 20 public: 21 int find(ErrorHandlerBase *r) { return handlers.find(r); } 22 int add(ErrorHandlerBase *r); 23 void remove(int i); 24 void remove(ErrorHandlerBase *r); 25 void removeAll(); 26 void send(const char *o, const char *m, const char *bl, int w) 27 { 28 send(handlers.size() - 1, o, m, bl, w); 29 } 30 ~ErrorManager() { removeAll(); } 29 31 }; 30 32 31 extern THREAD_LOCAL_DECL(ErrorManager, errmgr_instance);33 extern THREAD_LOCAL_DECL(ErrorManager, errmgr_instance); 32 34 33 35 //////////////////////////////////////// … … 35 37 class ErrorHandlerBase 36 38 { 37 friend class ErrorManager;38 39 ErrorManager* mgr;40 int options;39 friend class ErrorManager; 40 protected: 41 ErrorManager* mgr; 42 int options; 41 43 42 44 public: 43 45 44 enum HandlerOptions 45 { DontBlock=1, CannotBeBlocked=2, DontEnable=4 }; 46 enum HandlerOptions 47 { 48 DontBlock = 1, CannotBeBlocked = 2, DontEnable = 4, Paused = 8 49 }; 46 50 47 void FMprintf(const char *o,const char *m,int w,const char *bl, ...);48 void send(const char *o,const char *m,const char *bl,int w);51 void FMprintf(const char *o, const char *m, int w, const char *bl, ...); 52 void send(const char *o, const char *m, const char *bl, int w); 49 53 50 bool isEnabled() {return mgr?1:0;} 51 void enable(); 52 void disable(); 54 bool isEnabled() { return mgr ? 1 : 0; } 55 void enable(); 56 void disable(); 57 bool isPaused() { return (options & Paused) != 0; } 58 void pause(); 59 void resume(); 53 60 54 ErrorHandlerBase(int opts=0):mgr(0),options(opts) 55 {if (!(options&DontEnable)) enable();} 56 virtual ~ErrorHandlerBase() 57 {disable();} 61 ErrorHandlerBase(int opts = 0) :mgr(0), options(opts) 62 { 63 if (!(options&DontEnable)) enable(); 64 } 65 virtual ~ErrorHandlerBase() 66 { 67 disable(); 68 } 58 69 59 virtual void handle(const char *o,const char *m,const char *bl,int w) {}70 virtual void handle(const char *o, const char *m, const char *bl, int w) {} 60 71 }; 61 72 62 73 /////////////////////////////////////////// 63 74 64 class ErrorHandler : public ErrorHandlerBase75 class ErrorHandler : public ErrorHandlerBase 65 76 { 66 67 int maxlevel,errcount,warncount,storlevel,storcount,infocount;68 SString msgs;77 protected: 78 int maxlevel, errcount, warncount, storlevel, storcount, infocount; 79 SString msgs; 69 80 70 81 public: 71 82 72 void reset() {maxlevel=FMLV_INFO-1; errcount=warncount=storcount=infocount=0; msgs=0;}83 void reset() { maxlevel = FMLV_INFO - 1; errcount = warncount = storcount = infocount = 0; msgs = 0; } 73 84 74 enum Options2 75 { StoreFirstMessage=8, StoreAllMessages=16 }; 85 enum Options2 86 { 87 StoreFirstMessage = 16, StoreAllMessages = 32 88 }; 76 89 77 int getErrorCount() {return errcount;}78 int getWarningCount() {return warncount;}79 int getInfoCount() {return infocount;}80 int getStoredCount() {return storcount;}81 int getErrorLevel() {return maxlevel;}82 const SString& getMessages() {return msgs;}90 int getErrorCount() { return errcount; } 91 int getWarningCount() { return warncount; } 92 int getInfoCount() { return infocount; } 93 int getStoredCount() { return storcount; } 94 int getErrorLevel() { return maxlevel; } 95 const SString& getMessages() { return msgs; } 83 96 84 ErrorHandler(int opts=0,int store=FMLV_ERROR):ErrorHandlerBase(opts),storlevel(store) 85 {reset();} 97 ErrorHandler(int opts = 0, int store = FMLV_ERROR) :ErrorHandlerBase(opts), storlevel(store) 98 { 99 reset(); 100 } 86 101 87 void handle(const char *o,const char *m,const char *bl,int w);102 void handle(const char *o, const char *m, const char *bl, int w); 88 103 }; 89 104 90 class ErrorRedirector : public ErrorHandlerBase105 class ErrorRedirector : public ErrorHandlerBase 91 106 { 92 107 ErrorManager *other_mgr; 93 108 public: 94 109 ErrorRedirector(ErrorManager *om) 95 :ErrorHandlerBase(), other_mgr(om) {}110 :ErrorHandlerBase(), other_mgr(om) {} 96 111 97 void handle(const char *o, const char *m,const char *bl,int w)98 99 other_mgr->send(o, m,bl,w);100 112 void handle(const char *o, const char *m, const char *bl, int w) 113 { 114 other_mgr->send(o, m, bl, w); 115 } 101 116 }; 102 117 103 118 #endif 104
Note: See TracChangeset
for help on using the changeset viewer.