2009-06-17 12:03:21 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
|
|
|
static GSList *history_drivers = NULL;
|
|
|
|
|
2009-08-20 21:29:18 +00:00
|
|
|
struct history_foreach_data {
|
|
|
|
const struct ofono_call *call;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
time_t start;
|
|
|
|
time_t end;
|
|
|
|
};
|
|
|
|
|
|
|
|
time_t when;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2009-06-17 12:03:21 +00:00
|
|
|
static struct ofono_history_context *history_context_create(
|
|
|
|
struct ofono_modem *modem,
|
|
|
|
struct ofono_history_driver *driver)
|
|
|
|
{
|
|
|
|
struct ofono_history_context *context;
|
|
|
|
|
|
|
|
if (driver->probe == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
context = g_try_new0(struct ofono_history_context, 1);
|
|
|
|
|
|
|
|
if (context == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
context->driver = driver;
|
|
|
|
context->modem = modem;
|
|
|
|
|
|
|
|
if (driver->probe(context) < 0) {
|
|
|
|
g_free(context);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
2009-08-20 21:29:18 +00:00
|
|
|
static void context_remove(struct ofono_atom *atom)
|
|
|
|
{
|
|
|
|
struct ofono_history_context *context = __ofono_atom_get_data(atom);
|
|
|
|
|
|
|
|
if (context->driver->remove)
|
|
|
|
context->driver->remove(context);
|
|
|
|
|
|
|
|
g_free(context);
|
|
|
|
}
|
|
|
|
|
2009-07-29 17:59:39 +00:00
|
|
|
void __ofono_history_probe_drivers(struct ofono_modem *modem)
|
2009-06-17 12:03:21 +00:00
|
|
|
{
|
|
|
|
struct ofono_history_driver *driver;
|
2009-08-20 21:29:18 +00:00
|
|
|
struct ofono_history_context *context;
|
|
|
|
GSList *l;
|
2009-06-17 12:03:21 +00:00
|
|
|
|
|
|
|
for (l = history_drivers; l; l = l->next) {
|
|
|
|
driver = l->data;
|
|
|
|
|
|
|
|
context = history_context_create(modem, driver);
|
|
|
|
|
|
|
|
if (!context)
|
|
|
|
continue;
|
|
|
|
|
2009-08-20 21:29:18 +00:00
|
|
|
__ofono_modem_add_atom(modem, OFONO_ATOM_TYPE_HISTORY,
|
|
|
|
context_remove, context);
|
2009-06-17 12:03:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-20 21:29:18 +00:00
|
|
|
static void history_call_ended(struct ofono_atom *atom, void *data)
|
2009-06-17 12:03:21 +00:00
|
|
|
{
|
2009-08-20 21:29:18 +00:00
|
|
|
struct ofono_history_context *context = __ofono_atom_get_data(atom);
|
|
|
|
struct history_foreach_data *hfd = data;
|
2009-06-17 12:03:21 +00:00
|
|
|
|
2009-08-20 21:29:18 +00:00
|
|
|
if (context->driver->call_ended == NULL)
|
|
|
|
return;
|
2009-06-17 12:03:21 +00:00
|
|
|
|
2009-08-20 21:29:18 +00:00
|
|
|
context->driver->call_ended(context, hfd->call, hfd->start, hfd->end);
|
2009-06-17 12:03:21 +00:00
|
|
|
}
|
|
|
|
|
2009-07-29 17:59:39 +00:00
|
|
|
void __ofono_history_call_ended(struct ofono_modem *modem,
|
2009-06-17 12:03:21 +00:00
|
|
|
const struct ofono_call *call,
|
|
|
|
time_t start, time_t end)
|
|
|
|
{
|
2009-08-20 21:29:18 +00:00
|
|
|
struct history_foreach_data hfd;
|
2009-06-17 12:03:21 +00:00
|
|
|
|
2009-08-20 21:29:18 +00:00
|
|
|
hfd.call = call;
|
|
|
|
hfd.start = start;
|
|
|
|
hfd.end = end;
|
2009-06-17 12:03:21 +00:00
|
|
|
|
2009-08-20 21:29:18 +00:00
|
|
|
__ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_HISTORY,
|
|
|
|
history_call_ended, &hfd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void history_call_missed(struct ofono_atom *atom, void *data)
|
|
|
|
{
|
|
|
|
struct ofono_history_context *context = __ofono_atom_get_data(atom);
|
|
|
|
struct history_foreach_data *hfd = data;
|
|
|
|
|
|
|
|
if (context->driver->call_missed == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
context->driver->call_missed(context, hfd->call, hfd->when);
|
2009-06-17 12:03:21 +00:00
|
|
|
}
|
|
|
|
|
2009-07-29 17:59:39 +00:00
|
|
|
void __ofono_history_call_missed(struct ofono_modem *modem,
|
2009-06-17 12:03:21 +00:00
|
|
|
const struct ofono_call *call, time_t when)
|
|
|
|
{
|
2009-08-20 21:29:18 +00:00
|
|
|
struct history_foreach_data hfd;
|
2009-06-17 12:03:21 +00:00
|
|
|
|
2009-08-20 21:29:18 +00:00
|
|
|
hfd.call = call;
|
|
|
|
hfd.when = when;
|
2009-06-17 12:03:21 +00:00
|
|
|
|
2009-08-20 21:29:18 +00:00
|
|
|
__ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_HISTORY,
|
|
|
|
history_call_missed, &hfd);
|
2009-06-17 12:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ofono_history_driver_register(const struct ofono_history_driver *driver)
|
|
|
|
{
|
|
|
|
DBG("driver: %p name: %s", driver, driver->name);
|
|
|
|
|
|
|
|
history_drivers = g_slist_prepend(history_drivers, (void *)driver);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ofono_history_driver_unregister(const struct ofono_history_driver *driver)
|
|
|
|
{
|
|
|
|
DBG("driver: %p name: %s", driver, driver->name);
|
|
|
|
|
|
|
|
history_drivers = g_slist_remove(history_drivers, driver);
|
|
|
|
}
|