/*
    GDAM - Geoff & Dave's Audio Mixer
    Copyright (C) 1999    Dave Benson, Geoff Matters.

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    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 library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA

    Contact:
        daveb@ffem.org <Dave Benson>
        geoff@ugcs.caltech.edu <Geoff Matters>
*/
#ifndef __GDAM_DEBUG_H_
#define __GDAM_DEBUG_H_
#include <glib.h>

#include "gdamautoconf.h"

#ifndef G_STRINGIFY
#define G_STRINGIFY(x) #x
#endif

#ifndef _
#define _(string) (string)
#endif


#ifdef PREFIX_TOKEN
#define PREFIX       G_STRINGIFY(PREFIX_TOKEN)
#endif



extern gboolean      gdam_debugging_on;

void                 gdam_debug(const char* format, ...);

/* A static array like:
 *    { "a:arg", "d:dispatch", NULL }
 *
 * Warning: this function g_errors if called twice!
 */
void                 gdam_debug_register_names (const char * names []);
gboolean             gdam_debug_turn_on_debug_flag (const char *flag);


/* PRIVATE (mostly)
 * Turn a particular debugging option on or off;
 * str must be non-NULL if `on'.
 */
void                 gdam_debug_switch(int c, gboolean on, const char *str);


#if GDAM_DEBUG_REFERENCING

#include <gtk/gtkobject.h>
#define gtk_object_ref(obj) 						    \
	G_STMT_START {							    \
		g_message("ref: %p, line %d, file %s; "			    \
				"type=%s; count=%d++",			    \
					obj, __LINE__,__FILE__,		    \
					gtk_type_name(GTK_OBJECT_TYPE(obj)),\
				(obj)->ref_count);			    \
				gtk_object_ref(obj);			    \
		       } G_STMT_END
#define gtk_object_unref(obj)                                               \
        G_STMT_START {							    \
		g_message("unref: %p, line %d, file %s; "		    \
		                  "type=%s; count=%d--",                    \
					obj, __LINE__,__FILE__,
					gtk_type_name(GTK_OBJECT_TYPE(obj)),\
					(obj)->ref_count);		    \
				gtk_object_unref(obj);			    \
			       } G_STMT_END
#endif

#endif
