XRootD
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. More...
 
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 retval=-1, const char *alt=0)
 

Detailed Description

Definition at line 36 of file XrdOucECMsg.hh.

Constructor & Destructor Documentation

◆ XrdOucECMsg()

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

Definition at line 167 of file XrdOucECMsg.hh.

167 : msgID(msgid) {}

◆ ~XrdOucECMsg()

XrdOucECMsg::~XrdOucECMsg ( )
inline

Definition at line 168 of file XrdOucECMsg.hh.

168 {}

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 50 of file XrdOucECMsg.hh.

50 {Delim = dlm; return *this;}

◆ 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  if (!rst)
44  {ecm = ecMsg;
45  return eCode;
46  }
47 
48  int ec = eCode;
49  eCode = 0;
50  ecm = std::move(ecMsg);
51  ecMsg.erase();
52  return ec;
53 }

References ec.

Referenced by 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 69 of file XrdOucECMsg.hh.

69 {return !ecMsg.empty();}

◆ Msg() [1/2]

std::string& XrdOucECMsg::Msg ( )
inline

Return the message string.

Returns
A reference to the message string.

Definition at line 77 of file XrdOucECMsg.hh.

77 {return ecMsg;}

◆ 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 59 of file XrdOucECMsg.cc.

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

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 91 of file XrdOucECMsg.cc.

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

Referenced by XrdPosixAdmin::isOK(), and SetErrno().

+ Here is the caller graph for this function:

◆ 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 112 of file XrdOucECMsg.cc.

113 {
114  char buffer[2048];
115 
116 // Format the message
117 //
118  int n = vsnprintf(buffer, sizeof(buffer), fmt, aP);
119 
120 // Append as needed
121 //
122  if (n > (int)sizeof(buffer)) n = sizeof(buffer);
123  Setup(pfx, n);
124  ecMsg.append(buffer);
125 }

◆ 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 131 of file XrdOucECMsg.cc.

132 {
133  int n = 0;
134 
135  for (int i = 0; i < vecN; i++) n += strlen(vecP[i]);
136  Setup(pfx, n);
137  for (int i = 0; i < vecN; i++) ecMsg.append(vecP[i]);
138 }

Referenced by Msg().

+ Here is the caller graph for this function:

◆ operator=() [1/4]

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

Definition at line 162 of file XrdOucECMsg.hh.

162 {ecMsg = rhs; return *this;};

◆ operator=() [2/4]

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

Assignment operators for convenience.

Definition at line 158 of file XrdOucECMsg.hh.

158 {eCode = rhs; return *this;};

◆ operator=() [3/4]

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

Definition at line 160 of file XrdOucECMsg.hh.

160 {ecMsg = rhs; return *this;};

◆ operator=() [4/4]

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

Definition at line 164 of file XrdOucECMsg.hh.

165  {ecMsg = rhs.ecMsg; eCode = rhs.eCode; return *this;};

◆ 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 138 of file XrdOucECMsg.hh.

138 {eCode = ecc; if (ecm) ecMsg = ecm;}

Referenced by XrdPosixAdmin::isOK().

+ Here is the caller graph for this function:

◆ Set() [2/2]

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

Definition at line 140 of file XrdOucECMsg.hh.

140 {eCode = ecc; ecMsg = ecm;}

◆ SetErrno()

int XrdOucECMsg::SetErrno ( int  ecc,
int  retval = -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 144 of file XrdOucECMsg.cc.

145 {
146  if (!alt || *alt != '*')
147  {if (!msgID) ecMsg = (alt ? alt : XrdSysE2T(ecc));
148  else Msgf(msgID, XrdSysE2T(ecc));
149  }
150  errno = eCode = ecc;
151  return ret;
152 }
const char * XrdSysE2T(int errcode)
Definition: XrdSysE2T.cc:104
void Msgf(const char *pfx, const char *fmt,...)
Definition: XrdOucECMsg.cc:91

References Msgf(), and XrdSysE2T().

Referenced by XrdPosixXrootd::Access(), XrdPosixXrootd::Close(), XrdPosixXrootd::Closedir(), XrdPosixDir::Open(), XrdPosixXrootd::Opendir(), XrdPosixXrootd::Pread(), XrdPosixXrootd::Pwrite(), XrdPosixAdmin::Query(), XrdPosixXrootd::QueryError(), XrdPosixXrootd::Readdir64(), XrdPosixXrootd::Rename(), and XrdPosixXrootd::Telldir().

+ 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: