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_elements(DBusMessageIter *dict)
32 DBusMessageIter entry, value, iter;
33 const char *key = "Elements";
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_element_list(CONNMAN_ELEMENT_TYPE_UNKNOWN, &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 DBusMessage *get_properties(DBusConnection *conn,
57 DBusMessage *msg, void *data)
60 DBusMessageIter array, dict;
64 reply = dbus_message_new_method_return(msg);
68 dbus_message_iter_init_append(reply, &array);
70 dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
71 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
72 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
73 DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
75 append_elements(&dict);
77 dbus_message_iter_close_container(&array, &dict);
82 static DBusMessage *register_agent(DBusConnection *conn,
83 DBusMessage *msg, void *data)
86 const char *sender, *path;
90 sender = dbus_message_get_sender(msg);
92 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
95 reply = dbus_message_new_method_return(msg);
99 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
101 __connman_agent_register(sender, path);
106 static DBusMessage *unregister_agent(DBusConnection *conn,
107 DBusMessage *msg, void *data)
110 const char *sender, *path;
112 DBG("conn %p", conn);
114 sender = dbus_message_get_sender(msg);
116 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
119 reply = dbus_message_new_method_return(msg);
123 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
125 __connman_agent_unregister(sender, path);
130 static DBusMessage *list_profiles(DBusConnection *conn,
131 DBusMessage *msg, void *data)
134 DBusMessageIter array, iter;
136 DBG("conn %p", conn);
138 reply = dbus_message_new_method_return(msg);
142 dbus_message_iter_init_append(reply, &array);
144 dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
145 DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
147 __connman_profile_list(&iter);
149 dbus_message_iter_close_container(&array, &iter);
154 static DBusMessage *list_elements(DBusConnection *conn,
155 DBusMessage *msg, void *data)
158 DBusMessageIter array, iter;
160 DBG("conn %p", conn);
162 reply = dbus_message_new_method_return(msg);
166 dbus_message_iter_init_append(reply, &array);
168 dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
169 DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
171 __connman_element_list(CONNMAN_ELEMENT_TYPE_UNKNOWN, &iter);
173 dbus_message_iter_close_container(&array, &iter);
178 static GDBusMethodTable manager_methods[] = {
179 { "GetProperties", "", "a{sv}", get_properties },
180 { "RegisterAgent", "o", "", register_agent },
181 { "UnregisterAgent", "o", "", unregister_agent },
182 { "ListProfiles", "", "ao", list_profiles },
183 { "ListElements", "", "ao", list_elements },
187 static GDBusSignalTable manager_signals[] = {
188 { "PropertyChanged", "sv" },
189 { "ElementAdded", "o" },
190 { "ElementUpdated", "o" },
191 { "ElementRemoved", "o" },
195 static DBusMessage *nm_sleep(DBusConnection *conn,
196 DBusMessage *msg, void *data)
200 DBG("conn %p", conn);
202 reply = dbus_message_new_method_return(msg);
206 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
211 static DBusMessage *nm_wake(DBusConnection *conn,
212 DBusMessage *msg, void *data)
216 DBG("conn %p", conn);
218 reply = dbus_message_new_method_return(msg);
222 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
228 NM_STATE_UNKNOWN = 0,
232 NM_STATE_DISCONNECTED
235 static DBusMessage *nm_state(DBusConnection *conn,
236 DBusMessage *msg, void *data)
241 DBG("conn %p", conn);
243 reply = dbus_message_new_method_return(msg);
247 state = NM_STATE_DISCONNECTED;
249 dbus_message_append_args(reply, DBUS_TYPE_UINT32, &state,
255 static GDBusMethodTable nm_methods[] = {
256 { "sleep", "", "", nm_sleep },
257 { "wake", "", "", nm_wake },
258 { "state", "", "u", nm_state },
262 static DBusConnection *connection = NULL;
263 static gboolean nm_compat = FALSE;
265 int __connman_manager_init(DBusConnection *conn, gboolean compat)
267 DBG("conn %p", conn);
269 connection = dbus_connection_ref(conn);
270 if (connection == NULL)
273 g_dbus_register_interface(connection, CONNMAN_MANAGER_PATH,
274 CONNMAN_MANAGER_INTERFACE,
276 manager_signals, NULL, NULL, NULL);
278 if (compat == TRUE) {
279 g_dbus_register_interface(connection, NM_PATH, NM_INTERFACE,
280 nm_methods, NULL, NULL, NULL, NULL);
288 void __connman_manager_cleanup(void)
290 DBG("conn %p", connection);
292 if (nm_compat == TRUE) {
293 g_dbus_unregister_interface(connection, NM_PATH, NM_INTERFACE);
296 g_dbus_unregister_interface(connection, CONNMAN_MANAGER_PATH,
297 CONNMAN_MANAGER_INTERFACE);
299 dbus_connection_unref(connection);