[pulseaudio-discuss] [PATCH 4/4] bluetooth: Create oFono backend
Luiz Augusto von Dentz
luiz.dentz at gmail.com
Wed Aug 13 05:23:08 PDT 2014
From: João Paulo Rechi Vita <jprvita at openbossa.org>
---
configure.ac | 4 +-
src/modules/bluetooth/backend-ofono.c | 143 ++++++++++++++++++++++++++++++++++
2 files changed, 145 insertions(+), 2 deletions(-)
create mode 100644 src/modules/bluetooth/backend-ofono.c
diff --git a/configure.ac b/configure.ac
index 2beca1f..7beb4d1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1030,9 +1030,9 @@ AM_CONDITIONAL([HAVE_BLUEZ], [test "x$HAVE_BLUEZ" = x1])
## Headset profiles backend ##
AC_ARG_WITH(bluetooth_headset_backend,
-AS_HELP_STRING([--with-bluetooth-headset-backend=<null>],[Backend for Bluetooth headset profiles (null)]))
+AS_HELP_STRING([--with-bluetooth-headset-backend=<ofono|null>],[Backend for Bluetooth headset profiles (ofono)]))
if test -z "$with_bluetooth_headset_backend" ; then
- BLUETOOTH_HEADSET_BACKEND=null
+ BLUETOOTH_HEADSET_BACKEND=ofono
else
BLUETOOTH_HEADSET_BACKEND=$with_bluetooth_headset_backend
fi
diff --git a/src/modules/bluetooth/backend-ofono.c b/src/modules/bluetooth/backend-ofono.c
new file mode 100644
index 0000000..4c0e241
--- /dev/null
+++ b/src/modules/bluetooth/backend-ofono.c
@@ -0,0 +1,143 @@
+/***
+ This file is part of PulseAudio.
+
+ Copyright 2013 João Paulo Rechi Vita
+
+ PulseAudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ PulseAudio 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 Lesser General Public
+ License along with PulseAudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <pulsecore/core-util.h>
+#include <pulsecore/dbus-shared.h>
+
+#include "backend.h"
+
+#define OFONO_SERVICE "org.ofono"
+#define HF_AUDIO_AGENT_INTERFACE OFONO_SERVICE ".HandsfreeAudioAgent"
+
+#define HF_AUDIO_AGENT_PATH "/HandsfreeAudioAgent"
+
+#define HF_AUDIO_AGENT_XML \
+ DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
+ "<node>" \
+ " <interface name=\"org.freedesktop.DBus.Introspectable\">" \
+ " <method name=\"Introspect\">" \
+ " <arg direction=\"out\" type=\"s\" />" \
+ " </method>" \
+ " </interface>" \
+ " <interface name=\"org.ofono.HandsfreeAudioAgent\">" \
+ " <method name=\"Release\">" \
+ " </method>" \
+ " <method name=\"NewConnection\">" \
+ " <arg direction=\"in\" type=\"o\" name=\"card_path\" />" \
+ " <arg direction=\"in\" type=\"h\" name=\"sco_fd\" />" \
+ " <arg direction=\"in\" type=\"y\" name=\"codec\" />" \
+ " </method>" \
+ " </interface>" \
+ "</node>"
+
+struct hf_backend_data {
+ pa_core *core;
+ pa_dbus_connection *connection;
+};
+
+static DBusMessage *hf_audio_agent_release(DBusConnection *c, DBusMessage *m, void *data) {
+ DBusMessage *r = dbus_message_new_error(m, "org.ofono.Error.NotImplemented", "Operation is not implemented");
+ return r;
+}
+
+static DBusMessage *hf_audio_agent_new_connection(DBusConnection *c, DBusMessage *m, void *data) {
+ DBusMessage *r = dbus_message_new_error(m, "org.ofono.Error.NotImplemented", "Operation is not implemented");
+ return r;
+}
+
+static DBusHandlerResult hf_audio_agent_handler(DBusConnection *c, DBusMessage *m, void *data) {
+ hf_backend_data_t *hfdata = data;
+ DBusMessage *r = NULL;
+ const char *path, *interface, *member;
+
+ pa_assert(hfdata);
+
+ path = dbus_message_get_path(m);
+ interface = dbus_message_get_interface(m);
+ member = dbus_message_get_member(m);
+
+ if (!pa_streq(path, HF_AUDIO_AGENT_PATH))
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ pa_log_debug("dbus: path=%s, interface=%s, member=%s", path, interface, member);
+
+ if (dbus_message_is_method_call(m, "org.freedesktop.DBus.Introspectable", "Introspect")) {
+ const char *xml = HF_AUDIO_AGENT_XML;
+
+ pa_assert_se(r = dbus_message_new_method_return(m));
+ pa_assert_se(dbus_message_append_args(r, DBUS_TYPE_STRING, &xml, DBUS_TYPE_INVALID));
+
+ } else if (dbus_message_is_method_call(m, HF_AUDIO_AGENT_INTERFACE, "NewConnection"))
+ r = hf_audio_agent_new_connection(c, m, data);
+ else if (dbus_message_is_method_call(m, HF_AUDIO_AGENT_INTERFACE, "Release"))
+ r = hf_audio_agent_release(c, m, data);
+ else
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ if (r) {
+ pa_assert_se(dbus_connection_send(pa_dbus_connection_get(hfdata->connection), r, NULL));
+ dbus_message_unref(r);
+ }
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+hf_backend_data_t *hf_backend_new(pa_core *c) {
+ hf_backend_data_t *data;
+ DBusError err;
+ static const DBusObjectPathVTable vtable_hf_audio_agent = {
+ .message_function = hf_audio_agent_handler,
+ };
+
+ pa_assert(c);
+
+ data = pa_xnew0(hf_backend_data_t, 1);
+ data->core = c;
+
+ dbus_error_init(&err);
+
+ if (!(data->connection = pa_dbus_bus_get(c, DBUS_BUS_SYSTEM, &err))) {
+ pa_log("Failed to get D-Bus connection: %s", err.message);
+ dbus_error_free(&err);
+ return NULL;
+ }
+
+ pa_assert_se(dbus_connection_register_object_path(pa_dbus_connection_get(data->connection), HF_AUDIO_AGENT_PATH,
+ &vtable_hf_audio_agent, data));
+
+ return data;
+}
+
+void hf_backend_free(hf_backend_data_t *data) {
+ pa_assert(data);
+
+ if (data->connection) {
+ dbus_connection_unregister_object_path(pa_dbus_connection_get(data->connection), HF_AUDIO_AGENT_PATH);
+
+ pa_dbus_connection_unref(data->connection);
+ }
+
+ pa_xfree(data);
+}
--
1.9.3
More information about the pulseaudio-discuss
mailing list