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
|
/*
* 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 ModemDebugFlags modem_debug_flags = 0;
static const GDebugKey modem_debug_keys[] = {
{ "dbus", MODEM_SERVICE_DBUS },
{ "call", MODEM_SERVICE_CALL },
{ "tones", MODEM_SERVICE_TONES },
{ "sms", MODEM_SERVICE_SMS },
{ "sim", MODEM_SERVICE_SIM },
{ "modem", MODEM_SERVICE_MODEM }
};
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_SERVICE_CALL)
return "Modem-Call";
else if (flag == MODEM_SERVICE_TONES)
return "Modem-Tones";
else if (flag == MODEM_SERVICE_SMS)
return "Modem-SMS";
else if (flag == MODEM_SERVICE_SIM)
return "Modem-SIM";
else
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);
}
|