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
30 static GSList *driver_list = NULL;
31 static GHashTable *server_hash = NULL;
33 static gint compare_priority(gconstpointer a, gconstpointer b)
35 const struct connman_timeserver_driver *driver1 = a;
36 const struct connman_timeserver_driver *driver2 = b;
38 return driver2->priority - driver1->priority;
42 * connman_timeserver_driver_register:
43 * @driver: timeserver driver definition
45 * Register a new timeserver driver
47 * Returns: %0 on success
49 int connman_timeserver_driver_register(struct connman_timeserver_driver *driver)
51 DBG("driver %p name %s", driver, driver->name);
53 driver_list = g_slist_insert_sorted(driver_list, driver,
60 * connman_timeserver_driver_unregister:
61 * @driver: timeserver driver definition
63 * Remove a previously registered timeserver driver
65 void connman_timeserver_driver_unregister(struct connman_timeserver_driver *driver)
67 DBG("driver %p name %s", driver, driver->name);
69 driver_list = g_slist_remove(driver_list, driver);
73 * connman_timeserver_append:
74 * @server: server address
76 * Append time server server address to current list
78 int connman_timeserver_append(char *server)
82 DBG("server %s", server);
87 /* This server is already handled by a driver */
88 if (g_hash_table_lookup(server_hash, server))
91 for (list = driver_list; list; list = list->next) {
92 struct connman_timeserver_driver *driver = list->data;
94 if (driver->append == NULL)
97 if (driver->append(server) == 0) {
98 g_hash_table_insert(server_hash, server, driver);
107 * connman_timeserver_remove:
108 * @server: server address
110 * Remover time server server address from current list
112 int connman_timeserver_remove(char *server)
114 struct connman_timeserver_driver *driver;
116 DBG("server %s", server);
121 driver = g_hash_table_lookup(server_hash, server);
125 if (driver->remove == NULL)
128 return driver->remove(server);
131 void connman_timeserver_sync(void)
137 for (list = driver_list; list; list = list->next) {
138 struct connman_timeserver_driver *driver = list->data;
140 if (driver->sync == NULL)
147 int __connman_timeserver_init(void)
151 server_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
157 void __connman_timeserver_cleanup(void)
161 g_hash_table_destroy(server_hash);