diff options
author | Aki Niemi <aki.niemi@nokia.com> | 2010-05-18 17:07:54 +0300 |
---|---|---|
committer | Aki Niemi <aki.niemi@nokia.com> | 2010-05-19 10:46:18 +0300 |
commit | b8ec7553efd0108cf453e763af5ba19f537366b2 (patch) | |
tree | c6f65f439ee3d1cc877cec85da958ab9c53d0046 /src/nettime.c | |
parent | 1d7fe6aa5a4958ff2723f02031774c08f3d3fee6 (diff) | |
download | ofono-b8ec7553efd0108cf453e763af5ba19f537366b2.tar.bz2 |
Add network time support
Adding a new notify function in the netreg atom for notifying a
received Network Identification and Timezone (NITZ) indication. This
data is consumed via a nettime plugin, of which there is also an
example.
Diffstat (limited to 'src/nettime.c')
-rw-r--r-- | src/nettime.c | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/src/nettime.c b/src/nettime.c new file mode 100644 index 00000000..b17e375b --- /dev/null +++ b/src/nettime.c @@ -0,0 +1,121 @@ +/* + * + * oFono - Open Source Telephony + * + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). + * + * 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 *nettime_drivers = NULL; + +static struct ofono_nettime_context *nettime_context_create( + struct ofono_modem *modem, + struct ofono_nettime_driver *driver) +{ + struct ofono_nettime_context *context; + + if (driver->probe == NULL) + return NULL; + + context = g_try_new0(struct ofono_nettime_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; +} + +static void context_remove(struct ofono_atom *atom) +{ + struct ofono_nettime_context *context = __ofono_atom_get_data(atom); + + if (context->driver->remove) + context->driver->remove(context); + + g_free(context); +} + +void __ofono_nettime_probe_drivers(struct ofono_modem *modem) +{ + struct ofono_nettime_driver *driver; + struct ofono_nettime_context *context; + GSList *l; + + for (l = nettime_drivers; l; l = l->next) { + driver = l->data; + + context = nettime_context_create(modem, driver); + + if (!context) + continue; + + __ofono_modem_add_atom(modem, OFONO_ATOM_TYPE_NETTIME, + context_remove, context); + } +} + +static void nettime_info_received(struct ofono_atom *atom, void *data) +{ + struct ofono_nettime_context *context = __ofono_atom_get_data(atom); + struct ofono_network_time *info = data; + + if (context->driver->info_received == NULL) + return; + + context->driver->info_received(context, info); +} + +void __ofono_nettime_info_received(struct ofono_modem *modem, + struct ofono_network_time *info) +{ + __ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_NETTIME, + nettime_info_received, info); +} + +int ofono_nettime_driver_register(const struct ofono_nettime_driver *driver) +{ + DBG("driver: %p name: %s", driver, driver->name); + + nettime_drivers = g_slist_prepend(nettime_drivers, (void *)driver); + + return 0; +} + +void ofono_nettime_driver_unregister(const struct ofono_nettime_driver *driver) +{ + DBG("driver: %p name: %s", driver, driver->name); + + nettime_drivers = g_slist_remove(nettime_drivers, driver); +} |