XrdSysError.hh

Go to the documentation of this file.
00001 #ifndef __SYS_ERROR_H__
00002 #define __SYS_ERROR_H__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                        X r d S y s E r r o r . h h                         */
00006 /*                                                                            */
00007 /*(c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University   */
00008 /*       All Rights Reserved. See XrdInfo.cc for complete License Terms       */
00009 /*Produced by Andrew Hanushevsky for Stanford University under contract       */
00010 /*           DE-AC03-76-SFO0515 with the Deprtment of Energy                  */
00011 /******************************************************************************/
00012 
00013 //          $Id: XrdSysError.hh 28902 2009-06-11 12:36:21Z ganis $
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 /*                      o o u c _ E r r o r _ T a b l e                       */
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;            // -> Next table or 0;
00046 int               base_msgnum;     // Starting message number
00047 int               last_msgnum;     // Ending   message number
00048 const char      **msg_text;        // Array of message text
00049 };
00050   
00051 /******************************************************************************/
00052 /*                  L o g   M a s k   D e f i n i t i o n s                   */
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 /*                            o o u c _ E r r o r                             */
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 // addTable allows you to add a new error table for errno handling. Any
00083 // number of table may be added and must consist of statis message text
00084 // since the table are deleted but the text is not freed. Error tables
00085 // must be setup without multi-threading.  There is only one global table.
00086 //
00087 static void addTable(XrdSysError_Table *etp) {etp->next = etab; etab = etp;}
00088 
00089 // baseFD() returns the original FD associated with this object.
00090 //
00091 int baseFD();
00092 
00093 // ec2text tyranslates an error code to the correspodning error text or returns
00094 // null if matching text cannot be found.
00095 //
00096 static char *ec2text(int ecode);
00097 
00098 // Emsg() produces a message of various forms. The message is written to the 
00099 // constructor specified file descriptor. See variations below.
00100 //
00101 // <datetime> <epfx><esfx>: error <ecode> (syser[<ecode>]); <text1> <text2>"
00102 // (returns abs(ecode)).
00103 //
00104 int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0);
00105 
00106 // <datetime> <epfx><esfx>: <text1> <text2> <text3>
00107 //
00108 void Emsg(const char *esfx, const char *text1, 
00109                             const char *text2=0,
00110                             const char *text3=0);
00111 
00112 // <datetime> <epfx><esfx>: <text1> <text2> <text3>
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 // logger() sets/returns the logger object for this message message handler.
00121 //
00122 XrdSysLogger *logger(XrdSysLogger *lp=0)
00123                    {XrdSysLogger *oldp = Logger;
00124                     if (lp) Logger = lp;
00125                     return oldp;
00126                    }
00127 
00128 // Say() route a line without timestamp or prefix
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 // Set the loging mask (only used by clients of this object)
00134 //
00135 void setMsgMask(int mask) {msgMask = mask;}
00136 
00137 // SetPrefix() dynamically changes the error prefix
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 // TBeg() is used to start a trace on ostream cerr. The TEnd() ends the trace.
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

Generated on Tue Jul 5 14:47:03 2011 for ROOT_528-00b_version by  doxygen 1.5.1