psError.h

Go to the documentation of this file.
00001 /** @file  psError.h
00002  *
00003  *  @brief error reporting functions
00004  *
00005  *  Error reporting functions shall be used to create log entries in the
00006  *  event errors are detected.  The messages shall give enough information
00007  *  to allow the user to know where the error has occurred and the type
00008  *  of error detected.
00009  *
00010  *  @author RHL, Princeton
00011  *  @author Eric Van Alst, MHPCC
00012  *
00013  *  @version $Revision: 1.32 $ $Name:  $
00014  *  @date $Date: 2007/01/23 22:47:23 $
00015  *
00016  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
00017  */
00018 
00019 #ifndef PS_ERROR_H
00020 #define PS_ERROR_H
00021 
00022 /// @addtogroup SysUtils System Utilities
00023 /// @{
00024 
00025 #include<stdio.h>
00026 #include<stdbool.h>
00027 #include<stdarg.h>
00028 
00029 #include "psErrorCodes.h"
00030 
00031 #define _(string) string
00032 
00033 /** Error message object */
00034 typedef struct
00035 {
00036     char* name;                        ///< category of code that caused the error
00037     psErrorCode code;                  ///< class of error
00038     char* msg;                         ///< the message associated with the error
00039 }
00040 psErr;
00041 
00042 /** Get a error from the error stack
00043  *
00044  *  Previous errors on the stack are returned by psErrorGet (a value of 0
00045  *  passed to psErrorGet is equivalent to a call to psErrorLast).
00046  *
00047  *  if no error is at the which position, a non-NULL psErr is returned with
00048  *  code PS_ERR_NONE.
00049  *
00050  *  @return    Error message object at 'which'
00051  */
00052 psErr* psErrorGet(
00053     long which                          ///< position in the error stack. 0 is last error on stack.
00054 );
00055 
00056 /** Get last error put on the error stack
00057  *
00058  *  The last error reported is available from psErrorLast; if no errors are
00059  *  current, a non-NULL psErr is returned with code PS_ERR_NONE.
00060  *
00061  *  @return psErr*     Reference to last error message on error stack
00062  */
00063 psErr* psErrorLast(void);
00064 
00065 /** Get errorCode of last error put on the error stack
00066  *
00067  *  @return psErrorCode     last error code, or PS_ERR_NONE
00068  */
00069 psErrorCode psErrorCodeLast(void);
00070 
00071 /** Clears the error stack.
00072  *
00073  *  The error stack may be completely cleared with psErrorClear.
00074  *
00075  */
00076 void psErrorClear(void);
00077 
00078 /** Get the error stack depth
00079  *
00080  *  @return int The number of items on the error stack
00081  */
00082 long psErrorGetStackSize();
00083 
00084 /** Prints error stack to specified open file descriptor
00085  *
00086  *  The entire error stack may be printed to an open file descriptor by
00087  *  calling psErrorStackPrint; if and only if there are current errors, the
00088  *  printf-style string format is first printed to the file descriptor fd. In
00089  *  this printout, error codes are replaced by their string equivalents.
00090  *
00091  */
00092 #ifdef __GNUC__
00093 void psErrorStackPrint(
00094     FILE* fd,                          ///< destination file descriptor
00095     const char* format,                ///< printf-style format of header line
00096     ...                                ///< any parameters required in format
00097 ) __attribute__((format(printf, 2, 3)));
00098 #else // __GNUC__
00099 void psErrorStackPrint(
00100     FILE* fd,                          ///< destination file descriptor
00101     const char* format,                ///< printf-style format of header line
00102     ...                                ///< any parameters required in format
00103 );
00104 #endif // __GNUC__
00105 
00106 
00107 #ifndef SWIG
00108 /** Prints error stack to specified open file descriptor
00109  *
00110  *  The entire error stack may be printed to an open file descriptor by
00111  *  calling psErrorStackPrintV; if and only if there are current errors, the
00112  *  vprintf-style string format is first printed to the file descriptor fd. In
00113  *  this printout, error codes are replaced by their string equivalents.
00114  *
00115  */
00116 void psErrorStackPrintV(
00117     FILE* fd,                          ///< destination file descriptor
00118     const char* format,                   ///< printf-style format of header line
00119     va_list va                         ///< any parameters required in format
00120 );
00121 #endif // #ifndef SWIG
00122 
00123 #ifdef DOXYGEN
00124 /** Reports an error message to the logging facility
00125  *
00126  *  This function will invoke the psLogMsg function with a level of
00127  *  PS_LOG_ERROR and pass the parameters name and format to generate a proper
00128  *  log message.
00129  *
00130  *  This function modifies the error stack.
00131  *
00132  *  @return psErrorCode    the given error code
00133  */
00134 psErrorCode psError(
00135     psErrorCode code,                  ///< Error class code
00136     psBool new,                        ///< true if error originates at this location
00137     const char* format,                ///< printf-style format of header line
00138     ...                                ///< any parameters required in format
00139 );
00140 
00141 /** Logs a warning message.
00142  *
00143  *  This procedure logs a message to the destination set by a prior
00144  *  call to psLogSetDestination(), This is equivalent to calling
00145  *  psLogMsg with a level of PS_LOG_WARN.
00146  *
00147  */
00148 void psWarning(
00149     const char* format,                ///< printf-style format of header line
00150     ...                                ///< any parameters required in format
00151 );
00152 #else // #ifdef DOXYGEN
00153 
00154 /** Reports an error message to the logging facility
00155  *
00156  *  This function will invoke the psLogMsg function with a level of
00157  *  PS_LOG_ERROR and pass the parameters name and format to generate a proper
00158  *  log message.  This function is used to check a specific code location.
00159  *
00160  *  This function modifies the error stack.
00161  *
00162  *  @return psErrorcode    the given error code
00163  */
00164 #ifdef __GNUC__
00165 psErrorCode p_psError(
00166     const char* filename,              ///< file name
00167     unsigned int lineno,               ///< line number in file
00168     const char* func,                  ///< function name
00169     psErrorCode code,                  ///< Error class code
00170     bool new,                          ///< true if error originates at this location
00171     const char* format,                ///< printf-style format of header line
00172     ...                                ///< any parameters required in format
00173 ) __attribute__((format(printf, 6, 7)));
00174 #else // __GNUC__
00175 psErrorCode p_psError(
00176     const char* filename,              ///< file name
00177     unsigned int lineno,               ///< line number in file
00178     const char* func,                  ///< function name
00179     psErrorCode code,                  ///< Error class code
00180     bool new,                          ///< true if error originates at this location
00181     const char* format,                ///< printf-style format of header line
00182     ...                                ///< any parameters required in format
00183 );
00184 #endif // __GNUC__
00185 
00186 /** Logs a warning message.
00187  *
00188  *  This procedure logs a message to the destination set by a prior call to
00189  *  psLogSetDestination().  This is equivalent to calling psLogMsg with a level of
00190  *  PS_LOG_WARN.  This function is used to check a specific code location.
00191  *
00192 */
00193 #ifdef __GNUC__
00194 void p_psWarning(
00195     const char* file,                  ///< file name
00196     int lineno,                        ///< line number in file
00197     const char* func,                  ///< function name
00198     const char* format,                ///< printf-style format of header line
00199     ...                                ///< any parameters required in format
00200 ) __attribute__((format(printf, 4, 5)));
00201 #else // __GNUC__
00202 void p_psWarning(
00203     const char* file,                  ///< file name
00204     int lineno,                        ///< line number in file
00205     const char* func,                  ///< function name
00206     const char* format,                ///< printf-style format of header line
00207     ...                                ///< any parameters required in format
00208 );
00209 #endif // __GNUC__
00210 
00211 
00212 #ifndef SWIG
00213 #define psError(code,new,...) p_psError(__FILE__,__LINE__,__func__,code,new,__VA_ARGS__)
00214 #define psWarning(...) p_psWarning(__FILE__,__LINE__,__func__,__VA_ARGS__)
00215 #endif // #ifndef SWIG
00216 
00217 #endif // ! DOXYGEN
00218 
00219 /** Create a new psErr struct
00220  *
00221  *  Creates a new psErr struct, making a copy of the parameters.
00222  *
00223  *  @return psErr*     new psErr object
00224  */
00225 psErr* psErrAlloc(
00226     const char* name,                  ///< Name of error in the form aaa.bbb.ccc
00227     psErrorCode code,                  ///< Error class code
00228     const char* msg                    ///< Error message
00229 );
00230 
00231 /// @}
00232 #endif

Generated on Fri Feb 2 22:24:35 2007 for pslib by  doxygen 1.5.1