00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef CPL_ERROR_H_INCLUDED
00032 #define CPL_ERROR_H_INCLUDED
00033
00034 #include "cpl_port.h"
00035
00036
00037
00038
00039
00046 CPL_C_START
00047
00048 typedef enum
00049 {
00050 CE_None = 0,
00051 CE_Debug = 1,
00052 CE_Warning = 2,
00053 CE_Failure = 3,
00054 CE_Fatal = 4
00055 } CPLErr;
00056
00057
00058
00059
00060
00061 #ifdef STRICT_CPLERRORNUM_TYPE
00062
00063
00064
00065
00066 typedef enum
00067 {
00068 CPLE_None,
00069 CPLE_AppDefined,
00070 CPLE_OutOfMemory,
00071 CPLE_FileIO,
00072 CPLE_OpenFailed,
00073 CPLE_IllegalArg,
00074 CPLE_NotSupported,
00075 CPLE_AssertionFailed,
00076 CPLE_NoWriteAccess,
00077 CPLE_UserInterrupt,
00078 CPLE_ObjectNull,
00079 CPLE_HttpResponse,
00080 CPLE_HttpResponse,
00081 CPLE_AWSBucketNotFound,
00082 CPLE_AWSObjectNotFound,
00083 CPLE_AWSAccessDenied,
00084 CPLE_AWSInvalidCredentials,
00085 CPLE_AWSSignatureDoesNotMatch,
00086 } CPLErrorNum;
00087
00088 #else
00089
00090 typedef int CPLErrorNum;
00091
00092 #define CPLE_None 0
00093 #define CPLE_AppDefined 1
00094 #define CPLE_OutOfMemory 2
00095 #define CPLE_FileIO 3
00096 #define CPLE_OpenFailed 4
00097 #define CPLE_IllegalArg 5
00098 #define CPLE_NotSupported 6
00099 #define CPLE_AssertionFailed 7
00100 #define CPLE_NoWriteAccess 8
00101 #define CPLE_UserInterrupt 9
00102 #define CPLE_ObjectNull 10
00103
00104
00105
00106
00107 #define CPLE_HttpResponse 11
00108 #define CPLE_AWSBucketNotFound 12
00109 #define CPLE_AWSObjectNotFound 13
00110 #define CPLE_AWSAccessDenied 14
00111 #define CPLE_AWSInvalidCredentials 15
00112 #define CPLE_AWSSignatureDoesNotMatch 16
00113
00114
00115
00116 #endif
00117
00118 void CPL_DLL CPLError(CPLErr eErrClass, CPLErrorNum err_no, const char *fmt, ...) CPL_PRINT_FUNC_FORMAT (3, 4);
00119 void CPL_DLL CPLErrorV(CPLErr, CPLErrorNum, const char *, va_list );
00120 void CPL_DLL CPLEmergencyError( const char * ) CPL_NO_RETURN;
00121 void CPL_DLL CPL_STDCALL CPLErrorReset( void );
00122 CPLErrorNum CPL_DLL CPL_STDCALL CPLGetLastErrorNo( void );
00123 CPLErr CPL_DLL CPL_STDCALL CPLGetLastErrorType( void );
00124 const char CPL_DLL * CPL_STDCALL CPLGetLastErrorMsg( void );
00125 void CPL_DLL * CPL_STDCALL CPLGetErrorHandlerUserData(void);
00126 void CPL_DLL CPLErrorSetState( CPLErr eErrClass, CPLErrorNum err_no, const char* pszMsg );
00127 void CPL_DLL CPLCleanupErrorMutex( void );
00128
00129 typedef void (CPL_STDCALL *CPLErrorHandler)(CPLErr, CPLErrorNum, const char*);
00130
00131 void CPL_DLL CPL_STDCALL CPLLoggingErrorHandler( CPLErr, CPLErrorNum, const char * );
00132 void CPL_DLL CPL_STDCALL CPLDefaultErrorHandler( CPLErr, CPLErrorNum, const char * );
00133 void CPL_DLL CPL_STDCALL CPLQuietErrorHandler( CPLErr, CPLErrorNum, const char * );
00134 void CPLTurnFailureIntoWarning(int bOn );
00135
00136 CPLErrorHandler CPL_DLL CPL_STDCALL CPLSetErrorHandler(CPLErrorHandler);
00137 CPLErrorHandler CPL_DLL CPL_STDCALL CPLSetErrorHandlerEx(CPLErrorHandler, void*);
00138 void CPL_DLL CPL_STDCALL CPLPushErrorHandler( CPLErrorHandler );
00139 void CPL_DLL CPL_STDCALL CPLPushErrorHandlerEx( CPLErrorHandler, void* );
00140 void CPL_DLL CPL_STDCALL CPLSetCurrentErrorHandlerCatchDebug( int bCatchDebug );
00141 void CPL_DLL CPL_STDCALL CPLPopErrorHandler(void);
00142
00143 void CPL_DLL CPL_STDCALL CPLDebug( const char *, const char *, ... ) CPL_PRINT_FUNC_FORMAT (2, 3);
00144 void CPL_DLL CPL_STDCALL _CPLAssert( const char *, const char *, int ) CPL_NO_RETURN;
00145
00146 #ifdef DEBUG
00147 # define CPLAssert(expr) ((expr) ? (void)(0) : _CPLAssert(#expr,__FILE__,__LINE__))
00148 #else
00149 # define CPLAssert(expr)
00150 #endif
00151
00152 CPL_C_END
00153
00154
00155
00156
00157 #ifdef DEBUG
00158 # define VALIDATE_POINTER_ERR CE_Fatal
00159 #else
00160 # define VALIDATE_POINTER_ERR CE_Failure
00161 #endif
00162
00163 #define VALIDATE_POINTER0(ptr, func) \
00164 do { if( NULL == ptr ) \
00165 { \
00166 CPLErr const ret = VALIDATE_POINTER_ERR; \
00167 CPLError( ret, CPLE_ObjectNull, \
00168 "Pointer \'%s\' is NULL in \'%s\'.\n", #ptr, (func)); \
00169 return; }} while(0)
00170
00171 #define VALIDATE_POINTER1(ptr, func, rc) \
00172 do { if( NULL == ptr ) \
00173 { \
00174 CPLErr const ret = VALIDATE_POINTER_ERR; \
00175 CPLError( ret, CPLE_ObjectNull, \
00176 "Pointer \'%s\' is NULL in \'%s\'.\n", #ptr, (func)); \
00177 return (rc); }} while(0)
00178
00179 #endif