XrdOucErrInfo.hh

Go to the documentation of this file.
00001 #ifndef __OUC_ERRINFO_H__
00002 #define __OUC_ERRINFO_H__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                      X r d O u c E r r I n f o . h h                       */
00006 /*                                                                            */
00007 /* (c) 2043 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 Department 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 
00033 #include <string.h>      // For strlcpy()
00034 #include <sys/types.h>
00035 
00036 #include "XrdSys/XrdSysPlatform.hh"
00037 
00038 /******************************************************************************/
00039 /*                              X r d O u c E I                               */
00040 /******************************************************************************/
00041 
00042 struct XrdOucEI      // Err information structure
00043 { 
00044  static const size_t Max_Error_Len = 2048;
00045  static const int    Path_Offset   = 1024;
00046 
00047 const      char *user;
00048            int   code;
00049            char  message[Max_Error_Len];
00050 
00051            void clear(const char *usr=0) 
00052                      {code=0; message[0]='\0'; user = (usr ? usr : "?");}
00053 
00054            XrdOucEI &operator =(const XrdOucEI &rhs)
00055                {code = rhs.code;
00056                 user = rhs.user;
00057                 strcpy(message, rhs.message); 
00058                 return *this;
00059                }
00060            XrdOucEI(const char *usr) {clear(usr);}
00061 };
00062 
00063 /******************************************************************************/
00064 /*                         X r d O u c E r r I n f o                          */
00065 /******************************************************************************/
00066 
00067 class XrdOucEICB;
00068 class XrdOucEnv;
00069 class XrdSysSemaphore;
00070   
00071 class XrdOucErrInfo
00072 {
00073 public:
00074        void  clear() {ErrInfo.clear();}
00075 
00076 inline void  setErrArg(unsigned long long cbarg=0) {ErrCBarg = cbarg;}
00077 inline void  setErrCB(XrdOucEICB *cb, unsigned long long cbarg=0)
00078                      {ErrCB = cb; ErrCBarg = cbarg;}
00079 inline int   setErrCode(int code) {return ErrInfo.code = code;}
00080 inline int   setErrInfo(int code, const char *message)
00081                 {strlcpy(ErrInfo.message, message, sizeof(ErrInfo.message));
00082                  return ErrInfo.code = code;
00083                 }
00084 inline int   setErrInfo(int code, const char *txtlist[], int n)
00085                 {int i, j = 0, k = sizeof(ErrInfo.message), l;
00086                  for (i = 0; i < n && k > 1; i++)
00087                      {l = strlcpy(&ErrInfo.message[j], txtlist[i], k);
00088                       j += l; k -= l;
00089                      }
00090                  return ErrInfo.code = code;
00091                 }
00092 inline void  setErrUser(const char *user) {ErrInfo.user = (user ? user : "?");}
00093 
00094 inline unsigned long long  getErrArg() {return ErrCBarg;}
00095 
00096 inline char               *getMsgBuff(int &mblen)
00097                                    {mblen = sizeof(ErrInfo.message);
00098                                     return ErrInfo.message;
00099                                    }
00100 inline XrdOucEICB         *getErrCB() {return ErrCB;}
00101 inline XrdOucEICB         *getErrCB(unsigned long long &ap) 
00102                                    {ap = ErrCBarg; return ErrCB;}
00103 inline int                 getErrInfo() {return ErrInfo.code;}
00104 inline int                 getErrInfo(XrdOucEI &errorParm)
00105                                    {errorParm = ErrInfo; return ErrInfo.code;}
00106 inline const char         *getErrText()
00107                                    {return (const char *)ErrInfo.message;}
00108 inline const char         *getErrText(int &ecode)
00109                                    {ecode = ErrInfo.code; 
00110                                     return (const char *)ErrInfo.message;}
00111 inline const char         *getErrUser() {return ErrInfo.user;}
00112 
00113 inline XrdOucEnv          *getEnv() {return (ErrCB ? 0 : ErrEnv);}
00114 
00115 inline XrdOucEnv          *setEnv(XrdOucEnv *newEnv)
00116                                  {XrdOucEnv *oldEnv = (ErrCB ? 0 : ErrEnv);
00117                                   ErrEnv = newEnv;
00118                                   ErrCB  = 0;
00119                                   return oldEnv;
00120                                  }
00121 
00122 inline const char         *getErrData()
00123                                  {return (dOff < 0 ? 0 : ErrInfo.message+dOff);}
00124 
00125 inline void                setErrData(const char *Data, int Offs=0)
00126                                  {if (!Data) dOff = -1;
00127                                      else {strlcpy(ErrInfo.message+Offs, Data,
00128                                                    sizeof(ErrInfo.message)-Offs);
00129                                            dOff = Offs;
00130                                           }
00131                                  }
00132 
00133 inline int                 getErrMid() {return mID;}
00134 
00135 inline void                setErrMid(int  mid) {mID = mid;}
00136 
00137          XrdOucErrInfo &operator =(const XrdOucErrInfo &rhs)
00138                         {ErrInfo = rhs.ErrInfo;
00139                          ErrCB   = rhs.ErrCB;
00140                          ErrCBarg= rhs.ErrCBarg;
00141                          mID     = rhs.mID;
00142                          dOff    = -1;
00143                          return *this;
00144                         }
00145 
00146          XrdOucErrInfo(const char *user=0,XrdOucEICB *cb=0,
00147                        unsigned long long ca=0, int mid=0)
00148                     : ErrInfo(user), ErrCB(cb), ErrCBarg(ca), mID(mid), 
00149                       dOff(-1), Reserved0(0), Reserved1(0) {}
00150 
00151          XrdOucErrInfo(const char *user,XrdOucEnv *envp)
00152                     : ErrInfo(user), ErrCB(0), ErrEnv(envp), mID(0),
00153                       dOff(-1), Reserved0(0), Reserved1(0) {}
00154 
00155          XrdOucErrInfo(const char *user, int MonID)
00156                     : ErrInfo(user), ErrCB(0), ErrCBarg(0), mID(MonID),
00157                       dOff(-1), Reserved0(0), Reserved1(0) {}
00158 
00159 virtual ~XrdOucErrInfo() {}
00160 
00161 protected:
00162 
00163 XrdOucEI            ErrInfo;
00164 XrdOucEICB         *ErrCB;
00165 union {
00166 unsigned long long  ErrCBarg;
00167 XrdOucEnv          *ErrEnv;
00168       };
00169 int                 mID;
00170 short               dOff;
00171 short               Reserved0;
00172 void               *Reserved1;
00173 };
00174 
00175 /******************************************************************************/
00176 /*                            X r d O u c E I C B                             */
00177 /******************************************************************************/
00178 
00179 class XrdOucEICB
00180 {
00181 public:
00182 
00183 // Done() is invoked when the requested operation completes. Arguments are:
00184 //        Result - the original function's result (may be changed).
00185 //        eInfo  - Associated error information. The eInfo object may not be
00186 //                 modified until it's own callback Done() method is called, if
00187 //                 supplied. If the callback function in eInfo is zero, then the
00188 //                 eInfo object is deleted by the invoked callback. Otherwise,
00189 //                 that method must be invoked by this callback function after
00190 //                 the actual callback message is sent. This allows the callback
00191 //                 requestor to do post-processing and be asynchronous.
00192 //        Path   - Optionally, the path related to thid request. It is used
00193 //                 for tracing and detailed monitoring purposes.
00194 //
00195 //
00196 virtual void        Done(int           &Result,   //I/O: Function result
00197                          XrdOucErrInfo *eInfo,    // In: Error Info
00198                          const char    *Path=0)=0;// In: Relevant path
00199 
00200 // Same() is invoked to determine if two arguments refer to the same user.
00201 //        True is returned if so, false, otherwise.
00202 //
00203 virtual int         Same(unsigned long long arg1, unsigned long long arg2)=0;
00204 
00205                     XrdOucEICB() {}
00206 virtual            ~XrdOucEICB() {}
00207 };
00208 #endif

Generated on 16 Jan 2014 for xrootd by  doxygen 1.4.7