Mercurial > projects > xinhibit-applet
annotate xia-debug.c @ 9:d83540fd999c version-2
Release version 2
author | Guido Berhoerster <guido+xinhibit-applet@berhoerster.name> |
---|---|
date | Thu, 08 Aug 2013 16:24:35 +0200 |
parents | a47449b807b2 |
children |
rev | line source |
---|---|
0
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
1 /* |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
2 * Copyright (C) 2013 Guido Berhoerster <guido+xinhibit-applet@berhoerster.name> |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
3 * |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
4 * Permission is hereby granted, free of charge, to any person obtaining |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
5 * a copy of this software and associated documentation files (the |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
6 * "Software"), to deal in the Software without restriction, including |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
7 * without limitation the rights to use, copy, modify, merge, publish, |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
8 * distribute, sublicense, and/or sell copies of the Software, and to |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
9 * permit persons to whom the Software is furnished to do so, subject to |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
10 * the following conditions: |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
11 * |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
12 * The above copyright notice and this permission notice shall be included |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
13 * in all copies or substantial portions of the Software. |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
14 * |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
22 */ |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
23 |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
24 #include <string.h> |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
25 #include <stdarg.h> |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
26 #include <glib.h> |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
27 |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
28 #include "xia-debug.h" |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
29 |
8
a47449b807b2
Remove unused function
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
0
diff
changeset
|
30 #if !GLIB_CHECK_VERSION(2, 32, 0) |
0
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
31 static void |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
32 dummy_log_handler(const gchar *log_domain, GLogLevelFlags log_level, |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
33 const gchar *message, gpointer data) |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
34 { |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
35 /* Swallow all messages */ |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
36 } |
8
a47449b807b2
Remove unused function
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
0
diff
changeset
|
37 #endif /* !GLIB_CHECK_VERSION (2,32,0) */ |
0
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
38 |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
39 void |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
40 xia_debug_init(gboolean debug_mode) |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
41 { |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
42 /* |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
43 * glib >= 2.32 only shows debug messages if G_MESSAGES_DEBUG contains |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
44 * the log domain or "all", earlier glib version always show debugging |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
45 * output |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
46 */ |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
47 #if GLIB_CHECK_VERSION(2, 32, 0) |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
48 const gchar *debug_env; |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
49 gchar *debug_env_new; |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
50 |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
51 if (debug_mode) { |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
52 debug_env = g_getenv("G_MESSAGES_DEBUG"); |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
53 |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
54 if (debug_env == NULL) { |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
55 g_setenv("G_MESSAGES_DEBUG", G_LOG_DOMAIN, TRUE); |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
56 } else if (strstr(debug_env, G_LOG_DOMAIN) == NULL) { |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
57 debug_env_new = g_strdup_printf("%s %s", debug_env, |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
58 G_LOG_DOMAIN); |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
59 g_setenv("G_MESSAGES_DEBUG", debug_env_new, TRUE); |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
60 g_free(debug_env_new); |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
61 } |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
62 } |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
63 #else |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
64 if (!debug_mode) { |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
65 g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
66 dummy_log_handler, NULL); |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
67 } |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
68 #endif /* GLIB_CHECK_VERSION (2,32,0) */ |
9a16bf50daba
Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff
changeset
|
69 } |