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_info_enable_category (gint category) {
102 _gst_info_categories |= (1 << category);
106 gst_info_disable_category (gint category) {
107 _gst_info_categories &= ~ (1 << category);
111 gst_debug_set_categories (guint32 categories) {
112 _gst_debug_categories = categories;
116 gst_debug_get_categories () {
117 return _gst_debug_categories;
121 gst_debug_enable_category (gint category) {
122 _gst_debug_categories |= (1 << category);
126 gst_debug_disable_category (gint category) {
127 _gst_debug_categories &= ~ (1 << category);
131 gst_get_category_name (gint category) {
132 if ((category >= 0) && (category < GST_CAT_MAX_CATEGORY))
133 return _gst_info_category_strings[category];
140 /***** ERROR system *****/
141 GstErrorHandler _gst_error_handler = gst_default_error_handler;
144 gst_default_error_handler (gchar *file, gchar *function,
145 gint line, gchar *debug_string,
146 void *element, void *object, gchar *string)
152 // if there are NULL pointers, point them to null strings to clean up output
153 if (!debug_string) debug_string = "";
154 if (!string) string = "";
156 // print out a preamble
157 fprintf(stderr,"***** GStreamer ERROR ***** in file %s at %s:%d%s\n",
158 file,function,line,debug_string);
160 // if there's an element, print out the pertinent information
162 if (GST_IS_OBJECT(element)) {
163 path = gst_object_get_path_string(element);
164 fprintf(stderr,"Element: %s",path);
165 chars = 9 + strlen(path);
168 fprintf(stderr,"Element ptr: %p",element);
169 chars = 15 + sizeof(void*)*2;
173 // if there's an object, print it out as well
175 // attempt to pad the line, or create a new one
177 for (i=0;i<(40-chars)/8+1;i++) fprintf(stderr,"\t");
179 fprintf(stderr,"\n");
181 if (GST_IS_OBJECT(object)) {
182 path = gst_object_get_path_string(object);
183 fprintf(stderr,"Object: %s",path);
186 fprintf(stderr,"Object ptr: %p",object);
190 fprintf(stderr,"\n");
191 fprintf(stderr,"Error: %s\n",string);
195 fprintf(stderr,"***** attempting to stack trace.... *****\n");
197 g_on_error_stack_trace (_gst_progname);