[beast/devel: 29/77] SFI: add Bse debugging API



commit 4991530eb178cddadc0bdefef7995f229ef9e472
Author: Tim Janik <timj gnu org>
Date:   Sun Apr 7 14:52:33 2013 +0200

    SFI: add Bse debugging API

 sfi/sfiwrapper.cc |   40 ++++++++++++++++++++++++++++++++++++++++
 sfi/sfiwrapper.hh |   19 +++++++++++++++++--
 2 files changed, 57 insertions(+), 2 deletions(-)
---
diff --git a/sfi/sfiwrapper.cc b/sfi/sfiwrapper.cc
index c3e2e25..b7f2bef 100644
--- a/sfi/sfiwrapper.cc
+++ b/sfi/sfiwrapper.cc
@@ -2,6 +2,46 @@
 #include "sfiwrapper.hh"
 #include <birnet/birnet.hh>
 #include <errno.h>
+
+namespace Bse {
+
+/// Caching flag to inhibit useless bse_debug() calls.
+bool volatile _cached_bse_debug = true;
+
+/// Issue a debugging message, configurable via #$BSE_DEBUG.
+void
+bse_debug (const char *key, const char *file_path, const int line, const char *format, ...)
+{
+  va_list vargs;
+  va_start (vargs, format);
+  envkey_debug_message ("BSE_DEBUG", key, file_path, line, format, vargs, &_cached_rapicorn_debug);
+  va_end (vargs);
+}
+
+#ifdef DOXYGEN
+/** Check if debugging is enabled for @a key.
+ * This function checks if #$BSE_DEBUG contains @a key or "all" and returns true
+ * if debugging is enabled for the given key. The @a key argument may be NULL in which
+ * case the function checks if general debugging is enabled.
+ */
+bool bse_debug_enabled (const char *key);
+#endif // DOXYGEN
+
+bool
+_bse_debug_enabled (const char *key)
+{
+  return envkey_debug_check ("BSE_DEBUG", key, &_cached_bse_debug);
+}
+
+/// Check if the feature toggle @a key is enabled in #$BSE_FLIPPER.
+bool
+bse_flipper_check (const char *key)
+{
+  return envkey_flipper_check ("BSE_FLIPPER", key);
+}
+
+} // Bse
+
 /* --- initialization --- */
 void
 sfi_init (int            *argcp,
diff --git a/sfi/sfiwrapper.hh b/sfi/sfiwrapper.hh
index 447ef65..e52fd3f 100644
--- a/sfi/sfiwrapper.hh
+++ b/sfi/sfiwrapper.hh
@@ -6,10 +6,25 @@
 #include <birnet/birnetcdefs.h> /* include glib before birnet for G_LOG_DOMAIN */
 #include <birnet/birnetutils.hh>
 
-// FIXME: Introduce symbols from Rapicorn to ease transition.
 namespace Bse {
 
-};
+// == Likelyness Hinting ==
+#define BSE_ISLIKELY(expr)      RAPICORN_ISLIKELY(expr) ///< Compiler hint that @a expr is likely to be true.
+#define BSE_UNLIKELY(expr)      RAPICORN_UNLIKELY(expr) ///< Compiler hint that @a expr is unlikely to be 
true.
+#define BSE_LIKELY              BSE_ISLIKELY            ///< Compiler hint that @a expr is likely to be true.
+
+// == Debugging ==
+/// Issue a general purpose debugging message, configurable via #$BSE_DEBUG.
+#define BSE_DEBUG(...)          do { if (BSE_UNLIKELY (Bse::_cached_bse_debug)) Bse::bse_debug (NULL, 
RAPICORN_PRETTY_FILE, __LINE__, __VA_ARGS__); } while (0)
+/// Issue a debugging message if debugging for @a key is enabled via #$BSE_DEBUG.
+#define BSE_KEY_DEBUG(key,...)  do { if (BSE_UNLIKELY (Bse::_cached_bse_debug)) Bse::bse_debug (key, 
RAPICORN_PRETTY_FILE, __LINE__, __VA_ARGS__); } while (0)
+extern bool volatile _cached_bse_debug;
+void        bse_debug         (const char*, const char*, int, const char*, ...) RAPICORN_PRINTF (4, 5);
+bool       _bse_debug_enabled (const char *key);
+inline bool bse_debug_enabled (const char *key = NULL) { return BSE_UNLIKELY (_cached_bse_debug) && 
_bse_debug_enabled (key); }
+bool        bse_flipper_check (const char *key);
+
+} // Bse
 
 /* sfiwrapper.h is a thin C language wrapper around C++ features
  * provided by libbirnet.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]