Revision: 69039
          http://sourceforge.net/p/brlcad/code/69039
Author:   brlcad
Date:     2016-10-13 03:45:04 +0000 (Thu, 13 Oct 2016)
Log Message:
-----------
separate the hook and bombing-related functions from log.h into their own 
headers so we can further group calls topically.  retaining includes in log.h 
to avoid changing callee's just yet.

Modified Paths:
--------------
    brlcad/trunk/include/bu/log.h

Added Paths:
-----------
    brlcad/trunk/include/bu/bomb.h
    brlcad/trunk/include/bu/hook.h

Added: brlcad/trunk/include/bu/bomb.h
===================================================================
--- brlcad/trunk/include/bu/bomb.h                              (rev 0)
+++ brlcad/trunk/include/bu/bomb.h      2016-10-13 03:45:04 UTC (rev 69039)
@@ -0,0 +1,150 @@
+/*                        B O M B . H
+ * BRL-CAD
+ *
+ * Copyright (c) 2004-2016 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+
+#ifndef BU_BOMB_H
+#define BU_BOMB_H
+
+#include "common.h"
+
+#include <stdio.h> /* for FILE */
+
+#include "bu/defines.h"
+#include "bu/hook.h"
+
+
+__BEGIN_DECLS
+
+/** @{ */
+/** @file bu/bomb.h */
+
+/**
+ * this routine provides a trace of the call stack to the caller,
+ * generally called either directly, via a signal handler, or through
+ * bu_bomb() with the appropriate bu_debug flags set.
+ *
+ * the routine waits indefinitely (in a spin loop) until a signal
+ * (SIGINT) is received, at which point execution continues, or until
+ * some other signal is received that terminates the application.
+ *
+ * the stack backtrace will be written to the provided 'fp' file
+ * pointer.  it's the caller's responsibility to open and close
+ * that pointer if necessary.  If 'fp' is NULL, stdout will be used.
+ *
+ * returns truthfully if a backtrace was attempted.
+ */
+BU_EXPORT extern int bu_backtrace(FILE *fp);
+
+
+/**
+ * Adds a hook to the list of bu_bomb hooks.  The top (newest) one of these
+ * will be called with its associated client data and a string to be
+ * processed.  Typically, these hook functions will display the output
+ * (possibly in an X window) or record it.
+ *
+ * NOTE: The hook functions are all non-PARALLEL.
+ */
+BU_EXPORT extern void bu_bomb_add_hook(bu_hook_t func, void *clientdata);
+
+
+/**
+ * Abort the running process.
+ *
+ * The bu_bomb routine is called on a fatal error, generally where no
+ * recovery is possible.  Error handlers may, however, be registered
+ * with BU_SETJUMP().  This routine intentionally limits calls to
+ * other functions and intentionally uses no stack variables.  Just in
+ * case the application is out of memory, bu_bomb deallocates a small
+ * buffer of memory.
+ *
+ * Before termination, it optionally performs the following operations
+ * in the order listed:
+ *
+ * 1. Outputs str to standard error
+ *
+ * 2. Calls any callback functions set in the global bu_bomb_hook_list
+ *    variable with str passed as an argument.
+ *
+ * 3. Jumps to any user specified error handler registered with the
+ *    BU_SETJUMP() facility.
+ *
+ * 4. Outputs str to the terminal device in case standard error is
+ *    redirected.
+ *
+ * 5. Aborts abnormally (via abort()) if BU_DEBUG_COREDUMP is defined.
+ *
+ * 6. Exits with exit(12).
+ *
+ * Only produce a core-dump when that debugging bit is set.  Note that
+ * this function is meant to be a last resort semi-graceful abort.
+ *
+ * This routine should never return unless there is a BU_SETJUMP()
+ * handler registered.
+ */
+BU_EXPORT extern void bu_bomb(const char *str) _BU_ATTR_ANALYZE_NORETURN 
_BU_ATTR_NORETURN;
+
+
+/**
+ * Semi-graceful termination of the application that doesn't cause a
+ * stack trace, exiting with the specified status after printing the
+ * given message.  It's okay for this routine to use the stack,
+ * contrary to bu_bomb's behavior since it should be called for
+ * expected termination situations.
+ *
+ * This routine should generally not be called within a library.  Use
+ * bu_bomb or (better) cascade the error back up to the application.
+ *
+ * This routine should never return.
+ */
+BU_EXPORT extern void bu_exit(int status, const char *fmt, ...) 
_BU_ATTR_ANALYZE_NORETURN _BU_ATTR_NORETURN _BU_ATTR_PRINTF23;
+
+
+/**
+ * @brief
+ * Generate a crash report file, including a call stack backtrace and
+ * other system details.
+ */
+
+/**
+ * this routine writes out details of the currently running process to
+ * the specified file, including an informational header about the
+ * execution environment, stack trace details, kernel and hardware
+ * information, and current version information.
+ *
+ * returns truthfully if the crash report was written.
+ *
+ * due to various reasons, this routine is NOT thread-safe.
+ */
+BU_EXPORT extern int bu_crashreport(const char *filename);
+
+/** @} */
+
+__END_DECLS
+
+#endif  /* BU_LOG_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */


Property changes on: brlcad/trunk/include/bu/bomb.h
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: brlcad/trunk/include/bu/hook.h
===================================================================
--- brlcad/trunk/include/bu/hook.h                              (rev 0)
+++ brlcad/trunk/include/bu/hook.h      2016-10-13 03:45:04 UTC (rev 69039)
@@ -0,0 +1,142 @@
+/*                        H O O K . H
+ * BRL-CAD
+ *
+ * Copyright (c) 2004-2016 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+
+#ifndef BU_HOOK_H
+#define BU_HOOK_H
+
+#include "common.h"
+
+#include "bu/defines.h"
+#include "bu/list.h"
+
+
+__BEGIN_DECLS
+
+/** @addtogroup bu_log
+ *
+ * @brief
+ * BRL-CAD support library, error logging routines.
+ *
+ * Note that the user may provide his own logging routine, by replacing these
+ * functions.  That is why this is in file of its own.  For example, LGT and
+ * RTSRV take advantage of this.
+ *
+ * Here is an example of how to set up a custom logging callback.  While bu_log
+ * presently writes to STDERR by default, this behavior should not be relied
+ * upon and may be changed to STDOUT in the future without notice.
+ *
+ @code
+ --- BEGIN EXAMPLE ---
+
+ int log_output_to_file(void *data, void *str)
+ {
+   FILE *fp = (FILE *)data;
+   fprintf(fp, "LOG: %s", str);
+   return 0;
+ }
+
+ int main(int ac, char *av[])
+ {
+   FILE *fp = fopen("whatever.log", "w+");
+   bu_log_add_hook(log_output_to_file, (void *)fp);
+   bu_log("Logging to file.\n");
+   bu_log_delete_hook(log_output_to_file, (void *)fp);
+   bu_log("Logging to stderr.\n");
+   fclose(fp);
+   return 0;
+ }
+
+ --- END EXAMPLE ---
+ @endcode
+ *
+ */
+/** @{ */
+/** @file bu/log.h */
+
+
+/** log indentation hook */
+typedef int (*bu_hook_t)(void *, void *);
+
+struct bu_hook_list {
+    struct bu_list l; /**< linked list */
+    bu_hook_t hookfunc; /**< function to call */
+    void *clientdata; /**< data for caller */
+};
+typedef struct bu_hook_list bu_hook_list_t;
+#define BU_HOOK_LIST_NULL ((struct bu_hook_list *) 0)
+
+/**
+ * assert the integrity of a non-head node bu_hook_list struct.
+ */
+#define BU_CK_HOOK_LIST(_hl) BU_CKMAG(_hl, BU_HOOK_LIST_MAGIC, "bu_hook_list")
+
+/**
+ * initialize a bu_hook_list struct without allocating any memory.
+ * this macro is not suitable for initialization of a list head node.
+ */
+#define BU_HOOK_LIST_INIT(_hl) { \
+       BU_LIST_INIT_MAGIC(&(_hl)->l, BU_HOOK_LIST_MAGIC); \
+       (_hl)->hookfunc = (_hl)->clientdata = NULL; \
+    }
+
+/**
+ * macro suitable for declaration statement initialization of a
+ * bu_hook_list struct.  does not allocate memory.  not suitable for
+ * initialization of a list head node.
+ */
+#define BU_HOOK_LIST_INIT_ZERO { {BU_HOOK_LIST_MAGIC, BU_LIST_NULL, 
BU_LIST_NULL}, NULL, NULL }
+
+/**
+ * returns truthfully whether a non-head node bu_hook_list has been
+ * initialized via BU_HOOK_LIST_INIT() or BU_HOOK_LIST_INIT_ZERO.
+ */
+#define BU_HOOK_LIST_IS_INITIALIZED(_p) (((struct bu_hook_list *)(_p) != 
BU_HOOK_LIST_NULL) && LIKELY((_p)->l.magic == BU_HOOK_LIST_MAGIC))
+
+/** @brief BRL-CAD support library's hook utility. */
+BU_EXPORT extern void bu_hook_list_init(struct bu_hook_list *hlp);
+BU_EXPORT extern void bu_hook_add(struct bu_hook_list *hlp,
+                                 bu_hook_t func,
+                                 void *clientdata);
+BU_EXPORT extern void bu_hook_delete(struct bu_hook_list *hlp,
+                                    bu_hook_t func,
+                                    void *clientdata);
+BU_EXPORT extern void bu_hook_call(struct bu_hook_list *hlp,
+                                  void *buf);
+BU_EXPORT extern void bu_hook_save_all(struct bu_hook_list *hlp,
+                                      struct bu_hook_list *save_hlp);
+BU_EXPORT extern void bu_hook_delete_all(struct bu_hook_list *hlp);
+BU_EXPORT extern void bu_hook_restore_all(struct bu_hook_list *hlp,
+                                         struct bu_hook_list *restore_hlp);
+
+/** @} */
+
+__END_DECLS
+
+#endif  /* BU_LOG_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */


Property changes on: brlcad/trunk/include/bu/hook.h
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: brlcad/trunk/include/bu/log.h
===================================================================
--- brlcad/trunk/include/bu/log.h       2016-10-13 03:41:47 UTC (rev 69038)
+++ brlcad/trunk/include/bu/log.h       2016-10-13 03:45:04 UTC (rev 69039)
@@ -29,8 +29,11 @@
 #include "bu/defines.h"
 #include "bu/magic.h"
 #include "bu/parse.h"
-#include "bu/list.h"
+#include "bu/hook.h"
 
+#include "bu/bomb.h" /* XXX not used here, not intended to be kept included 
here */
+
+
 __BEGIN_DECLS
 
 /** @addtogroup bu_log
@@ -74,145 +77,8 @@
 /** @{ */
 /** @file bu/log.h */
 
-/** @brief Extract a backtrace of the current call stack. */
-
 /**
- * this routine provides a trace of the call stack to the caller,
- * generally called either directly, via a signal handler, or through
- * bu_bomb() with the appropriate bu_debug flags set.
- *
- * the routine waits indefinitely (in a spin loop) until a signal
- * (SIGINT) is received, at which point execution continues, or until
- * some other signal is received that terminates the application.
- *
- * the stack backtrace will be written to the provided 'fp' file
- * pointer.  it's the caller's responsibility to open and close
- * that pointer if necessary.  If 'fp' is NULL, stdout will be used.
- *
- * returns truthfully if a backtrace was attempted.
- */
-BU_EXPORT extern int bu_backtrace(FILE *fp);
-
-/** log indentation hook */
-typedef int (*bu_hook_t)(void *, void *);
-
-struct bu_hook_list {
-    struct bu_list l; /**< linked list */
-    bu_hook_t hookfunc; /**< function to call */
-    void *clientdata; /**< data for caller */
-};
-typedef struct bu_hook_list bu_hook_list_t;
-#define BU_HOOK_LIST_NULL ((struct bu_hook_list *) 0)
-
-/**
- * assert the integrity of a non-head node bu_hook_list struct.
- */
-#define BU_CK_HOOK_LIST(_hl) BU_CKMAG(_hl, BU_HOOK_LIST_MAGIC, "bu_hook_list")
-
-/**
- * initialize a bu_hook_list struct without allocating any memory.
- * this macro is not suitable for initialization of a list head node.
- */
-#define BU_HOOK_LIST_INIT(_hl) { \
-       BU_LIST_INIT_MAGIC(&(_hl)->l, BU_HOOK_LIST_MAGIC); \
-       (_hl)->hookfunc = (_hl)->clientdata = NULL; \
-    }
-
-/**
- * macro suitable for declaration statement initialization of a
- * bu_hook_list struct.  does not allocate memory.  not suitable for
- * initialization of a list head node.
- */
-#define BU_HOOK_LIST_INIT_ZERO { {BU_HOOK_LIST_MAGIC, BU_LIST_NULL, 
BU_LIST_NULL}, NULL, NULL }
-
-/**
- * returns truthfully whether a non-head node bu_hook_list has been
- * initialized via BU_HOOK_LIST_INIT() or BU_HOOK_LIST_INIT_ZERO.
- */
-#define BU_HOOK_LIST_IS_INITIALIZED(_p) (((struct bu_hook_list *)(_p) != 
BU_HOOK_LIST_NULL) && LIKELY((_p)->l.magic == BU_HOOK_LIST_MAGIC))
-
-/** @brief Main functions for exiting/bombing. */
-
-/**
- * Adds a hook to the list of bu_bomb hooks.  The top (newest) one of these
- * will be called with its associated client data and a string to be
- * processed.  Typically, these hook functions will display the output
- * (possibly in an X window) or record it.
- *
- * NOTE: The hook functions are all non-PARALLEL.
- */
-BU_EXPORT extern void bu_bomb_add_hook(bu_hook_t func, void *clientdata);
-
-/**
- * Abort the running process.
- *
- * The bu_bomb routine is called on a fatal error, generally where no
- * recovery is possible.  Error handlers may, however, be registered
- * with BU_SETJUMP().  This routine intentionally limits calls to
- * other functions and intentionally uses no stack variables.  Just in
- * case the application is out of memory, bu_bomb deallocates a small
- * buffer of memory.
- *
- * Before termination, it optionally performs the following operations
- * in the order listed:
- *
- * 1. Outputs str to standard error
- *
- * 2. Calls any callback functions set in the global bu_bomb_hook_list
- *    variable with str passed as an argument.
- *
- * 3. Jumps to any user specified error handler registered with the
- *    BU_SETJUMP() facility.
- *
- * 4. Outputs str to the terminal device in case standard error is
- *    redirected.
- *
- * 5. Aborts abnormally (via abort()) if BU_DEBUG_COREDUMP is defined.
- *
- * 6. Exits with exit(12).
- *
- * Only produce a core-dump when that debugging bit is set.  Note that
- * this function is meant to be a last resort semi-graceful abort.
- *
- * This routine should never return unless there is a BU_SETJUMP()
- * handler registered.
- */
-BU_EXPORT extern void bu_bomb(const char *str) _BU_ATTR_ANALYZE_NORETURN 
_BU_ATTR_NORETURN;
-
-/**
- * Semi-graceful termination of the application that doesn't cause a
- * stack trace, exiting with the specified status after printing the
- * given message.  It's okay for this routine to use the stack,
- * contrary to bu_bomb's behavior since it should be called for
- * expected termination situations.
- *
- * This routine should generally not be called within a library.  Use
- * bu_bomb or (better) cascade the error back up to the application.
- *
- * This routine should never return.
- */
-BU_EXPORT extern void bu_exit(int status, const char *fmt, ...) 
_BU_ATTR_ANALYZE_NORETURN _BU_ATTR_NORETURN _BU_ATTR_PRINTF23;
-
-/**
  * @brief
- * Generate a crash report file, including a call stack backtrace and
- * other system details.
- */
-
-/**
- * this routine writes out details of the currently running process to
- * the specified file, including an informational header about the
- * execution environment, stack trace details, kernel and hardware
- * information, and current version information.
- *
- * returns truthfully if the crash report was written.
- *
- * due to various reasons, this routine is NOT thread-safe.
- */
-BU_EXPORT extern int bu_crashreport(const char *filename);
-
-/**
- * @brief
  * fgets replacement function that also handles CR as an EOL marker
  */
 
@@ -231,22 +97,6 @@
 
 BU_EXPORT extern void bu_setlinebuf(FILE *fp);
 
-/** @brief BRL-CAD support library's hook utility. */
-BU_EXPORT extern void bu_hook_list_init(struct bu_hook_list *hlp);
-BU_EXPORT extern void bu_hook_add(struct bu_hook_list *hlp,
-                                 bu_hook_t func,
-                                 void *clientdata);
-BU_EXPORT extern void bu_hook_delete(struct bu_hook_list *hlp,
-                                    bu_hook_t func,
-                                    void *clientdata);
-BU_EXPORT extern void bu_hook_call(struct bu_hook_list *hlp,
-                                  void *buf);
-BU_EXPORT extern void bu_hook_save_all(struct bu_hook_list *hlp,
-                                      struct bu_hook_list *save_hlp);
-BU_EXPORT extern void bu_hook_delete_all(struct bu_hook_list *hlp);
-BU_EXPORT extern void bu_hook_restore_all(struct bu_hook_list *hlp,
-                                         struct bu_hook_list *restore_hlp);
-
 /** @brief parallel safe version of fprintf for logging */
 
 /**

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to