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 veasion 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
36 static GSList *g_drivers = NULL;
38 struct ofono_audio_settings {
41 const struct ofono_audio_settings_driver *driver;
43 struct ofono_atom *atom;
46 void ofono_audio_settings_active_notify(struct ofono_audio_settings *as,
49 const char *path = __ofono_atom_get_path(as->atom);
50 DBusConnection *conn = ofono_dbus_get_connection();
52 if (as->active == active)
55 DBG("active %d", active);
59 ofono_dbus_signal_property_changed(conn, path,
60 OFONO_AUDIO_SETTINGS_INTERFACE,
61 "Active", DBUS_TYPE_BOOLEAN, &as->active);
65 void ofono_audio_settings_mode_notify(struct ofono_audio_settings *as,
68 const char *path = __ofono_atom_get_path(as->atom);
69 DBusConnection *conn = ofono_dbus_get_connection();
74 as->mode = g_strdup(mode);
79 ofono_dbus_signal_property_changed(conn, path,
80 OFONO_AUDIO_SETTINGS_INTERFACE,
81 "Mode", DBUS_TYPE_STRING, &as->mode);
84 static DBusMessage *audio_get_properties_reply(DBusMessage *msg,
85 struct ofono_audio_settings *as)
91 reply = dbus_message_new_method_return(msg);
95 dbus_message_iter_init_append(reply, &iter);
97 dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
98 OFONO_PROPERTIES_ARRAY_SIGNATURE,
101 ofono_dbus_dict_append(&dict, "Active", DBUS_TYPE_BOOLEAN, &as->active);
104 ofono_dbus_dict_append(&dict, "Mode",
105 DBUS_TYPE_STRING, &as->mode);
107 dbus_message_iter_close_container(&iter, &dict);
112 static DBusMessage *audio_get_properties(DBusConnection *conn,
113 DBusMessage *msg, void *data)
115 struct ofono_audio_settings *as = data;
117 return audio_get_properties_reply(msg, as);
120 static const GDBusMethodTable audio_methods[] = {
121 { GDBUS_ASYNC_METHOD("GetProperties",
122 NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
123 audio_get_properties) },
127 static const GDBusSignalTable audio_signals[] = {
128 { GDBUS_SIGNAL("PropertyChanged",
129 GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
133 int ofono_audio_settings_driver_register(const struct ofono_audio_settings_driver *d)
135 DBG("driver: %p, name: %s", d, d->name);
137 if (d->probe == NULL)
140 g_drivers = g_slist_prepend(g_drivers, (void *) d);
145 void ofono_audio_settings_driver_unregister(const struct ofono_audio_settings_driver *d)
147 DBG("driver: %p, name: %s", d, d->name);
149 g_drivers = g_slist_remove(g_drivers, (void *) d);
152 static void audio_settings_unregister(struct ofono_atom *atom)
154 struct ofono_audio_settings *as = __ofono_atom_get_data(atom);
155 const char *path = __ofono_atom_get_path(as->atom);
156 DBusConnection *conn = ofono_dbus_get_connection();
157 struct ofono_modem *modem = __ofono_atom_get_modem(as->atom);
159 ofono_modem_remove_interface(modem, OFONO_AUDIO_SETTINGS_INTERFACE);
160 g_dbus_unregister_interface(conn, path, OFONO_AUDIO_SETTINGS_INTERFACE);
163 static void audio_settings_remove(struct ofono_atom *atom)
165 struct ofono_audio_settings *as = __ofono_atom_get_data(atom);
167 DBG("atom: %p", atom);
172 if (as->driver && as->driver->remove)
173 as->driver->remove(as);
179 struct ofono_audio_settings *ofono_audio_settings_create(struct ofono_modem *modem,
184 struct ofono_audio_settings *as;
190 as = g_try_new0(struct ofono_audio_settings, 1);
194 as->atom = __ofono_modem_add_atom(modem, OFONO_ATOM_TYPE_AUDIO_SETTINGS,
195 audio_settings_remove, as);
197 for (l = g_drivers; l; l = l->next) {
198 const struct ofono_audio_settings_driver *drv = l->data;
200 if (g_strcmp0(drv->name, driver) != 0)
203 if (drv->probe(as, vendor, data) < 0)
213 void ofono_audio_settings_register(struct ofono_audio_settings *as)
215 DBusConnection *conn = ofono_dbus_get_connection();
216 struct ofono_modem *modem = __ofono_atom_get_modem(as->atom);
217 const char *path = __ofono_atom_get_path(as->atom);
219 if (!g_dbus_register_interface(conn, path,
220 OFONO_AUDIO_SETTINGS_INTERFACE,
221 audio_methods, audio_signals,
223 ofono_error("Could not create %s interface",
224 OFONO_AUDIO_SETTINGS_INTERFACE);
229 ofono_modem_add_interface(modem, OFONO_AUDIO_SETTINGS_INTERFACE);
230 __ofono_atom_register(as->atom, audio_settings_unregister);
233 void ofono_audio_settings_remove(struct ofono_audio_settings *as)
235 __ofono_atom_free(as->atom);
238 void ofono_audio_settings_set_data(struct ofono_audio_settings *as, void *data)
240 as->driver_data = data;
243 void *ofono_audio_settings_get_data(struct ofono_audio_settings *as)
245 return as->driver_data;
248 struct ofono_modem *ofono_audio_settings_get_modem(struct ofono_audio_settings *as)
250 return __ofono_atom_get_modem(as->atom);