diff --git a/include/Makefile.am b/include/Makefile.am index cc48b373..70e4f3e3 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,7 +1,7 @@ includedir = @includedir@/ofono -include_HEADERS = log.h plugin.h +include_HEADERS = log.h plugin.h history.h nodist_include_HEADERS = version.h diff --git a/include/history.h b/include/history.h new file mode 100644 index 00000000..afb4f168 --- /dev/null +++ b/include/history.h @@ -0,0 +1,56 @@ +/* + * + * oFono - Open Telephony stack for Linux + * + * 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 + * + */ + +#ifndef __OFONO_HISTORY_H +#define __OFONO_HISTORY_H + +#ifdef __cplusplus +extern "C" { +#endif + +enum ofono_disconnect_reason; +struct ofono_call; + +struct ofono_history_context { + struct ofono_history_driver *driver; + struct ofono_modem *modem; + void *data; +}; + +struct ofono_history_driver { + const char *name; + int (*probe)(struct ofono_history_context *context); + void (*remove)(struct ofono_history_context *context); + void (*call_ended)(struct ofono_history_context *context, + const struct ofono_call *call, + time_t start, time_t end); + void (*call_missed)(struct ofono_history_context *context, + const struct ofono_call *call, time_t when); +}; + +int ofono_history_driver_register(const struct ofono_history_driver *driver); +void ofono_history_driver_unregister(const struct ofono_history_driver *driver); + +#ifdef __cplusplus +} +#endif + +#endif /* __OFONO_HISTORY_H */ diff --git a/plugins/Makefile.am b/plugins/Makefile.am index b65bc731..310ad459 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -3,16 +3,26 @@ builtin_modules = builtin_sources = builtin_cflags = +if MAINTAINER_MODE +builtin_modules += example_history +builtin_sources += example_history.c +endif + noinst_LTLIBRARIES = libbuiltin.la libbuiltin_la_SOURCES = $(builtin_sources) libbuiltin_la_LDFLAGS = -libbuiltin_la_CFLAGS = $(AM_CFLAGS) $(builtin_cflags) -DOFONO_PLUGIN_BUILTIN +libbuiltin_la_CFLAGS = $(AM_CFLAGS) $(builtin_cflags) -DOFONO_PLUGIN_BUILTIN \ + -DOFONO_API_SUBJECT_TO_CHANGE BUILT_SOURCES = builtin.h nodist_libbuiltin_la_SOURCES = $(BUILT_SOURCES) +AM_CFLAGS = -fvisibility=hidden @GLIB_CFLAGS@ @GDBUS_CFLAGS@ + +INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/src + CLEANFILES = $(BUILT_SOURCES) MAINTAINERCLEANFILES = Makefile.in diff --git a/plugins/example_history.c b/plugins/example_history.c new file mode 100644 index 00000000..3ebf7434 --- /dev/null +++ b/plugins/example_history.c @@ -0,0 +1,123 @@ +/* + * + * 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 +#endif + +#include +#include + +#include +#include +#include + +#include "driver.h" +#include "common.h" + +static int example_history_probe(struct ofono_history_context *context) +{ + ofono_debug("Example History Probe for modem: %p", context->modem); + return 0; +} + +static void example_history_remove(struct ofono_history_context *context) +{ + ofono_debug("Example History Remove for modem: %p", context->modem); +} + +static void example_history_call_ended(struct ofono_history_context *context, + const struct ofono_call *call, + time_t start, time_t end) +{ + const char *from = "Unknown"; + char buf[128]; + + ofono_debug("Call Ended on modem: %p", context->modem); + + if (call->type != 0) + return; + + ofono_debug("Voice Call, %s", + call->direction ? "Incoming" : "Outgoing"); + + if (call->clip_validity == 0) + from = phone_number_to_string(&call->phone_number); + + if (call->direction == 0) + ofono_debug("To: %s", from); + else + ofono_debug("From: %s", from); + + strftime(buf, 127, "%a, %d %b %Y %H:%M:%S %z", localtime(&start)); + buf[127] = '\0'; + ofono_debug("StartTime: %s", buf); + + strftime(buf, 127, "%a, %d %b %Y %H:%M:%S %z", localtime(&end)); + buf[127] = '\0'; + ofono_debug("EndTime: %s", buf); +} + +static void example_history_call_missed(struct ofono_history_context *context, + const struct ofono_call *call, + time_t when) +{ + const char *from = "Unknown"; + char buf[128]; + + ofono_debug("Call Missed on modem: %p", context->modem); + + if (call->type != 0) + return; + + ofono_debug("Voice Call, %s", + call->direction ? "Incoming" : "Outgoing"); + + if (call->clip_validity == 0) + from = phone_number_to_string(&call->phone_number); + + ofono_debug("From: %s", from); + strftime(buf, 127, "%a, %d %b %Y %H:%M:%S %z", localtime(&when)); + buf[127] = '\0'; + ofono_debug("When: %s", buf); +} + +static struct ofono_history_driver example_driver = { + .name = "Example Call History", + .probe = example_history_probe, + .remove = example_history_remove, + .call_ended = example_history_call_ended, + .call_missed = example_history_call_missed, +}; + +static int example_history_init(void) +{ + return ofono_history_driver_register(&example_driver); +} + +static void example_history_exit(void) +{ + ofono_history_driver_unregister(&example_driver); +} + +OFONO_PLUGIN_DEFINE(example_history, "Example Call History Plugin", + VERSION, OFONO_PLUGIN_PRIORITY_DEFAULT, + example_history_init, example_history_exit) diff --git a/src/Makefile.am b/src/Makefile.am index fd42cf4c..adfa6083 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,7 +13,7 @@ ofonod_SOURCES = main.c ofono.h log.c plugin.c \ network.c voicecall.c ussd.h ussd.c sms.c \ call-settings.c call-forwarding.c call-meter.c \ smsutil.h smsutil.c cssn.h cssn.c call-barring.c sim.h sim.c \ - phonebook.c + phonebook.c history.c ofonod_LDADD = $(top_builddir)/plugins/libbuiltin.la \ $(top_builddir)/drivers/libbuiltin.la \ 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 +#endif + +#include +#include + +#include + +#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); +} diff --git a/src/manager.c b/src/manager.c index 10700c08..18da8c34 100644 --- a/src/manager.c +++ b/src/manager.c @@ -62,6 +62,11 @@ static int modem_list(char ***modems) return 0; } +GSList *ofono_manager_get_modems() +{ + return g_modem_list; +} + struct ofono_modem *ofono_modem_register(struct ofono_modem_attribute_ops *ops) { struct ofono_modem *modem; @@ -75,6 +80,7 @@ struct ofono_modem *ofono_modem_register(struct ofono_modem_attribute_ops *ops) ++g_next_modem_id; + ofono_history_probe_drivers(modem); g_modem_list = g_slist_prepend(g_modem_list, modem); if (modem_list(&modems) == 0) { @@ -97,6 +103,7 @@ int ofono_modem_unregister(struct ofono_modem *m) if (modem == NULL) return -1; + ofono_history_remove_drivers(modem); modem_remove(modem); g_modem_list = g_slist_remove(g_modem_list, modem); diff --git a/src/modem.h b/src/modem.h index c643de45..6ed4a2a3 100644 --- a/src/modem.h +++ b/src/modem.h @@ -42,6 +42,8 @@ struct ofono_modem { struct sim_manager_data *sim_manager; struct sms_manager_data *sms_manager; struct phonebook_data *phonebook; + + GSList *history_contexts; }; struct ofono_modem *modem_create(int id, struct ofono_modem_attribute_ops *ops); diff --git a/src/ofono.h b/src/ofono.h index 0a7d32a8..99cbd607 100644 --- a/src/ofono.h +++ b/src/ofono.h @@ -26,6 +26,8 @@ int __ofono_manager_init(); void __ofono_manager_cleanup(); +GSList *ofono_manager_get_modems(); + #include int __ofono_log_init(gboolean detach, gboolean debug); @@ -37,3 +39,15 @@ void __ofono_toggle_debug(void); int __ofono_plugin_init(const char *pattern, const char *exclude); void __ofono_plugin_cleanup(void); + +#include + +void ofono_history_probe_drivers(struct ofono_modem *modem); +void ofono_history_remove_drivers(struct ofono_modem *modem); + +void ofono_history_call_ended(struct ofono_modem *modem, + const struct ofono_call *call, + time_t start, time_t end); + +void ofono_history_call_missed(struct ofono_modem *modem, + const struct ofono_call *call, time_t when); diff --git a/src/voicecall.c b/src/voicecall.c index c35262de..409d97a4 100644 --- a/src/voicecall.c +++ b/src/voicecall.c @@ -62,6 +62,7 @@ struct voicecall { struct ofono_call *call; struct ofono_modem *modem; time_t start_time; + time_t detect_time; }; static void generic_callback(const struct ofono_error *error, void *data); @@ -1206,6 +1207,8 @@ void ofono_voicecall_disconnected(struct ofono_modem *modem, int id, GSList *l; struct voicecalls_data *calls = modem->voicecalls; struct voicecall *call; + time_t ts; + enum call_status prev_status; ofono_debug("Got disconnection event for id: %d, reason: %d", id, reason); @@ -1220,6 +1223,9 @@ void ofono_voicecall_disconnected(struct ofono_modem *modem, int id, call = l->data; + ts = time(NULL); + prev_status = call->call->status; + l = g_slist_find_custom(calls->multiparty_list, GINT_TO_POINTER(id), call_compare_by_id); @@ -1242,6 +1248,12 @@ void ofono_voicecall_disconnected(struct ofono_modem *modem, int id, /* TODO: Emit disconnect reason */ voicecall_set_call_status(modem, call, CALL_STATUS_DISCONNECTED); + if (prev_status == CALL_STATUS_INCOMING) + ofono_history_call_missed(modem, call->call, ts); + else + ofono_history_call_ended(modem, call->call, + call->detect_time, ts); + voicecall_dbus_unregister(modem, call); calls->call_list = g_slist_remove(calls->call_list, call); @@ -1295,6 +1307,8 @@ void ofono_voicecall_notify(struct ofono_modem *modem, const struct ofono_call * goto err; } + v->detect_time = time(NULL); + if (!voicecall_dbus_register(v)) { ofono_error("Unable to register voice call"); goto err; @@ -1460,6 +1474,8 @@ static void dial_callback(const struct ofono_error *error, void *data) goto out; } + v->detect_time = time(NULL); + ofono_debug("Registering new call: %d", call->id); voicecall_dbus_register(v);