5 * Copyright (C) 2007 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 const char *master_state = "unknown";
32 static DBusMessage *list_interfaces(DBusConnection *conn,
33 DBusMessage *msg, void *data)
36 DBusMessageIter array, iter;
40 reply = dbus_message_new_method_return(msg);
44 dbus_message_iter_init_append(reply, &array);
46 dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
47 DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
49 __connman_iface_list(&iter);
51 dbus_message_iter_close_container(&array, &iter);
56 static DBusMessage *get_state(DBusConnection *conn,
57 DBusMessage *msg, void *data)
63 reply = dbus_message_new_method_return(msg);
67 dbus_message_append_args(reply, DBUS_TYPE_STRING, &master_state,
73 static DBusMessage *register_agent(DBusConnection *conn,
74 DBusMessage *msg, void *data)
77 const char *sender, *path;
81 sender = dbus_message_get_sender(msg);
83 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
86 reply = dbus_message_new_method_return(msg);
90 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
92 __connman_agent_register(sender, path);
97 static DBusMessage *unregister_agent(DBusConnection *conn,
98 DBusMessage *msg, void *data)
101 const char *sender, *path;
103 DBG("conn %p", conn);
105 sender = dbus_message_get_sender(msg);
107 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
110 reply = dbus_message_new_method_return(msg);
114 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
116 __connman_agent_unregister(sender, path);
121 static GDBusMethodTable manager_methods[] = {
122 { "ListInterfaces", "", "ao", list_interfaces },
123 { "GetState", "", "s", get_state },
124 { "RegisterAgent", "o", "", register_agent },
125 { "UnregisterAgent", "o", "", unregister_agent },
129 static GDBusSignalTable manager_signals[] = {
130 { "InterfaceAdded", "o" },
131 { "InterfaceRemoved", "o" },
132 { "StateChanged", "s" },
136 static DBusMessage *activate_device(DBusConnection *conn,
137 DBusMessage *msg, void *data)
142 DBG("conn %p", conn);
144 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
147 DBG("device %s", path);
149 reply = dbus_message_new_method_return(msg);
153 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
158 static DBusMessage *set_wireless(DBusConnection *conn,
159 DBusMessage *msg, void *data)
164 DBG("conn %p", conn);
166 dbus_message_get_args(msg, NULL, DBUS_TYPE_BOOLEAN, &enabled,
169 reply = dbus_message_new_method_return(msg);
173 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
178 static DBusMessage *get_wireless(DBusConnection *conn,
179 DBusMessage *msg, void *data)
182 dbus_bool_t enabled = TRUE;
184 DBG("conn %p", conn);
186 reply = dbus_message_new_method_return(msg);
190 dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &enabled,
196 static DBusMessage *do_sleep(DBusConnection *conn,
197 DBusMessage *msg, void *data)
201 DBG("conn %p", conn);
203 reply = dbus_message_new_method_return(msg);
207 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
212 static DBusMessage *do_wake(DBusConnection *conn,
213 DBusMessage *msg, void *data)
217 DBG("conn %p", conn);
219 reply = dbus_message_new_method_return(msg);
223 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
229 NM_STATE_UNKNOWN = 0,
233 NM_STATE_DISCONNECTED
236 static DBusMessage *do_state(DBusConnection *conn,
237 DBusMessage *msg, void *data)
240 dbus_uint32_t state = NM_STATE_DISCONNECTED;
242 DBG("conn %p", conn);
244 reply = dbus_message_new_method_return(msg);
248 dbus_message_append_args(reply, DBUS_TYPE_UINT32, &state,
254 static GDBusMethodTable nm_methods[] = {
255 { "getDevices", "", "ao", list_interfaces },
256 { "setActiveDevice", "o", "", activate_device },
257 { "setWirelessEnabled", "b", "", set_wireless },
258 { "getWirelessEnabled", "", "b", get_wireless },
259 { "sleep", "", "", do_sleep },
260 { "wake", "", "", do_wake },
261 { "state", "", "u", do_state },
265 static DBusConnection *connection = NULL;
266 static int nm_compat = 0;
268 int __connman_manager_init(DBusConnection *conn, int compat)
270 DBG("conn %p", conn);
272 connection = dbus_connection_ref(conn);
273 if (connection == NULL)
276 g_dbus_register_object(connection, CONNMAN_MANAGER_PATH, NULL, NULL);
278 g_dbus_register_interface(connection, CONNMAN_MANAGER_PATH,
279 CONNMAN_MANAGER_INTERFACE,
281 manager_signals, NULL);
284 g_dbus_register_object(connection, NM_PATH, NULL, NULL);
286 g_dbus_register_interface(connection, NM_PATH, NM_INTERFACE,
287 nm_methods, NULL, NULL);
295 void __connman_manager_cleanup(void)
297 DBG("conn %p", connection);
300 g_dbus_unregister_interface(connection, NM_PATH, NM_INTERFACE);
302 g_dbus_unregister_object(connection, NM_PATH);
305 g_dbus_unregister_interface(connection, CONNMAN_MANAGER_PATH,
306 CONNMAN_MANAGER_INTERFACE);
308 g_dbus_unregister_object(connection, CONNMAN_MANAGER_PATH);
310 dbus_connection_unref(connection);