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)
81 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
84 reply = dbus_message_new_method_return(msg);
88 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
90 __connman_agent_register(path);
95 static DBusMessage *unregister_agent(DBusConnection *conn,
96 DBusMessage *msg, void *data)
101 DBG("conn %p", conn);
103 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
106 reply = dbus_message_new_method_return(msg);
110 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
112 __connman_agent_unregister(path);
117 static GDBusMethodTable manager_methods[] = {
118 { "ListInterfaces", "", "ao", list_interfaces },
119 { "GetState", "", "s", get_state },
120 { "RegisterAgent", "o", "", register_agent },
121 { "UnregisterAgent", "o", "", unregister_agent },
125 static GDBusSignalTable manager_signals[] = {
126 { "InterfaceAdded", "o" },
127 { "InterfaceRemoved", "o" },
128 { "StateChanged", "s" },
132 static DBusMessage *activate_device(DBusConnection *conn,
133 DBusMessage *msg, void *data)
138 DBG("conn %p", conn);
140 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
143 DBG("device %s", path);
145 reply = dbus_message_new_method_return(msg);
149 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
154 static DBusMessage *set_wireless(DBusConnection *conn,
155 DBusMessage *msg, void *data)
160 DBG("conn %p", conn);
162 dbus_message_get_args(msg, NULL, DBUS_TYPE_BOOLEAN, &enabled,
165 reply = dbus_message_new_method_return(msg);
169 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
174 static DBusMessage *get_wireless(DBusConnection *conn,
175 DBusMessage *msg, void *data)
178 dbus_bool_t enabled = TRUE;
180 DBG("conn %p", conn);
182 reply = dbus_message_new_method_return(msg);
186 dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &enabled,
192 static DBusMessage *do_sleep(DBusConnection *conn,
193 DBusMessage *msg, void *data)
197 DBG("conn %p", conn);
199 reply = dbus_message_new_method_return(msg);
203 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
208 static DBusMessage *do_wake(DBusConnection *conn,
209 DBusMessage *msg, void *data)
213 DBG("conn %p", conn);
215 reply = dbus_message_new_method_return(msg);
219 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
225 NM_STATE_UNKNOWN = 0,
229 NM_STATE_DISCONNECTED
232 static DBusMessage *do_state(DBusConnection *conn,
233 DBusMessage *msg, void *data)
236 dbus_uint32_t state = NM_STATE_DISCONNECTED;
238 DBG("conn %p", conn);
240 reply = dbus_message_new_method_return(msg);
244 dbus_message_append_args(reply, DBUS_TYPE_UINT32, &state,
250 static GDBusMethodTable nm_methods[] = {
251 { "getDevices", "", "ao", list_interfaces },
252 { "setActiveDevice", "o", "", activate_device },
253 { "setWirelessEnabled", "b", "", set_wireless },
254 { "getWirelessEnabled", "", "b", get_wireless },
255 { "sleep", "", "", do_sleep },
256 { "wake", "", "", do_wake },
257 { "state", "", "u", do_state },
261 static DBusConnection *connection = NULL;
262 static int nm_compat = 0;
264 int __connman_manager_init(DBusConnection *conn, int compat)
266 DBG("conn %p", conn);
268 connection = dbus_connection_ref(conn);
269 if (connection == NULL)
272 g_dbus_register_object(connection, CONNMAN_MANAGER_PATH, NULL, NULL);
274 g_dbus_register_interface(connection, CONNMAN_MANAGER_PATH,
275 CONNMAN_MANAGER_INTERFACE,
277 manager_signals, NULL);
280 g_dbus_register_object(connection, NM_PATH, NULL, NULL);
282 g_dbus_register_interface(connection, NM_PATH, NM_INTERFACE,
283 nm_methods, NULL, NULL);
291 void __connman_manager_cleanup(void)
293 DBG("conn %p", connection);
296 g_dbus_unregister_interface(connection, NM_PATH, NM_INTERFACE);
298 g_dbus_unregister_object(connection, NM_PATH);
301 g_dbus_unregister_interface(connection, CONNMAN_MANAGER_PATH,
302 CONNMAN_MANAGER_INTERFACE);
304 g_dbus_unregister_object(connection, CONNMAN_MANAGER_PATH);
306 dbus_connection_unref(connection);