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

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