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 *register_agent(DBusConnection *conn,
31 DBusMessage *msg, void *data)
34 const char *sender, *path;
38 sender = dbus_message_get_sender(msg);
40 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
43 reply = dbus_message_new_method_return(msg);
47 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
49 __connman_agent_register(sender, path);
54 static DBusMessage *unregister_agent(DBusConnection *conn,
55 DBusMessage *msg, void *data)
58 const char *sender, *path;
62 sender = dbus_message_get_sender(msg);
64 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
67 reply = dbus_message_new_method_return(msg);
71 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
73 __connman_agent_unregister(sender, path);
78 static DBusMessage *list_elements(DBusConnection *conn,
79 DBusMessage *msg, void *data)
82 DBusMessageIter array, iter;
86 reply = dbus_message_new_method_return(msg);
90 dbus_message_iter_init_append(reply, &array);
92 dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
93 DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
95 __connman_element_list(CONNMAN_ELEMENT_TYPE_UNKNOWN, &iter);
97 dbus_message_iter_close_container(&array, &iter);
102 static DBusMessage *list_devices(DBusConnection *conn,
103 DBusMessage *msg, void *data)
106 DBusMessageIter array, iter;
108 DBG("conn %p", conn);
110 reply = dbus_message_new_method_return(msg);
114 dbus_message_iter_init_append(reply, &array);
116 dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
117 DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
119 __connman_element_list(CONNMAN_ELEMENT_TYPE_DEVICE, &iter);
121 dbus_message_iter_close_container(&array, &iter);
126 static GDBusMethodTable manager_methods[] = {
127 { "RegisterAgent", "o", "", register_agent },
128 { "UnregisterAgent", "o", "", unregister_agent },
130 { "ListElements", "", "ao", list_elements },
131 { "ListDevices", "", "ao", list_devices },
135 static GDBusSignalTable manager_signals[] = {
136 { "ElementAdded", "o" },
137 { "ElementUpdated", "o" },
138 { "ElementRemoved", "o" },
139 { "DeviceAdded", "o" },
140 { "DeviceRemoved", "o" },
144 static DBusMessage *nm_sleep(DBusConnection *conn,
145 DBusMessage *msg, void *data)
149 DBG("conn %p", conn);
151 reply = dbus_message_new_method_return(msg);
155 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
160 static DBusMessage *nm_wake(DBusConnection *conn,
161 DBusMessage *msg, void *data)
165 DBG("conn %p", conn);
167 reply = dbus_message_new_method_return(msg);
171 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
177 NM_STATE_UNKNOWN = 0,
181 NM_STATE_DISCONNECTED
184 static DBusMessage *nm_state(DBusConnection *conn,
185 DBusMessage *msg, void *data)
190 DBG("conn %p", conn);
192 reply = dbus_message_new_method_return(msg);
196 state = NM_STATE_DISCONNECTED;
198 dbus_message_append_args(reply, DBUS_TYPE_UINT32, &state,
204 static GDBusMethodTable nm_methods[] = {
205 { "sleep", "", "", nm_sleep },
206 { "wake", "", "", nm_wake },
207 { "state", "", "u", nm_state },
211 static DBusConnection *connection = NULL;
212 static gboolean nm_compat = FALSE;
214 int __connman_manager_init(DBusConnection *conn, gboolean compat)
216 DBG("conn %p", conn);
218 connection = dbus_connection_ref(conn);
219 if (connection == NULL)
222 g_dbus_register_interface(connection, CONNMAN_MANAGER_PATH,
223 CONNMAN_MANAGER_INTERFACE,
225 manager_signals, NULL, NULL, NULL);
227 if (compat == TRUE) {
228 g_dbus_register_interface(connection, NM_PATH, NM_INTERFACE,
229 nm_methods, NULL, NULL, NULL, NULL);
237 void __connman_manager_cleanup(void)
239 DBG("conn %p", connection);
241 if (nm_compat == TRUE) {
242 g_dbus_unregister_interface(connection, NM_PATH, NM_INTERFACE);
245 g_dbus_unregister_interface(connection, CONNMAN_MANAGER_PATH,
246 CONNMAN_MANAGER_INTERFACE);
248 dbus_connection_unref(connection);