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 char **timeservers_config = NULL;
32 static void append_timeservers(DBusMessageIter *iter, void *user_data)
36 if (timeservers_config == NULL)
39 for (i = 0; timeservers_config[i] != NULL; i++) {
40 dbus_message_iter_append_basic(iter,
41 DBUS_TYPE_STRING, ×ervers_config[i]);
45 static DBusMessage *get_properties(DBusConnection *conn,
46 DBusMessage *msg, void *data)
49 DBusMessageIter array, dict;
53 reply = dbus_message_new_method_return(msg);
57 dbus_message_iter_init_append(reply, &array);
59 connman_dbus_dict_open(&array, &dict);
61 connman_dbus_dict_append_array(&dict, "Timeservers",
62 DBUS_TYPE_STRING, append_timeservers, NULL);
64 connman_dbus_dict_close(&array, &dict);
69 static DBusMessage *set_property(DBusConnection *conn,
70 DBusMessage *msg, void *data)
72 DBusMessageIter iter, value;
78 if (dbus_message_iter_init(msg, &iter) == FALSE)
79 return __connman_error_invalid_arguments(msg);
81 dbus_message_iter_get_basic(&iter, &name);
82 dbus_message_iter_next(&iter);
83 dbus_message_iter_recurse(&iter, &value);
85 type = dbus_message_iter_get_arg_type(&value);
87 if (g_str_equal(name, "Timeservers") == TRUE) {
88 DBusMessageIter entry;
91 if (type != DBUS_TYPE_ARRAY)
92 return __connman_error_invalid_arguments(msg);
94 str = g_string_new(NULL);
96 return __connman_error_invalid_arguments(msg);
98 dbus_message_iter_recurse(&value, &entry);
100 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
103 dbus_message_iter_get_basic(&entry, &val);
104 dbus_message_iter_next(&entry);
107 g_string_append_printf(str, " %s", val);
109 g_string_append(str, val);
112 g_strfreev(timeservers_config);
115 timeservers_config = g_strsplit_set(str->str, " ", 0);
117 timeservers_config = NULL;
119 g_string_free(str, TRUE);
121 connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH,
122 CONNMAN_CLOCK_INTERFACE, "Timeservers",
123 DBUS_TYPE_STRING, append_timeservers, NULL);
125 return __connman_error_invalid_property(msg);
127 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
130 static GDBusMethodTable clock_methods[] = {
131 { "GetProperties", "", "a{sv}", get_properties },
132 { "SetProperty", "sv", "", set_property },
136 static GDBusSignalTable clock_signals[] = {
137 { "PropertyChanged", "sv" },
141 static DBusConnection *connection = NULL;
143 int __connman_clock_init(void)
147 connection = connman_dbus_get_connection();
148 if (connection == NULL)
151 g_dbus_register_interface(connection, CONNMAN_MANAGER_PATH,
152 CONNMAN_CLOCK_INTERFACE,
153 clock_methods, clock_signals,
159 void __connman_clock_cleanup(void)
163 if (connection == NULL)
166 g_dbus_unregister_interface(connection, CONNMAN_MANAGER_PATH,
167 CONNMAN_CLOCK_INTERFACE);
169 dbus_connection_unref(connection);
171 g_strfreev(timeservers_config);