diff options
author | Samuel Ortiz <sameo@linux.intel.com> | 2010-05-31 15:05:58 +0200 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2010-05-31 17:39:37 +0200 |
commit | dba90159b8bf8f065fcbce48432ef5da36a0c5ce (patch) | |
tree | a8d6d8480e00ecb0cf3c945235ae462ba6ebeaf3 /src/timeserver.c | |
parent | 679bb7a005c773149de0760a10c1935aab0fa24f (diff) | |
download | connman-dba90159b8bf8f065fcbce48432ef5da36a0c5ce.tar.gz connman-dba90159b8bf8f065fcbce48432ef5da36a0c5ce.tar.bz2 connman-dba90159b8bf8f065fcbce48432ef5da36a0c5ce.zip |
Complete timeserver API
The timeserver API now includes a sync() call in order to separate
timeserver peer addition from actual time syncing.
Diffstat (limited to 'src/timeserver.c')
-rw-r--r-- | src/timeserver.c | 67 |
1 files changed, 62 insertions, 5 deletions
diff --git a/src/timeserver.c b/src/timeserver.c index 12b604c6..bca66f3a 100644 --- a/src/timeserver.c +++ b/src/timeserver.c @@ -28,6 +28,7 @@ #include "connman.h" static GSList *driver_list = NULL; +static GHashTable *server_hash = NULL; static gint compare_priority(gconstpointer a, gconstpointer b) { @@ -74,16 +75,32 @@ void connman_timeserver_driver_unregister(struct connman_timeserver_driver *driv * * Append time server server address to current list */ -int connman_timeserver_append(const char *server) +int connman_timeserver_append(char *server) { + GSList *list; + DBG("server %s", server); if (server == NULL) return -EINVAL; - connman_info("Adding time server %s", server); + /* This server is already handled by a driver */ + if (g_hash_table_lookup(server_hash, server)) + return 0; - return 0; + for (list = driver_list; list; list = list->next) { + struct connman_timeserver_driver *driver = list->data; + + if (driver->append == NULL) + continue; + + if (driver->append(server) == 0) { + g_hash_table_insert(server_hash, server, driver); + return 0; + } + } + + return -ENOENT; } /** @@ -92,14 +109,54 @@ int connman_timeserver_append(const char *server) * * Remover time server server address from current list */ -int connman_timeserver_remove(const char *server) +int connman_timeserver_remove(char *server) { + struct connman_timeserver_driver *driver; + DBG("server %s", server); if (server == NULL) return -EINVAL; - connman_info("Removing time server %s", server); + driver = g_hash_table_lookup(server_hash, server); + if (driver == NULL) + return -EINVAL; + + if (driver->remove == NULL) + return -ENOENT; + + return driver->remove(server); +} + +void connman_timeserver_sync(void) +{ + GSList *list; + + DBG(""); + + for (list = driver_list; list; list = list->next) { + struct connman_timeserver_driver *driver = list->data; + + if (driver->sync == NULL) + continue; + + driver->sync(); + } +} + +int __connman_timeserver_init(void) +{ + DBG(""); + + server_hash = g_hash_table_new_full(g_str_hash, g_str_equal, + NULL, NULL); return 0; } + +void __connman_timeserver_cleanup(void) +{ + DBG(""); + + g_hash_table_destroy(server_hash); +} |