XRootD
XrdOucECMsg.hh
Go to the documentation of this file.
1 #ifndef __OUC_ECMSG_H__
2 #define __OUC_ECMSG_H__
3 /******************************************************************************/
4 /* */
5 /* X r d O u c E C M s g . h h */
6 /* */
7 /* (c) 2023 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* Produced by Andrew Hanushevsky for Stanford University under contract */
9 /* DE-AC02-76-SFO0515 with the Department of Energy */
10 /* */
11 /* This file is part of the XRootD software suite. */
12 /* */
13 /* XRootD is free software: you can redistribute it and/or modify it under */
14 /* the terms of the GNU Lesser General Public License as published by the */
15 /* Free Software Foundation, either version 3 of the License, or (at your */
16 /* option) any later version. */
17 /* */
18 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21 /* License for more details. */
22 /* */
23 /* You should have received a copy of the GNU Lesser General Public License */
24 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26 /* */
27 /* The copyright holder's institutional names and contributor's names may not */
28 /* be used to endorse or promote products derived from this software without */
29 /* specific prior written permission of the institution or contributor. */
30 /* */
31 /******************************************************************************/
32 
33 #include <cstdarg>
34 #include <string>
35 
36 #include "XrdSys/XrdSysPthread.hh"
37 
39 {
40 public:
41 
42 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
51 
52 XrdOucECMsg& Append(char dlm='\n')
53  {ecMTX.Lock(); Delim = dlm; ecMTX.UnLock(); return *this;}
54 
55 //-----------------------------------------------------------------------------
62 //-----------------------------------------------------------------------------
63 
64 int Get(std::string& ecm, bool rst=true);
65 
66 //-----------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
71 
72 bool hasMsg() const {ecMTX.Lock(); bool hm = !ecMsg.empty();
73  ecMTX.UnLock(); return hm;
74  }
75 
76 //-----------------------------------------------------------------------------
80 //-----------------------------------------------------------------------------
81 
82 std::string Msg() {ecMTX.Lock(); std::string m = ecMsg; ecMTX.UnLock();
83  return m;
84  }
85 
86 //-----------------------------------------------------------------------------
93 //-----------------------------------------------------------------------------
94 
95 void Msg(const char* pfx, const char* txt1,
96  const char* txt2=0, const char* txt3=0,
97  const char* txt4=0, const char* txt5=0);
98 
99 //-----------------------------------------------------------------------------
108 //-----------------------------------------------------------------------------
109 
110 void Msgf(const char *pfx, const char *fmt, ...);
111 
112 //-----------------------------------------------------------------------------
121 //-----------------------------------------------------------------------------
122 
123 void MsgVA(const char *pfx, const char *fmt, std::va_list aP);
124 
125 //-----------------------------------------------------------------------------
134 //-----------------------------------------------------------------------------
135 
136 void MsgVec(const char* pfx, char const* const* vecP, int vecN);
137 
138 //-----------------------------------------------------------------------------
143 //-----------------------------------------------------------------------------
144 
145 void Set(int ecc, const char* ecm="")
146  {ecMTX.Lock(); eCode = ecc; if (ecm) ecMsg = ecm; ecMTX.UnLock();}
147 
148 void Set(int ecc, std::string& ecm)
149  {ecMTX.Lock(); eCode = ecc; ecMsg = ecm; ecMTX.UnLock();}
150 
151 //-----------------------------------------------------------------------------
159 //-----------------------------------------------------------------------------
160 
161 int SetErrno(int ecc, int ret=-1, const char *alt=0);
162 
163 //-----------------------------------------------------------------------------
165 //-----------------------------------------------------------------------------
166 
167  XrdOucECMsg& operator=(const int rhs)
168  {ecMTX.Lock(); eCode = rhs; ecMTX.UnLock(); return *this;}
169 
170  XrdOucECMsg& operator=(const std::string& rhs)
171  {ecMTX.Lock(); ecMsg = rhs; ecMTX.UnLock(); return *this;}
172 
173  XrdOucECMsg& operator=(const char* rhs)
174  {ecMTX.Lock(); ecMsg = rhs; ecMTX.UnLock(); return *this;}
175 
177  {ecMTX.Lock(); ecMsg = rhs.ecMsg; eCode = rhs.eCode; ecMTX.UnLock();
178  return *this;
179  }
180 
181  XrdOucECMsg(const char *msgid=0) : msgID(msgid), eCode(0), Delim(0) {}
183 
184 private:
185 
186 void Setup(const char *pfx, int n);
187 mutable
188 XrdSysMutex ecMTX;
189 const char* msgID;
190 std::string ecMsg;
191 int eCode;
192 char Delim;
193 };
194 #endif
bool hasMsg() const
Definition: XrdOucECMsg.hh:72
XrdOucECMsg & operator=(const std::string &rhs)
Definition: XrdOucECMsg.hh:170
XrdOucECMsg & operator=(const int rhs)
Assignment operators for convenience.
Definition: XrdOucECMsg.hh:167
void MsgVA(const char *pfx, const char *fmt, std::va_list aP)
Definition: XrdOucECMsg.cc:116
std::string Msg()
Definition: XrdOucECMsg.hh:82
int SetErrno(int ecc, int ret=-1, const char *alt=0)
Definition: XrdOucECMsg.cc:152
XrdOucECMsg & operator=(const char *rhs)
Definition: XrdOucECMsg.hh:173
XrdOucECMsg(const char *msgid=0)
Definition: XrdOucECMsg.hh:181
void Set(int ecc, const char *ecm="")
Definition: XrdOucECMsg.hh:145
int Get(std::string &ecm, bool rst=true)
Definition: XrdOucECMsg.cc:41
void Set(int ecc, std::string &ecm)
Definition: XrdOucECMsg.hh:148
void MsgVec(const char *pfx, char const *const *vecP, int vecN)
Definition: XrdOucECMsg.cc:137
XrdOucECMsg & Append(char dlm='\n')
Definition: XrdOucECMsg.hh:52
XrdOucECMsg & operator=(XrdOucECMsg &rhs)
Definition: XrdOucECMsg.hh:176
void Msgf(const char *pfx, const char *fmt,...)
Definition: XrdOucECMsg.cc:93