X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-debug.h;h=828480bdedbae475eb4d4651f23c32b50ad9d1d0;hp=a63717e9565593eb6b85b5a3f5a5eebcfbcdc41a;hb=60da25f18dac811da77c20f86f5022bbc1aa5649;hpb=d43e126947075b066ac3563aa9c2996f1ba3becb diff --git a/src/modest-debug.h b/src/modest-debug.h index a63717e..828480b 100644 --- a/src/modest-debug.h +++ b/src/modest-debug.h @@ -27,52 +27,73 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include +#ifndef __MODEST_DEBUG_H__ +#define __MODEST_DEBUG_H__ -#define MODEST_DEBUG "MODEST_DEBUG" - -typedef enum { - MODEST_DEBUG_ABORT_ON_WARNING = 1 << 0, - MODEST_DEBUG_LOG_ACTIONS = 1 << 1, /* not in use atm */ - MODEST_DEBUG_DEBUG_OBJECTS = 1 << 2, /* for g_type_init */ - MODEST_DEBUG_DEBUG_SIGNALS = 1 << 3 /* for g_type_init */ -} ModestDebugFlags; +#include "modest-runtime.h" +/* some debugging macros */ /** - * modest_debug_get_flags - * - * get the debug flags for modest; they are read from the MODEST_DEBUG - * environment variable; the flags specified as strings, separated by ':'. - * Possible values are: - * - "abort-on-warning": abort the program when a gtk/glib/.. warning occurs. - * useful when running in debugger - * - "log-actions": log user actions (not in use atm) - * - "track-object": track the use of (g)objects in the program. this option influences - * g_type_init_with_debug_flags - * - "track-signals": track the use of (g)signals in the program. this option influences - * g_type_init_with_debug_flags - * if you would want to track signals and log actions, you could do something like: - * MODEST_DEBUG="log-actions:track-signals" ./modest - * NOTE that the flags will stay the same during the run of the program, even - * if the environment variable changes. + * MODEST_RUNTIME_VERIFY_OBJECT_LAST_REF: + * @OBJ: some (GObject) ptr + * @NAME: name of @OBJ * - * Returns: the bitwise OR of the debug flags - */ -ModestDebugFlags modest_debug_get_flags (void) G_GNUC_CONST; + * macro to check whether @obj holds only one more ref (ie. after the + * next unref it will die) + * + * not, a g_warning will be issued on stderr. NOTE: this is only active + * when MODEST_DEBUG contains "debug-objects". + * + ***/ +#define MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(OBJ,name) \ + do { \ + if (modest_runtime_get_debug_flags() & MODEST_RUNTIME_DEBUG_OBJECTS) \ + if (G_IS_OBJECT(OBJ) && G_OBJECT(OBJ)->ref_count != 1) \ + g_warning ("%s:%d: %s (" \ + #OBJ ") still holds a ref count of %d", \ + __FILE__,__LINE__,name, G_OBJECT(OBJ)->ref_count); \ + } while (0) + + + /** - * modest_g_type_init - * - * do a g_type_init_with_debug_flags based on the modest debug flags - */ -void modest_debug_g_type_init (void); + * MODEST_DEBUG_BLOCK: + * @BLOCK: some block of code + * + * macro to which run its argument (block) only when MODEST_DEBUG contains "debug-code" + * + ***/ +#define MODEST_DEBUG_BLOCK(BLOCK) \ + do { \ + if (modest_runtime_get_debug_flags() & MODEST_RUNTIME_DEBUG_CODE) { \ + BLOCK \ + } \ + } while (0) + /** - * modest_g_type_init + * MODEST_DEBUG_NOT_IMPLEMENTED: + * @WIN: the parent GtkWindow, or NULL * - * do set the logging based on the modest debug flags (ie. whether - * we should abort when a warning occurs. - */ -void modest_debug_logging_init (void); + * give a not-implemented-yet warning popup or g_warning + * + ***/ +#define MODEST_DEBUG_NOT_IMPLEMENTED(WIN) \ + do { \ + if (gtk_main_level() > 0) { \ + GtkWidget *popup; \ + popup = gtk_message_dialog_new (WIN,\ + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,\ + GTK_MESSAGE_WARNING, \ + GTK_BUTTONS_OK, \ + "Not yet implemented");\ + gtk_dialog_run (GTK_DIALOG(popup)); \ + gtk_widget_destroy (popup); \ + } else \ + g_warning ("%s:%d: Not yet implemented",__FILE__,__LINE__); \ + } while (0) \ + + +#endif /*__MODEST_DEBUG_H__*/