From ca95c87dae13d8346781323adc3390428aee1b76 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Thu, 20 Aug 2009 16:29:18 -0500 Subject: [PATCH] Port history to the new atom API Use __atom_foreach --- src/history.c | 85 ++++++++++++++++++++++++++++++++------------------- src/modem.c | 1 - src/ofono.h | 2 -- 3 files changed, 54 insertions(+), 34 deletions(-) diff --git a/src/history.c b/src/history.c index bfc82b4b..ee7a492e 100644 --- a/src/history.c +++ b/src/history.c @@ -32,6 +32,18 @@ static GSList *history_drivers = NULL; +struct history_foreach_data { + const struct ofono_call *call; + union { + struct { + time_t start; + time_t end; + }; + + time_t when; + }; +}; + static struct ofono_history_context *history_context_create( struct ofono_modem *modem, struct ofono_history_driver *driver) @@ -57,11 +69,21 @@ static struct ofono_history_context *history_context_create( return context; } +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); +} + void __ofono_history_probe_drivers(struct ofono_modem *modem) { - GSList *l; - struct ofono_history_context *context; struct ofono_history_driver *driver; + struct ofono_history_context *context; + GSList *l; for (l = history_drivers; l; l = l->next) { driver = l->data; @@ -71,56 +93,57 @@ void __ofono_history_probe_drivers(struct ofono_modem *modem) if (!context) continue; - modem->history_contexts = - g_slist_prepend(modem->history_contexts, context); + __ofono_modem_add_atom(modem, OFONO_ATOM_TYPE_HISTORY, + context_remove, context); } } -void __ofono_history_remove_drivers(struct ofono_modem *modem) +static void history_call_ended(struct ofono_atom *atom, void *data) { - GSList *l; - struct ofono_history_context *context; + struct ofono_history_context *context = __ofono_atom_get_data(atom); + struct history_foreach_data *hfd = data; - for (l = modem->history_contexts; l; l = l->next) { - context = l->data; + if (context->driver->call_ended == NULL) + return; - if (context->driver->remove) - context->driver->remove(context); - - g_free(context); - } - - g_slist_free(modem->history_contexts); - modem->history_contexts = NULL; + context->driver->call_ended(context, hfd->call, hfd->start, hfd->end); } 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; + struct history_foreach_data hfd; - for (l = modem->history_contexts; l; l = l->next) { - context = l->data; + hfd.call = call; + hfd.start = start; + hfd.end = end; - if (context->driver->call_ended) - context->driver->call_ended(context, call, start, end); - } + __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); } void __ofono_history_call_missed(struct ofono_modem *modem, const struct ofono_call *call, time_t when) { - struct ofono_history_context *context; - GSList *l; + struct history_foreach_data hfd; - for (l = modem->history_contexts; l; l = l->next) { - context = l->data; + hfd.call = call; + hfd.when = when; - if (context->driver->call_missed) - context->driver->call_missed(context, call, when); - } + __ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_HISTORY, + history_call_missed, &hfd); } int ofono_history_driver_register(const struct ofono_history_driver *driver) diff --git a/src/modem.c b/src/modem.c index bf1ca330..c3204160 100644 --- a/src/modem.c +++ b/src/modem.c @@ -834,7 +834,6 @@ 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/ofono.h b/src/ofono.h index 3f1f8115..29cc4099 100644 --- a/src/ofono.h +++ b/src/ofono.h @@ -71,7 +71,6 @@ struct ofono_modem { int next_atom_watch_id; struct ofono_modem_data *modem_info; - GSList *history_contexts; }; #include @@ -193,7 +192,6 @@ void __ofono_ussd_passwd_unregister(struct ofono_ussd *ussd, const char *sc); #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,