3 * oFono - Open Source Telephony
5 * Copyright (C) 2008-2011 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
32 static void append_modem(struct ofono_modem *modem, void *userdata)
34 DBusMessageIter *array = userdata;
35 const char *path = ofono_modem_get_path(modem);
36 DBusMessageIter entry, dict;
38 if (ofono_modem_is_registered(modem) == FALSE)
41 dbus_message_iter_open_container(array, DBUS_TYPE_STRUCT,
43 dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
45 dbus_message_iter_open_container(&entry, DBUS_TYPE_ARRAY,
46 OFONO_PROPERTIES_ARRAY_SIGNATURE,
49 __ofono_modem_append_properties(modem, &dict);
50 dbus_message_iter_close_container(&entry, &dict);
51 dbus_message_iter_close_container(array, &entry);
54 static DBusMessage *manager_get_modems(DBusConnection *conn,
55 DBusMessage *msg, void *data)
59 DBusMessageIter array;
61 reply = dbus_message_new_method_return(msg);
65 dbus_message_iter_init_append(reply, &iter);
67 dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
68 DBUS_STRUCT_BEGIN_CHAR_AS_STRING
69 DBUS_TYPE_OBJECT_PATH_AS_STRING
70 DBUS_TYPE_ARRAY_AS_STRING
71 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
72 DBUS_TYPE_STRING_AS_STRING
73 DBUS_TYPE_VARIANT_AS_STRING
74 DBUS_DICT_ENTRY_END_CHAR_AS_STRING
75 DBUS_STRUCT_END_CHAR_AS_STRING,
77 __ofono_modem_foreach(append_modem, &array);
78 dbus_message_iter_close_container(&iter, &array);
83 static const GDBusMethodTable manager_methods[] = {
84 { GDBUS_METHOD("GetModems",
85 NULL, GDBUS_ARGS({ "modems", "a(oa{sv})" }),
86 manager_get_modems) },
90 static const GDBusSignalTable manager_signals[] = {
91 { GDBUS_SIGNAL("ModemAdded",
92 GDBUS_ARGS({ "path", "o" }, { "properties", "a{sv}" })) },
93 { GDBUS_SIGNAL("ModemRemoved",
94 GDBUS_ARGS({ "path", "o" })) },
98 int __ofono_manager_init(void)
100 DBusConnection *conn = ofono_dbus_get_connection();
103 ret = g_dbus_register_interface(conn, OFONO_MANAGER_PATH,
104 OFONO_MANAGER_INTERFACE,
105 manager_methods, manager_signals,
114 void __ofono_manager_cleanup(void)
116 DBusConnection *conn = ofono_dbus_get_connection();
118 g_dbus_unregister_interface(conn, OFONO_MANAGER_PATH,
119 OFONO_MANAGER_INTERFACE);