Initial Import
[profile/ivi/json-glib.git] / json-glib / json-debug.h
1 #ifndef __JSON_DEBUG_H__
2 #define __JSON_DEBUG_H__
3
4 #include <glib.h>
5
6 G_BEGIN_DECLS
7
8 typedef enum {
9   JSON_DEBUG_PARSER  = 1 << 0,
10   JSON_DEBUG_GOBJECT = 1 << 1,
11   JSON_DEBUG_PATH    = 1 << 2
12 } JsonDebugFlags;
13
14 #ifdef JSON_ENABLE_DEBUG
15
16 # ifdef __GNUC__
17
18 # define JSON_NOTE(type,x,a...)                 G_STMT_START {  \
19         if (_json_get_debug_flags () & JSON_DEBUG_##type) {     \
20           g_message ("[" #type "] " G_STRLOC ": " x, ##a);      \
21         }                                       } G_STMT_END
22
23 # else
24 /* Try the C99 version; unfortunately, this does not allow us to pass
25  * empty arguments to the macro, which means we have to
26  * do an intemediate printf.
27  */
28 # define JSON_NOTE(type,...)                    G_STMT_START {  \
29         if (_json_get_debug_flags () & JSON_DEBUG_##type) {     \
30             gchar * _fmt = g_strdup_printf (__VA_ARGS__);       \
31             g_message ("[" #type "] " G_STRLOC ": %s",_fmt);    \
32             g_free (_fmt);                                      \
33         }                                       } G_STMT_END
34
35 # endif /* __GNUC__ */
36
37 #else
38
39 #define JSON_NOTE(type,...)         G_STMT_START { } G_STMT_END
40
41 #endif /* JSON_ENABLE_DEBUG */
42
43 JsonDebugFlags _json_get_debug_flags (void);
44
45 G_END_DECLS
46
47 #endif /* __JSON_DEBUG_H__ */