Remove 'inline' from a function that is never actually inlined under any circumstance...
[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 #include <glib/gmacros.h>
30
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
34
35 /* FIXME: convert to using G_STRLOC all the way if we can ! */
36
37 #ifndef FUNCTION
38 #ifdef G_GNUC_PRETTY_FUNCTION
39 #define FUNCTION G_GNUC_PRETTY_FUNCTION
40 #elif HAVE_FUNC
41 #define FUNCTION __func__
42 #elif HAVE_PRETTY_FUNCTION
43 #define FUNCTION __PRETTY_FUNCTION__
44 #elif HAVE_FUNCTION
45 #define FUNCTION __FUNCTION__
46 #else
47 #define FUNCTION ""
48 #endif
49 #endif /* ifndef FUNCTION */
50
51 /***** are we in the core or not? *****/
52 #ifdef __GST_PRIVATE_H__
53   #define _GST_DEBUG_INCORE TRUE
54 #else
55   #define _GST_DEBUG_INCORE FALSE
56 #endif
57
58
59 /* colorization stuff */
60 #ifdef GST_DEBUG_COLOR
61   #ifdef __GST_PRIVATE_H__   /* FIXME this should be some libgst.la -specific thing */
62     #define GST_DEBUG_CHAR_MODE "00"
63   #else
64     #define GST_DEBUG_CHAR_MODE "01"
65   #endif
66 #endif
67
68 gint _gst_debug_stringhash_color(gchar *file);
69
70
71
72 /**********************************************************************
73  * Categories
74  **********************************************************************/
75
76 const gchar *   gst_get_category_name   (gint category);
77
78 enum {
79   GST_CAT_GST_INIT = 0,         /* Library initialization */
80   GST_CAT_COTHREADS,            /* Cothread creation, etc. */
81   GST_CAT_COTHREAD_SWITCH,      /* Cothread switching */
82   GST_CAT_AUTOPLUG,             /* Successful autoplug results */
83   GST_CAT_AUTOPLUG_ATTEMPT,     /* Attempted autoplug operations */
84   GST_CAT_PARENTAGE,            /* GstBin parentage issues */
85   GST_CAT_STATES,               /* State changes and such */
86   GST_CAT_PLANNING,             /* Plan generation */
87   GST_CAT_SCHEDULING,           /* Schedule construction */
88   GST_CAT_DATAFLOW,             /* Events during actual data movement */
89   GST_CAT_BUFFER,               /* Buffer creation/destruction */
90   GST_CAT_CAPS,                 /* Capabilities matching */
91   GST_CAT_CLOCK,                /* Clocking */
92   GST_CAT_ELEMENT_PADS,         /* Element pad management */
93   GST_CAT_ELEMENT_FACTORY,      /* Elementfactory stuff */
94   GST_CAT_PADS,                 /* Pad creation/linking */
95   GST_CAT_PIPELINE,             /* Pipeline stuff */
96   GST_CAT_PLUGIN_LOADING,       /* Plugin loading */
97   GST_CAT_PLUGIN_ERRORS,        /* Errors during plugin loading */
98   GST_CAT_PLUGIN_INFO,          /* Plugin state information */
99   GST_CAT_PROPERTIES,           /* Properties */
100   GST_CAT_THREAD,               /* Thread creation/management */
101   GST_CAT_TYPES,                /* Typing */
102   GST_CAT_XML,                  /* XML load/save of everything */
103   GST_CAT_NEGOTIATION,          /* Caps Negotiation stuff */
104   GST_CAT_REFCOUNTING,          /* Ref Counting stuff */
105   GST_CAT_EVENT,                /* Event system */
106   GST_CAT_PARAMS,               /* Dynamic parameters */
107
108   GST_CAT_CALL_TRACE = 30,      /* Call tracing */
109
110   GST_CAT_MAX_CATEGORY = 31
111 };
112
113 extern const gchar *_gst_category_colors[32];
114
115 extern GStaticPrivate _gst_debug_cothread_index;
116
117
118 /**********************************************************************
119  * DEBUG system
120  **********************************************************************/
121
122 /* for include files that make too much noise normally */
123 #ifdef GST_DEBUG_FORCE_DISABLE
124 #undef GST_DEBUG_ENABLED
125 #endif
126 /* for applications that really really want all the noise */
127 #ifdef GST_DEBUG_FORCE_ENABLE
128 #define GST_DEBUG_ENABLED
129 #endif
130
131 /*#ifdef GST_DEBUG_ENABLED */
132 #define GST_DEBUG_ENABLE_CATEGORIES 0xffffffff
133 /*#else */
134 /*#define GST_DEBUG_ENABLE_CATEGORIES 0x00000000 */
135 /*#endif */
136
137
138 typedef void (*GstDebugHandler) (gint category,gboolean core,
139                                  const gchar *file,const gchar *function,
140                                  gint line,const gchar *debug_string,
141                                  void *element,gchar *string);
142
143 void gst_default_debug_handler (gint category,gboolean incore,
144                                 const gchar *file, const gchar *function,
145                                 gint line,const gchar *debug_string,
146                                 void *element,gchar *string);
147
148 extern guint32 _gst_debug_categories;
149 extern GstDebugHandler _gst_debug_handler;
150
151 /* fallback, this should probably be a 'weak' symbol or something */
152 G_GNUC_UNUSED static gchar *_debug_string = NULL;
153
154
155
156 #ifdef G_HAVE_ISO_VARARGS
157
158 #ifdef GST_DEBUG_ENABLED
159 #define GST_DEBUG(cat, ...) G_STMT_START{ \
160   if ((1<<cat) & _gst_debug_categories) \
161     _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
162                        NULL,g_strdup_printf( __VA_ARGS__ )); \
163 }G_STMT_END
164
165 #define GST_DEBUG_ELEMENT(cat, element, ...) G_STMT_START{ \
166   if ((1<<cat) & _gst_debug_categories) \
167     _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
168                        element,g_strdup_printf( __VA_ARGS__ )); \
169 }G_STMT_END
170
171 #else
172 #define GST_DEBUG(cat, ...)
173 #define GST_DEBUG_ELEMENT(cat,element, ...)
174 #endif
175
176 #elif defined(G_HAVE_GNUC_VARARGS)
177
178 #ifdef GST_DEBUG_ENABLED
179 #define GST_DEBUG(cat,format,args...) G_STMT_START{ \
180   if ((1<<cat) & _gst_debug_categories) \
181     _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
182                        NULL,g_strdup_printf( format , ## args )); \
183 }G_STMT_END
184
185 #define GST_DEBUG_ELEMENT(cat,element,format,args...) G_STMT_START{ \
186   if ((1<<cat) & _gst_debug_categories) \
187     _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
188                        element,g_strdup_printf( format , ## args )); \
189 }G_STMT_END
190
191 #else
192 #define GST_DEBUG(cat,format,args...)
193 #define GST_DEBUG_ELEMENT(cat,element,format,args...)
194 #endif
195
196 #endif
197
198
199
200
201 /********** some convenience macros for debugging **********/
202 #define GST_DEBUG_PAD_NAME(pad) \
203   (GST_OBJECT_PARENT(pad) != NULL) ? \
204   GST_OBJECT_NAME (GST_OBJECT_PARENT(pad)) : \
205   "''", GST_OBJECT_NAME (pad)
206
207 #ifdef G_HAVE_ISO_VARARGS
208
209 #ifdef GST_DEBUG_COLOR
210   #define GST_DEBUG_ENTER(...) GST_DEBUG( 31 , "\033[00;37mentering\033[00m: " __VA_ARGS__ )
211   #define GST_DEBUG_LEAVE(...) GST_DEBUG( 31 , "\033[00;37mleaving\033[00m: "  __VA_ARGS__ )
212 #else
213   #define GST_DEBUG_ENTER(...) GST_DEBUG( 31 , "entering: " __VA_ARGS__ )
214   #define GST_DEBUG_LEAVE(...) GST_DEBUG( 31 , "leaving: " __VA_ARGS__ )
215 #endif
216
217 #elif defined(G_HAVE_GNUC_VARARGS)
218
219 #ifdef GST_DEBUG_COLOR
220   #define GST_DEBUG_ENTER(format, args...) GST_DEBUG( 31 , format ": \033[00;37mentering\033[00m" , ##args )
221   #define GST_DEBUG_LEAVE(format, args...) GST_DEBUG( 31 , format ": \033[00;37mleaving\033[00m" , ##args )
222 #else
223   #define GST_DEBUG_ENTER(format, args...) GST_DEBUG( 31 , format ": entering" , ##args )
224   #define GST_DEBUG_LEAVE(format, args...) GST_DEBUG( 31 , format ": leaving" , ##args )
225 #endif
226
227 #endif
228
229
230 /***** Colorized debug for thread ids *****/
231 #ifdef GST_DEBUG_COLOR
232   #define GST_DEBUG_THREAD_FORMAT "\033[00;%dm%d\033[00m"
233   #define GST_DEBUG_THREAD_ARGS(id) ( ((id) < 0) ? 37 : ((id) % 6 + 31) ), (id)
234 #else
235   #define GST_DEBUG_THREAD_FORMAT "%d"
236   #define GST_DEBUG_THREAD_ARGS(id) (id)
237 #endif
238
239
240
241 /**********************************************************************
242  * The following is a DEBUG_ENTER implementation that will wrap the
243  * function it sits at the head of.  It removes the need for a
244  * DEBUG_LEAVE call.  However, it segfaults whenever it gets anywhere
245  * near cothreads.  We will not use it for the moment.
246  *
247 typedef void (*_debug_function_f)();
248 G_GNUC_UNUSED static gchar *_debug_string_pointer = NULL;
249 G_GNUC_UNUSED static GModule *_debug_self_module = NULL;
250
251 #ifdef G_HAVE_ISO_VARARGS
252
253 #define _DEBUG_ENTER_BUILTIN(...)                                                       \
254   static int _debug_in_wrapper = 0;                                                     \
255   gchar *_debug_string = ({                                                             \
256     if (!_debug_in_wrapper) {                                                           \
257       void *_return_value;                                                              \
258       gchar *_debug_string;                                                             \
259       _debug_function_f function;                                                       \
260       void *_function_args = __builtin_apply_args();                                    \
261       _debug_in_wrapper = 1;                                                            \
262       _debug_string = g_strdup_printf(GST_DEBUG_PREFIX(""));                            \
263       _debug_string_pointer = _debug_string;                                            \
264       fprintf(stderr,"%s: entered " FUNCTION, _debug_string);                           \ 
265       fprintf(stderr, __VA_ARGS__ );                                                    \
266       fprintf(stderr,"\n");                                                             \
267       if (_debug_self_module == NULL) _debug_self_module = g_module_open(NULL,0);       \
268       g_module_symbol(_debug_self_module,FUNCTION,(gpointer *)&function);               \
269       _return_value = __builtin_apply(function,_function_args,64);                      \
270       fprintf(stderr,"%s: left " FUNCTION, _debug_string);                              \
271       fprintf(stderr, __VA_ARGS__);                                                     \
272       fprintf(stderr,"\n");                                                             \
273       g_free(_debug_string);                                                            \
274       __builtin_return(_return_value);                                                  \
275     } else {                                                                            \
276       _debug_in_wrapper = 0;                                                            \
277     }                                                                                   \
278     _debug_string_pointer;                                                              \
279   });
280
281 #elif defined(G_HAVE_GNUC_VARARGS)
282
283 #define _DEBUG_ENTER_BUILTIN(format,args...)                                            \
284   static int _debug_in_wrapper = 0;                                                     \
285   gchar *_debug_string = ({                                                             \
286     if (!_debug_in_wrapper) {                                                           \
287       void *_return_value;                                                              \
288       gchar *_debug_string;                                                             \
289       _debug_function_f function;                                                       \
290       void *_function_args = __builtin_apply_args();                                    \
291       _debug_in_wrapper = 1;                                                            \
292       _debug_string = g_strdup_printf(GST_DEBUG_PREFIX(""));                            \
293       _debug_string_pointer = _debug_string;                                            \
294       fprintf(stderr,"%s: entered " FUNCTION format "\n" , _debug_string , ## args );   \
295       if (_debug_self_module == NULL) _debug_self_module = g_module_open(NULL,0);       \
296       g_module_symbol(_debug_self_module,FUNCTION,(gpointer *)&function);               \
297       _return_value = __builtin_apply(function,_function_args,64);                      \
298       fprintf(stderr,"%s: left " FUNCTION format "\n" , _debug_string , ## args ); \
299       g_free(_debug_string);                                                            \
300       __builtin_return(_return_value);                                                  \
301     } else {                                                                            \
302       _debug_in_wrapper = 0;                                                            \
303     }                                                                                   \
304     _debug_string_pointer;                                                              \
305   });
306
307 #endif
308
309 * WARNING: there's a gcc CPP bug lurking in here.  The extra space before the ##args    *
310  * somehow make the preprocessor leave the _debug_string. If it's removed, the          *
311  * _debug_string somehow gets stripped along with the ##args, and that's all she wrote. *
312
313 #ifdef G_HAVE_ISO_VARARGS
314
315 #define _DEBUG_BUILTIN(...)                                     \
316   if (_debug_string != (void *)-1) {                            \
317     if (_debug_string) {                                        \
318       fprintf(stderr, "%s: " _debug_string);                    \
319       fprintf(stderr, __VA_ARGS__);                             \
320     } else {                                                    \
321       fprintf(stderr,GST_DEBUG_PREFIX(": " __VA_ARGS__));       \
322     }                                                           \
323   }
324
325 #elif defined(G_HAVE_GNUC_VARARGS)
326
327 #define _DEBUG_BUILTIN(format,args...)                          \
328   if (_debug_string != (void *)-1) {                            \
329     if (_debug_string)                                          \
330       fprintf(stderr,"%s: " format , _debug_string , ## args);  \
331     else                                                        \
332       fprintf(stderr,GST_DEBUG_PREFIX(": " format , ## args));  \
333   }
334
335 #endif
336
337 */
338
339
340
341 /**********************************************************************
342  * INFO system
343  **********************************************************************/
344
345 typedef void (*GstInfoHandler) (gint category,gboolean incore,
346                                 const gchar *file,const gchar *function,
347                                 gint line,const gchar *debug_string,
348                                 void *element,gchar *string);
349
350 void gst_default_info_handler (gint category,gboolean incore,
351                                const gchar *file,const gchar *function,
352                                gint line,const gchar *debug_string,
353                                void *element,gchar *string);
354
355 void * _gst_debug_register_funcptr (void *ptr, gchar *ptrname);
356
357 extern GstInfoHandler _gst_info_handler;
358 extern guint32 _gst_info_categories;
359
360 /* for include files that make too much noise normally */
361 #ifdef GST_INFO_FORCE_DISABLE
362 #undef GST_INFO_ENABLED
363 #endif
364 /* for applications that really really want all the noise */
365 #ifdef GST_INFO_FORCE_ENABLE
366 #define GST_INFO_ENABLED
367 #endif
368
369 #ifdef G_HAVE_ISO_VARARGS
370
371 #ifdef GST_INFO_ENABLED
372 #define GST_INFO(cat,...) G_STMT_START{ \
373   if ((1<<cat) & _gst_info_categories) \
374     _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
375                       NULL,g_strdup_printf( __VA_ARGS__ )); \
376 }G_STMT_END
377
378 #define GST_INFO_ELEMENT(cat,element,...) G_STMT_START{ \
379   if ((1<<cat) & _gst_info_categories) \
380     _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
381                       element,g_strdup_printf( __VA_ARGS__ )); \
382 }G_STMT_END
383
384 #else
385 #define GST_INFO(cat,...) 
386 #define GST_INFO_ELEMENT(cat,element,...)
387 #endif
388
389 #elif defined(G_HAVE_GNUC_VARARGS)
390
391 #ifdef GST_INFO_ENABLED
392 #define GST_INFO(cat,format,args...) G_STMT_START{ \
393   if ((1<<cat) & _gst_info_categories) \
394     _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
395                       NULL,g_strdup_printf( format , ## args )); \
396 }G_STMT_END
397
398 #define GST_INFO_ELEMENT(cat,element,format,args...) G_STMT_START{ \
399   if ((1<<cat) & _gst_info_categories) \
400     _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,FUNCTION,__LINE__,_debug_string, \
401                       element,g_strdup_printf( format , ## args )); \
402 }G_STMT_END
403
404 #else
405 #define GST_INFO(cat,format,args...) 
406 #define GST_INFO_ELEMENT(cat,element,format,args...)
407 #endif
408
409 #endif
410
411
412 void            gst_info_set_categories         (guint32 categories);
413 guint32         gst_info_get_categories         (void);
414 void            gst_info_enable_category        (gint category);
415 void            gst_info_disable_category       (gint category);
416
417 void            gst_debug_set_categories        (guint32 categories);
418 guint32         gst_debug_get_categories        (void);
419 void            gst_debug_enable_category       (gint category);
420 void            gst_debug_disable_category      (gint category);
421
422
423
424
425 /**********************************************************************
426  * ERROR system
427  **********************************************************************/
428
429 typedef void (*GstErrorHandler) (gchar *file,gchar *function,
430                                  gint line,gchar *debug_string,
431                                  void *element,void *object,gchar *string);
432
433 void gst_default_error_handler (gchar *file,gchar *function,
434                                 gint line,gchar *debug_string,
435                                 void *element,void *object,gchar *string);
436
437 extern GstErrorHandler _gst_error_handler;
438
439 #ifdef G_HAVE_ISO_VARARGS
440
441 #define GST_ERROR(element,...) \
442   _gst_error_handler(__FILE__,FUNCTION,__LINE__,_debug_string, \
443                      element,NULL,g_strdup_printf( __VA_ARGS__ ))
444
445 #define GST_ERROR_OBJECT(element,object,...) \
446   _gst_error_handler(__FILE__,FUNCTION,__LINE__,_debug_string, \
447                      element,object,g_strdup_printf( __VA_ARGS__ ))
448
449 #elif defined(G_HAVE_GNUC_VARARGS)
450
451 #define GST_ERROR(element,format,args...) \
452   _gst_error_handler(__FILE__,FUNCTION,__LINE__,_debug_string, \
453                      element,NULL,g_strdup_printf( format , ## args ))
454
455 #define GST_ERROR_OBJECT(element,object,format,args...) \
456   _gst_error_handler(__FILE__,FUNCTION,__LINE__,_debug_string, \
457                      element,object,g_strdup_printf( format , ## args ))
458
459 #endif
460
461
462
463
464 /********** function pointer stuff **********/
465 extern GHashTable *__gst_function_pointers;
466
467 #if GST_DEBUG_ENABLED
468 #define GST_DEBUG_FUNCPTR(ptr) _gst_debug_register_funcptr((void *)(ptr), #ptr)
469 #define GST_DEBUG_FUNCPTR_NAME(ptr) _gst_debug_nameof_funcptr((void *)ptr)
470 #else
471 #define GST_DEBUG_FUNCPTR(ptr) (ptr)
472 #define GST_DEBUG_FUNCPTR_NAME(ptr) ""
473 #endif /* GST_DEBUG_ENABLED */
474
475 gchar *_gst_debug_nameof_funcptr (void *ptr);
476
477 void gst_debug_print_stack_trace (void);
478
479 #endif /* __GSTINFO_H__ */