core: Add support for audio settings interface

This commit is contained in:
Marcel Holtmann 2010-09-29 23:57:39 +09:00
parent 462d79b5fe
commit 760e1e4c04
5 changed files with 288 additions and 4 deletions

View File

@ -13,7 +13,7 @@ include_HEADERS = include/log.h include/plugin.h include/history.h \
include/cbs.h include/call-volume.h \
include/gprs.h include/gprs-context.h \
include/radio-settings.h include/stk.h \
include/nettime.h
include/audio-settings.h include/nettime.h
nodist_include_HEADERS = include/version.h
@ -299,7 +299,7 @@ src_ofonod_SOURCES = $(gdbus_sources) $(builtin_sources) src/ofono.ver \
src/gprs.c src/idmap.h src/idmap.c \
src/radio-settings.c src/stkutil.h src/stkutil.c \
src/nettime.c src/stkagent.c src/stkagent.h \
src/simfs.c src/simfs.h
src/simfs.c src/simfs.h src/audio-settings.c
src_ofonod_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl

59
include/audio-settings.h Normal file
View File

@ -0,0 +1,59 @@
/*
*
* oFono - Open Source Telephony
*
* Copyright (C) 2008-2010 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef __OFONO_AUDIO_SETTINGS_H
#define __OFONO_AUDIO_SETTINGS_H
#ifdef __cplusplus
extern "C" {
#endif
#include <ofono/types.h>
struct ofono_audio_settings;
struct ofono_audio_settings_driver {
const char *name;
int (*probe)(struct ofono_audio_settings *as,
unsigned int vendor, void *data);
void (*remove)(struct ofono_audio_settings *as);
};
void ofono_audio_settings_notify(struct ofono_audio_settings *as,
ofono_bool_t active);
int ofono_audio_settings_driver_register(const struct ofono_audio_settings_driver *d);
void ofono_audio_settings_driver_unregister(const struct ofono_audio_settings_driver *d);
struct ofono_audio_settings *ofono_audio_settings_create(struct ofono_modem *modem,
unsigned int vendor, const char *driver, void *data);
void ofono_audio_settings_register(struct ofono_audio_settings *as);
void ofono_audio_settings_remove(struct ofono_audio_settings *as);
void ofono_audio_settings_set_data(struct ofono_audio_settings *as, void *data);
void *ofono_audio_settings_get_data(struct ofono_audio_settings *as);
#ifdef __cplusplus
}
#endif
#endif /* __OFONO_AUDIO_SETTINGS_H */

View File

@ -47,6 +47,7 @@ extern "C" {
#define OFONO_NETWORK_OPERATOR_INTERFACE "org.ofono.NetworkOperator"
#define OFONO_PHONEBOOK_INTERFACE "org.ofono.Phonebook"
#define OFONO_RADIO_SETTINGS_INTERFACE "org.ofono.RadioSettings"
#define OFONO_AUDIO_SETTINGS_INTERFACE "org.ofono.AudioSettings"
#define OFONO_SIM_MANAGER_INTERFACE "org.ofono.SimManager"
#define OFONO_VOICECALL_INTERFACE "org.ofono.VoiceCall"
#define OFONO_VOICECALL_MANAGER_INTERFACE "org.ofono.VoiceCallManager"

222
src/audio-settings.c Normal file
View File

@ -0,0 +1,222 @@
/*
*
* oFono - Open Source Telephony
*
* Copyright (C) 2008-2010 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License veasion 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <glib.h>
#include <gdbus.h>
#include "ofono.h"
#include "common.h"
static GSList *g_drivers = NULL;
struct ofono_audio_settings {
ofono_bool_t active;
const struct ofono_audio_settings_driver *driver;
void *driver_data;
struct ofono_atom *atom;
};
void ofono_audio_settings_notify(struct ofono_audio_settings *as,
ofono_bool_t active)
{
const char *path = __ofono_atom_get_path(as->atom);
DBusConnection *conn = ofono_dbus_get_connection();
if (as->active == active)
return;
DBG("active %d", active);
as->active = active;
ofono_dbus_signal_property_changed(conn, path,
OFONO_AUDIO_SETTINGS_INTERFACE,
"Active", DBUS_TYPE_BOOLEAN, &as->active);
}
static DBusMessage *audio_get_properties_reply(DBusMessage *msg,
struct ofono_audio_settings *as)
{
DBusMessage *reply;
DBusMessageIter iter;
DBusMessageIter dict;
reply = dbus_message_new_method_return(msg);
if (!reply)
return NULL;
dbus_message_iter_init_append(reply, &iter);
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
OFONO_PROPERTIES_ARRAY_SIGNATURE,
&dict);
ofono_dbus_dict_append(&dict, "Active", DBUS_TYPE_BOOLEAN, &as->active);
dbus_message_iter_close_container(&iter, &dict);
return reply;
}
static DBusMessage *audio_get_properties(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct ofono_audio_settings *as = data;
return audio_get_properties_reply(msg, as);
}
static GDBusMethodTable audio_methods[] = {
{ "GetProperties", "", "a{sv}", audio_get_properties,
G_DBUS_METHOD_FLAG_ASYNC },
{ }
};
static GDBusSignalTable audio_signals[] = {
{ "PropertyChanged", "sv" },
{ }
};
int ofono_audio_settings_driver_register(const struct ofono_audio_settings_driver *d)
{
DBG("driver: %p, name: %s", d, d->name);
if (!d || !d->probe)
return -EINVAL;
g_drivers = g_slist_prepend(g_drivers, (void *)d);
return 0;
}
void ofono_audio_settings_driver_unregister(const struct ofono_audio_settings_driver *d)
{
DBG("driver: %p, name: %s", d, d->name);
if (!d)
return;
g_drivers = g_slist_remove(g_drivers, (void *)d);
}
static void audio_settings_unregister(struct ofono_atom *atom)
{
struct ofono_audio_settings *as = __ofono_atom_get_data(atom);
const char *path = __ofono_atom_get_path(as->atom);
DBusConnection *conn = ofono_dbus_get_connection();
struct ofono_modem *modem = __ofono_atom_get_modem(as->atom);
ofono_modem_remove_interface(modem, OFONO_AUDIO_SETTINGS_INTERFACE);
g_dbus_unregister_interface(conn, path, OFONO_AUDIO_SETTINGS_INTERFACE);
}
static void audio_settings_remove(struct ofono_atom *atom)
{
struct ofono_audio_settings *as = __ofono_atom_get_data(atom);
DBG("atom: %p", atom);
if (!as)
return;
if (as->driver && as->driver->remove)
as->driver->remove(as);
g_free(as);
}
struct ofono_audio_settings *ofono_audio_settings_create(struct ofono_modem *modem,
unsigned int vendor,
const char *driver,
void *data)
{
struct ofono_audio_settings *as;
GSList *l;
if (!driver)
return NULL;
as = g_try_new0(struct ofono_audio_settings, 1);
if (!as)
return NULL;
as->atom = __ofono_modem_add_atom(modem, OFONO_ATOM_TYPE_AUDIO_SETTINGS,
audio_settings_remove, as);
for (l = g_drivers; l; l = l->next) {
const struct ofono_audio_settings_driver *drv = l->data;
if (g_strcmp0(drv->name, driver) != 0)
continue;
if (drv->probe(as, vendor, data) < 0)
continue;
as->driver = drv;
break;
}
return as;
}
void ofono_audio_settings_register(struct ofono_audio_settings *as)
{
DBusConnection *conn = ofono_dbus_get_connection();
struct ofono_modem *modem = __ofono_atom_get_modem(as->atom);
const char *path = __ofono_atom_get_path(as->atom);
if (!g_dbus_register_interface(conn, path,
OFONO_AUDIO_SETTINGS_INTERFACE,
audio_methods, audio_signals,
NULL, as, NULL)) {
ofono_error("Could not create %s interface",
OFONO_AUDIO_SETTINGS_INTERFACE);
return;
}
ofono_modem_add_interface(modem, OFONO_AUDIO_SETTINGS_INTERFACE);
__ofono_atom_register(as->atom, audio_settings_unregister);
}
void ofono_audio_settings_remove(struct ofono_audio_settings *as)
{
__ofono_atom_free(as->atom);
}
void ofono_audio_settings_set_data(struct ofono_audio_settings *as, void *data)
{
as->driver_data = data;
}
void *ofono_audio_settings_get_data(struct ofono_audio_settings *as)
{
return as->driver_data;
}

View File

@ -121,8 +121,9 @@ enum ofono_atom_type {
OFONO_ATOM_TYPE_GPRS = 16,
OFONO_ATOM_TYPE_GPRS_CONTEXT = 17,
OFONO_ATOM_TYPE_RADIO_SETTINGS = 18,
OFONO_ATOM_TYPE_STK = 19,
OFONO_ATOM_TYPE_NETTIME = 20,
OFONO_ATOM_TYPE_AUDIO_SETTINGS = 19,
OFONO_ATOM_TYPE_STK = 20,
OFONO_ATOM_TYPE_NETTIME = 21,
};
enum ofono_atom_watch_condition {
@ -195,6 +196,7 @@ gboolean __ofono_call_settings_is_busy(struct ofono_call_settings *cs);
#include <ofono/gprs.h>
#include <ofono/gprs-context.h>
#include <ofono/radio-settings.h>
#include <ofono/audio-settings.h>
#include <ofono/voicecall.h>