5 * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 static GSList *driver_list = NULL;
33 static GHashTable *server_hash = NULL;
35 static gint compare_priority(gconstpointer a, gconstpointer b)
37 const struct connman_timeserver_driver *driver1 = a;
38 const struct connman_timeserver_driver *driver2 = b;
40 return driver2->priority - driver1->priority;
44 * connman_timeserver_driver_register:
45 * @driver: timeserver driver definition
47 * Register a new timeserver driver
49 * Returns: %0 on success
51 int connman_timeserver_driver_register(struct connman_timeserver_driver *driver)
53 DBG("driver %p name %s", driver, driver->name);
55 driver_list = g_slist_insert_sorted(driver_list, driver,
62 * connman_timeserver_driver_unregister:
63 * @driver: timeserver driver definition
65 * Remove a previously registered timeserver driver
67 void connman_timeserver_driver_unregister(struct connman_timeserver_driver *driver)
69 DBG("driver %p name %s", driver, driver->name);
71 driver_list = g_slist_remove(driver_list, driver);
75 * connman_timeserver_append:
76 * @server: server address
78 * Append time server server address to current list
80 int connman_timeserver_append(const char *server)
84 DBG("server %s", server);
89 /* This server is already handled by a driver */
90 if (g_hash_table_lookup(server_hash, server))
93 for (list = driver_list; list; list = list->next) {
94 struct connman_timeserver_driver *driver = list->data;
97 if (driver->append == NULL)
100 new_server = g_strdup(server);
101 if (new_server == NULL)
104 if (driver->append(server) == 0) {
105 g_hash_table_insert(server_hash, new_server, driver);
116 * connman_timeserver_remove:
117 * @server: server address
119 * Remover time server server address from current list
121 int connman_timeserver_remove(const char *server)
123 struct connman_timeserver_driver *driver;
125 DBG("server %s", server);
130 driver = g_hash_table_lookup(server_hash, server);
134 g_hash_table_remove(server_hash, server);
136 if (driver->remove == NULL)
139 return driver->remove(server);
142 void connman_timeserver_sync(void)
148 for (list = driver_list; list; list = list->next) {
149 struct connman_timeserver_driver *driver = list->data;
151 if (driver->sync == NULL)
158 int __connman_timeserver_init(void)
162 server_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
168 void __connman_timeserver_cleanup(void)
172 g_hash_table_destroy(server_hash);