| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#ifndef __TOOLERROR_H__ |
| 32 |
#define __TOOLERROR_H__ |
| 33 |
|
| 34 |
#ifndef __FFL__ |
| 35 |
#define __FFL__ __FILE__, __FUNCTION__, __LINE__ |
| 36 |
#endif |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
#define NO_ERROR 0 |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
#define CHK(Func) \ |
| 49 |
\ |
| 50 |
{ \ |
| 51 |
APIRET ec; \ |
| 52 |
if ((ec = Func) != NO_ERROR) \ |
| 53 |
{ \ |
| 54 |
(void)ToolErrorCheck (__FFL__, ec); \ |
| 55 |
return ec; \ |
| 56 |
} \ |
| 57 |
} \ |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
#define CHK_CONST(ec) \ |
| 62 |
{ \ |
| 63 |
(void)ToolErrorCheck (__FFL__, ec); \ |
| 64 |
return ec; \ |
| 65 |
} \ |
| 66 |
|
| 67 |
|
| 68 |
#define CHK_RET(Func) \ |
| 69 |
{ \ |
| 70 |
APIRET ec; \ |
| 71 |
if ((ec = Func) != NO_ERROR) \ |
| 72 |
return ec; \ |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
#define CHK_NORET(Func) \ |
| 77 |
{ \ |
| 78 |
APIRET ec; \ |
| 79 |
if ((ec = Func) != NO_ERROR) \ |
| 80 |
(void)ToolErrorCheck (__FFL__, ec); \ |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
#define TOOL_CHK(Fn) \ |
| 86 |
{ \ |
| 87 |
APIRET ec; \ |
| 88 |
if ((ec=Fn) != NO_ERROR) \ |
| 89 |
return ec; \ |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
typedef int APIRET; |
| 97 |
typedef int * pAPIRET; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
enum |
| 104 |
{ |
| 105 |
TOOL_ERROR_ENTRY_NOT_FOUND = ERROR_BASE_TOOL_ERROR + 1, |
| 106 |
TOOL_ERROR_DUPLICATE_ENTRY , |
| 107 |
TOOL_ERROR_NOT_INITIALISED , |
| 108 |
TOOL_ERROR_ALREADY_INITIALISED |
| 109 |
}; |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
typedef void (* t_pToolErrorLogFn)(const char *pFileName, const char *pFunctionName, int LineNr, const char *pFormat, va_list pArguments); |
| 116 |
|
| 117 |
APIRET ToolErrorSetLogFn (t_pToolErrorLogFn pLogFn); |
| 118 |
APIRET ToolErrorRegisterError (int ErrorCode, const char *pErrorMsg); |
| 119 |
APIRET ToolErrorGetMessage (int ErrorCode, const char **ppMessage); |
| 120 |
const char *ToolErrorMessage (int ErrorCode); |
| 121 |
const char *ToolErrorTranslateErrno (int Errno); |
| 122 |
|
| 123 |
|
| 124 |
APIRET ToolErrorInit (unsigned int MaxErrors); |
| 125 |
APIRET ToolErrorDeInit (void); |
| 126 |
|
| 127 |
APIRET ToolErrorCheck (char const *pFileName, char const *pFunctionName, int LineNr, APIRET ErrorCode); |
| 128 |
APIRET ToolErrorLog (char const *pFileName, char const *pFunctionName, int LineNr, const char * pFormat, ...) __attribute__ ((format (printf, 4, 5))); |
| 129 |
|
| 130 |
#define TOOL_ERROR_REGISTER_CODE(ErrorCode) ToolErrorRegisterError(ErrorCode, #ErrorCode) |
| 131 |
|
| 132 |
#endif |
| 133 |
|