]> git.0d.be Git - empathy.git/blob - libempathy/empathy-debug.c
disconnect from invalidated signal before unreferencing connections
[empathy.git] / libempathy / empathy-debug.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007 Collabora Ltd.
4  * Copyright (C) 2007 Nokia Corporation
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20
21 #include "config.h"
22
23 #include <errno.h>
24 #include <fcntl.h>
25 #include <stdarg.h>
26 #include <sys/stat.h>
27 #include <unistd.h>
28
29 #include <glib.h>
30 #include <glib/gstdio.h>
31
32 #include <telepathy-glib/debug.h>
33
34 #include "empathy-debug.h"
35
36 #ifdef ENABLE_DEBUG
37
38 static EmpathyDebugFlags flags = 0;
39
40 static GDebugKey keys[] = {
41   { "Tp", EMPATHY_DEBUG_TP },
42   { "Chat", EMPATHY_DEBUG_CHAT },
43   { "Contact", EMPATHY_DEBUG_CONTACT },
44   { "Account", EMPATHY_DEBUG_ACCOUNT },
45   { "Irc", EMPATHY_DEBUG_IRC },
46   { "Dispatcher", EMPATHY_DEBUG_DISPATCHER },
47   { "Ft", EMPATHY_DEBUG_FT },
48   { "Location", EMPATHY_DEBUG_LOCATION },
49   { "Other", EMPATHY_DEBUG_OTHER },
50   { 0, }
51 };
52
53 static void
54 debug_set_flags (EmpathyDebugFlags new_flags)
55 {
56   flags |= new_flags;
57 }
58
59 void
60 empathy_debug_set_flags (const gchar *flags_string)
61 {
62   guint nkeys;
63
64   for (nkeys = 0; keys[nkeys].value; nkeys++);
65
66   tp_debug_set_flags (flags_string);
67
68   if (flags_string)
69       debug_set_flags (g_parse_debug_string (flags_string, keys, nkeys));
70 }
71
72 gboolean
73 empathy_debug_flag_is_set (EmpathyDebugFlags flag)
74 {
75   return (flag & flags) != 0;
76 }
77
78 void
79 empathy_debug (EmpathyDebugFlags flag,
80                const gchar *format,
81                ...)
82 {
83   if (flag & flags)
84     {
85       va_list args;
86       va_start (args, format);
87       g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, args);
88       va_end (args);
89     }
90 }
91
92 #else
93
94 gboolean
95 empathy_debug_flag_is_set (EmpathyDebugFlags flag)
96 {
97   return FALSE;
98 }
99
100 void
101 empathy_debug (EmpathyDebugFlags flag, const gchar *format, ...)
102 {
103 }
104
105 void
106 empathy_debug_set_flags (const gchar *flags_string)
107 {
108 }
109
110 #endif /* ENABLE_DEBUG */
111