revert fix because GST_DEBUG_LEAVE("") doesn't work with it
[platform/upstream/gstreamer.git] / gst / gstinfo.h
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gstinfo.h: 
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 #ifndef __GSTINFO_H__
24 #define __GSTINFO_H__
25
26 #include <stdio.h>
27 #include <gmodule.h>
28 #include <unistd.h>
29
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33
34
35 /***** are we in the core or not? *****/
36 #ifdef __GST_PRIVATE_H__
37   #define _GST_DEBUG_INCORE TRUE
38 #else
39   #define _GST_DEBUG_INCORE FALSE
40 #endif
41
42
43 /* colorization stuff */
44 #ifdef GST_DEBUG_COLOR
45   #ifdef __GST_PRIVATE_H__   /* FIXME this should be some libgst.la -specific thing */
46     #define GST_DEBUG_CHAR_MODE "00"
47   #else
48     #define GST_DEBUG_CHAR_MODE "01"
49   #endif
50 #endif
51
52 gint _gst_debug_stringhash_color(gchar *file);
53
54
55
56 /**********************************************************************
57  * Categories
58  **********************************************************************/
59
60 const gchar *   gst_get_category_name   (gint category);
61
62 enum {
63   GST_CAT_GST_INIT = 0,         /* Library initialization */
64   GST_CAT_COTHREADS,            /* Cothread creation, etc. */
65   GST_CAT_COTHREAD_SWITCH,      /* Cothread switching */
66   GST_CAT_AUTOPLUG,             /* Successful autoplug results */
67   GST_CAT_AUTOPLUG_ATTEMPT,     /* Attempted autoplug operations */
68   GST_CAT_PARENTAGE,            /* GstBin parentage issues */
69   GST_CAT_STATES,               /* State changes and such */
70   GST_CAT_PLANNING,             /* Plan generation */
71   GST_CAT_SCHEDULING,           /* Schedule construction */
72   GST_CAT_DATAFLOW,             /* Events during actual data movement */
73   GST_CAT_BUFFER,               /* Buffer creation/destruction */
74   GST_CAT_CAPS,                 /* Capabilities matching */
75   GST_CAT_CLOCK,                /* Clocking */
76   GST_CAT_ELEMENT_PADS,         /* Element pad management */
77   GST_CAT_ELEMENT_FACTORY,      /* Elementfactory stuff */
78   GST_CAT_PADS,                 /* Pad creation/connection */
79   GST_CAT_PIPELINE,             /* Pipeline stuff */
80   GST_CAT_PLUGIN_LOADING,       /* Plugin loading */
81   GST_CAT_PLUGIN_ERRORS,        /* Errors during plugin loading */
82   GST_CAT_PLUGIN_INFO,          /* Plugin state information */
83   GST_CAT_PROPERTIES,           /* Properties */
84   GST_CAT_THREAD,               /* Thread creation/management */
85   GST_CAT_TYPES,                /* Typing */
86   GST_CAT_XML,                  /* XML load/save of everything */
87   GST_CAT_NEGOTIATION,          /* Caps Negotiation stuff */
88   GST_CAT_REFCOUNTING,          /* Ref Counting stuff */
89   GST_CAT_EVENT,                /* Event system */
90   GST_CAT_PARAMS,               /* Dynamic parameters */
91
92   GST_CAT_CALL_TRACE = 30,      /* Call tracing */
93
94   GST_CAT_MAX_CATEGORY = 31
95 };
96
97 extern const gchar *_gst_category_colors[32];
98
99
100
101 /**********************************************************************
102  * DEBUG system
103  **********************************************************************/
104
105 /* for include files that make too much noise normally */
106 #ifdef GST_DEBUG_FORCE_DISABLE
107 #undef GST_DEBUG_ENABLED
108 #endif
109 /* for applications that really really want all the noise */
110 #ifdef GST_DEBUG_FORCE_ENABLE
111 #define GST_DEBUG_ENABLED
112 #endif
113
114 /*#ifdef GST_DEBUG_ENABLED */
115 #define GST_DEBUG_ENABLE_CATEGORIES 0xffffffff
116 /*#else */
117 /*#define GST_DEBUG_ENABLE_CATEGORIES 0x00000000 */
118 /*#endif */
119
120
121 typedef void (*GstDebugHandler) (gint category,gboolean core,
122                                  const gchar *file,const gchar *function,
123                                  gint line,const gchar *debug_string,
124                                  void *element,gchar *string);
125
126 void gst_default_debug_handler (gint category,gboolean incore,
127                                 const gchar *file, const gchar *function,
128                                 gint line,const gchar *debug_string,
129                                 void *element,gchar *string);
130
131 extern guint32 _gst_debug_categories;
132 extern GstDebugHandler _gst_debug_handler;
133
134 /* fallback, this should probably be a 'weak' symbol or something */
135 G_GNUC_UNUSED static gchar *_debug_string = NULL;
136
137
138
139
140 #ifdef GST_DEBUG_ENABLED
141 #define GST_DEBUG(cat,format,args...) G_STMT_START{ \
142   if ((1<<cat) & _gst_debug_categories) \
143     _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
144                        NULL,g_strdup_printf( format , ## args )); \
145 }G_STMT_END
146
147 #define GST_DEBUG_ELEMENT(cat,element,format,args...) G_STMT_START{ \
148   if ((1<<cat) & _gst_debug_categories) \
149     _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
150                        element,g_strdup_printf( format , ## args )); \
151 }G_STMT_END
152
153 #else
154 #define GST_DEBUG(cat,format,args...)
155 #define GST_DEBUG_ELEMENT(cat,element,format,args...)
156 #endif
157
158
159
160
161 /********** some convenience macros for debugging **********/
162 #define GST_DEBUG_PAD_NAME(pad) \
163   (GST_OBJECT_PARENT(pad) != NULL) ? \
164   GST_OBJECT_NAME (GST_OBJECT_PARENT(pad)) : \
165   "''", GST_OBJECT_NAME (pad)
166
167 #ifdef GST_DEBUG_COLOR
168   #define GST_DEBUG_ENTER(format, args...) GST_DEBUG( 31 , format ": \033[00;37mentering\033[00m" , ##args )
169   #define GST_DEBUG_LEAVE(format, args...) GST_DEBUG( 31 , format ": \033[00;37mleaving\033[00m" , ##args )
170 #else
171   #define GST_DEBUG_ENTER(format, args...) GST_DEBUG( 31 , format ": entering" , ##args )
172   #define GST_DEBUG_LEAVE(format, args...) GST_DEBUG( 31 , format ": leaving" , ##args )
173 #endif
174
175
176 /***** Colorized debug for thread ids *****/
177 #ifdef GST_DEBUG_COLOR
178   #define GST_DEBUG_THREAD_FORMAT "\033[00;%dm%d\033[00m"
179   #define GST_DEBUG_THREAD_ARGS(id) ( ((id) < 0) ? 37 : ((id) % 6 + 31) ), (id)
180 #else
181   #define GST_DEBUG_THREAD_FORMAT "%d"
182   #define GST_DEBUG_THREAD_ARGS(id) (id)
183 #endif
184
185
186
187 /**********************************************************************
188  * The following is a DEBUG_ENTER implementation that will wrap the
189  * function it sits at the head of.  It removes the need for a
190  * DEBUG_LEAVE call.  However, it segfaults whenever it gets anywhere
191  * near cothreads.  We will not use it for the moment.
192  *
193 typedef void (*_debug_function_f)();
194 G_GNUC_UNUSED static gchar *_debug_string_pointer = NULL;
195 G_GNUC_UNUSED static GModule *_debug_self_module = NULL;
196
197 #define _DEBUG_ENTER_BUILTIN(format,args...)                                            \
198   static int _debug_in_wrapper = 0;                                                     \
199   gchar *_debug_string = ({                                                             \
200     if (!_debug_in_wrapper) {                                                           \
201       void *_return_value;                                                              \
202       gchar *_debug_string;                                                             \
203       _debug_function_f function;                                                       \
204       void *_function_args = __builtin_apply_args();                                    \
205       _debug_in_wrapper = 1;                                                            \
206       _debug_string = g_strdup_printf(GST_DEBUG_PREFIX(""));                            \
207       _debug_string_pointer = _debug_string;                                            \
208       fprintf(stderr,"%s: entered " __PRETTY_FUNCTION__ format "\n" , _debug_string , ## args ); \
209       if (_debug_self_module == NULL) _debug_self_module = g_module_open(NULL,0);       \
210       g_module_symbol(_debug_self_module,__FUNCTION__,(gpointer *)&function);           \
211       _return_value = __builtin_apply(function,_function_args,64);                      \
212       fprintf(stderr,"%s: left " __PRETTY_FUNCTION__ format "\n" , _debug_string , ## args ); \
213       g_free(_debug_string);                                                            \
214       __builtin_return(_return_value);                                                  \
215     } else {                                                                            \
216       _debug_in_wrapper = 0;                                                            \
217     }                                                                                   \
218     _debug_string_pointer;                                                              \
219   });
220
221 * WARNING: there's a gcc CPP bug lurking in here.  The extra space before the ##args    *
222  * somehow make the preprocessor leave the _debug_string. If it's removed, the          *
223  * _debug_string somehow gets stripped along with the ##args, and that's all she wrote. *
224 #define _DEBUG_BUILTIN(format,args...)                          \
225   if (_debug_string != (void *)-1) {                            \
226     if (_debug_string)                                          \
227       fprintf(stderr,"%s: " format , _debug_string , ## args);  \
228     else                                                        \
229       fprintf(stderr,GST_DEBUG_PREFIX(": " format , ## args));  \
230   }
231
232 */
233
234
235
236 /**********************************************************************
237  * INFO system
238  **********************************************************************/
239
240 typedef void (*GstInfoHandler) (gint category,gboolean incore,
241                                 const gchar *file,const gchar *function,
242                                 gint line,const gchar *debug_string,
243                                 void *element,gchar *string);
244
245 void gst_default_info_handler (gint category,gboolean incore,
246                                const gchar *file,const gchar *function,
247                                gint line,const gchar *debug_string,
248                                void *element,gchar *string);
249
250 extern GstInfoHandler _gst_info_handler;
251 extern guint32 _gst_info_categories;
252
253 /* for include files that make too much noise normally */
254 #ifdef GST_INFO_FORCE_DISABLE
255 #undef GST_INFO_ENABLED
256 #endif
257 /* for applications that really really want all the noise */
258 #ifdef GST_INFO_FORCE_ENABLE
259 #define GST_INFO_ENABLED
260 #endif
261
262 #ifdef GST_INFO_ENABLED
263 #define GST_INFO(cat,format,args...) G_STMT_START{ \
264   if ((1<<cat) & _gst_info_categories) \
265     _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
266                       NULL,g_strdup_printf( format , ## args )); \
267 }G_STMT_END
268
269 #define GST_INFO_ELEMENT(cat,element,format,args...) G_STMT_START{ \
270   if ((1<<cat) & _gst_info_categories) \
271     _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
272                       element,g_strdup_printf( format , ## args )); \
273 }G_STMT_END
274
275 #else
276 #define GST_INFO(cat,format,args...) 
277 #define GST_INFO_ELEMENT(cat,element,format,args...)
278 #endif
279
280
281 void            gst_info_set_categories         (guint32 categories);
282 guint32         gst_info_get_categories         (void);
283 void            gst_info_enable_category        (gint category);
284 void            gst_info_disable_category       (gint category);
285
286 void            gst_debug_set_categories        (guint32 categories);
287 guint32         gst_debug_get_categories        (void);
288 void            gst_debug_enable_category       (gint category);
289 void            gst_debug_disable_category      (gint category);
290
291
292
293
294 /**********************************************************************
295  * ERROR system
296  **********************************************************************/
297
298 typedef void (*GstErrorHandler) (gchar *file,gchar *function,
299                                  gint line,gchar *debug_string,
300                                  void *element,void *object,gchar *string);
301
302 void gst_default_error_handler (gchar *file,gchar *function,
303                                 gint line,gchar *debug_string,
304                                 void *element,void *object,gchar *string);
305
306 extern GstErrorHandler _gst_error_handler;
307
308 #define GST_ERROR(element,format,args...) \
309   _gst_error_handler(__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
310                      element,NULL,g_strdup_printf( format , ## args ))
311
312 #define GST_ERROR_OBJECT(element,object,format,args...) \
313   _gst_error_handler(__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
314                      element,object,g_strdup_printf( format , ## args ))
315
316
317
318
319 /********** function pointer stuff **********/
320 extern GHashTable *__gst_function_pointers;
321
322
323 #if GST_DEBUG_ENABLED
324 #define GST_DEBUG_FUNCPTR(ptr) _gst_debug_register_funcptr((void *)(ptr), #ptr)
325 #define GST_DEBUG_FUNCPTR_NAME(ptr) _gst_debug_nameof_funcptr((void *)ptr)
326 #else
327 #define GST_DEBUG_FUNCPTR(ptr) (ptr)
328 #define GST_DEBUG_FUNCPTR_NAME(ptr) ""
329 #endif
330
331 static inline void *
332 _gst_debug_register_funcptr (void *ptr, gchar *ptrname) 
333 {
334   if (!__gst_function_pointers) __gst_function_pointers = g_hash_table_new(g_direct_hash,g_direct_equal);
335   if (!g_hash_table_lookup(__gst_function_pointers,ptr))
336     g_hash_table_insert(__gst_function_pointers,ptr,ptrname);
337   return ptr;
338 }
339
340 gchar *_gst_debug_nameof_funcptr (void *ptr);
341
342 void gst_debug_print_stack_trace (void);
343
344
345
346 #endif /* __GSTINFO_H__ */