X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-debug.h;h=828480bdedbae475eb4d4651f23c32b50ad9d1d0;hp=cc3eb3122bbe79e2da558a128364fa5a40a3b32a;hb=12a672c559d983c4e49a7e4054ee14c0177ecb1c;hpb=7b459c93311d95a1ca4cbb708de5c8e32e6cf54b diff --git a/src/modest-debug.h b/src/modest-debug.h index cc3eb31..828480b 100644 --- a/src/modest-debug.h +++ b/src/modest-debug.h @@ -30,58 +30,70 @@ #ifndef __MODEST_DEBUG_H__ #define __MODEST_DEBUG_H__ -#include -#include +#include "modest-runtime.h" -G_BEGIN_DECLS +/* some debugging macros */ + +/** + * MODEST_RUNTIME_VERIFY_OBJECT_LAST_REF: + * @OBJ: some (GObject) ptr + * @NAME: name of @OBJ + * + * 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) -#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; /** - * 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_DEBUG_BLOCK: + * @BLOCK: some block of code * - * Returns: the bitwise OR of the debug flags - */ -ModestDebugFlags modest_debug_get_flags (void) G_GNUC_CONST; + * 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 - * - * do a g_type_init_with_debug_flags based on the modest debug flags - */ -void modest_debug_g_type_init (void); /** - * 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); - -G_END_DECLS + * 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__*/