xrootd
XrdOucErrInfo.hh
Go to the documentation of this file.
1 #ifndef __OUC_ERRINFO_H__
2 #define __OUC_ERRINFO_H__
3 /******************************************************************************/
4 /* */
5 /* X r d O u c E r r I n f o . h h */
6 /* */
7 /* (c) 2043 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC03-76-SFO0515 with the Department of Energy */
11 /* */
12 /******************************************************************************/
13 
14 #include <string.h> // For strlcpy()
15 #include <sys/types.h>
16 
17 #include "XrdSys/XrdSysPlatform.hh"
18 
19 /******************************************************************************/
20 /* X r d O u c E I */
21 /******************************************************************************/
22 
23 struct XrdOucEI // Err information structure
24 {
25  static const size_t Max_Error_Len = 2048;
26  static const int Path_Offset = 1024;
27 
28 const char *user;
29  int code;
31 
32  void clear(const char *usr=0)
33  {code=0; message[0]='\0'; user = (usr ? usr : "?");}
34 
36  {code = rhs.code;
37  user = rhs.user;
38  strcpy(message, rhs.message);
39  return *this;
40  }
41  XrdOucEI(const char *usr) {clear(usr);}
42 };
43 
44 /******************************************************************************/
45 /* X r d O u c E r r I n f o */
46 /******************************************************************************/
47 
48 class XrdOucEICB;
49 class XrdOucEnv;
50 class XrdSysSemaphore;
51 
53 {
54 public:
55  void clear() {ErrInfo.clear();}
56 
57 inline void setErrArg(unsigned long long cbarg=0) {ErrCBarg = cbarg;}
58 inline void setErrCB(XrdOucEICB *cb, unsigned long long cbarg=0)
59  {ErrCB = cb; ErrCBarg = cbarg;}
60 inline int setErrCode(int code) {return ErrInfo.code = code;}
61 inline int setErrInfo(int code, const char *message)
62  {strlcpy(ErrInfo.message, message, sizeof(ErrInfo.message));
63  return ErrInfo.code = code;
64  }
65 inline int setErrInfo(int code, const char *txtlist[], int n)
66  {int i, j = 0, k = sizeof(ErrInfo.message), l;
67  for (i = 0; i < n && k > 1; i++)
68  {l = strlcpy(&ErrInfo.message[j], txtlist[i], k);
69  j += l; k -= l;
70  }
71  return ErrInfo.code = code;
72  }
73 inline void setErrUser(const char *user) {ErrInfo.user = (user ? user : "?");}
74 
75 inline unsigned long long getErrArg() {return ErrCBarg;}
76 
77 inline char *getMsgBuff(int &mblen)
78  {mblen = sizeof(ErrInfo.message);
79  return ErrInfo.message;
80  }
81 inline XrdOucEICB *getErrCB() {return ErrCB;}
82 inline XrdOucEICB *getErrCB(unsigned long long &ap)
83  {ap = ErrCBarg; return ErrCB;}
84 inline int getErrInfo() {return ErrInfo.code;}
85 inline int getErrInfo(XrdOucEI &errorParm)
86  {errorParm = ErrInfo; return ErrInfo.code;}
87 inline const char *getErrText()
88  {return (const char *)ErrInfo.message;}
89 inline const char *getErrText(int &ecode)
90  {ecode = ErrInfo.code;
91  return (const char *)ErrInfo.message;}
92 inline const char *getErrUser() {return ErrInfo.user;}
93 
94 inline XrdOucEnv *getEnv() {return (ErrCB ? 0 : ErrEnv);}
95 
96 inline XrdOucEnv *setEnv(XrdOucEnv *newEnv)
97  {XrdOucEnv *oldEnv = (ErrCB ? 0 : ErrEnv);
98  ErrEnv = newEnv;
99  ErrCB = 0;
100  return oldEnv;
101  }
102 
103 inline const char *getErrData()
104  {return (dOff < 0 ? 0 : ErrInfo.message+dOff);}
105 
106 inline void setErrData(const char *Data, int Offs=0)
107  {if (!Data) dOff = -1;
108  else {strlcpy(ErrInfo.message+Offs, Data,
109  sizeof(ErrInfo.message)-Offs);
110  dOff = Offs;
111  }
112  }
113 
114 inline int getErrMid() {return mID;}
115 
116 inline void setErrMid(int mid) {mID = mid;}
117 
119  {ErrInfo = rhs.ErrInfo;
120  ErrCB = rhs.ErrCB;
121  ErrCBarg= rhs.ErrCBarg;
122  mID = rhs.mID;
123  dOff = -1;
124  return *this;
125  }
126 
127  XrdOucErrInfo(const char *user=0,XrdOucEICB *cb=0,
128  unsigned long long ca=0, int mid=0)
129  : ErrInfo(user), ErrCB(cb), ErrCBarg(ca), mID(mid),
130  dOff(-1), Reserved0(0), Reserved1(0) {}
131 
132  XrdOucErrInfo(const char *user,XrdOucEnv *envp)
133  : ErrInfo(user), ErrCB(0), ErrEnv(envp), mID(0),
134  dOff(-1), Reserved0(0), Reserved1(0) {}
135 
136  XrdOucErrInfo(const char *user, int MonID)
137  : ErrInfo(user), ErrCB(0), ErrCBarg(0), mID(MonID),
138  dOff(-1), Reserved0(0), Reserved1(0) {}
139 
140 virtual ~XrdOucErrInfo() {}
141 
142 protected:
143 
146 union {
147 unsigned long long ErrCBarg;
149  };
150 int mID;
151 short dOff;
152 short Reserved0;
153 void *Reserved1;
154 };
155 
156 /******************************************************************************/
157 /* X r d O u c E I C B */
158 /******************************************************************************/
159 
161 {
162 public:
163 
164 // Done() is invoked when the requested operation completes. Arguments are:
165 // Result - the original function's result (may be changed).
166 // eInfo - Associated error information. The eInfo object may not be
167 // modified until it's own callback Done() method is called, if
168 // supplied. If the callback function in eInfo is zero, then the
169 // eInfo object is deleted by the invoked callback. Otherwise,
170 // that method must be invoked by this callback function after
171 // the actual callback message is sent. This allows the callback
172 // requestor to do post-processing and be asynchronous.
173 // Path - Optionally, the path related to thid request. It is used
174 // for tracing and detailed monitoring purposes.
175 //
176 //
177 virtual void Done(int &Result, //I/O: Function result
178  XrdOucErrInfo *eInfo, // In: Error Info
179  const char *Path=0)=0;// In: Relevant path
180 
181 // Same() is invoked to determine if two arguments refer to the same user.
182 // True is returned if so, false, otherwise.
183 //
184 virtual int Same(unsigned long long arg1, unsigned long long arg2)=0;
185 
187 virtual ~XrdOucEICB() {}
188 };
189 #endif