summaryrefslogtreecommitdiff
path: root/src/ring-debug.c
blob: fc8a06ecb56259ab0b9ff5b47397c6eaabd85719 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
 * ring-debug.c - Debugging utilities
 *
 * Copyright (C) 2007-2010 Nokia Corporation
 *   @author Pekka Pessi <first.surname@nokia.com>
 *
 * This work is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This work is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this work; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "config.h"

#include "ring-debug.h"

#ifdef ENABLE_DEBUG

#include <stdarg.h>

#include <glib.h>

#include <telepathy-glib/debug.h>

void modem_debug_set_flags(int flags);
void modem_debug_set_flags_from_env(void);

static RingDebugFlags ring_debug_flags = 0;

static const GDebugKey ring_debug_keys[] = {
  { "media-channel", RING_DEBUG_MEDIA },
  { "call",          RING_DEBUG_MEDIA },
  { "media",         RING_DEBUG_MEDIA },
  { "connection",    RING_DEBUG_CONNECTION },
  { "text-channel",  RING_DEBUG_SMS },
  { "text",          RING_DEBUG_SMS },
  { "sms",           RING_DEBUG_SMS },
};

void
ring_debug_set_flags (RingDebugFlags new_flags)
{
  ring_debug_flags |= new_flags;
}

gboolean
ring_debug_flag_is_set (RingDebugFlags flag)
{
  return (flag & ring_debug_flags) != 0;
}

void
ring_debug (RingDebugFlags flag,
  const char *format,
  ...)
{
  if (flag & ring_debug_flags)
  {
    va_list args;
    va_start (args, format);
    g_logv ("Ring", G_LOG_LEVEL_DEBUG, format, args);
    va_end (args);
  }
}

#endif /* ENABLE_DEBUG */

void
ring_message (const char *format, ...)
{
  va_list ap;
  va_start (ap, format);
  g_logv ("Ring", G_LOG_LEVEL_MESSAGE, format, ap);
  va_end (ap);
}

void
ring_warning (const char *format, ...)
{
  va_list ap;
  va_start (ap, format);
  g_logv ("Ring", G_LOG_LEVEL_WARNING, format, ap);
  va_end (ap);
}

void
ring_critical (const char *format, ...)
{
  va_list ap;
  va_start (ap, format);
  g_logv ("Ring", G_LOG_LEVEL_CRITICAL, format, ap);
  va_end (ap);
}

void
ring_debug_set_flags_from_env (void)
{
  tp_debug_divert_messages(g_getenv("RING_LOGFILE"));

  const char *flags_string;

  flags_string = g_getenv("RING_DEBUG");

#if ENABLE_DEBUG
  if (flags_string)
  {
    tp_debug_set_flags (flags_string);

    ring_debug_set_flags (g_parse_debug_string (flags_string,
        ring_debug_keys,
        G_N_ELEMENTS(ring_debug_keys)));
  }
#endif

  if (flags_string && g_str_equal(flags_string, "all"))
    modem_debug_set_flags(~0);
  else
    modem_debug_set_flags_from_env();

  tp_debug_set_persistent(g_getenv("RING_PERSIST") != NULL);
}