1 /*<private_header>*/
2 
3 #ifndef __DEBUG_H__
4 #define __DEBUG_H__
5 
6 #include "config.h"
7 
8 #include <glib.h>
9 
10 #include <telepathy-glib/debug.h>
11 
12 G_BEGIN_DECLS
13 
14 /* Please keep this enum in sync with #keys, the section gtkdoc,
15  * and #key_to_domain, in debug.c */
16 typedef enum
17 {
18   TP_DEBUG_MISC          = 1 << 0,
19   TP_DEBUG_GROUPS        = 1 << 1,
20   TP_DEBUG_PROPERTIES    = 1 << 2,
21   TP_DEBUG_IM            = 1 << 3,
22   TP_DEBUG_CONNECTION    = 1 << 4,
23   TP_DEBUG_PARAMS        = 1 << 5,
24   TP_DEBUG_PRESENCE      = 1 << 6,
25   TP_DEBUG_MANAGER       = 1 << 7,
26   TP_DEBUG_CHANNEL       = 1 << 8,
27   TP_DEBUG_PROXY         = 1 << 9,
28   TP_DEBUG_HANDLES       = 1 << 10,
29   TP_DEBUG_CONTACTS      = 1 << 11,
30   TP_DEBUG_ACCOUNTS      = 1 << 12,
31   TP_DEBUG_DISPATCHER    = 1 << 13,
32   TP_DEBUG_CLIENT        = 1 << 14,
33   TP_DEBUG_CONTACT_LISTS = 1 << 15,
34   TP_DEBUG_SASL          = 1 << 16,
35   TP_DEBUG_ROOM_CONFIG   = 1 << 17,
36   TP_DEBUG_CALL          = 1 << 18,
37   /* Quis custodiet ipsos custodes? */
38   TP_DEBUG_DEBUGGER      = 1 << 19,
39   TP_DEBUG_TLS           = 1 << 20
40 } TpDebugFlags;
41 
42 gboolean _tp_debug_flag_is_set (TpDebugFlags flag);
43 void _tp_debug_set_flags (TpDebugFlags flags);
44 void _tp_log (GLogLevelFlags level, TpDebugFlags flag, const gchar *format, ...)
45     G_GNUC_PRINTF (3, 4);
46 gboolean _tp_debug_is_persistent (void);
47 
48 #define _TP_DEBUG_IS_PERSISTENT (_tp_debug_is_persistent ())
49 
50 G_END_DECLS
51 
52 #endif /* __DEBUG_H__ */
53 
54 /* ------------------------------------ */
55 
56 /* Below this point is outside the __DEBUG_H__ guard - so it can take effect
57  * more than once. So you can do:
58  *
59  * #define DEBUG_FLAG TP_DEBUG_ONE_THING
60  * #include "telepathy-glib/debug-internal.h"
61  * ...
62  * DEBUG ("if we're debugging one thing");
63  * ...
64  * #undef DEBUG_FLAG
65  * #define DEBUG_FLAG TP_DEBUG_OTHER_THING
66  * #include "telepathy-glib/debug-internal.h"
67  * ...
68  * DEBUG ("if we're debugging the other thing");
69  * ...
70  */
71 
72 #ifdef DEBUG_FLAG
73 
74 #undef ERROR
75 #define ERROR(format, ...) \
76   do \
77     { \
78       _tp_log (G_LOG_LEVEL_ERROR, DEBUG_FLAG, "%s: " format, \
79           G_STRFUNC, ##__VA_ARGS__); \
80       g_assert_not_reached (); \
81     } \
82   while (0)
83 
84 #undef CRITICAL
85 #define CRITICAL(format, ...) \
86   _tp_log (G_LOG_LEVEL_CRITICAL, DEBUG_FLAG, "%s: " format, \
87       G_STRFUNC, ##__VA_ARGS__)
88 #undef WARNING
89 #define WARNING(format, ...) \
90   _tp_log (G_LOG_LEVEL_WARNING, DEBUG_FLAG, "%s: " format, \
91       G_STRFUNC, ##__VA_ARGS__)
92 #undef MESSAGE
93 #define MESSAGE(format, ...) \
94   _tp_log (G_LOG_LEVEL_MESSAGE, DEBUG_FLAG, "%s: " format, \
95       G_STRFUNC, ##__VA_ARGS__)
96 #undef INFO
97 #define INFO(format, ...) \
98   _tp_log (G_LOG_LEVEL_INFO, DEBUG_FLAG, "%s: " format, \
99       G_STRFUNC, ##__VA_ARGS__)
100 
101 #undef DEBUG
102 #undef DEBUGGING
103 
104 #ifdef ENABLE_DEBUG
105 #   define DEBUG(format, ...) \
106       _tp_log (G_LOG_LEVEL_DEBUG, DEBUG_FLAG, "%s: " format, \
107           G_STRFUNC, ##__VA_ARGS__)
108 #   define DEBUGGING _tp_debug_flag_is_set (DEBUG_FLAG)
109 #else /* !defined (ENABLE_DEBUG) */
110 #   ifndef DEBUG_STUB_DEFINED
111 static inline void
112 DEBUG (
113     const gchar *format,
114     ...)
115 {
116 }
117 #   define DEBUG_STUB_DEFINED 1
118 #   endif // ifndef DEBUG_STUB_DEFINED
119 
120 #   define DEBUGGING 0
121 #endif /* !defined (ENABLE_DEBUG) */
122 
123 #endif /* defined (DEBUG_FLAG) */
124