XrdSysError.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                        X r d S y s E r r o r . c c                         */
00004 /*                                                                            */
00005 /*(c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University   */
00006 /*       All Rights Reserved. See XrdInfo.cc for complete License Terms       */
00007 /*Produced by Andrew Hanushevsky for Stanford University under contract       */
00008 /*           DE-AC03-76-SFO0515 with the Deprtment of Energy                  */
00009 /******************************************************************************/
00010  
00011 //         $Id: XrdSysError.cc 28902 2009-06-11 12:36:21Z ganis $
00012 
00013 const char *XrdSysErrorCVSID = "$Id: XrdSysError.cc 28902 2009-06-11 12:36:21Z ganis $";
00014 
00015 #include <ctype.h>
00016 #ifndef WIN32
00017 #include <unistd.h>
00018 #include <errno.h>
00019 #include <stdlib.h>
00020 #include <stdio.h>
00021 #include <string.h>
00022 #include <strings.h>
00023 #include <sys/types.h>
00024 #include <sys/uio.h>
00025 #else
00026 #include <stdlib.h>
00027 #include <stdio.h>
00028 #include <string.h>
00029 #include <sys/types.h>
00030 #include "XrdSys/XrdWin32.hh"
00031 #endif
00032 
00033 #include "XrdSys/XrdSysError.hh"
00034 #include "XrdSys/XrdSysHeaders.hh"
00035 #include "XrdSys/XrdSysLogger.hh"
00036 #include "XrdSys/XrdSysPlatform.hh"
00037 
00038 /******************************************************************************/
00039 /*                               d e f i n e s                                */
00040 /******************************************************************************/
00041 
00042 #define Set_IOV_Item(x, y) {iov[iovpnt].iov_base  = (caddr_t)x;\
00043                             iov[iovpnt++].iov_len = y;}
00044 
00045 #define Set_IOV_Buff(x)    {iov[iovpnt].iov_base  = (caddr_t)x;\
00046                             iov[iovpnt++].iov_len = strlen(x);}
00047 
00048 /******************************************************************************/
00049 /*                               G l o b a l s                                */
00050 /******************************************************************************/
00051   
00052 XrdSysError_Table *XrdSysError::etab = 0;
00053 
00054 /******************************************************************************/
00055 /*                                b a s e F D                                 */
00056 /******************************************************************************/
00057   
00058 int XrdSysError::baseFD() {return Logger->originalFD();}
00059 
00060 /******************************************************************************/
00061 /*                               e c 2 t e x t                                */
00062 /******************************************************************************/
00063 
00064 char *XrdSysError::ec2text(int ecode)
00065 {
00066     int xcode;
00067     char *etxt = 0;
00068     XrdSysError_Table *etp = etab;
00069 
00070     xcode = (ecode < 0 ? -ecode : ecode);
00071     while((etp != 0) && !(etxt = etp->Lookup(xcode))) etp = etp->next;
00072     if (!etxt) etxt = strerror(xcode);
00073     return etxt;
00074 }
00075   
00076 /******************************************************************************/
00077 /*                                  E m s g                                   */
00078 /******************************************************************************/
00079 
00080 int XrdSysError::Emsg(const char *esfx, int ecode, const char *txt1, 
00081                                                    const char *txt2)
00082 {
00083     struct iovec iov[16];
00084     int iovpnt = 0;
00085     char ebuff[16], etbuff[80], *etxt = 0;
00086 
00087     if (!(etxt = ec2text(ecode)))
00088        {snprintf(ebuff, sizeof(ebuff), "reason unknown (%d)", ecode); 
00089         etxt = ebuff;
00090        } else if (isupper(static_cast<int>(*etxt)))
00091                  {strlcpy(etbuff, etxt, sizeof(etbuff));
00092                   *etbuff = static_cast<char>(tolower(static_cast<int>(*etxt)));
00093                   etxt = etbuff;
00094                  }
00095 
00096                          Set_IOV_Item(0,0);                          //  0
00097     if (epfx && epfxlen) Set_IOV_Item(epfx, epfxlen);                //  1
00098     if (esfx           ) Set_IOV_Buff(esfx);                         //  2
00099                          Set_IOV_Item(": Unable to ", 12);           //  3
00100                          Set_IOV_Buff(txt1);                         //  4
00101     if (txt2 && txt2[0]){Set_IOV_Item(" ", 1);                       //  5
00102                          Set_IOV_Buff(txt2); }                       //  6
00103                          Set_IOV_Item("; ", 2);                      //  7
00104                          Set_IOV_Buff(etxt);                         //  8
00105                          Set_IOV_Item("\n", 1);                      //  9
00106     Logger->Put(iovpnt, iov);
00107 
00108     return ecode;
00109 }
00110   
00111 void XrdSysError::Emsg(const char *esfx, const char *txt1, 
00112                                          const char *txt2, 
00113                                          const char *txt3)
00114 {
00115     struct iovec iov[16];
00116     int iovpnt = 0;
00117 
00118                          Set_IOV_Item(0,0);                          //  0
00119     if (epfx && epfxlen) Set_IOV_Item(epfx, epfxlen);                //  1
00120     if (esfx           ) Set_IOV_Buff(esfx);                         //  2
00121                          Set_IOV_Item(": ", 2);                      //  3
00122                          Set_IOV_Buff(txt1);                         //  4
00123     if (txt2 && txt2[0]){Set_IOV_Item(" ", 1);                       //  5
00124                          Set_IOV_Buff(txt2);}                        //  6
00125     if (txt3 && txt3[0]){Set_IOV_Item(" ", 1);                       //  7
00126                          Set_IOV_Buff(txt3);}                        //  8
00127                          Set_IOV_Item("\n", 1);                      //  9
00128     Logger->Put(iovpnt, iov);
00129 }
00130 
00131 /******************************************************************************/
00132 /*                                   S a y                                    */
00133 /******************************************************************************/
00134   
00135 void XrdSysError::Say(const char *txt1, const char *txt2, const char *txt3,
00136                       const char *txt4, const char *txt5, const char *txt6)
00137 {
00138     struct iovec iov[9];
00139     int iovpnt = 0;
00140     if (txt1)            Set_IOV_Buff(txt1)                          //  0
00141        else              Set_IOV_Item(0,0);
00142     if (txt2 && txt2[0]) Set_IOV_Buff(txt2);                         //  1
00143     if (txt3 && txt3[0]) Set_IOV_Buff(txt3);                         //  2
00144     if (txt4 && txt4[0]) Set_IOV_Buff(txt4);                         //  3
00145     if (txt5 && txt5[0]) Set_IOV_Buff(txt5);                         //  4
00146     if (txt6 && txt6[0]) Set_IOV_Buff(txt6);                         //  5
00147                          Set_IOV_Item("\n", 1);                      //  6
00148     Logger->Put(iovpnt, iov);
00149 }
00150  
00151 /******************************************************************************/
00152 /*                                  T b e g                                   */
00153 /******************************************************************************/
00154   
00155 void XrdSysError::TBeg(const char *txt1, const char *txt2, const char *txt3)
00156 {
00157  cerr <<Logger->traceBeg();
00158  if (txt1) cerr <<txt1 <<' ';
00159  if (txt2) cerr <<epfx <<txt2 <<": ";
00160  if (txt3) cerr <<txt3;
00161 }
00162 
00163 /******************************************************************************/
00164 /*                                  T E n d                                   */
00165 /******************************************************************************/
00166   
00167 void XrdSysError::TEnd() {cerr <<endl; Logger->traceEnd();}

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