aboutsummaryrefslogtreecommitdiffstats
path: root/ATTIC/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0003-dbus-request-a-name-on-startup.patch
diff options
context:
space:
mode:
Diffstat (limited to 'ATTIC/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0003-dbus-request-a-name-on-startup.patch')
-rw-r--r--ATTIC/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0003-dbus-request-a-name-on-startup.patch153
1 files changed, 153 insertions, 0 deletions
diff --git a/ATTIC/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0003-dbus-request-a-name-on-startup.patch b/ATTIC/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0003-dbus-request-a-name-on-startup.patch
new file mode 100644
index 00000000..1ef59296
--- /dev/null
+++ b/ATTIC/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0003-dbus-request-a-name-on-startup.patch
@@ -0,0 +1,153 @@
+From 4c14fffbd20a6dd9e6ceca1eb1726ceaafab7410 Mon Sep 17 00:00:00 2001
+From: Thierry Bultel <thierry.bultel@iot.bzh>
+Date: Fri, 18 Jan 2019 11:45:29 +0100
+Subject: [PATCH 3/3] dbus: request a name on startup
+
+When the service thread is ready, ask a name to dbus
+The advantage of doing that is that client applications
+can check dbus for bluez-alsa presence, without having
+to implement any kinf of polling logic. Also, this
+way, they can be notified on the service exit, to
+perform any needed cleanup.
+Since there must be an instance of bluealsa daemon
+per hci device, the dbus name will be
+'org.bluez-alsa.hci0', 'org.bluez-alsa.hci1' ...
+and so on.
+
+Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
+---
+ configure.ac | 10 ++++++++++
+ src/Makefile.am | 3 +++
+ src/bluez-alsa.conf | 14 ++++++++++++++
+ src/main.c | 32 ++++++++++++++++++++++++++++++++
+ 4 files changed, 59 insertions(+)
+ create mode 100644 src/bluez-alsa.conf
+
+diff --git a/configure.ac b/configure.ac
+index 6323d60..d4ec7d4 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -130,6 +130,16 @@ AC_ARG_WITH([alsaconfdir],
+ [alsaconfdir="$sysconfdir/alsa/conf.d"],
+ [alsaconfdir="$datadir/alsa/alsa.conf.d"])])
+
++AC_ARG_WITH(dbusconfdir, AC_HELP_STRING([--with-dbusconfdir=PATH],
++ [path to D-Bus config directory]), [path_dbusconf=${withval}],
++ [path_dbusconf="`$PKG_CONFIG --variable=sysconfdir dbus-1`"])
++if (test -z "${path_dbusconf}"); then
++ DBUS_CONFDIR="${sysconfdir}/dbus-1/system.d"
++else
++ DBUS_CONFDIR="${path_dbusconf}/dbus-1/system.d"
++fi
++AC_SUBST(DBUS_CONFDIR)
++
+ test "x$prefix" = xNONE && prefix=$ac_default_prefix
+ test "x$exec_prefix" = xNONE && exec_prefix=$prefix
+
+diff --git a/src/Makefile.am b/src/Makefile.am
+index 5626ae5..c501f2e 100644
+--- a/src/Makefile.am
++++ b/src/Makefile.am
+@@ -23,6 +23,9 @@ bluealsa_SOURCES += \
+ ofono-iface.c
+ endif
+
++dbusconfdir = @DBUS_CONFDIR@
++dist_dbusconf_DATA = bluez-alsa.conf
++
+ AM_CFLAGS = \
+ @BLUEZ_CFLAGS@ \
+ @GLIB2_CFLAGS@ \
+diff --git a/src/bluez-alsa.conf b/src/bluez-alsa.conf
+new file mode 100644
+index 0000000..6b999d6
+--- /dev/null
++++ b/src/bluez-alsa.conf
+@@ -0,0 +1,14 @@
++<!-- This configuration file specifies the required security policies
++ for bluez-alsa core daemon to work. -->
++
++<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
++ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
++<busconfig>
++
++ <!-- ../system.conf have denied everything, so we just punch some holes -->
++
++ <policy user="root">
++ <allow own_prefix="org.bluez-alsa"/>
++ </policy>
++
++</busconfig>
+diff --git a/src/main.c b/src/main.c
+index 9cef402..9183978 100644
+--- a/src/main.c
++++ b/src/main.c
+@@ -12,6 +12,7 @@
+ # include "config.h"
+ #endif
+
++#define _GNU_SOURCE
+ #include <errno.h>
+ #include <getopt.h>
+ #include <signal.h>
+@@ -58,6 +59,20 @@ static char *get_a2dp_codecs(
+ return g_strjoinv(", ", (char **)tmp);
+ }
+
++static void name_acquired_handler(
++ GDBusConnection *connection,
++ const gchar *name,
++ gpointer user_data) {
++ debug("Acquired name: %s", name);
++}
++
++static void name_lost_handler(
++ GDBusConnection *connection,
++ const gchar *name,
++ gpointer user_data) {
++ debug("Lost name: %s", name);
++}
++
+ static GMainLoop *loop = NULL;
+ static void main_loop_stop(int sig) {
+ /* Call to this handler restores the default action, so on the
+@@ -318,6 +333,7 @@ int main(int argc, char **argv) {
+ GError *err;
+
+ err = NULL;
++
+ address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
+ if ((config.dbus = g_dbus_connection_new_for_address_sync(address,
+ G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
+@@ -336,6 +352,19 @@ int main(int argc, char **argv) {
+ ofono_register();
+ #endif
+
++ char * name_on_bus = NULL;
++ asprintf(&name_on_bus, "org.bluez-alsa.%s", config.hci_dev.name);
++
++ guint g_dbusid;
++ g_dbusid = g_bus_own_name_on_connection(config.dbus,
++ name_on_bus,
++ G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
++ G_BUS_NAME_OWNER_FLAGS_REPLACE,
++ name_acquired_handler,
++ name_lost_handler,
++ NULL,
++ NULL);
++
+ /* In order to receive EPIPE while writing to the pipe whose reading end
+ * is closed, the SIGPIPE signal has to be handled. For more information
+ * see the io_thread_write_pcm() function. */
+@@ -359,5 +388,8 @@ int main(int argc, char **argv) {
+ bluealsa_ctl_free();
+ bluealsa_config_free();
+
++ g_bus_unown_name (g_dbusid);
++ free(name_on_bus);
++
+ return EXIT_SUCCESS;
+ }
+--
+2.16.4
+