5 * Copyright (C) 2007-2008 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 void append_profiles(DBusMessageIter *dict)
32 DBusMessageIter entry, value, iter;
33 const char *key = "Profiles";
35 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
38 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
40 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
41 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
44 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
45 DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
47 __connman_profile_list(&iter);
49 dbus_message_iter_close_container(&value, &iter);
51 dbus_message_iter_close_container(&entry, &value);
53 dbus_message_iter_close_container(dict, &entry);
56 static void append_devices(DBusMessageIter *dict)
58 DBusMessageIter entry, value, iter;
59 const char *key = "Devices";
61 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
64 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
66 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
67 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
70 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
71 DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
73 __connman_element_list(NULL, CONNMAN_ELEMENT_TYPE_DEVICE, &iter);
75 dbus_message_iter_close_container(&value, &iter);
77 dbus_message_iter_close_container(&entry, &value);
79 dbus_message_iter_close_container(dict, &entry);
82 static void append_connections(DBusMessageIter *dict)
84 DBusMessageIter entry, value, iter;
85 const char *key = "Connections";
87 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
90 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
92 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
93 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
96 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
97 DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
99 __connman_element_list(NULL, CONNMAN_ELEMENT_TYPE_CONNECTION, &iter);
101 dbus_message_iter_close_container(&value, &iter);
103 dbus_message_iter_close_container(&entry, &value);
105 dbus_message_iter_close_container(dict, &entry);
108 static void append_state(DBusMessageIter *dict, const char *state)
110 DBusMessageIter entry, value;
111 const char *key = "State";
113 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
116 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
118 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
119 DBUS_TYPE_STRING_AS_STRING, &value);
121 dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &state);
123 dbus_message_iter_close_container(&entry, &value);
125 dbus_message_iter_close_container(dict, &entry);
128 static DBusMessage *get_properties(DBusConnection *conn,
129 DBusMessage *msg, void *data)
132 DBusMessageIter array, dict;
134 DBG("conn %p", conn);
136 reply = dbus_message_new_method_return(msg);
140 dbus_message_iter_init_append(reply, &array);
142 dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
143 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
144 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
145 DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
147 append_profiles(&dict);
149 append_devices(&dict);
150 append_connections(&dict);
152 if (__connman_element_count(NULL, CONNMAN_ELEMENT_TYPE_CONNECTION) > 0)
153 append_state(&dict, "online");
155 append_state(&dict, "offline");
157 dbus_message_iter_close_container(&array, &dict);
162 static DBusMessage *register_agent(DBusConnection *conn,
163 DBusMessage *msg, void *data)
166 const char *sender, *path;
168 DBG("conn %p", conn);
170 sender = dbus_message_get_sender(msg);
172 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
175 reply = dbus_message_new_method_return(msg);
179 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
181 __connman_agent_register(sender, path);
186 static DBusMessage *unregister_agent(DBusConnection *conn,
187 DBusMessage *msg, void *data)
190 const char *sender, *path;
192 DBG("conn %p", conn);
194 sender = dbus_message_get_sender(msg);
196 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
199 reply = dbus_message_new_method_return(msg);
203 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
205 __connman_agent_unregister(sender, path);
211 static DBusMessage *list_elements(DBusConnection *conn,
212 DBusMessage *msg, void *data)
215 DBusMessageIter array, iter;
217 DBG("conn %p", conn);
219 reply = dbus_message_new_method_return(msg);
223 dbus_message_iter_init_append(reply, &array);
225 dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
226 DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
228 __connman_element_list(CONNMAN_ELEMENT_TYPE_UNKNOWN, &iter);
230 dbus_message_iter_close_container(&array, &iter);
236 static GDBusMethodTable manager_methods[] = {
237 { "GetProperties", "", "a{sv}", get_properties },
238 { "RegisterAgent", "o", "", register_agent },
239 { "UnregisterAgent", "o", "", unregister_agent },
241 { "ListElements", "", "ao", list_elements },
246 static GDBusSignalTable manager_signals[] = {
247 { "PropertyChanged", "sv" },
249 { "ElementAdded", "o" },
250 { "ElementUpdated", "o" },
251 { "ElementRemoved", "o" },
256 static DBusMessage *nm_sleep(DBusConnection *conn,
257 DBusMessage *msg, void *data)
261 DBG("conn %p", conn);
263 reply = dbus_message_new_method_return(msg);
267 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
272 static DBusMessage *nm_wake(DBusConnection *conn,
273 DBusMessage *msg, void *data)
277 DBG("conn %p", conn);
279 reply = dbus_message_new_method_return(msg);
283 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
289 NM_STATE_UNKNOWN = 0,
293 NM_STATE_DISCONNECTED
296 static DBusMessage *nm_state(DBusConnection *conn,
297 DBusMessage *msg, void *data)
302 DBG("conn %p", conn);
304 reply = dbus_message_new_method_return(msg);
308 state = NM_STATE_DISCONNECTED;
310 dbus_message_append_args(reply, DBUS_TYPE_UINT32, &state,
316 static GDBusMethodTable nm_methods[] = {
317 { "sleep", "", "", nm_sleep },
318 { "wake", "", "", nm_wake },
319 { "state", "", "u", nm_state },
323 static DBusConnection *connection = NULL;
324 static gboolean nm_compat = FALSE;
326 int __connman_manager_init(DBusConnection *conn, gboolean compat)
328 DBG("conn %p", conn);
330 connection = dbus_connection_ref(conn);
331 if (connection == NULL)
334 g_dbus_register_interface(connection, CONNMAN_MANAGER_PATH,
335 CONNMAN_MANAGER_INTERFACE,
337 manager_signals, NULL, NULL, NULL);
339 if (compat == TRUE) {
340 g_dbus_register_interface(connection, NM_PATH, NM_INTERFACE,
341 nm_methods, NULL, NULL, NULL, NULL);
349 void __connman_manager_cleanup(void)
351 DBG("conn %p", connection);
353 if (nm_compat == TRUE) {
354 g_dbus_unregister_interface(connection, NM_PATH, NM_INTERFACE);
357 g_dbus_unregister_interface(connection, CONNMAN_MANAGER_PATH,
358 CONNMAN_MANAGER_INTERFACE);
360 dbus_connection_unref(connection);