1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
3 * Copyright (C) 2007 Collabora Ltd.
4 * Copyright (C) 2007 Nokia Corporation
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.
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.
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
22 #include "tpaw-debug.h"
26 static TpawDebugFlags flags = 0;
28 static GDebugKey keys[] = {
29 { "Tp", TPAW_DEBUG_TP },
30 { "Chat", TPAW_DEBUG_CHAT },
31 { "Contact", TPAW_DEBUG_CONTACT },
32 { "Account", TPAW_DEBUG_ACCOUNT },
33 { "Irc", TPAW_DEBUG_IRC },
34 { "Dispatcher", TPAW_DEBUG_DISPATCHER },
35 { "Ft", TPAW_DEBUG_FT },
36 { "Location", TPAW_DEBUG_LOCATION },
37 { "Other", TPAW_DEBUG_OTHER },
38 { "Connectivity", TPAW_DEBUG_CONNECTIVITY },
39 { "ImportMc4Accounts", TPAW_DEBUG_IMPORT_MC4_ACCOUNTS },
40 { "Tests", TPAW_DEBUG_TESTS },
41 { "Voip", TPAW_DEBUG_VOIP },
42 { "Tls", TPAW_DEBUG_TLS },
43 { "Sasl", TPAW_DEBUG_SASL },
44 { "Camera", TPAW_DEBUG_CAMERA },
49 debug_set_flags (TpawDebugFlags new_flags)
55 tpaw_debug_set_flags (const gchar *flags_string)
59 for (nkeys = 0; keys[nkeys].value; nkeys++);
62 debug_set_flags (g_parse_debug_string (flags_string, keys, nkeys));
66 tpaw_debug_flag_is_set (TpawDebugFlags flag)
68 return (flag & flags) != 0;
71 GHashTable *flag_to_keys = NULL;
74 debug_flag_to_key (TpawDebugFlags flag)
76 if (flag_to_keys == NULL)
80 flag_to_keys = g_hash_table_new_full (g_direct_hash, g_direct_equal,
83 for (i = 0; keys[i].value; i++)
85 GDebugKey key = (GDebugKey) keys[i];
86 g_hash_table_insert (flag_to_keys, GUINT_TO_POINTER (key.value),
91 return g_hash_table_lookup (flag_to_keys, GUINT_TO_POINTER (flag));
95 tpaw_debug_free (void)
97 if (flag_to_keys == NULL)
100 g_hash_table_unref (flag_to_keys);
105 log_to_debug_sender (TpawDebugFlags flag,
106 const gchar *message)
108 TpDebugSender *sender;
112 sender = tp_debug_sender_dup ();
114 g_get_current_time (&now);
116 domain = g_strdup_printf ("%s/%s", G_LOG_DOMAIN, debug_flag_to_key (flag));
118 tp_debug_sender_add_message (sender, &now, domain, G_LOG_LEVEL_DEBUG, message);
121 g_object_unref (sender);
125 tpaw_debug (TpawDebugFlags flag,
132 va_start (args, format);
133 message = g_strdup_vprintf (format, args);
136 log_to_debug_sender (flag, message);
139 g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s", message);
147 tpaw_debug_flag_is_set (TpawDebugFlags flag)
153 tpaw_debug (TpawDebugFlags flag, const gchar *format, ...)
158 tpaw_debug_set_flags (const gchar *flags_string)
162 #endif /* ENABLE_DEBUG */