summaryrefslogtreecommitdiff
path: root/modem/debug.c
blob: de19b77509e731ffa60e631b8376b597be34f8df (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
131
132
133
/*
 * modem/debug.c - Debugging facilities
 *
 * Copyright (C) 2008 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 <stdarg.h>
#include <glib.h>

#include "modem/debug.h"

static ModemLogFlags modem_debug_flags = 0;

static const GDebugKey modem_debug_keys[] = {
  { "dbus", MODEM_LOG_DBUS },
  { "modem", MODEM_LOG_MODEM },
  { "call",  MODEM_LOG_CALL },
  { "sms", MODEM_LOG_SMS },
  { "sim", MODEM_LOG_SIM },
  { "audio", MODEM_LOG_AUDIO },
  { "radio", MODEM_LOG_RADIO },
  { "settings", MODEM_LOG_SETTINGS },
  { "gprs", MODEM_LOG_GPRS },
  { "cdma", MODEM_LOG_CDMA },
};

void
modem_debug_set_flags_from_env(void)
{
  const char *flags_string;
  int flags = 0;

  flags_string = g_getenv("MODEM_DEBUG");

  if (flags_string) {
    flags |= g_parse_debug_string(flags_string,
             modem_debug_keys,
             G_N_ELEMENTS(modem_debug_keys));
  }

  flags_string = g_getenv("CALL_DEBUG");

  if (flags_string) {
    flags |= g_parse_debug_string(flags_string,
             modem_debug_keys,
             G_N_ELEMENTS(modem_debug_keys));
  }

  if (flags)
    modem_debug_set_flags(flags);
}

void
modem_debug_set_flags(int new_flags)
{
  modem_debug_flags |= new_flags;
}

gboolean
modem_debug_flag_is_set(int flag)
{
  return (modem_debug_flags & flag) != 0;
}

char const *
modem_debug_domain(int flag)
{
  if (flag & MODEM_LOG_CDMA)
    return "modem-cdma";
  if (flag & MODEM_LOG_CALL)
    return "modem-call";
  if (flag & MODEM_LOG_SMS)
    return "modem-sms";
  if (flag & MODEM_LOG_SIM)
    return "modem-sim";
  if (flag & MODEM_LOG_AUDIO)
    return "modem-audio";
  if (flag & MODEM_LOG_RADIO)
    return "modem-radio";
  if (flag & MODEM_LOG_SETTINGS)
    return "modem-settings";
  if (flag & MODEM_LOG_GPRS)
    return "modem-gprs";

  return "modem";
}


void
modem_debug(int flag, const char *format, ...)
{
  if (flag & modem_debug_flags) {
    va_list args;
    va_start(args, format);
    g_logv(modem_debug_domain(flag), G_LOG_LEVEL_DEBUG, format, args);
    va_end(args);
  }
}

void
modem_message(int flag, const char *format, ...)
{
  va_list args;
  va_start(args, format);
  g_logv(modem_debug_domain(flag), G_LOG_LEVEL_MESSAGE, format, args);
  va_end(args);
}

void
modem_critical(int flag, const char *format, ...)
{
  va_list args;
  va_start(args, format);
  g_logv(modem_debug_domain(flag), G_LOG_LEVEL_WARNING, format, args);
  va_end(args);
}