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 DBusMessage *list_interfaces(DBusConnection *conn,
31 DBusMessage *msg, void *data)
34 DBusMessageIter array, iter;
38 reply = dbus_message_new_method_return(msg);
42 dbus_message_iter_init_append(reply, &array);
44 dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
45 DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
47 __connman_iface_list(&iter);
49 dbus_message_iter_close_container(&array, &iter);
54 static DBusMessage *get_state(DBusConnection *conn,
55 DBusMessage *msg, void *data)
62 reply = dbus_message_new_method_return(msg);
66 if (__connman_iface_is_connected() == TRUE)
71 dbus_message_append_args(reply, DBUS_TYPE_STRING, &state,
77 static DBusMessage *register_agent(DBusConnection *conn,
78 DBusMessage *msg, void *data)
81 const char *sender, *path;
85 sender = dbus_message_get_sender(msg);
87 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
90 reply = dbus_message_new_method_return(msg);
94 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
96 __connman_agent_register(sender, path);
101 static DBusMessage *unregister_agent(DBusConnection *conn,
102 DBusMessage *msg, void *data)
105 const char *sender, *path;
107 DBG("conn %p", conn);
109 sender = dbus_message_get_sender(msg);
111 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
114 reply = dbus_message_new_method_return(msg);
118 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
120 __connman_agent_unregister(sender, path);
125 static GDBusMethodTable manager_methods[] = {
126 { "ListInterfaces", "", "ao", list_interfaces },
127 { "GetState", "", "s", get_state },
128 { "RegisterAgent", "o", "", register_agent },
129 { "UnregisterAgent", "o", "", unregister_agent },
133 static GDBusSignalTable manager_signals[] = {
134 { "InterfaceAdded", "o" },
135 { "InterfaceRemoved", "o" },
136 { "StateChanged", "s" },
140 static DBusMessage *nm_sleep(DBusConnection *conn,
141 DBusMessage *msg, void *data)
145 DBG("conn %p", conn);
147 reply = dbus_message_new_method_return(msg);
151 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
156 static DBusMessage *nm_wake(DBusConnection *conn,
157 DBusMessage *msg, void *data)
161 DBG("conn %p", conn);
163 reply = dbus_message_new_method_return(msg);
167 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
173 NM_STATE_UNKNOWN = 0,
177 NM_STATE_DISCONNECTED
180 static DBusMessage *nm_state(DBusConnection *conn,
181 DBusMessage *msg, void *data)
186 DBG("conn %p", conn);
188 reply = dbus_message_new_method_return(msg);
192 if (__connman_iface_is_connected() == TRUE)
193 state = NM_STATE_CONNECTED;
195 state = NM_STATE_DISCONNECTED;
197 dbus_message_append_args(reply, DBUS_TYPE_UINT32, &state,
203 static GDBusMethodTable nm_methods[] = {
204 { "sleep", "", "", nm_sleep },
205 { "wake", "", "", nm_wake },
206 { "state", "", "u", nm_state },
210 static DBusConnection *connection = NULL;
211 static int nm_compat = 0;
213 int __connman_manager_init(DBusConnection *conn, int compat)
215 DBG("conn %p", conn);
217 connection = dbus_connection_ref(conn);
218 if (connection == NULL)
221 g_dbus_register_object(connection, CONNMAN_MANAGER_PATH, NULL, NULL);
223 g_dbus_register_interface(connection, CONNMAN_MANAGER_PATH,
224 CONNMAN_MANAGER_INTERFACE,
226 manager_signals, NULL);
229 g_dbus_register_object(connection, NM_PATH, NULL, NULL);
231 g_dbus_register_interface(connection, NM_PATH, NM_INTERFACE,
232 nm_methods, NULL, NULL);
240 void __connman_manager_cleanup(void)
242 DBG("conn %p", connection);
245 g_dbus_unregister_interface(connection, NM_PATH, NM_INTERFACE);
247 g_dbus_unregister_object(connection, NM_PATH);
250 g_dbus_unregister_interface(connection, CONNMAN_MANAGER_PATH,
251 CONNMAN_MANAGER_INTERFACE);
253 g_dbus_unregister_object(connection, CONNMAN_MANAGER_PATH);
255 dbus_connection_unref(connection);