[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r3448 - in GNUnet/src: include util/error util/loggers
From: |
durner |
Subject: |
[GNUnet-SVN] r3448 - in GNUnet/src: include util/error util/loggers |
Date: |
Sun, 8 Oct 2006 03:36:32 -0700 (PDT) |
Author: durner
Date: 2006-10-08 03:36:25 -0700 (Sun, 08 Oct 2006)
New Revision: 3448
Modified:
GNUnet/src/include/gnunet_util_error.h
GNUnet/src/util/error/error.c
GNUnet/src/util/loggers/file.c
GNUnet/src/util/loggers/memory.c
Log:
get user confirmation before shutdown (rfc; useful on graphical systems where
output disappears when the app exists)
Modified: GNUnet/src/include/gnunet_util_error.h
===================================================================
--- GNUnet/src/include/gnunet_util_error.h 2006-10-08 07:38:25 UTC (rev
3447)
+++ GNUnet/src/include/gnunet_util_error.h 2006-10-08 10:36:25 UTC (rev
3448)
@@ -77,6 +77,12 @@
GE_KIND kind,
const char * message,
...);
+
+/**
+ * @brief Get user confirmation (e.g. before the app shuts down and closes the
+ * error message
+ */
+void GE_CONFIRM(struct GE_Context * ctx);
void GE_setDefaultContext(struct GE_Context * ctx);
@@ -94,6 +100,11 @@
typedef void (*GE_CtxFree)(void * ctx);
/**
+ * User-defined method to wait for user confirmation
+ */
+typedef void (*GE_Confirm)(void * ctx);
+
+/**
* Create a log context that calls a callback function
* for matching events.
*
@@ -106,7 +117,8 @@
GE_create_context_callback(GE_KIND mask,
GE_LogHandler handler,
void * ctx,
- GE_CtxFree liberator);
+ GE_CtxFree liberator,
+ GE_Confirm confirm);
/**
* Free a log context.
@@ -160,9 +172,9 @@
*/
#define IF_GELOG(ctx, kind, a) do { if (GE_isLogged(ctx, kind)) { a; } }
while(0);
-#define GE_ASSERT(ctx, cond) do { if (! (cond)) { GE_LOG(ctx, GE_DEVELOPER |
GE_USER | GE_FATAL | GE_IMMEDIATE, _("Assertion failed at %s:%d in %s.\n"),
__FILE__, __LINE__, __FUNCTION__); abort(); } } while(0);
+#define GE_ASSERT(ctx, cond) do { if (! (cond)) { GE_LOG(ctx, GE_DEVELOPER |
GE_USER | GE_FATAL | GE_IMMEDIATE, _("Assertion failed at %s:%d in %s.\n"),
__FILE__, __LINE__, __FUNCTION__); GE_CONFIRM(ctx); abort(); } } while(0);
-#define GE_ASSERT_FLF(ctx, cond, file, line, function) do { if (! (cond)) {
GE_LOG(ctx, GE_DEVELOPER | GE_USER | GE_FATAL | GE_IMMEDIATE, _("Assertion
failed at %s:%d in %s.\n"), file, line, function); abort(); } } while(0);
+#define GE_ASSERT_FLF(ctx, cond, file, line, function) do { if (! (cond)) {
GE_LOG(ctx, GE_DEVELOPER | GE_USER | GE_FATAL | GE_IMMEDIATE, _("Assertion
failed at %s:%d in %s.\n"), file, line, function); GE_CONFIRM(ctx); abort(); }
} while(0);
#define GE_BREAK(ctx, cond) do { if (! (cond)) { GE_LOG(ctx, GE_DEVELOPER |
GE_USER | GE_FATAL | GE_IMMEDIATE, _("Assertion failed at %s:%d in %s.\n"),
__FILE__, __LINE__, __FUNCTION__); } } while(0);
@@ -180,14 +192,14 @@
* a failure of the command 'cmd' with the message given
* by strerror(errno).
*/
-#define GE_DIE_STRERROR(ctx, level, cmd) do { GE_LOG(ctx, level, _("`%s'
failed at %s:%d in %s with error: %s\n"), cmd, __FILE__, __LINE__,
__FUNCTION__, STRERROR(errno)); abort(); } while(0);
+#define GE_DIE_STRERROR(ctx, level, cmd) do { GE_LOG(ctx, level, _("`%s'
failed at %s:%d in %s with error: %s\n"), cmd, __FILE__, __LINE__,
__FUNCTION__, STRERROR(errno)); GE_CONFIRM(ctx); abort(); } while(0);
/**
* Log an error message at log-level 'level' that indicates
* a failure of the command 'cmd' with the message given
* by strerror(errno).
*/
-#define GE_DIE_STRERROR_FLF(ctx, level, cmd, file, line, function) do {
GE_LOG(ctx, level, _("`%s' failed at %s:%d in %s with error: %s\n"), cmd, file,
line, function, STRERROR(errno)); abort(); } while(0);
+#define GE_DIE_STRERROR_FLF(ctx, level, cmd, file, line, function) do {
GE_LOG(ctx, level, _("`%s' failed at %s:%d in %s with error: %s\n"), cmd, file,
line, function, STRERROR(errno)); GE_CONFIRM(ctx); abort(); } while(0);
/**
* Log an error message at log-level 'level' that indicates
@@ -208,7 +220,7 @@
* a failure of the command 'cmd' on file 'filename'
* with the message given by strerror(errno).
*/
-#define GE_DIE_STRERROR_FILE(ctx, level, cmd, filename) do { GE_LOG(ctx,
level, _("`%s' failed on file `%s' at %s:%d in %s with error: %s\n"), cmd,
filename,__FILE__, __LINE__, __FUNCTION__, STRERROR(errno)); abort(); }
while(0);
+#define GE_DIE_STRERROR_FILE(ctx, level, cmd, filename) do { GE_LOG(ctx,
level, _("`%s' failed on file `%s' at %s:%d in %s with error: %s\n"), cmd,
filename,__FILE__, __LINE__, __FUNCTION__, STRERROR(errno)); GE_CONFIRM(ctx);
abort(); } while(0);
#if 0 /* keep Emacsens' auto-indent happy */
Modified: GNUnet/src/util/error/error.c
===================================================================
--- GNUnet/src/util/error/error.c 2006-10-08 07:38:25 UTC (rev 3447)
+++ GNUnet/src/util/error/error.c 2006-10-08 10:36:25 UTC (rev 3448)
@@ -24,8 +24,10 @@
*
* @author Christian Grothoff
*/
+#include <conio.h>
+
+#include "platform.h"
#include "gnunet_util_error.h"
-#include "platform.h"
/**
* Default context for logging errors; used
@@ -38,6 +40,7 @@
GE_LogHandler handler;
void * cls;
GE_CtxFree destruct;
+ GE_Confirm confirm;
} GE_Context;
/**
@@ -65,7 +68,15 @@
char * buf;
if (ctx == NULL)
+ {
ctx = defaultContext;
+#ifdef WINDOWS
+ /* Most tools disband the console window early in the initialization
+ process, so we have to create a new one if we're logging to the
+ default context. */
+ AllocConsole();
+#endif
+ }
if ( (ctx != NULL) &&
(! GE_applies(kind, ctx->mask)) )
return;
@@ -97,6 +108,30 @@
}
/**
+ * @brief Get user confirmation (e.g. before the app shuts down and closes the
+ * error message
+ */
+void GE_CONFIRM(struct GE_Context * ctx)
+{
+ if (ctx == NULL)
+ {
+ /* @TODO: we probably ought to get confirmations in all graphical
+ environments */
+#ifdef WINDOWS
+ /* Console open? */
+ if (GetStdHandle(STD_ERROR_HANDLE) != NULL)
+ {
+ fprintf(stderr,
+ _("\nPress any key to continue\n"));
+ getch();
+ }
+#endif
+ }
+ else if (ctx->confirm)
+ ctx->confirm(ctx->cls);
+}
+
+/**
* Create a log context that calls a callback function
* for matching events.
*
@@ -108,7 +143,8 @@
GE_create_context_callback(GE_KIND mask,
GE_LogHandler handler,
void * ctx,
- GE_CtxFree liberator) {
+ GE_CtxFree liberator,
+ GE_Confirm confirm) {
GE_Context * ret;
ret = malloc(sizeof(GE_Context));
@@ -118,6 +154,7 @@
ret->handler = handler;
ret->cls = ctx;
ret->destruct = liberator;
+ ret->confirm = confirm;
return ret;
}
Modified: GNUnet/src/util/loggers/file.c
===================================================================
--- GNUnet/src/util/loggers/file.c 2006-10-08 07:38:25 UTC (rev 3447)
+++ GNUnet/src/util/loggers/file.c 2006-10-08 10:36:25 UTC (rev 3448)
@@ -306,7 +306,8 @@
return GE_create_context_callback(mask,
&filelogger,
fctx,
- &fileclose);
+ &fileclose,
+ NULL);
}
@@ -332,7 +333,8 @@
return GE_create_context_callback(mask,
&filelogger,
fctx,
- &fileclose);
+ &fileclose,
+ NULL);
}
@@ -358,6 +360,7 @@
return GE_create_context_callback(mask,
&filelogger,
fctx,
- &fileclose);
+ &fileclose,
+ NULL);
}
Modified: GNUnet/src/util/loggers/memory.c
===================================================================
--- GNUnet/src/util/loggers/memory.c 2006-10-08 07:38:25 UTC (rev 3447)
+++ GNUnet/src/util/loggers/memory.c 2006-10-08 10:36:25 UTC (rev 3448)
@@ -88,7 +88,8 @@
return GE_create_context_callback(mask,
&memorylogger,
memory,
- NULL);
+ NULL,
+ NULL);
}
/**
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r3448 - in GNUnet/src: include util/error util/loggers,
durner <=