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