Initial Import
[profile/ivi/json-glib.git] / json-glib / json-debug.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include "json-debug.h"
6
7 static unsigned int json_debug_flags     = 0;
8 static gboolean     json_debug_flags_set = FALSE;
9
10 #ifdef JSON_ENABLE_DEBUG
11 static const GDebugKey json_debug_keys[] = {
12   { "parser", JSON_DEBUG_PARSER },
13   { "gobject", JSON_DEBUG_GOBJECT },
14   { "path", JSON_DEBUG_PATH }
15 };
16 #endif /* JSON_ENABLE_DEBUG */
17
18 JsonDebugFlags
19 _json_get_debug_flags (void)
20 {
21 #ifdef JSON_ENABLE_DEBUG
22   const gchar *env_str;
23
24   if (json_debug_flags_set)
25     return json_debug_flags;
26
27   env_str = g_getenv ("JSON_DEBUG");
28   if (env_str != NULL && *env_str != '\0')
29     {
30       json_debug_flags |= g_parse_debug_string (env_str,
31                                                 json_debug_keys,
32                                                 G_N_ELEMENTS (json_debug_keys));
33     }
34
35   json_debug_flags_set = TRUE;
36 #endif /* JSON_ENABLE_DEBUG */
37
38   return json_debug_flags;
39 }