3 * oFono - Open Source Telephony
5 * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
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.
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.
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
33 static GSList *history_drivers = NULL;
35 struct history_call_foreach_data {
36 const struct ofono_call *call;
47 struct history_sms_foreach_data {
48 const struct ofono_uuid *uuid;
53 const struct tm *remote;
54 const struct tm *local;
58 enum ofono_history_sms_status status;
63 static struct ofono_history_context *history_context_create(
64 struct ofono_modem *modem,
65 struct ofono_history_driver *driver)
67 struct ofono_history_context *context;
69 if (driver->probe == NULL)
72 context = g_try_new0(struct ofono_history_context, 1);
77 context->driver = driver;
78 context->modem = modem;
80 if (driver->probe(context) < 0) {
88 static void context_remove(struct ofono_atom *atom)
90 struct ofono_history_context *context = __ofono_atom_get_data(atom);
92 if (context->driver->remove)
93 context->driver->remove(context);
98 void __ofono_history_probe_drivers(struct ofono_modem *modem)
100 struct ofono_history_driver *driver;
101 struct ofono_history_context *context;
104 for (l = history_drivers; l; l = l->next) {
107 context = history_context_create(modem, driver);
111 __ofono_modem_add_atom(modem, OFONO_ATOM_TYPE_HISTORY,
112 context_remove, context);
116 static void history_call_ended(struct ofono_atom *atom, void *data)
118 struct ofono_history_context *context = __ofono_atom_get_data(atom);
119 struct history_call_foreach_data *hfd = data;
121 if (context->driver->call_ended == NULL)
124 context->driver->call_ended(context, hfd->call, hfd->start, hfd->end);
127 void __ofono_history_call_ended(struct ofono_modem *modem,
128 const struct ofono_call *call,
129 time_t start, time_t end)
131 struct history_call_foreach_data hfd;
137 __ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_HISTORY,
138 history_call_ended, &hfd);
141 static void history_call_missed(struct ofono_atom *atom, void *data)
143 struct ofono_history_context *context = __ofono_atom_get_data(atom);
144 struct history_call_foreach_data *hfd = data;
146 if (context->driver->call_missed == NULL)
149 context->driver->call_missed(context, hfd->call, hfd->when);
152 void __ofono_history_call_missed(struct ofono_modem *modem,
153 const struct ofono_call *call, time_t when)
155 struct history_call_foreach_data hfd;
160 __ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_HISTORY,
161 history_call_missed, &hfd);
164 static void history_sms_received(struct ofono_atom *atom, void *data)
166 struct ofono_history_context *context = __ofono_atom_get_data(atom);
167 struct history_sms_foreach_data *hfd = data;
169 if (context->driver->sms_received == NULL)
172 context->driver->sms_received(context, hfd->uuid, hfd->address,
173 hfd->remote, hfd->local, hfd->text);
176 void __ofono_history_sms_received(struct ofono_modem *modem,
177 const struct ofono_uuid *uuid,
179 const struct tm *remote,
180 const struct tm *local,
183 struct history_sms_foreach_data hfd;
191 __ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_HISTORY,
192 history_sms_received, &hfd);
195 static void history_sms_send_pending(struct ofono_atom *atom, void *data)
197 struct ofono_history_context *context = __ofono_atom_get_data(atom);
198 struct history_sms_foreach_data *hfd = data;
200 if (context->driver->sms_send_pending == NULL)
203 context->driver->sms_send_pending(context, hfd->uuid, hfd->address,
204 hfd->when, hfd->text);
207 void __ofono_history_sms_send_pending(struct ofono_modem *modem,
208 const struct ofono_uuid *uuid,
210 time_t when, const char *text)
212 struct history_sms_foreach_data hfd;
218 hfd.status = OFONO_HISTORY_SMS_STATUS_PENDING;
220 __ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_HISTORY,
221 history_sms_send_pending, &hfd);
224 static void history_sms_send_status(struct ofono_atom *atom, void *data)
226 struct ofono_history_context *context = __ofono_atom_get_data(atom);
227 struct history_sms_foreach_data *hfd = data;
229 if (context->driver->sms_send_status == NULL)
232 context->driver->sms_send_status(context, hfd->uuid,
233 hfd->when, hfd->status);
236 void __ofono_history_sms_send_status(struct ofono_modem *modem,
237 const struct ofono_uuid *uuid,
239 enum ofono_history_sms_status status)
241 struct history_sms_foreach_data hfd;
249 __ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_HISTORY,
250 history_sms_send_status, &hfd);
253 int ofono_history_driver_register(const struct ofono_history_driver *driver)
255 DBG("driver: %p name: %s", driver, driver->name);
257 history_drivers = g_slist_prepend(history_drivers, (void *) driver);
262 void ofono_history_driver_unregister(const struct ofono_history_driver *driver)
264 DBG("driver: %p name: %s", driver, driver->name);
266 history_drivers = g_slist_remove(history_drivers, driver);