Open Source Telephony
 help / color / mirror / Atom feed
From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau <frederic.dalleau@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH v2 5/9] hsp_ag: add modem watch
Date: Thu, 17 Mar 2011 19:55:44 +0100	[thread overview]
Message-ID: <1300388148-925-6-git-send-email-frederic.dalleau@linux.intel.com> (raw)
In-Reply-To: <1300388148-925-1-git-send-email-frederic.dalleau@linux.intel.com>

[-- Attachment #1: Type: text/plain, Size: 2845 bytes --]

---
 plugins/hsp_ag.c |   76 +++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 67 insertions(+), 9 deletions(-)

diff --git a/plugins/hsp_ag.c b/plugins/hsp_ag.c
index a8e6f40..5a60269 100644
--- a/plugins/hsp_ag.c
+++ b/plugins/hsp_ag.c
@@ -47,7 +47,9 @@
 
 #define HSP_RFCOMM_CHAN 17
 
-static struct server *hsp;
+static struct server *server;
+static guint modemwatch_id;
+static GList *modems;
 
 static const gchar *hsp_record =
 "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
@@ -90,25 +92,81 @@ static const gchar *hsp_record =
 " </attribute>\n"
 "</record>\n";
 
-static void connect_cb(GIOChannel *channel, GError *err, gpointer user_data)
+static void connect_cb(GIOChannel *channel, GError *err, gpointer data)
+{	int fd;
+	struct ofono_emulator *em;
+	struct ofono_modem *modem;
+
+	/* Pick the first powered modem */
+	modem = modems->data;
+	DBG("Picked modem %p for emulator", modem);
+
+	em = ofono_emulator_create(modem, OFONO_EMULATOR_TYPE_HSP);
+	if (em == NULL)
+		return;
+
+	fd = g_io_channel_unix_get_fd(channel);
+
+	ofono_emulator_register(em, fd);
+
+	g_io_channel_set_close_on_unref(channel, FALSE);
+}
+
+static void voicecall_watch(struct ofono_atom *atom,
+				enum ofono_atom_watch_condition cond,
+				void *data)
 {
+	struct ofono_modem *modem = data;
+
+	if (cond == OFONO_ATOM_WATCH_CONDITION_REGISTERED) {
+		modems = g_list_append(modems, modem);
+
+		if (modems->next == NULL)
+			server = bluetooth_register_server(HSP_RFCOMM_CHAN,
+							hsp_record,
+							connect_cb,
+							NULL);
+	} else {
+		modems = g_list_remove(modems, modem);
+		if (modems == NULL &&  server != NULL) {
+			bluetooth_unregister_server(server);
+			server = NULL;
+		}
+	}
 }
 
-static int hsp_ag_init(void)
+static void modem_watch(struct ofono_modem *modem, gboolean added, void *user)
 {
-	hsp = bluetooth_register_server(HSP_RFCOMM_CHAN, hsp_record, connect_cb, NULL);
+	DBG("modem: %p, added: %d", modem, added);
 
-	if(!hsp)
-		return -1;
+	if (added == FALSE)
+		return;
+
+	__ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_VOICECALL,
+					voicecall_watch, modem, NULL);
+}
+
+static void call_modemwatch(struct ofono_modem *modem, void *user)
+{
+	modem_watch(modem, TRUE, user);
+}
+
+static int hsp_ag_init(void)
+{
+	modemwatch_id = __ofono_modemwatch_add(modem_watch, NULL, NULL);
+	__ofono_modem_foreach(call_modemwatch, NULL);
 
-	DBG("HSP Gateway profile starting");
 	return 0;
 }
 
 static void hsp_ag_exit(void)
 {
-	if(hsp)
-		bluetooth_unregister_server(hsp);
+	__ofono_modemwatch_remove(modemwatch_id);
+
+	if (server) {
+		bluetooth_unregister_server(server);
+		server = NULL;
+	}
 }
 
 OFONO_PLUGIN_DEFINE(hsp_ag, "Headset Gateway Profile", VERSION,
-- 
1.7.1


  parent reply	other threads:[~2011-03-17 18:55 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-17 18:55 [PATCH v2 0/9] HSP profile implementation =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-17 18:55 ` [PATCH v2 1/9] bluetooth: add functions for sco connection =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-18 20:27   ` Denis Kenzior
2011-03-19 11:06     ` Johan Hedberg
2011-03-21 17:08       ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-17 18:55 ` [PATCH v2 2/9] emulator: add hsp emulator type =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-17 18:55 ` [PATCH v2 3/9] hsp_ag: add hsp atom type =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-17 18:55 ` [PATCH v2 4/9] hsp_ag: Initial plugin commit =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-17 18:55 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau [this message]
2011-03-17 18:55 ` [PATCH v2 6/9] emulator: add CKPD support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-18 20:25   ` Denis Kenzior
2011-03-21 18:15     ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-21 18:28       ` Denis Kenzior
2011-03-17 18:55 ` [PATCH v2 7/9] emulator: add audio connection API =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-17 18:55 ` [PATCH v2 8/9] emulator: implement " =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-17 18:55 ` [PATCH v2 9/9] hsp_ag: add audio connection support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-21 12:53 ` [PATCH v2 0/9] HSP profile implementation Luiz Augusto von Dentz
2011-03-21 18:10   ` =?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=1300388148-925-6-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