Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

psError.h

Go to the documentation of this file.
00001 /** @file  psError.h
00002  *
00003  *  @brief Contains the declarations for the 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  *  @ingroup ErrorHandling
00011  *
00012  *  @author Eric Van Alst, MHPCC
00013  *
00014  *  @version $Revision: 1.26 $ $Name: rel12 $
00015  *  @date $Date: 2006/06/02 21:33:34 $
00016  *
00017  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
00018  */
00019 
00020 #ifndef PS_ERROR_H
00021 #define PS_ERROR_H
00022 
00023 #include<stdio.h>
00024 #include<stdbool.h>
00025 #include<stdarg.h>
00026 
00027 #include "psErrorCodes.h"
00028 
00029 /** @addtogroup ErrorHandling
00030  *  @{
00031  */
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     psS32 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 psS32   The number of items on the error stack
00081  */
00082 unsigned int 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 fmt is first printed to the file descriptor fd. In
00089  *  this printout, error codes are replaced by their string equivalents.
00090  *
00091  */
00092 void psErrorStackPrint(
00093     FILE* fd,                          ///< destination file descriptor
00094     const char* format,                   ///< printf-style format of header line
00095     ...                                ///< any parameters required in fmt
00096 );
00097 
00098 #ifndef SWIG
00099 /** Prints error stack to specified open file descriptor
00100  *
00101  *  The entire error stack may be printed to an open file descriptor by
00102  *  calling psErrorStackPrintV; if and only if there are current errors, the
00103  *  vprintf-style string fmt is first printed to the file descriptor fd. In
00104  *  this printout, error codes are replaced by their string equivalents.
00105  *
00106  */
00107 void psErrorStackPrintV(
00108     FILE* fd,                          ///< destination file descriptor
00109     const char* format,                   ///< printf-style format of header line
00110     va_list va                         ///< any parameters required in fmt
00111 );
00112 #endif // #ifndef SWIG
00113 
00114 #ifdef DOXYGEN
00115 /** Reports an error message to the logging facility
00116  *
00117  *  This function will invoke the psLogMsg function with a level of
00118  *  PS_LOG_ERROR and pass the parameters name and fmt to generate a proper
00119  *  log message.
00120  *
00121  *  This function modifies the error stack.
00122  *
00123  *  @return psErrorCode    the given error code
00124  */
00125 psErrorCode psError(
00126     psErrorCode code,                  ///< Error class code
00127     psBool new,                        ///< true if error originates at this location
00128     const char* fmt,                   ///< printf-style format of header line
00129     ...                                ///< any parameters required in fmt
00130 );
00131 
00132 /** Logs a warning message.
00133  *
00134  *  This procedure logs a message to the destination set by a prior
00135  *  call to psLogSetDestination(), This is equivalent to calling
00136  *  psLogMsg with a level of PS_LOG_WARN.
00137  *
00138  */
00139 void psWarning(
00140     const char* fmt,                   ///< printf-style format of header line
00141     ...                                ///< any parameters required in fmt
00142 );
00143 #else // #ifdef DOXYGEN
00144 
00145 /** Reports an error message to the logging facility
00146  *
00147  *  This function will invoke the psLogMsg function with a level of
00148  *  PS_LOG_ERROR and pass the parameters name and fmt to generate a proper
00149  *  log message.  This function is used to check a specific code location.
00150  *
00151  *  This function modifies the error stack.
00152  *
00153  *  @return psErrorcode    the given error code
00154  */
00155 psErrorCode p_psError(
00156     const char* filename,              ///< file name
00157     unsigned int lineno,               ///< line number in file
00158     const char* func,                  ///< function name
00159     psErrorCode code,                  ///< Error class code
00160     bool new,                          ///< true if error originates at this location
00161     const char* format,                ///< printf-style format of header line
00162     ...                                ///< any parameters required in fmt
00163 );
00164 
00165 /** Logs a warning message.
00166  *
00167  *  This procedure logs a message to the destination set by a prior call to
00168  *  psLogSetDestination().  This is equivalent to calling psLogMsg with a level of
00169  *  PS_LOG_WARN.  This function is used to check a specific code location.
00170  *
00171 */
00172 void p_psWarning(
00173     const char* file,                  ///< file name
00174     int lineno,                        ///< line number in file
00175     const char* func,                  ///< function name
00176     const char* fmt,                   ///< printf-style format of header line
00177     ...                                ///< any parameters required in fmt
00178 );
00179 
00180 
00181 #ifndef SWIG
00182 #define psError(code,new,...) p_psError(__FILE__,__LINE__,__func__,code,new,__VA_ARGS__)
00183 #define psWarning(...) p_psWarning(__FILE__,__LINE__,__func__,__VA_ARGS__)
00184 #endif // #ifndef SWIG
00185 
00186 #endif // ! DOXYGEN
00187 
00188 /** Create a new psErr struct
00189  *
00190  *  Creates a new psErr struct, making a copy of the parameters.
00191  *
00192  *  @return psErr*     new psErr object
00193  */
00194 psErr* psErrAlloc(
00195     const char* name,                  ///< Name of error in the form aaa.bbb.ccc
00196     psErrorCode code,                  ///< Error class code
00197     const char* msg                    ///< Error message
00198 );
00199 
00200 /* @} */// End of SysUtils Functions
00201 
00202 #endif

Generated on Mon Jul 3 14:13:44 2006 for Pan-STARRS Foundation Library by  doxygen 1.4.4