1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
/*
*
* Connection Manager
*
* Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <gdbus.h>
#include "connman.h"
static char **timeservers_config = NULL;
static void append_timeservers(DBusMessageIter *iter, void *user_data)
{
int i;
if (timeservers_config == NULL)
return;
for (i = 0; timeservers_config[i] != NULL; i++) {
dbus_message_iter_append_basic(iter,
DBUS_TYPE_STRING, ×ervers_config[i]);
}
}
static DBusMessage *get_properties(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply;
DBusMessageIter array, dict;
DBG("conn %p", conn);
reply = dbus_message_new_method_return(msg);
if (reply == NULL)
return NULL;
dbus_message_iter_init_append(reply, &array);
connman_dbus_dict_open(&array, &dict);
connman_dbus_dict_append_array(&dict, "Timeservers",
DBUS_TYPE_STRING, append_timeservers, NULL);
connman_dbus_dict_close(&array, &dict);
return reply;
}
static DBusMessage *set_property(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessageIter iter, value;
const char *name;
int type;
DBG("conn %p", conn);
if (dbus_message_iter_init(msg, &iter) == FALSE)
return __connman_error_invalid_arguments(msg);
dbus_message_iter_get_basic(&iter, &name);
dbus_message_iter_next(&iter);
dbus_message_iter_recurse(&iter, &value);
type = dbus_message_iter_get_arg_type(&value);
if (g_str_equal(name, "Timeservers") == TRUE) {
DBusMessageIter entry;
GString *str;
if (type != DBUS_TYPE_ARRAY)
return __connman_error_invalid_arguments(msg);
str = g_string_new(NULL);
if (str == NULL)
return __connman_error_invalid_arguments(msg);
dbus_message_iter_recurse(&value, &entry);
while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
const char *val;
dbus_message_iter_get_basic(&entry, &val);
dbus_message_iter_next(&entry);
if (str->len > 0)
g_string_append_printf(str, " %s", val);
else
g_string_append(str, val);
}
g_strfreev(timeservers_config);
if (str->len > 0)
timeservers_config = g_strsplit_set(str->str, " ", 0);
else
timeservers_config = NULL;
g_string_free(str, TRUE);
connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH,
CONNMAN_CLOCK_INTERFACE, "Timeservers",
DBUS_TYPE_STRING, append_timeservers, NULL);
} else
return __connman_error_invalid_property(msg);
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
static GDBusMethodTable clock_methods[] = {
{ "GetProperties", "", "a{sv}", get_properties },
{ "SetProperty", "sv", "", set_property },
{ },
};
static GDBusSignalTable clock_signals[] = {
{ "PropertyChanged", "sv" },
{ },
};
static DBusConnection *connection = NULL;
int __connman_clock_init(void)
{
DBG("");
connection = connman_dbus_get_connection();
if (connection == NULL)
return -1;
g_dbus_register_interface(connection, CONNMAN_MANAGER_PATH,
CONNMAN_CLOCK_INTERFACE,
clock_methods, clock_signals,
NULL, NULL, NULL);
return 0;
}
void __connman_clock_cleanup(void)
{
DBG("");
if (connection == NULL)
return;
g_dbus_unregister_interface(connection, CONNMAN_MANAGER_PATH,
CONNMAN_CLOCK_INTERFACE);
dbus_connection_unref(connection);
g_strfreev(timeservers_config);
}
|