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 /*Produced by Andrew Hanushevsky for Stanford University under contract       */
00009 /*           DE-AC02-76-SFO0515 with the Deprtment of Energy                  */
00010 /*                                                                            */
00011 /* This file is part of the XRootD software suite.                            */
00012 /*                                                                            */
00013 /* XRootD is free software: you can redistribute it and/or modify it under    */
00014 /* the terms of the GNU Lesser General Public License as published by the     */
00015 /* Free Software Foundation, either version 3 of the License, or (at your     */
00016 /* option) any later version.                                                 */
00017 /*                                                                            */
00018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
00019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
00020 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
00021 /* License for more details.                                                  */
00022 /*                                                                            */
00023 /* You should have received a copy of the GNU Lesser General Public License   */
00024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
00025 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
00026 /*                                                                            */
00027 /* The copyright holder's institutional names and contributor's names may not */
00028 /* be used to endorse or promote products derived from this software without  */
00029 /* specific prior written permission of the institution or contributor.       */
00030 /******************************************************************************/
00031  
00032 #include <stdlib.h>
00033 #ifndef WIN32
00034 #include <unistd.h>
00035 #include <string.h>
00036 #include <strings.h>
00037 #else
00038 #include <string.h>
00039 #endif
00040 
00041 /******************************************************************************/
00042 /*                      o o u c _ E r r o r _ T a b l e                       */
00043 /******************************************************************************/
00044 
00045 class XrdSysError_Table
00046 {
00047 public:
00048 friend class XrdSysError;
00049 
00050 char  *Lookup(int mnum)
00051              {return (char *)(mnum < base_msgnum || mnum > last_msgnum
00052                              ? 0 : msg_text[mnum - base_msgnum]);
00053              }
00054        XrdSysError_Table(int base, int last, const char **text)
00055                         : next(0),
00056                           base_msgnum(base),
00057                           last_msgnum(last),
00058                           msg_text(text) {}
00059       ~XrdSysError_Table() {}
00060 
00061 private:
00062 XrdSysError_Table *next;            // -> Next table or 0;
00063 int               base_msgnum;     // Starting message number
00064 int               last_msgnum;     // Ending   message number
00065 const char      **msg_text;        // Array of message text
00066 };
00067   
00068 /******************************************************************************/
00069 /*                  L o g   M a s k   D e f i n i t i o n s                   */
00070 /******************************************************************************/
00071   
00072 const int SYS_LOG_01 =   1;
00073 const int SYS_LOG_02 =   2;
00074 const int SYS_LOG_03 =   4;
00075 const int SYS_LOG_04 =   8;
00076 const int SYS_LOG_05 =  16;
00077 const int SYS_LOG_06 =  32;
00078 const int SYS_LOG_07 =  64;
00079 const int SYS_LOG_08 = 128;
00080 
00081 /******************************************************************************/
00082 /*                            o o u c _ E r r o r                             */
00083 /******************************************************************************/
00084 
00085 class XrdSysLogger;
00086   
00087 class XrdSysError
00088 {
00089 public:
00090          XrdSysError(XrdSysLogger *lp, const char *ErrPrefix="sys")
00091                     : epfx(0),
00092                       epfxlen(0),
00093                       msgMask(-1),
00094                       Logger(lp)
00095                     { SetPrefix(ErrPrefix); }
00096 
00097         ~XrdSysError() {}
00098 
00099 // addTable allows you to add a new error table for errno handling. Any
00100 // number of table may be added and must consist of statis message text
00101 // since the table are deleted but the text is not freed. Error tables
00102 // must be setup without multi-threading.  There is only one global table.
00103 //
00104 static void addTable(XrdSysError_Table *etp) {etp->next = etab; etab = etp;}
00105 
00106 // baseFD() returns the original FD associated with this object.
00107 //
00108 int baseFD();
00109 
00110 // ec2text tyranslates an error code to the correspodning error text or returns
00111 // null if matching text cannot be found.
00112 //
00113 static char *ec2text(int ecode);
00114 
00115 // Emsg() produces a message of various forms. The message is written to the 
00116 // constructor specified file descriptor. See variations below.
00117 //
00118 // <datetime> <epfx><esfx>: error <ecode> (syser[<ecode>]); <text1> <text2>"
00119 // (returns abs(ecode)).
00120 //
00121 int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0);
00122 
00123 // <datetime> <epfx><esfx>: <text1> <text2> <text3>
00124 //
00125 void Emsg(const char *esfx, const char *text1, 
00126                             const char *text2=0,
00127                             const char *text3=0);
00128 
00129 // <datetime> <epfx><esfx>: <text1> <text2> <text3>
00130 //
00131 inline void Log(int mask, const char *esfx, 
00132                           const char *text1,
00133                           const char *text2=0,
00134                           const char *text3=0)
00135                {if (mask & msgMask) Emsg(esfx, text1, text2, text3);}
00136 
00137 // logger() sets/returns the logger object for this message message handler.
00138 //
00139 XrdSysLogger *logger(XrdSysLogger *lp=0)
00140                    {XrdSysLogger *oldp = Logger;
00141                     if (lp) Logger = lp;
00142                     return oldp;
00143                    }
00144 
00145 // Say() route a line without timestamp or prefix
00146 //
00147 void Say(const char *text1,   const char *text2=0, const char *txt3=0,
00148          const char *text4=0, const char *text5=0, const char *txt6=0);
00149 
00150 // Set the loging mask (only used by clients of this object)
00151 //
00152 void setMsgMask(int mask) {msgMask = mask;}
00153 
00154 // SetPrefix() dynamically changes the error prefix
00155 //
00156 inline const char *SetPrefix(const char *prefix)
00157                         {const char *oldpfx = epfx;
00158                          epfx = prefix; epfxlen = strlen(epfx);
00159                          return oldpfx;
00160                         }
00161 
00162 // TBeg() is used to start a trace on ostream cerr. The TEnd() ends the trace.
00163 //
00164 void TBeg(const char *txt1=0, const char *txt2=0, const char *txt3=0);
00165 void TEnd();
00166 
00167 private:
00168 
00169 static XrdSysError_Table *etab;
00170 const char               *epfx;
00171 int                       epfxlen;
00172 int                       msgMask;
00173 XrdSysLogger             *Logger;
00174 };
00175 #endif

Generated on 12 Dec 2014 for xrootd by  doxygen 1.4.7