2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstinfo.c: INFO, ERROR, and DEBUG systems
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #include "gst_private.h"
26 extern gchar *_gst_progname;
29 /***** DEBUG system *****/
30 GHashTable *__gst_function_pointers = NULL;
34 /***** INFO system *****/
35 GstInfoHandler _gst_info_handler = gst_default_info_handler;
36 #ifdef GST_INFO_ENABLED_VERBOSE
37 guint32 _gst_info_categories = 0xffffffff;
39 guint32 _gst_info_categories = 0x00000001;
42 static gchar *_gst_info_category_strings[] = {
69 gst_default_info_handler (gint category, gchar *file, gchar *function,
70 gint line, gchar *debug_string,
71 void *element, gchar *string)
74 gchar *elementname = empty,*location = empty;
76 if (debug_string == NULL) debug_string = "";
77 if (category != GST_CAT_GST_INIT)
78 location = g_strdup_printf("%s:%d%s:",function,line,debug_string);
79 if (element && GST_IS_ELEMENT (element))
80 elementname = g_strdup_printf (" [%s]",gst_element_get_name (element));
82 fprintf(stderr,"INFO:%s%s %s\n",location,elementname,string);
84 if (location != empty) g_free(location);
85 if (elementname != empty) g_free(elementname);
91 gst_info_set_categories (guint32 categories) {
92 _gst_info_categories = categories;
96 gst_info_get_categories () {
97 return _gst_info_categories;
101 gst_get_category_name (gint category) {
102 if ((category >= 0) && (category < GST_CAT_MAX_CATEGORY))
103 return _gst_info_category_strings[category];
109 gst_info_enable_category (gint category) {
110 _gst_info_categories |= (1 << category);
114 gst_info_disable_category (gint category) {
115 _gst_info_categories &= ~ (1 << category);
120 /***** ERROR system *****/
121 GstErrorHandler _gst_error_handler = gst_default_error_handler;
124 gst_default_error_handler (gchar *file, gchar *function,
125 gint line, gchar *debug_string,
126 void *element, void *object, gchar *string)
132 // if there are NULL pointers, point them to null strings to clean up output
133 if (!debug_string) debug_string = "";
134 if (!string) string = "";
136 // print out a preamble
137 fprintf(stderr,"***** GStreamer ERROR ***** in file %s at %s:%d%s\n",
138 file,function,line,debug_string);
140 // if there's an element, print out the pertinent information
142 if (GST_IS_OBJECT(element)) {
143 path = gst_object_get_path_string(element);
144 fprintf(stderr,"Element: %s",path);
145 chars = 9 + strlen(path);
148 fprintf(stderr,"Element ptr: %p",element);
149 chars = 15 + sizeof(void*)*2;
153 // if there's an object, print it out as well
155 // attempt to pad the line, or create a new one
157 for (i=0;i<(40-chars)/8+1;i++) fprintf(stderr,"\t");
159 fprintf(stderr,"\n");
161 if (GST_IS_OBJECT(object)) {
162 path = gst_object_get_path_string(object);
163 fprintf(stderr,"Object: %s",path);
166 fprintf(stderr,"Object ptr: %p",object);
170 fprintf(stderr,"\n");
171 fprintf(stderr,"Error: %s\n",string);
175 fprintf(stderr,"***** attempting to stack trace.... *****\n");
177 g_on_error_stack_trace (_gst_progname);
182 gst_info_init (int *argc,