~awe/phablet-extras/ofono-lp1204683

« back to all changes in this revision

Viewing changes to src/cssn.c

  • Committer: Bazaar Package Importer
  • Author(s): Andres Salomon
  • Date: 2009-08-15 15:55:11 UTC
  • Revision ID: james.westby@ubuntu.com-20090815155511-frst06dijguhyfi4
Tags: upstream-0.3
ImportĀ upstreamĀ versionĀ 0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 *  oFono - Open Source Telephony
 
4
 *
 
5
 *  Copyright (C) 2008-2009  Intel Corporation. All rights reserved.
 
6
 *
 
7
 *  This program is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU General Public License version 2 as
 
9
 *  published by the Free Software Foundation.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 *
 
20
 */
 
21
 
 
22
#ifdef HAVE_CONFIG_H
 
23
#include <config.h>
 
24
#endif
 
25
 
 
26
#include <string.h>
 
27
#include <stdio.h>
 
28
 
 
29
#include <glib.h>
 
30
 
 
31
#include "ofono.h"
 
32
 
 
33
#include "driver.h"
 
34
#include "common.h"
 
35
#include "cssn.h"
 
36
 
 
37
struct cssn_data {
 
38
        GSList *mo_handler_list;
 
39
        GSList *mt_handler_list;
 
40
};
 
41
 
 
42
struct mo_handler {
 
43
        enum ss_cssi code1;
 
44
        mo_ss_notify_cb cb;
 
45
        void *cb_data;
 
46
};
 
47
 
 
48
struct mt_handler {
 
49
        enum ss_cssu code2;
 
50
        mt_ss_notify_cb cb;
 
51
        void *cb_data;
 
52
};
 
53
 
 
54
static gint ss_handler_compare(gconstpointer a, gconstpointer b)
 
55
{
 
56
        return memcmp(a, b, sizeof(struct mo_handler));
 
57
}
 
58
 
 
59
void ofono_mo_ss_register(struct ofono_modem *modem, enum ss_cssi code1,
 
60
                mo_ss_notify_cb cb, void *userdata)
 
61
{
 
62
        struct cssn_data *ss = modem->cssn;
 
63
        struct mo_handler *handler = g_try_new0(struct mo_handler, 1);
 
64
 
 
65
        handler->code1 = code1;
 
66
        handler->cb = cb;
 
67
        handler->cb_data = userdata;
 
68
 
 
69
        ss->mo_handler_list = g_slist_prepend(ss->mo_handler_list, handler);
 
70
}
 
71
 
 
72
void ofono_mo_ss_unregister(struct ofono_modem *modem, enum ss_cssi code1,
 
73
                mo_ss_notify_cb cb, void *userdata)
 
74
{
 
75
        struct cssn_data *ss = modem->cssn;
 
76
        struct mo_handler val = { code1, cb, userdata };
 
77
        GSList *l = g_slist_find_custom(ss->mo_handler_list, &val,
 
78
                        ss_handler_compare);
 
79
 
 
80
        if (!l) {
 
81
                ofono_error("An unregistered handler passed to "
 
82
                                "ofono_mo_ss_unregister");
 
83
                return;
 
84
        }
 
85
 
 
86
        g_free(l->data);
 
87
        ss->mo_handler_list = g_slist_delete_link(ss->mo_handler_list, l);
 
88
}
 
89
 
 
90
void ofono_mt_ss_register(struct ofono_modem *modem, enum ss_cssu code2,
 
91
                mt_ss_notify_cb cb, void *userdata)
 
92
{
 
93
        struct cssn_data *ss = modem->cssn;
 
94
        struct mt_handler *handler = g_try_new0(struct mt_handler, 1);
 
95
 
 
96
        handler->code2 = code2;
 
97
        handler->cb = cb;
 
98
        handler->cb_data = userdata;
 
99
 
 
100
        ss->mt_handler_list = g_slist_prepend(ss->mt_handler_list, handler);
 
101
}
 
102
 
 
103
void ofono_mt_ss_unregister(struct ofono_modem *modem, enum ss_cssu code2,
 
104
                mt_ss_notify_cb cb, void *userdata)
 
105
{
 
106
        struct cssn_data *ss = modem->cssn;
 
107
        struct mt_handler val = { code2, cb, userdata };
 
108
        GSList *l = g_slist_find_custom(ss->mt_handler_list, &val,
 
109
                        ss_handler_compare);
 
110
 
 
111
        if (!l) {
 
112
                ofono_error("An unregistered handler passed to "
 
113
                                "ofono_mt_ss_unregister");
 
114
                return;
 
115
        }
 
116
 
 
117
        g_free(l->data);
 
118
        ss->mt_handler_list = g_slist_delete_link(ss->mt_handler_list, l);
 
119
}
 
120
 
 
121
void ofono_cssn_init(struct ofono_modem *modem)
 
122
{
 
123
        struct cssn_data *ss = g_try_new0(struct cssn_data, 1);
 
124
 
 
125
        modem->cssn = ss;
 
126
}
 
127
 
 
128
static void cssn_free_handlers(GSList *l)
 
129
{
 
130
        GSList *iter;
 
131
 
 
132
        for (iter = l; iter; iter = iter->next)
 
133
                g_free(iter->data);
 
134
        g_slist_free(l);
 
135
}
 
136
 
 
137
void ofono_cssn_exit(struct ofono_modem *modem)
 
138
{
 
139
        if (!modem->cssn)
 
140
                return;
 
141
 
 
142
        cssn_free_handlers(modem->cssn->mo_handler_list);
 
143
        cssn_free_handlers(modem->cssn->mt_handler_list);
 
144
        g_free(modem->cssn);
 
145
 
 
146
        modem->cssn = NULL;
 
147
}
 
148
 
 
149
void ofono_cssi_notify(struct ofono_modem *modem, int code1, int index)
 
150
{
 
151
        struct cssn_data *ss = modem->cssn;
 
152
        struct mo_handler *h;
 
153
        GSList *l;
 
154
 
 
155
        for (l = ss->mo_handler_list; l; l = l->next) {
 
156
                h = l->data;
 
157
                if (h->code1 == (enum ss_cssi) code1)
 
158
                        h->cb(index, h->cb_data);
 
159
        }
 
160
}
 
161
 
 
162
void ofono_cssu_notify(struct ofono_modem *modem, int code2, int index,
 
163
                        const struct ofono_phone_number *ph)
 
164
{
 
165
        struct cssn_data *ss = modem->cssn;
 
166
        struct mt_handler *h;
 
167
        GSList *l;
 
168
 
 
169
        for (l = ss->mt_handler_list; l; l = l->next) {
 
170
                h = l->data;
 
171
                if (h->code2 == (enum ss_cssu) code2)
 
172
                        h->cb(index, ph, h->cb_data);
 
173
        }
 
174
}