* @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);
#include <connman/timeserver.h>
+int __connman_timeserver_init(void);
+void __connman_timeserver_cleanup(void);
+
#include <connman/dhcp.h>
int __connman_dhcp_init(void);
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);
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);
__connman_udev_init();
__connman_task_init();
__connman_session_init();
+ __connman_timeserver_init();
__connman_plugin_init(option_plugin, option_noplugin);
__connman_plugin_cleanup();
+ __connman_timeserver_cleanup();
__connman_session_cleanup();
__connman_task_cleanup();
__connman_udev_cleanup();
#include "connman.h"
static GSList *driver_list = NULL;
+static GHashTable *server_hash = NULL;
static gint compare_priority(gconstpointer a, gconstpointer b)
{
*
* 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;
}
/**
*
* 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);
+}