|
Packit |
79f644 |
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
|
|
Packit |
79f644 |
/*
|
|
Packit |
79f644 |
* Copyright (C) 2007 Collabora Ltd.
|
|
Packit |
79f644 |
* Copyright (C) 2007 Nokia Corporation
|
|
Packit |
79f644 |
*
|
|
Packit |
79f644 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
79f644 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
79f644 |
* License as published by the Free Software Foundation; either
|
|
Packit |
79f644 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
79f644 |
*
|
|
Packit |
79f644 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
79f644 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
79f644 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
79f644 |
* Lesser General Public License for more details.
|
|
Packit |
79f644 |
*
|
|
Packit |
79f644 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
79f644 |
* License along with this library; if not, write to the Free Software
|
|
Packit |
79f644 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit |
79f644 |
*/
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#include "config.h"
|
|
Packit |
79f644 |
#include "tpaw-debug.h"
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#ifdef ENABLE_DEBUG
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static TpawDebugFlags flags = 0;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static GDebugKey keys[] = {
|
|
Packit |
79f644 |
{ "Account", TPAW_DEBUG_ACCOUNT },
|
|
Packit |
79f644 |
{ "Irc", TPAW_DEBUG_IRC },
|
|
Packit |
79f644 |
{ "Other", TPAW_DEBUG_OTHER },
|
|
Packit |
79f644 |
{ 0, }
|
|
Packit |
79f644 |
};
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
debug_set_flags (TpawDebugFlags new_flags)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
flags |= new_flags;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
void
|
|
Packit |
79f644 |
tpaw_debug_set_flags (const gchar *flags_string)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
guint nkeys;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
for (nkeys = 0; keys[nkeys].value; nkeys++);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (flags_string)
|
|
Packit |
79f644 |
debug_set_flags (g_parse_debug_string (flags_string, keys, nkeys));
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
gboolean
|
|
Packit |
79f644 |
tpaw_debug_flag_is_set (TpawDebugFlags flag)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
return (flag & flags) != 0;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static GHashTable *flag_to_keys = NULL;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static const gchar *
|
|
Packit |
79f644 |
debug_flag_to_key (TpawDebugFlags flag)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
if (flag_to_keys == NULL)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
guint i;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
flag_to_keys = g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
|
Packit |
79f644 |
NULL, g_free);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
for (i = 0; keys[i].value; i++)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
GDebugKey key = (GDebugKey) keys[i];
|
|
Packit |
79f644 |
g_hash_table_insert (flag_to_keys, GUINT_TO_POINTER (key.value),
|
|
Packit |
79f644 |
g_strdup (key.key));
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
return g_hash_table_lookup (flag_to_keys, GUINT_TO_POINTER (flag));
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
void
|
|
Packit |
79f644 |
tpaw_debug_free (void)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
if (flag_to_keys == NULL)
|
|
Packit |
79f644 |
return;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_hash_table_unref (flag_to_keys);
|
|
Packit |
79f644 |
flag_to_keys = NULL;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
log_to_debug_sender (TpawDebugFlags flag,
|
|
Packit |
79f644 |
const gchar *message)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
TpDebugSender *sender;
|
|
Packit |
79f644 |
gchar *domain;
|
|
Packit |
79f644 |
GTimeVal now;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
sender = tp_debug_sender_dup ();
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_get_current_time (&now;;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
domain = g_strdup_printf ("%s/%s", G_LOG_DOMAIN, debug_flag_to_key (flag));
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
tp_debug_sender_add_message (sender, &now, domain, G_LOG_LEVEL_DEBUG, message);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_free (domain);
|
|
Packit |
79f644 |
g_object_unref (sender);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
void
|
|
Packit |
79f644 |
tpaw_debug (TpawDebugFlags flag,
|
|
Packit |
79f644 |
const gchar *format,
|
|
Packit |
79f644 |
...)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
gchar *message;
|
|
Packit |
79f644 |
va_list args;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
va_start (args, format);
|
|
Packit |
79f644 |
message = g_strdup_vprintf (format, args);
|
|
Packit |
79f644 |
va_end (args);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
log_to_debug_sender (flag, message);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
if (flag & flags)
|
|
Packit |
79f644 |
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s", message);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_free (message);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#else
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
gboolean
|
|
Packit |
79f644 |
tpaw_debug_flag_is_set (TpawDebugFlags flag)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
return FALSE;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
void
|
|
Packit |
79f644 |
tpaw_debug (TpawDebugFlags flag, const gchar *format, ...)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
void
|
|
Packit |
79f644 |
tpaw_debug_set_flags (const gchar *flags_string)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#endif /* ENABLE_DEBUG */
|