58#define MAX_STRING_LENGTH 200
143 cpl_msg_error (__func__,
"Error handling system was not initialized "
144 "when called from %s:%s:%d!", file, func, line);
147 if (cpl_error_get_code () == CPL_ERROR_NONE) {
148 if (
queue.is_empty) {
168 if (!
queue.is_empty) {
170 is_mismatch = !(strcmp (er.
filename, cpl_error_get_file ()) == 0 &&
171 strcmp (er.
function, cpl_error_get_function ()) == 0 &&
172 strcmp (er.
cplmessage, cpl_error_get_message ()) == 0 &&
180 if (
queue.is_empty || is_mismatch) {
194 cpl_error_code ec_cpl;
195 unsigned int line_cpl;
207 ec_cpl = cpl_error_get_code ();
208 line_cpl = cpl_error_get_line ();
211 if (
queue.is_empty) {
215 cpl_error_set_message_macro (er.
function,
261 const char *file,
unsigned int line)
265 if (ec == CPL_ERROR_NONE) {
266 cpl_msg_error (__func__,
"The error code CPL_ERROR_NONE was set from "
267 "%s:%s:%d! Code changed to CPL_ERROR_UNSPECIFIED",
270 ec = CPL_ERROR_UNSPECIFIED;
274 if (
queue.is_empty) {
287 queue.is_empty = CPL_FALSE;
288 cpl_error_set_message_macro (func, ec, file, line,
" ");
297 strncpy (
queue.errors[
queue.last].cplmessage, cpl_error_get_message (),
329 va_start (al, format);
350 queue.is_empty = CPL_TRUE;
378 cpl_msg_severity severity,
379 cpl_msg_severity trace_severity)
384 void (*error_msg_func) (
const char *,
const char *, ...);
385 void (*trace_msg_func) (
const char *,
const char *, ...);
391 error_msg_func = (void(*)(
const char*,
const char*,...))&cpl_msg_debug;
394 error_msg_func = (void(*)(
const char*,
const char*,...))&cpl_msg_info;
396 case CPL_MSG_WARNING:
397 error_msg_func = (void(*)(
const char*,
const char*,...))&cpl_msg_warning;
400 error_msg_func = (void(*)(
const char*,
const char*,...))&cpl_msg_error;
403 error_msg_func = NULL;
406 cpl_msg_error (func,
"Unknown message level: %d !", severity);
407 error_msg_func = (void(*)(
const char*,
const char*,...))&cpl_msg_error;
411 switch (trace_severity) {
413 trace_msg_func = (void(*)(
const char*,
const char*,...))&cpl_msg_debug;
416 trace_msg_func = (void(*)(
const char*,
const char*,...))&cpl_msg_info;
418 case CPL_MSG_WARNING:
419 trace_msg_func = (void(*)(
const char*,
const char*,...))&cpl_msg_warning;
422 trace_msg_func = (void(*)(
const char*,
const char*,...))&cpl_msg_error;
425 trace_msg_func = NULL;
428 cpl_msg_error (func,
"Unknown message level: %d !", severity);
429 trace_msg_func = (void(*)(
const char*,
const char*,...))&cpl_msg_error;
433 if (cpl_error_get_code () == CPL_ERROR_NONE) {
434 if (error_msg_func != NULL) {
435 error_msg_func (func,
"No error has occurred");
440 cpl_error_code current_ec;
449 if (trace_msg_func != NULL) {
450 trace_msg_func (func,
"An error occurred, " "dumping error trace:");
451 trace_msg_func (func,
" ");
458 current_ec = CPL_ERROR_NONE;
462 cpl_boolean empty_message;
466 c =
queue.errors[i].errormessage;
467 empty_message = CPL_TRUE;
469 empty_message = empty_message && (*c ==
' ');
480 if (error_msg_func != NULL) {
481 error_msg_func (func,
"%s",
queue.errors[i].cplmessage);
484 else if (
queue.errors[i].errorcode == current_ec) {
486 if (error_msg_func != NULL) {
487 error_msg_func (func,
"%s",
queue.errors[i].errormessage);
493 if (error_msg_func != NULL) {
494 error_msg_func (func,
"%s (%s)",
495 queue.errors[i].errormessage,
496 queue.errors[i].cplmessage);
500 if (trace_msg_func != NULL) {
501 trace_msg_func (func,
" in [%d]%s() at %s:%-3d",
506 queue.errors[i].function,
507 queue.errors[i].filename,
queue.errors[i].linenumber);
508 trace_msg_func (func,
" ");
511 current_ec =
queue.errors[i].errorcode;
513 }
while ((
unsigned int) i !=
queue.last);
static cpl_boolean is_initialized
#define MAX_STRING_LENGTH
cpl_error_code xsh_irplib_error_push_macro(const char *func, cpl_error_code ec, const char *file, unsigned int line)
Set or propagate an error.
void xsh_irplib_error_reset(void)
Reset the error state.
static void irplib_error_validate_state(const char *func, const char *file, unsigned int line)
Synchronize IRPLIB error state with CPL's error state.
void xsh_irplib_error_dump_macro(const char *func, const char *file, unsigned int line, cpl_msg_severity severity, cpl_msg_severity trace_severity)
Print the error queue.
static char error_msg[MAX_STRING_LENGTH]
void xsh_irplib_error_set_msg(const char *format,...)
Temporarily store an error message.
irplib_error errors[MAX_ERRORS]
char filename[MAX_STRING_LENGTH]
char cplmessage[MAX_STRING_LENGTH]
char function[MAX_STRING_LENGTH]