From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau <frederic.dalleau@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH v5 7/7] handsfree-audio: Add USR1 signal to connect audio
Date: Tue, 27 Aug 2013 18:59:43 +0200 [thread overview]
Message-ID: <1377622783-22845-8-git-send-email-frederic.dalleau@linux.intel.com> (raw)
In-Reply-To: <1377622783-22845-1-git-send-email-frederic.dalleau@linux.intel.com>
[-- Attachment #1: Type: text/plain, Size: 4193 bytes --]
From: Frederic Danis <frederic.danis@linux.intel.com>
---
tools/handsfree-audio.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 90 insertions(+)
diff --git a/tools/handsfree-audio.c b/tools/handsfree-audio.c
index 1201a62..26415fa 100644
--- a/tools/handsfree-audio.c
+++ b/tools/handsfree-audio.c
@@ -48,6 +48,7 @@
#define HFP_AUDIO_MANAGER_INTERFACE OFONO_SERVICE ".HandsfreeAudioManager"
#define HFP_AUDIO_AGENT_PATH "/hfpaudioagent"
#define HFP_AUDIO_AGENT_INTERFACE OFONO_SERVICE ".HandsfreeAudioAgent"
+#define HFP_AUDIO_CARD_INTERFACE OFONO_SERVICE ".HandsfreeAudioCard"
#define HFP_AUDIO_CVSD 1
#define HFP_AUDIO_MSBC 2
@@ -67,6 +68,8 @@ static gboolean option_nomsbc = FALSE;
static const char sntable[4] = { 0x08, 0x38, 0xC8, 0xF8 };
static const int audio_rates[3] = { 0, 8000, 16000 };
+static char *card_path = NULL;
+
struct msbc_parser {
uint8_t buffer[60];
int parsed;
@@ -732,6 +735,71 @@ static void sig_term(int sig)
g_main_loop_quit(main_loop);
}
+static void sig_user(int sig)
+{
+ DBusMessage *msg;
+
+ if (sig == SIGUSR1) {
+ if (card_path == NULL) {
+ DBG("No audio card");
+ return;
+ }
+
+ DBG("Request audio connection");
+
+ msg = dbus_message_new_method_call(OFONO_SERVICE, card_path,
+ HFP_AUDIO_CARD_INTERFACE, "Connect");
+ if (msg == NULL) {
+ DBG("Not enough memory");
+ return;
+ }
+
+ g_dbus_send_message(conn, msg);
+ }
+}
+
+static gboolean card_added(DBusConnection *connection, DBusMessage *message,
+ void *user_data)
+{
+ DBusMessageIter iter;
+ const char *path;
+
+ dbus_message_iter_init(message, &iter);
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
+ return FALSE;
+
+ dbus_message_iter_get_basic(&iter, &path);
+ DBG("%s", path);
+
+ if (card_path == NULL)
+ card_path = g_strdup(path);
+
+ return TRUE;
+}
+
+static gboolean card_removed(DBusConnection *connection, DBusMessage *message,
+ void *user_data)
+{
+ DBusMessageIter iter;
+ const char *path;
+
+ dbus_message_iter_init(message, &iter);
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
+ return FALSE;
+
+ dbus_message_iter_get_basic(&iter, &path);
+ DBG("%s", path);
+
+ if (g_str_equal(card_path, path)) {
+ g_free(card_path);
+ card_path = NULL;
+ }
+
+ return TRUE;
+}
+
static GOptionEntry options[] = {
{ "nocvsd", 'c', 0, G_OPTION_ARG_NONE, &option_nocvsd,
"Disable CVSD support" },
@@ -746,7 +814,10 @@ int main(int argc, char **argv)
GError *error = NULL;
DBusError err;
guint watch;
+ guint add_card_watch = 0;
+ guint remove_card_watch = 0;
struct sigaction sa;
+ struct sigaction sa_user;
context = g_option_context_new(NULL);
g_option_context_add_main_entries(context, options, NULL);
@@ -776,6 +847,10 @@ int main(int argc, char **argv)
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
+ memset(&sa_user, 0, sizeof(sa_user));
+ sa_user.sa_handler = sig_user;
+ sigaction(SIGUSR1, &sa_user, NULL);
+
conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err);
if (conn == NULL) {
if (dbus_error_is_set(&err) == TRUE) {
@@ -793,17 +868,32 @@ int main(int argc, char **argv)
watch = g_dbus_add_service_watch(conn, OFONO_SERVICE,
ofono_connect, ofono_disconnect, NULL, NULL);
+ add_card_watch = g_dbus_add_signal_watch(conn, OFONO_SERVICE,
+ HFP_AUDIO_MANAGER_PATH,
+ HFP_AUDIO_MANAGER_INTERFACE,
+ "CardAdded", card_added,
+ NULL, NULL);
+ remove_card_watch = g_dbus_add_signal_watch(conn, OFONO_SERVICE,
+ HFP_AUDIO_MANAGER_PATH,
+ HFP_AUDIO_MANAGER_INTERFACE,
+ "CardRemoved", card_removed,
+ NULL, NULL);
+
g_main_loop_run(main_loop);
while (threads != NULL)
hfp_audio_thread_free(threads->data);
g_dbus_remove_watch(conn, watch);
+ g_dbus_remove_watch(conn, add_card_watch);
+ g_dbus_remove_watch(conn, remove_card_watch);
hfp_audio_agent_destroy(conn);
dbus_connection_unref(conn);
g_main_loop_unref(main_loop);
+ g_free(card_path);
+
return 0;
}
--
1.7.9.5
next prev parent reply other threads:[~2013-08-27 16:59 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-27 16:59 [PATCH v5 0/7] bluetooth: handsfree audio agent =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2013-08-27 16:59 ` [PATCH v5 1/7] handsfree-audio: Initial DBUS code =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2013-08-29 17:14 ` Denis Kenzior
2013-08-30 10:20 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= DALLEAU
2013-09-02 16:41 ` Denis Kenzior
2013-08-27 16:59 ` [PATCH v5 2/7] handsfree-audio: Build handsfree-audio command line tool =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2013-08-27 16:59 ` [PATCH v5 3/7] handsfree-audio: Add Alsa dependancy =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2013-08-27 16:59 ` [PATCH v5 4/7] handsfree-audio: Implement alsa playback =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2013-08-27 16:59 ` [PATCH v5 5/7] handsfree-audio: Add SBC dependency =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2013-08-27 16:59 ` [PATCH v5 6/7] handsfree-audio: mSBC support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2013-08-27 16:59 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau [this message]
2013-08-29 17:32 ` [PATCH v5 7/7] handsfree-audio: Add USR1 signal to connect audio Denis Kenzior
2013-08-30 10:23 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= DALLEAU
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1377622783-22845-8-git-send-email-frederic.dalleau@linux.intel.com \
--to=frederic.dalleau@linux.intel.com \
--cc=ofono@ofono.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox