|
||||
File indexing completed on 2025-01-30 10:27:56
0001 #ifndef __SYS_ERROR_H__ 0002 #define __SYS_ERROR_H__ 0003 /******************************************************************************/ 0004 /* */ 0005 /* X r d S y s E r r o r . h h */ 0006 /* */ 0007 /*(c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */ 0008 /*Produced by Andrew Hanushevsky for Stanford University under contract */ 0009 /* DE-AC02-76-SFO0515 with the Deprtment of Energy */ 0010 /* */ 0011 /* This file is part of the XRootD software suite. */ 0012 /* */ 0013 /* XRootD is free software: you can redistribute it and/or modify it under */ 0014 /* the terms of the GNU Lesser General Public License as published by the */ 0015 /* Free Software Foundation, either version 3 of the License, or (at your */ 0016 /* option) any later version. */ 0017 /* */ 0018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 0019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 0020 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 0021 /* License for more details. */ 0022 /* */ 0023 /* You should have received a copy of the GNU Lesser General Public License */ 0024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 0025 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 0026 /* */ 0027 /* The copyright holder's institutional names and contributor's names may not */ 0028 /* be used to endorse or promote products derived from this software without */ 0029 /* specific prior written permission of the institution or contributor. */ 0030 /******************************************************************************/ 0031 0032 #include <cstdlib> 0033 #ifndef WIN32 0034 #include <unistd.h> 0035 #include <cstring> 0036 #include <strings.h> 0037 #else 0038 #include <cstring> 0039 #endif 0040 0041 /******************************************************************************/ 0042 /* o o u c _ E r r o r _ T a b l e */ 0043 /******************************************************************************/ 0044 0045 class XrdSysError_Table 0046 { 0047 public: 0048 friend class XrdSysError; 0049 0050 char *Lookup(int mnum) 0051 {return (char *)(mnum < base_msgnum || mnum > last_msgnum 0052 ? 0 : msg_text[mnum - base_msgnum]); 0053 } 0054 XrdSysError_Table(int base, int last, const char **text) 0055 : next(0), 0056 base_msgnum(base), 0057 last_msgnum(last), 0058 msg_text(text) {} 0059 ~XrdSysError_Table() {} 0060 0061 private: 0062 XrdSysError_Table *next; // -> Next table or 0; 0063 int base_msgnum; // Starting message number 0064 int last_msgnum; // Ending message number 0065 const char **msg_text; // Array of message text 0066 }; 0067 0068 /******************************************************************************/ 0069 /* L o g M a s k D e f i n i t i o n s */ 0070 /******************************************************************************/ 0071 0072 const int SYS_LOG_01 = 1; 0073 const int SYS_LOG_02 = 2; 0074 const int SYS_LOG_03 = 4; 0075 const int SYS_LOG_04 = 8; 0076 const int SYS_LOG_05 = 16; 0077 const int SYS_LOG_06 = 32; 0078 const int SYS_LOG_07 = 64; 0079 const int SYS_LOG_08 = 128; 0080 // 0x00000100 to 0x0000ffff reseved for XRootD use 0081 // 0x00010000 to 0xffff0000 reseved for non-XRootD use 0082 0083 /******************************************************************************/ 0084 /* o o u c _ E r r o r */ 0085 /******************************************************************************/ 0086 0087 class XrdSysLogger; 0088 0089 class XrdSysError 0090 { 0091 public: 0092 XrdSysError(XrdSysLogger *lp, const char *ErrPrefix="sys") 0093 : epfx(0), 0094 epfxlen(0), 0095 msgMask(-1), 0096 Logger(lp) 0097 { SetPrefix(ErrPrefix); } 0098 0099 ~XrdSysError() {} 0100 0101 // addTable allows you to add a new error table for errno handling. Any 0102 // number of table may be added and must consist of statis message text 0103 // since the table are deleted but the text is not freed. Error tables 0104 // must be setup without multi-threading. There is only one global table. 0105 // 0106 static void addTable(XrdSysError_Table *etp) {etp->next = etab; etab = etp;} 0107 0108 // baseFD() returns the original FD associated with this object. 0109 // 0110 int baseFD(); 0111 0112 // ec2text tyranslates an error code to the correspodning error text or returns 0113 // null if matching text cannot be found. 0114 // 0115 static const char *ec2text(int ecode); 0116 0117 // Emsg() produces a message of various forms. The message is written to the 0118 // constructor specified file descriptor. See variations below. 0119 // 0120 // <datetime> <epfx><esfx>: error <ecode> (syser[<ecode>]); <text1> <text2>" 0121 // (returns abs(ecode)). 0122 // 0123 int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0); 0124 0125 // <datetime> <epfx><esfx>: <text1> <text2> <text3> 0126 // 0127 void Emsg(const char *esfx, const char *text1, 0128 const char *text2=0, 0129 const char *text3=0); 0130 0131 // <datetime> <epfx><esfx>: <text1> <text2> <text3> 0132 // 0133 inline void Log(int mask, const char *esfx, 0134 const char *text1, 0135 const char *text2=0, 0136 const char *text3=0) 0137 {if (mask & msgMask) Emsg(esfx, text1, text2, text3);} 0138 0139 // logger() sets/returns the logger object for this message message handler. 0140 // 0141 XrdSysLogger *logger(XrdSysLogger *lp=0) 0142 {XrdSysLogger *oldp = Logger; 0143 if (lp) Logger = lp; 0144 return oldp; 0145 } 0146 0147 // Say() route a line without timestamp or prefix 0148 // 0149 void Say(const char *text1, const char *text2=0, const char *txt3=0, 0150 const char *text4=0, const char *text5=0, const char *txt6=0); 0151 0152 // Set/Get the loging mask (only used by clients of this object) 0153 // 0154 void setMsgMask(int mask) {msgMask = mask;} 0155 0156 int getMsgMask() {return msgMask;} 0157 0158 // SetPrefix() dynamically changes the error prefix 0159 // 0160 inline const char *SetPrefix(const char *prefix) 0161 {const char *oldpfx = epfx; 0162 epfx = prefix; epfxlen = strlen(epfx); 0163 return oldpfx; 0164 } 0165 0166 // TBeg() is used to start a trace on std::ostream std::cerr. The TEnd() ends the trace. 0167 // 0168 void TBeg(const char *txt1=0, const char *txt2=0, const char *txt3=0); 0169 void TEnd(); 0170 0171 private: 0172 0173 static XrdSysError_Table *etab; 0174 const char *epfx; 0175 int epfxlen; 0176 int msgMask; 0177 XrdSysLogger *Logger; 0178 }; 0179 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |