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 GDBusMethodTable manager_methods[] = {
74 { "ListInterfaces", "", "ao", list_interfaces },
75 { "GetState", "", "s", get_state },
79 static GDBusSignalTable manager_signals[] = {
80 { "InterfaceAdded", "o" },
81 { "InterfaceRemoved", "o" },
82 { "StateChanged", "s" },
86 static DBusMessage *activate_device(DBusConnection *conn,
87 DBusMessage *msg, void *data)
94 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
97 DBG("device %s", path);
99 reply = dbus_message_new_method_return(msg);
103 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
108 static DBusMessage *set_wireless(DBusConnection *conn,
109 DBusMessage *msg, void *data)
114 DBG("conn %p", conn);
116 dbus_message_get_args(msg, NULL, DBUS_TYPE_BOOLEAN, &enabled,
119 reply = dbus_message_new_method_return(msg);
123 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
128 static DBusMessage *get_wireless(DBusConnection *conn,
129 DBusMessage *msg, void *data)
132 dbus_bool_t enabled = TRUE;
134 DBG("conn %p", conn);
136 reply = dbus_message_new_method_return(msg);
140 dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &enabled,
146 static DBusMessage *do_sleep(DBusConnection *conn,
147 DBusMessage *msg, void *data)
151 DBG("conn %p", conn);
153 reply = dbus_message_new_method_return(msg);
157 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
162 static DBusMessage *do_wake(DBusConnection *conn,
163 DBusMessage *msg, void *data)
167 DBG("conn %p", conn);
169 reply = dbus_message_new_method_return(msg);
173 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
179 NM_STATE_UNKNOWN = 0,
183 NM_STATE_DISCONNECTED
186 static DBusMessage *do_state(DBusConnection *conn,
187 DBusMessage *msg, void *data)
190 dbus_uint32_t state = NM_STATE_DISCONNECTED;
192 DBG("conn %p", conn);
194 reply = dbus_message_new_method_return(msg);
198 dbus_message_append_args(reply, DBUS_TYPE_UINT32, &state,
204 static GDBusMethodTable nm_methods[] = {
205 { "getDevices", "", "ao", list_interfaces },
206 { "setActiveDevice", "o", "", activate_device },
207 { "setWirelessEnabled", "b", "", set_wireless },
208 { "getWirelessEnabled", "", "b", get_wireless },
209 { "sleep", "", "", do_sleep },
210 { "wake", "", "", do_wake },
211 { "state", "", "u", do_state },
215 static DBusConnection *connection = NULL;
216 static int nm_compat = 0;
218 int __connman_manager_init(DBusConnection *conn, int compat)
220 DBG("conn %p", conn);
222 connection = dbus_connection_ref(conn);
223 if (connection == NULL)
226 g_dbus_register_object(connection, CONNMAN_MANAGER_PATH, NULL, NULL);
228 g_dbus_register_interface(connection, CONNMAN_MANAGER_PATH,
229 CONNMAN_MANAGER_INTERFACE,
231 manager_signals, NULL);
234 g_dbus_register_object(connection, NM_PATH, NULL, NULL);
236 g_dbus_register_interface(connection, NM_PATH, NM_INTERFACE,
237 nm_methods, NULL, NULL);
245 void __connman_manager_cleanup(void)
247 DBG("conn %p", connection);
250 g_dbus_unregister_interface(connection, NM_PATH, NM_INTERFACE);
252 g_dbus_unregister_object(connection, NM_PATH);
255 g_dbus_unregister_interface(connection, CONNMAN_MANAGER_PATH,
256 CONNMAN_MANAGER_INTERFACE);
258 g_dbus_unregister_object(connection, CONNMAN_MANAGER_PATH);
260 dbus_connection_unref(connection);