00001 #ifndef __SYS_ERROR_H__
00002 #define __SYS_ERROR_H__
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014  
00015 #include <stdlib.h>
00016 #ifndef WIN32
00017 #include <unistd.h>
00018 #include <string.h>
00019 #include <strings.h>
00020 #else
00021 #include <string.h>
00022 #endif
00023 
00024 
00025 
00026 
00027 
00028 class XrdSysError_Table
00029 {
00030 public:
00031 friend class XrdSysError;
00032 
00033 char  *Lookup(int mnum)
00034              {return (char *)(mnum < base_msgnum || mnum > last_msgnum
00035                              ? 0 : msg_text[mnum - base_msgnum]);
00036              }
00037        XrdSysError_Table(int base, int last, const char **text)
00038                         : next(0),
00039                           base_msgnum(base),
00040                           last_msgnum(last),
00041                           msg_text(text) {}
00042       ~XrdSysError_Table() {}
00043 
00044 private:
00045 XrdSysError_Table *next;            
00046 int               base_msgnum;     
00047 int               last_msgnum;     
00048 const char      **msg_text;        
00049 };
00050   
00051 
00052 
00053 
00054   
00055 const int SYS_LOG_01 =   1;
00056 const int SYS_LOG_02 =   2;
00057 const int SYS_LOG_03 =   4;
00058 const int SYS_LOG_04 =   8;
00059 const int SYS_LOG_05 =  16;
00060 const int SYS_LOG_06 =  32;
00061 const int SYS_LOG_07 =  64;
00062 const int SYS_LOG_08 = 128;
00063 
00064 
00065 
00066 
00067 
00068 class XrdSysLogger;
00069   
00070 class XrdSysError
00071 {
00072 public:
00073          XrdSysError(XrdSysLogger *lp, const char *ErrPrefix="sys")
00074                     : epfx(0),
00075                       epfxlen(0),
00076                       msgMask(-1),
00077                       Logger(lp)
00078                     { SetPrefix(ErrPrefix); }
00079 
00080         ~XrdSysError() {}
00081 
00082 
00083 
00084 
00085 
00086 
00087 static void addTable(XrdSysError_Table *etp) {etp->next = etab; etab = etp;}
00088 
00089 
00090 
00091 int baseFD();
00092 
00093 
00094 
00095 
00096 static char *ec2text(int ecode);
00097 
00098 
00099 
00100 
00101 
00102 
00103 
00104 int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0);
00105 
00106 
00107 
00108 void Emsg(const char *esfx, const char *text1, 
00109                             const char *text2=0,
00110                             const char *text3=0);
00111 
00112 
00113 
00114 inline void Log(int mask, const char *esfx, 
00115                           const char *text1,
00116                           const char *text2=0,
00117                           const char *text3=0)
00118                {if (mask & msgMask) Emsg(esfx, text1, text2, text3);}
00119 
00120 
00121 
00122 XrdSysLogger *logger(XrdSysLogger *lp=0)
00123                    {XrdSysLogger *oldp = Logger;
00124                     if (lp) Logger = lp;
00125                     return oldp;
00126                    }
00127 
00128 
00129 
00130 void Say(const char *text1,   const char *text2=0, const char *txt3=0,
00131          const char *text4=0, const char *text5=0, const char *txt6=0);
00132 
00133 
00134 
00135 void setMsgMask(int mask) {msgMask = mask;}
00136 
00137 
00138 
00139 inline const char *SetPrefix(const char *prefix)
00140                         {const char *oldpfx = epfx;
00141                          epfx = prefix; epfxlen = strlen(epfx);
00142                          return oldpfx;
00143                         }
00144 
00145 
00146 
00147 void TBeg(const char *txt1=0, const char *txt2=0, const char *txt3=0);
00148 void TEnd();
00149 
00150 private:
00151 
00152 static XrdSysError_Table *etab;
00153 const char               *epfx;
00154 int                       epfxlen;
00155 int                       msgMask;
00156 XrdSysLogger             *Logger;
00157 };
00158 #endif