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.1.1.1 $ $Name:  $
00015  *  @date $Date: 2005/09/14 20:42:48 $
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 /** Clears the error stack.
00066  *
00067  *  The error stack may be completely cleared with psErrorClear.
00068  *
00069  */
00070 void psErrorClear(void);
00071 
00072 /** Get the error stack depth
00073  *
00074  *  @return psS32   The number of items on the error stack
00075  */
00076 unsigned int psErrorGetStackSize();
00077 
00078 /** Prints error stack to specified open file descriptor
00079  *
00080  *  The entire error stack may be printed to an open file descriptor by
00081  *  calling psErrorStackPrint; if and only if there are current errors, the
00082  *  printf-style string fmt is first printed to the file descriptor fd. In
00083  *  this printout, error codes are replaced by their string equivalents.
00084  *
00085  */
00086 void psErrorStackPrint(
00087     FILE* fd,                          ///< destination file descriptor
00088     const char* format,                   ///< printf-style format of header line
00089     ...                                ///< any parameters required in fmt
00090 );
00091 
00092 #ifndef SWIG
00093 /** Prints error stack to specified open file descriptor
00094  *
00095  *  The entire error stack may be printed to an open file descriptor by
00096  *  calling psErrorStackPrintV; if and only if there are current errors, the
00097  *  vprintf-style string fmt is first printed to the file descriptor fd. In
00098  *  this printout, error codes are replaced by their string equivalents.
00099  *
00100  */
00101 void psErrorStackPrintV(
00102     FILE* fd,                          ///< destination file descriptor
00103     const char* format,                   ///< printf-style format of header line
00104     va_list va                         ///< any parameters required in fmt
00105 );
00106 #endif // #ifndef SWIG
00107 
00108 #ifdef DOXYGEN
00109 /** Reports an error message to the logging facility
00110  *
00111  *  This function will invoke the psLogMsg function with a level of
00112  *  PS_LOG_ERROR and pass the parameters name and fmt to generate a proper
00113  *  log message.
00114  *
00115  *  This function modifies the error stack.
00116  *
00117  *  @return psErrorCode    the given error code
00118  */
00119 psErrorCode psError(
00120     psErrorCode code,                  ///< Error class code
00121     psBool new,                        ///< true if error originates at this location
00122     const char* fmt,                   ///< printf-style format of header line
00123     ...                                ///< any parameters required in fmt
00124 );
00125 
00126 /** Logs a warning message.
00127  *
00128  *  This procedure logs a message to the destination set by a prior
00129  *  call to psLogSetDestination(), This is equivalent to calling
00130  *  psLogMsg with a level of PS_LOG_WARN.
00131  *
00132  */
00133 void psWarning(
00134     const char* fmt,                   ///< printf-style format of header line
00135     ...                                ///< any parameters required in fmt
00136 );
00137 #else // #ifdef DOXYGEN
00138 
00139 /** Reports an error message to the logging facility
00140  *
00141  *  This function will invoke the psLogMsg function with a level of
00142  *  PS_LOG_ERROR and pass the parameters name and fmt to generate a proper
00143  *  log message.  This function is used to check a specific code location.
00144  *
00145  *  This function modifies the error stack.
00146  *
00147  *  @return psErrorcode    the given error code
00148  */
00149 psErrorCode p_psError(
00150     const char* filename,              ///< file name
00151     unsigned int lineno,               ///< line number in file
00152     const char* func,                  ///< function name
00153     psErrorCode code,                  ///< Error class code
00154     bool new,                          ///< true if error originates at this location
00155     const char* format,                ///< printf-style format of header line
00156     ...                                ///< any parameters required in fmt
00157 );
00158 
00159 /** Logs a warning message.
00160  *
00161  *  This procedure logs a message to the destination set by a prior call to
00162  *  psLogSetDestination().  This is equivalent to calling psLogMsg with a level of
00163  *  PS_LOG_WARN.  This function is used to check a specific code location.
00164  *
00165 */
00166 void p_psWarning(
00167     const char* file,                  ///< file name
00168     int lineno,                        ///< line number in file
00169     const char* func,                  ///< function name
00170     const char* fmt,                   ///< printf-style format of header line
00171     ...                                ///< any parameters required in fmt
00172 );
00173 
00174 
00175 #ifndef SWIG
00176 #define psError(code,new,...) p_psError(__FILE__,__LINE__,__func__,code,new,__VA_ARGS__)
00177 #define psWarning(...) p_psWarning(__FILE__,__LINE__,__func__,__VA_ARGS__)
00178 #endif // #ifndef SWIG
00179 
00180 #endif // ! DOXYGEN
00181 
00182 /** Create a new psErr struct
00183  *
00184  *  Creates a new psErr struct, making a copy of the parameters.
00185  *
00186  *  @return psErr*     new psErr object
00187  */
00188 psErr* psErrAlloc(
00189     const char* name,                  ///< Name of error in the form aaa.bbb.ccc
00190     psErrorCode code,                  ///< Error class code
00191     const char* msg                    ///< Error message
00192 );
00193 
00194 /* @} */// End of SysUtils Functions
00195 
00196 #endif

Generated on Wed Sep 14 10:42:48 2005 for Pan-STARRS Foundation Library by  doxygen 1.4.2