|
xrootd
|
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 /* 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 Department of Energy */ 00011 /* */ 00012 /******************************************************************************/ 00013 00014 #include <string.h> // For strlcpy() 00015 #include <sys/types.h> 00016 00017 #include "XrdSys/XrdSysPlatform.hh" 00018 00019 /******************************************************************************/ 00020 /* X r d O u c E I */ 00021 /******************************************************************************/ 00022 00023 struct XrdOucEI // Err information structure 00024 { 00025 static const size_t Max_Error_Len = 2048; 00026 00027 const char *user; 00028 int code; 00029 char message[Max_Error_Len]; 00030 00031 void clear(const char *usr=0) 00032 {code=0; message[0]='\0'; user = (usr ? usr : "?");} 00033 00034 XrdOucEI &operator =(const XrdOucEI &rhs) 00035 {code = rhs.code; 00036 user = rhs.user; 00037 strcpy(message, rhs.message); 00038 return *this; 00039 } 00040 XrdOucEI(const char *usr) {clear(usr);} 00041 }; 00042 00043 /******************************************************************************/ 00044 /* X r d O u c E r r I n f o */ 00045 /******************************************************************************/ 00046 00047 class XrdOucEICB; 00048 class XrdOucEnv; 00049 class XrdSysSemaphore; 00050 00051 class XrdOucErrInfo 00052 { 00053 public: 00054 void clear() {ErrInfo.clear();} 00055 00056 inline void setErrArg(unsigned long long cbarg=0) {ErrCBarg = cbarg;} 00057 inline void setErrCB(XrdOucEICB *cb, unsigned long long cbarg=0) 00058 {ErrCB = cb; ErrCBarg = cbarg;} 00059 inline int setErrCode(int code) {return ErrInfo.code = code;} 00060 inline int setErrInfo(int code, const char *message) 00061 {strlcpy(ErrInfo.message, message, sizeof(ErrInfo.message)); 00062 return ErrInfo.code = code; 00063 } 00064 inline int setErrInfo(int code, const char *txtlist[], int n) 00065 {int i, j = 0, k = sizeof(ErrInfo.message), l; 00066 for (i = 0; i < n && k > 1; i++) 00067 {l = strlcpy(&ErrInfo.message[j], txtlist[i], k); 00068 j += l; k -= l; 00069 } 00070 return ErrInfo.code = code; 00071 } 00072 inline void setErrUser(const char *user) {ErrInfo.user = (user ? user : "?");} 00073 00074 inline unsigned long long getErrArg() {return ErrCBarg;} 00075 00076 inline char *getMsgBuff(int &mblen) 00077 {mblen = sizeof(ErrInfo.message); 00078 return ErrInfo.message; 00079 } 00080 inline XrdOucEICB *getErrCB() {return ErrCB;} 00081 inline XrdOucEICB *getErrCB(unsigned long long &ap) 00082 {ap = ErrCBarg; return ErrCB;} 00083 inline int getErrInfo() {return ErrInfo.code;} 00084 inline int getErrInfo(XrdOucEI &errorParm) 00085 {errorParm = ErrInfo; return ErrInfo.code;} 00086 inline const char *getErrText() 00087 {return (const char *)ErrInfo.message;} 00088 inline const char *getErrText(int &ecode) 00089 {ecode = ErrInfo.code; 00090 return (const char *)ErrInfo.message;} 00091 inline const char *getErrUser() {return ErrInfo.user;} 00092 00093 inline XrdOucEnv *getEnv() {return (ErrCB ? 0 : ErrEnv);} 00094 00095 inline XrdOucEnv *setEnv(XrdOucEnv *newEnv) 00096 {XrdOucEnv *oldEnv = (ErrCB ? 0 : ErrEnv); 00097 ErrEnv = newEnv; 00098 ErrCB = 0; 00099 return oldEnv; 00100 } 00101 00102 XrdOucErrInfo &operator =(const XrdOucErrInfo &rhs) 00103 {ErrInfo = rhs.ErrInfo; 00104 ErrCB = rhs.ErrCB; 00105 ErrCBarg= rhs.ErrCBarg; 00106 return *this; 00107 } 00108 00109 XrdOucErrInfo(const char *user=0,XrdOucEICB *cb=0,unsigned long long ca=0) 00110 : ErrInfo(user), ErrCB(cb), ErrCBarg(ca){} 00111 00112 XrdOucErrInfo(const char *user,XrdOucEnv *envp) 00113 : ErrInfo(user), ErrCB(0), ErrEnv(envp) {} 00114 00115 virtual ~XrdOucErrInfo() {} 00116 00117 protected: 00118 00119 XrdOucEI ErrInfo; 00120 XrdOucEICB *ErrCB; 00121 union { 00122 unsigned long long ErrCBarg; 00123 XrdOucEnv *ErrEnv; 00124 }; 00125 }; 00126 00127 /******************************************************************************/ 00128 /* X r d O u c E I C B */ 00129 /******************************************************************************/ 00130 00131 class XrdOucEICB 00132 { 00133 public: 00134 00135 // Done() is invoked when the requested operation completes. Arguments are: 00136 // Result - the original function's result (may be changed). 00137 // eInfo - Associated error information. The eInfo object may not be 00138 // modified until it's own callback Done() method is called, if 00139 // supplied. If the callback function in eInfo is zero, then the 00140 // eInfo object is deleted by the invoked callback. Otherwise, 00141 // that method must be invoked by this callback function after 00142 // the actual callback message is sent. This allows the callback 00143 // requestor to do post-processing and be asynchronous. 00144 // 00145 // 00146 virtual void Done(int &Result, //I/O: Function result 00147 XrdOucErrInfo *eInfo)=0; // In: Error Info 00148 00149 // Same() is invoked to determine if two arguments refer to the same user. 00150 // True is returned if so, false, otherwise. 00151 // 00152 virtual int Same(unsigned long long arg1, unsigned long long arg2)=0; 00153 00154 XrdOucEICB() {} 00155 virtual ~XrdOucEICB() {} 00156 }; 00157 #endif
1.7.5