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.20 $ $Name: rel5_0 $
00015  *  @date $Date: 2005/03/22 21:52:49 $
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 psS32 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* fmt,                   ///< 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* fmt,                   ///< printf-style format of header line
00104     va_list va                         ///< any parameters required in fmt
00105 );
00106 #endif
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,
00123     ...
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,
00135     ...
00136 );
00137 #else
00138 psErrorCode p_psError(
00139     const char* file,
00140     int lineno,
00141     const char* func,
00142     psErrorCode code,                  ///< Error class code
00143     psBool new,                        ///< true if error originates at this location
00144     const char* fmt,
00145     ...
00146 );
00147 void p_psWarning(
00148     const char* file,
00149     int lineno,
00150     const char* func,
00151     const char* fmt,
00152     ...
00153 );
00154 
00155 
00156 #ifndef SWIG
00157 #define psError(code,new,...) p_psError(__FILE__,__LINE__,__func__,code,new,__VA_ARGS__)
00158 #define psWarning(...) p_psWarning(__FILE__,__LINE__,__func__,__VA_ARGS__)
00159 #endif
00160 
00161 #endif
00162 
00163 /** Create a new psErr struct
00164  *
00165  *  Creates a new psErr struct, making a copy of the parameters.
00166  *
00167  *  @return psErr*     new psErr object
00168  */
00169 psErr* psErrAlloc(
00170     const char* name,                  ///< Name of error in the form aaa.bbb.ccc
00171     psErrorCode code,                  ///< Error class code
00172     const char* msg                    ///< Error message
00173 );
00174 
00175 /* @} */// End of SysUtils Functions
00176 
00177 #endif

Generated on Mon Apr 4 18:24:44 2005 for Pan-STARRS Foundation Library by  doxygen 1.3.9.1