summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Ortiz <sameo@linux.intel.com>2010-05-31 15:05:58 +0200
committerSamuel Ortiz <sameo@linux.intel.com>2010-05-31 17:39:37 +0200
commitdba90159b8bf8f065fcbce48432ef5da36a0c5ce (patch)
treea8d6d8480e00ecb0cf3c945235ae462ba6ebeaf3
parent679bb7a005c773149de0760a10c1935aab0fa24f (diff)
downloadconnman-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.
-rw-r--r--include/timeserver.h10
-rw-r--r--src/connman.h3
-rw-r--r--src/ipv4.c6
-rw-r--r--src/main.c2
-rw-r--r--src/timeserver.c67
5 files changed, 77 insertions, 11 deletions
diff --git a/include/timeserver.h b/include/timeserver.h
index d2863e86..f1b5c9c8 100644
--- a/include/timeserver.h
+++ b/include/timeserver.h
@@ -32,14 +32,16 @@ extern "C" {
* @short_description: Functions for handling time servers (including NTP)
*/
-int connman_timeserver_append(const char *server);
-int connman_timeserver_remove(const char *server);
+int connman_timeserver_append(char *server);
+int connman_timeserver_remove(char *server);
+void connman_timeserver_sync(void);
struct connman_timeserver_driver {
const char *name;
int priority;
- int (*append) (const char *server);
- int (*remove) (const char *server);
+ int (*append) (char *server);
+ int (*remove) (char *server);
+ void (*sync) (void);
};
int connman_timeserver_driver_register(struct connman_timeserver_driver *driver);
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);
diff --git a/src/ipv4.c b/src/ipv4.c
index d3bc8461..4fc6a9f4 100644
--- a/src/ipv4.c
+++ b/src/ipv4.c
@@ -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);
diff --git a/src/main.c b/src/main.c
index 0ba7521c..ac1be834 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);
+}