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 | |
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')
-rw-r--r-- | src/connman.h | 3 | ||||
-rw-r--r-- | src/ipv4.c | 6 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/timeserver.c | 67 |
4 files changed, 71 insertions, 7 deletions
diff --git a/src/connman.h b/src/connman.h index 1546f7d4..62113466 100644 --- a/src/connman.h +++ b/src/connman.h @@ -253,6 +253,9 @@ int __connman_utsname_set_domainname(const char *domainname); #include <connman/timeserver.h> +int __connman_timeserver_init(void); +void __connman_timeserver_cleanup(void); + #include <connman/dhcp.h> int __connman_dhcp_init(void); @@ -167,7 +167,8 @@ static int ipv4_probe(struct connman_element *element) struct connman_element *connection; struct connman_ipv4 ipv4; const char *address = NULL, *netmask = NULL, *broadcast = NULL; - const char *nameserver = NULL, *timeserver = NULL; + const char *nameserver = NULL; + char *timeserver = NULL; DBG("element %p name %s", element, element->name); @@ -224,7 +225,8 @@ static int ipv4_probe(struct connman_element *element) static void ipv4_remove(struct connman_element *element) { - const char *nameserver = NULL, *timeserver = NULL; + const char *nameserver = NULL; + char *timeserver = NULL; DBG("element %p name %s", element, element->name); @@ -230,6 +230,7 @@ int main(int argc, char *argv[]) __connman_udev_init(); __connman_task_init(); __connman_session_init(); + __connman_timeserver_init(); __connman_plugin_init(option_plugin, option_noplugin); @@ -251,6 +252,7 @@ int main(int argc, char *argv[]) __connman_plugin_cleanup(); + __connman_timeserver_cleanup(); __connman_session_cleanup(); __connman_task_cleanup(); __connman_udev_cleanup(); 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); +} |