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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
/*
*
* oFono - Open Source Telephony
*
* Copyright (C) 2008-2009 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include <stdio.h>
#include <glib.h>
#include "ofono.h"
#include "driver.h"
#include "common.h"
#include "cssn.h"
struct cssn_data {
GSList *mo_handler_list;
GSList *mt_handler_list;
};
struct mo_handler {
enum ss_cssi code1;
mo_ss_notify_cb cb;
void *cb_data;
};
struct mt_handler {
enum ss_cssu code2;
mt_ss_notify_cb cb;
void *cb_data;
};
static gint ss_handler_compare(gconstpointer a, gconstpointer b)
{
return memcmp(a, b, sizeof(struct mo_handler));
}
void ofono_mo_ss_register(struct ofono_modem *modem, enum ss_cssi code1,
mo_ss_notify_cb cb, void *userdata)
{
struct cssn_data *ss = modem->cssn;
struct mo_handler *handler = g_try_new0(struct mo_handler, 1);
handler->code1 = code1;
handler->cb = cb;
handler->cb_data = userdata;
ss->mo_handler_list = g_slist_prepend(ss->mo_handler_list, handler);
}
void ofono_mo_ss_unregister(struct ofono_modem *modem, enum ss_cssi code1,
mo_ss_notify_cb cb, void *userdata)
{
struct cssn_data *ss = modem->cssn;
struct mo_handler val = { code1, cb, userdata };
GSList *l = g_slist_find_custom(ss->mo_handler_list, &val,
ss_handler_compare);
if (!l) {
ofono_error("An unregistered handler passed to "
"ofono_mo_ss_unregister");
return;
}
g_free(l->data);
ss->mo_handler_list = g_slist_delete_link(ss->mo_handler_list, l);
}
void ofono_mt_ss_register(struct ofono_modem *modem, enum ss_cssu code2,
mt_ss_notify_cb cb, void *userdata)
{
struct cssn_data *ss = modem->cssn;
struct mt_handler *handler = g_try_new0(struct mt_handler, 1);
handler->code2 = code2;
handler->cb = cb;
handler->cb_data = userdata;
ss->mt_handler_list = g_slist_prepend(ss->mt_handler_list, handler);
}
void ofono_mt_ss_unregister(struct ofono_modem *modem, enum ss_cssu code2,
mt_ss_notify_cb cb, void *userdata)
{
struct cssn_data *ss = modem->cssn;
struct mt_handler val = { code2, cb, userdata };
GSList *l = g_slist_find_custom(ss->mt_handler_list, &val,
ss_handler_compare);
if (!l) {
ofono_error("An unregistered handler passed to "
"ofono_mt_ss_unregister");
return;
}
g_free(l->data);
ss->mt_handler_list = g_slist_delete_link(ss->mt_handler_list, l);
}
void ofono_cssn_init(struct ofono_modem *modem)
{
struct cssn_data *ss = g_try_new0(struct cssn_data, 1);
modem->cssn = ss;
}
static void cssn_free_handlers(GSList *l)
{
GSList *iter;
for (iter = l; iter; iter = iter->next)
g_free(iter->data);
g_slist_free(l);
}
void ofono_cssn_exit(struct ofono_modem *modem)
{
if (!modem->cssn)
return;
cssn_free_handlers(modem->cssn->mo_handler_list);
cssn_free_handlers(modem->cssn->mt_handler_list);
g_free(modem->cssn);
modem->cssn = NULL;
}
void ofono_cssi_notify(struct ofono_modem *modem, int code1, int index)
{
struct cssn_data *ss = modem->cssn;
struct mo_handler *h;
GSList *l;
for (l = ss->mo_handler_list; l; l = l->next) {
h = l->data;
if (h->code1 == (enum ss_cssi) code1)
h->cb(index, h->cb_data);
}
}
void ofono_cssu_notify(struct ofono_modem *modem, int code2, int index,
const struct ofono_phone_number *ph)
{
struct cssn_data *ss = modem->cssn;
struct mt_handler *h;
GSList *l;
for (l = ss->mt_handler_list; l; l = l->next) {
h = l->data;
if (h->code2 == (enum ss_cssu) code2)
h->cb(index, ph, h->cb_data);
}
}
|