diff options
author | Denis Kenzior <denkenz@gmail.com> | 2009-06-17 07:03:21 -0500 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2009-06-17 18:20:20 -0500 |
commit | 1dbfc02d6cfa2666caa56382158c579197f5b114 (patch) | |
tree | d0b88a7c99a19ba03f16a7b40327a5413728e1e6 /src/history.c | |
parent | c892f36dc285a7713fd6d48e50f0f926cbe6ee83 (diff) | |
download | ofono-1dbfc02d6cfa2666caa56382158c579197f5b114.tar.bz2 |
Add call-history driver type
Diffstat (limited to 'src/history.c')
-rw-r--r-- | src/history.c | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/src/history.c b/src/history.c new file mode 100644 index 00000000..1720cf90 --- /dev/null +++ b/src/history.c @@ -0,0 +1,142 @@ +/* + * + * 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 "modem.h" + +static GSList *history_drivers = NULL; + +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; +} + +void ofono_history_probe_drivers(struct ofono_modem *modem) +{ + GSList *l; + struct ofono_history_context *context; + struct ofono_history_driver *driver; + + for (l = history_drivers; l; l = l->next) { + driver = l->data; + + context = history_context_create(modem, driver); + + if (!context) + continue; + + modem->history_contexts = + g_slist_prepend(modem->history_contexts, context); + } +} + +void ofono_history_remove_drivers(struct ofono_modem *modem) +{ + GSList *l; + struct ofono_history_context *context; + + for (l = modem->history_contexts; l; l = l->next) { + context = l->data; + + if (context->driver->remove) + context->driver->remove(context); + + g_free(context); + } + + g_slist_free(modem->history_contexts); + modem->history_contexts = NULL; +} + +void ofono_history_call_ended(struct ofono_modem *modem, + const struct ofono_call *call, + time_t start, time_t end) +{ + struct ofono_history_context *context; + GSList *l; + + for (l = modem->history_contexts; l; l = l->next) { + context = l->data; + + if (context->driver->call_ended) + context->driver->call_ended(context, call, start, end); + } +} + +void ofono_history_call_missed(struct ofono_modem *modem, + const struct ofono_call *call, time_t when) +{ + struct ofono_history_context *context; + GSList *l; + + for (l = modem->history_contexts; l; l = l->next) { + context = l->data; + + if (context->driver->call_missed) + context->driver->call_missed(context, call, when); + } +} + +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); +} |