XRootD
Loading...
Searching...
No Matches
XrdOucECMsg Class Reference

#include <XrdOucECMsg.hh>

+ Collaboration diagram for XrdOucECMsg:

Public Member Functions

 XrdOucECMsg (const char *msgid=0)
 
 ~XrdOucECMsg ()
 
XrdOucECMsgAppend (char dlm='\n')
 
int Get (std::string &ecm, bool rst=true)
 
bool hasMsg () const
 
std::string Msg ()
 
void Msg (const char *pfx, const char *txt1, const char *txt2=0, const char *txt3=0, const char *txt4=0, const char *txt5=0)
 
void Msgf (const char *pfx, const char *fmt,...)
 
void MsgVA (const char *pfx, const char *fmt, std::va_list aP)
 
void MsgVec (const char *pfx, char const *const *vecP, int vecN)
 
XrdOucECMsgoperator= (const char *rhs)
 
XrdOucECMsgoperator= (const int rhs)
 Assignment operators for convenience.
 
XrdOucECMsgoperator= (const std::string &rhs)
 
XrdOucECMsgoperator= (XrdOucECMsg &rhs)
 
void Set (int ecc, const char *ecm="")
 
void Set (int ecc, std::string &ecm)
 
int SetErrno (int ecc, int ret=-1, const char *alt=0)
 

Detailed Description

Definition at line 38 of file XrdOucECMsg.hh.

Constructor & Destructor Documentation

◆ XrdOucECMsg()

XrdOucECMsg::XrdOucECMsg ( const char * msgid = 0)
inline

Definition at line 181 of file XrdOucECMsg.hh.

181: msgID(msgid), eCode(0), Delim(0) {}

Referenced by Append(), operator=(), operator=(), operator=(), and operator=().

+ Here is the caller graph for this function:

◆ ~XrdOucECMsg()

XrdOucECMsg::~XrdOucECMsg ( )
inline

Definition at line 182 of file XrdOucECMsg.hh.

182{}

Member Function Documentation

◆ Append()

XrdOucECMsg & XrdOucECMsg::Append ( char dlm = '\n')
inline

Append subsequent message to contents of ecMsg using delimeter. Append allows method chaining for a more natural progamming style.

Parameters
dlm!0 -> The character to use as message separator. dlm =0 -> Turns off appending, next message replaces ecMsg.
Returns
Reference to the subject object.

Definition at line 52 of file XrdOucECMsg.hh.

53 {ecMTX.Lock(); Delim = dlm; ecMTX.UnLock(); return *this;}

References XrdOucECMsg().

+ Here is the call graph for this function:

◆ Get()

int XrdOucECMsg::Get ( std::string & ecm,
bool rst = true )

Get err code and error message.

Parameters
ecmReference to std:string where message is to be placed.
rstWhen true, the eCode and internal string are set to null.
Returns
the error code, eCode, and associated error message.

Definition at line 41 of file XrdOucECMsg.cc.

42{
43 XrdSysMutexHelper mScope(ecMTX);
44
45 if (!rst)
46 {ecm = ecMsg;
47 return eCode;
48 }
49
50 int ec = eCode;
51 eCode = 0;
52 ecm = std::move(ecMsg);
53 ecMsg.erase();
54 return ec;
55}

References ec.

Referenced by XrdPosixXrootd::QueryError(), and XrdPosixXrootd::QueryError().

+ Here is the caller graph for this function:

◆ hasMsg()

bool XrdOucECMsg::hasMsg ( ) const
inline

Determine if an error text message exists.

Returns
true if an error text message exists, false otherwise.

Definition at line 72 of file XrdOucECMsg.hh.

72 {ecMTX.Lock(); bool hm = !ecMsg.empty();
73 ecMTX.UnLock(); return hm;
74 }

◆ Msg() [1/2]

std::string XrdOucECMsg::Msg ( )
inline

Return the message string.

Returns
A reference to the message string.

Definition at line 82 of file XrdOucECMsg.hh.

82 {ecMTX.Lock(); std::string m = ecMsg; ecMTX.UnLock();
83 return m;
84 }

◆ Msg() [2/2]

void XrdOucECMsg::Msg ( const char * pfx,
const char * txt1,
const char * txt2 = 0,
const char * txt3 = 0,
const char * txt4 = 0,
const char * txt5 = 0 )

Insert a space delimited error message into ecMsg string.

Parameters
pfx!0 -> the text to prefix the message; the message is formed as pfx: txt1 [txt2] [txt3] pfx =0 -> insert message into ecMsg without a prefix.
txt1,txt2,txt3,txt4,txt5the message to be inserted to ecMsg.

Definition at line 61 of file XrdOucECMsg.cc.

64{
65
66 const char *vecP[10];
67 int n = 0;
68 bool xSpace = false;
69
70 if (txt1 && *txt1) {vecP[n++] = txt1; xSpace = true;}
71 if (txt2 && *txt2) {if (xSpace) vecP[n++] = " ";
72 vecP[n++] = txt2; xSpace = true;
73 }
74 if (txt3 && *txt3) {if (xSpace) vecP[n++] = " ";
75 vecP[n++] = txt3; xSpace = true;
76 }
77 if (txt4 && *txt4) {if (xSpace) vecP[n++] = " ";
78 vecP[n++] = txt4; xSpace = true;
79 }
80 if (txt5 && *txt5) {if (xSpace) vecP[n++] = " ";
81 vecP[n++] = txt5;
82 }
83
84// Route the message appropriately
85//
86 MsgVec(pfx, vecP, n);
87}
void MsgVec(const char *pfx, char const *const *vecP, int vecN)

References MsgVec().

+ Here is the call graph for this function:

◆ Msgf()

void XrdOucECMsg::Msgf ( const char * pfx,
const char * fmt,
... )

Insert a formated error message into ecMsg using variable args.

Parameters
pfx!0 -> the text to prefix the message; the message is formed as <pfx>: <formated_text> pfx =0 -> insert message without a prefix.
fmtthe message formatting template (i.e. sprintf format).
...the arguments that should be used with the template. The formatted message is truncated at 2048 bytes.

Definition at line 93 of file XrdOucECMsg.cc.

94{
95 char buffer[2048];
96 va_list args;
97 va_start (args, fmt);
98
99// Format the message
100//
101 int n = vsnprintf(buffer, sizeof(buffer), fmt, args);
102
103// Append as needed
104//
105 if (n > (int)sizeof(buffer)) n = sizeof(buffer);
106 ecMTX.Lock();
107 Setup(pfx, n);
108 ecMsg.append(buffer);
109 ecMTX.UnLock();
110}

◆ MsgVA()

void XrdOucECMsg::MsgVA ( const char * pfx,
const char * fmt,
std::va_list aP )

Insert a formated error message into the ecMsg using a va_list.

Parameters
pfx!0 -> the text to prefix the message; the message is formed as <pfx>: <formated_text> pfx =0 -> add message to the log without a prefix.
fmtthe message formatting template (i.e. sprintf format).
aPthe arguments that should be used with the template. The formatted message is truncated at 2048 bytes.

Definition at line 116 of file XrdOucECMsg.cc.

117{
118 char buffer[2048];
119
120// Format the message
121//
122 int n = vsnprintf(buffer, sizeof(buffer), fmt, aP);
123
124// Append as needed
125//
126 if (n > (int)sizeof(buffer)) n = sizeof(buffer);
127 ecMTX.Lock();
128 Setup(pfx, n);
129 ecMsg.append(buffer);
130 ecMTX.UnLock();
131}

◆ MsgVec()

void XrdOucECMsg::MsgVec ( const char * pfx,
char const *const * vecP,
int vecN )

Insert a formated error message into ecMsg using an iovec.

Parameters
pfx!0 -> the text to prefix the message; the message is formed as pfx: <iovec> pfx =0 -> insert message into ecMsg without a prefix.
vecPpointer to a vector strings to insert into the message. Spaces are not inserted between the elements.
vecNthe number of elements in vecP.

Definition at line 137 of file XrdOucECMsg.cc.

138{
139 int n = 0;
140
141 for (int i = 0; i < vecN; i++) n += strlen(vecP[i]);
142 ecMTX.Lock();
143 Setup(pfx, n);
144 for (int i = 0; i < vecN; i++) ecMsg.append(vecP[i]);
145 ecMTX.UnLock();
146}

Referenced by Msg().

+ Here is the caller graph for this function:

◆ operator=() [1/4]

XrdOucECMsg & XrdOucECMsg::operator= ( const char * rhs)
inline

Definition at line 173 of file XrdOucECMsg.hh.

174 {ecMTX.Lock(); ecMsg = rhs; ecMTX.UnLock(); return *this;}

References XrdOucECMsg().

+ Here is the call graph for this function:

◆ operator=() [2/4]

XrdOucECMsg & XrdOucECMsg::operator= ( const int rhs)
inline

Assignment operators for convenience.

Definition at line 167 of file XrdOucECMsg.hh.

168 {ecMTX.Lock(); eCode = rhs; ecMTX.UnLock(); return *this;}

References XrdOucECMsg().

+ Here is the call graph for this function:

◆ operator=() [3/4]

XrdOucECMsg & XrdOucECMsg::operator= ( const std::string & rhs)
inline

Definition at line 170 of file XrdOucECMsg.hh.

171 {ecMTX.Lock(); ecMsg = rhs; ecMTX.UnLock(); return *this;}

References XrdOucECMsg().

+ Here is the call graph for this function:

◆ operator=() [4/4]

XrdOucECMsg & XrdOucECMsg::operator= ( XrdOucECMsg & rhs)
inline

Definition at line 176 of file XrdOucECMsg.hh.

177 {ecMTX.Lock(); ecMsg = rhs.ecMsg; eCode = rhs.eCode; ecMTX.UnLock();
178 return *this;
179 }

References XrdOucECMsg().

+ Here is the call graph for this function:

◆ Set() [1/2]

void XrdOucECMsg::Set ( int ecc,
const char * ecm = "" )
inline

Set error message and error code.

Parameters
eccThe error code.
ecmThe error message, if nil then message is not changed.

Definition at line 145 of file XrdOucECMsg.hh.

146 {ecMTX.Lock(); eCode = ecc; if (ecm) ecMsg = ecm; ecMTX.UnLock();}

Referenced by XrdPosixMap::Entry2Buf().

+ Here is the caller graph for this function:

◆ Set() [2/2]

void XrdOucECMsg::Set ( int ecc,
std::string & ecm )
inline

Definition at line 148 of file XrdOucECMsg.hh.

149 {ecMTX.Lock(); eCode = ecc; ecMsg = ecm; ecMTX.UnLock();}

◆ SetErrno()

int XrdOucECMsg::SetErrno ( int ecc,
int ret = -1,
const char * alt = 0 )

Set default error message, error code, and errno.

Parameters
eccThe error code.
retThe value to be returned, default -1.
altAlternative message, default text of ecc error.
Returns
The ret parameter value is returned.

Definition at line 152 of file XrdOucECMsg.cc.

153{
154 XrdSysMutexHelper mScope(ecMTX);
155
156 if (!alt || *alt != '*')
157 {if (!alt) alt = XrdSysE2T(ecc);
158 Setup(msgID, strlen(alt));
159 ecMsg.append(alt);
160 }
161 errno = eCode = ecc;
162 return ret;
163}
const char * XrdSysE2T(int errcode)
Definition XrdSysE2T.cc:104

References XrdSysE2T().

Referenced by XrdPosixXrootd::Pread(), and XrdPosixXrootd::Pwrite().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: