Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
The change Arnaud wanted so much: Big Star Erradication
[simgrid.git] / include / xbt / error.h
index 029d263..4dabcc8 100644 (file)
@@ -3,7 +3,7 @@
 /* gras/error.h - Error tracking support                                    */
 
 /* Authors: Martin Quinson                                                  */
-/* Copyright (C) 2003 the OURAGAN project.                                  */
+/* Copyright (C) 2003,2004 da GRAS posse.                                   */
 
 /* This program is free software; you can redistribute it and/or modify it
    under the terms of the license (GNU LGPL) which comes with this package. */
 #ifndef GRAS_ERROR_H
 #define GRAS_ERROR_H
 
-#include <stddef.h>    /* offsetof() */
-#include <sys/types.h>  /* size_t */
-#include <stdarg.h>
-#ifdef HAVE_EXECINFO_H
-#include <execinfo.h>  /* to print the backtrace */
-#endif
+#include <stdio.h> /* FIXME: Get rid of it */
 
-/* C++ users need love */
-#ifndef BEGIN_DECL
-# ifdef __cplusplus
-#  define BEGIN_DECL extern "C" {
-# else
-#  define BEGIN_DECL 
-# endif
-#endif
+#include "xbt/misc.h" /* BEGIN_DECL */
+#include "xbt/log.h"
 
-/*! C++ users need love */
-#ifndef END_DECL
-# ifdef __cplusplus
-#  define END_DECL }
-# else
-#  define END_DECL 
-# endif
+#ifdef HAVE_EXECINFO_H
+#include <execinfo.h>  /* to print the backtrace */
 #endif
-/* End of cruft for C++ */
 
 BEGIN_DECL
 
 typedef enum {
-  no_error=0,     /* succes */
-  malloc_error,   /* Well known error */
-  mismatch_error, /* The provided ID does not match */
-  system_error,   /* a syscall did fail */
-  network_error,  /* error while sending/receiving data */
-  timeout_error,  /* not quick enough, dude */
-  thread_error,   /* error while [un]locking */
-  unknown_error 
+  no_error=0,       /* succes */
+  mismatch_error=1, /* The provided ID does not match */
+  system_error=2,   /* a syscall did fail */
+  network_error=3,  /* error while sending/receiving data */
+  timeout_error=4,  /* not quick enough, dude */
+  thread_error=5,   /* error while [un]locking */
+  unknown_error=6,
+     
+  /* remote errors: result of a RMI/RPC.
+     no_error(=0) is the same for both */   
+  remote_mismatch_error=129,
+  remote_system_error,
+  remote_network_error,
+  remote_timeout_error,
+  remote_thread_error,
+  remote_unknown_error
 } gras_error_t;
 
 /*@observer@*/ const char *gras_error_name(gras_error_t errcode);
@@ -68,7 +59,7 @@ typedef enum {
             __FILE__,__LINE__,                                \
              gras_error_name(errcode));                        \
      fflush(stdout);                                           \
-     abort();                                                  \
+     gras_abort();                                             \
   } } while(0)
 
 #define TRYEXPECT(action,expected_error)  do {                 \
@@ -77,7 +68,7 @@ typedef enum {
     fprintf(stderr,"Got error %s (instead of %s expected)\n",  \
            gras_error_name(errcode),                          \
            gras_error_name(expected_error));                  \
-    abort();                                                   \
+    gras_abort();                                              \
   }                                                            \
 } while(0)
 
@@ -103,7 +94,7 @@ typedef enum {
   return code;                                                 \
 } while (0)
 
-#else
+#else /* if 0 */
 #define _GRAS_ERR_PRE do {
 #define _GRAS_ERR_POST(code)                                   \
   return code;                                                 \
@@ -139,12 +130,10 @@ typedef enum {
           __FILE__,__LINE__,__FUNCTION__,a1,a2,a3,a4,a5,a6); \
   _GRAS_ERR_POST(code)
 
-#define RAISE_MALLOC     RAISE0(malloc_error,"Malloc error")
+//#define RAISE_MALLOC     RAISE0(malloc_error,"Malloc error")
 #define RAISE_IMPOSSIBLE RAISE0(unknown_error,"The Impossible did happen")
 #define RAISE_UNIMPLEMENTED RAISE1(unknown_error,"Function %s unimplemented",__FUNCTION__)
 
-#define gras_abort abort
-
 #ifdef NDEBUG
 #define gras_assert(cond)
 #define gras_assert0(cond,msg)
@@ -164,6 +153,12 @@ typedef enum {
 #define gras_assert5(cond,msg,a,b,c,d,e)   if (!(cond)) { CRITICAL5(msg,a,b,c,d,e); gras_abort(); }
 #define gras_assert6(cond,msg,a,b,c,d,e,f) if (!(cond)) { CRITICAL6(msg,a,b,c,d,e,f); gras_abort(); }
 #endif
+
+void gras_die(const char *msg);
+
+#define DIE_IMPOSSIBLE gras_assert0(0,"The Impossible did happen (yet again)")
+#define gras_assert_error(a) gras_assert1(errcode == (a), "Error %s unexpected",gras_error_name(errcode))
+
 END_DECL
 
 #endif /* GRAS_ERROR_H */