Open Source Telephony
 help / color / mirror / Atom feed
From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis <frederic.danis@linux.intel.com>
To: ofono@ofono.org
Subject: [RFC v4 03/10] hfp_ag: Update to org.bluez.Telephony interface
Date: Fri, 06 Apr 2012 15:17:05 +0200	[thread overview]
Message-ID: <1333718232-8447-4-git-send-email-frederic.danis@linux.intel.com> (raw)
In-Reply-To: <1333718232-8447-1-git-send-email-frederic.danis@linux.intel.com>

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

Bluez moves agent registration from a per device interface to
a per adapter interface.
Update hfp_ag modem emulator to reflect this change.
---
 plugins/hfp_ag.c |  126 ++++++++++++++++++++++++------------------------------
 1 files changed, 56 insertions(+), 70 deletions(-)

diff --git a/plugins/hfp_ag.c b/plugins/hfp_ag.c
index c2d1d30..ea9c112 100644
--- a/plugins/hfp_ag.c
+++ b/plugins/hfp_ag.c
@@ -35,97 +35,83 @@
 
 #include "bluetooth.h"
 
-#define HFP_AG_CHANNEL	13
+#define AGENT_PATH "/hfp_ag"
+#define VERSION_1_5 0x0105
+#define FEATURES	(HFP_AG_FEATURE_3WAY | HFP_AG_FEATURE_REJECT_CALL | \
+			HFP_AG_FEATURE_ENHANCED_CALL_STATUS | \
+			HFP_AG_FEATURE_ENHANCED_CALL_CONTROL | \
+			HFP_AG_FEATURE_EXTENDED_RES_CODE)
+
+#ifndef DBUS_TYPE_UNIX_FD
+#define DBUS_TYPE_UNIX_FD -1
+#endif
 
-static struct server *server;
 static guint modemwatch_id;
 static GList *modems;
 static GHashTable *sim_hash = NULL;
 
-static const gchar *hfp_ag_record =
-"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
-"<record>\n"
-"  <attribute id=\"0x0001\">\n"
-"    <sequence>\n"
-"      <uuid value=\"0x111F\"/>\n"
-"      <uuid value=\"0x1203\"/>\n"
-"    </sequence>\n"
-"  </attribute>\n"
-"\n"
-"  <attribute id=\"0x0004\">\n"
-"    <sequence>\n"
-"      <sequence>\n"
-"        <uuid value=\"0x0100\"/>\n"
-"      </sequence>\n"
-"      <sequence>\n"
-"        <uuid value=\"0x0003\"/>\n"
-"        <uint8 value=\"13\" name=\"channel\"/>\n"
-"      </sequence>\n"
-"    </sequence>\n"
-"  </attribute>\n"
-"\n"
-"  <attribute id=\"0x0009\">\n"
-"    <sequence>\n"
-"      <sequence>\n"
-"        <uuid value=\"0x111E\"/>\n"
-"        <uint16 value=\"0x0105\" name=\"version\"/>\n"
-"      </sequence>\n"
-"    </sequence>\n"
-"  </attribute>\n"
-"\n"
-"  <attribute id=\"0x0100\">\n"
-"    <text value=\"Hands-Free Audio Gateway\" name=\"name\"/>\n"
-"  </attribute>\n"
-"\n"
-"  <attribute id=\"0x0301\">\n"
-"    <uint8 value=\"0x01\" />\n"
-"  </attribute>\n"
-"\n"
-"  <attribute id=\"0x0311\">\n"
-"    <uint16 value=\"0x0001\" />\n"
-"  </attribute>\n"
-"</record>\n";
-
-static void hfp_ag_connect_cb(GIOChannel *io, GError *err, gpointer user_data)
+static DBusMessage *hfp_ag_agent_new_connection(DBusConnection *conn,
+						DBusMessage *msg, void *data)
 {
-	struct ofono_modem *modem;
-	struct ofono_emulator *em;
 	int fd;
+	const char *device, *uuid;
+	const char *path = NULL;
+	guint16 version = 0;
+	guint16 features = 0;
+	struct ofono_emulator *em;
+	struct ofono_modem *modem;
 
-	DBG("");
+	fd = bluetooth_parse_newconnection_message(msg, &device, &uuid,
+						&version, &features, &path);
+	if (fd < 0)
+		return __ofono_error_invalid_args(msg);
 
-	if (err) {
-		DBG("%s", err->message);
-		return;
-	}
+	DBG("New connection for %s on %s (version 0x%04X, features 0x%02X, " \
+					"media transport path: %s)",
+					device, uuid, version, features, path);
 
 	/* Pick the first voicecall capable modem */
 	modem = modems->data;
 	if (modem == NULL)
-		return;
+		return __ofono_error_failed(msg);
 
 	DBG("Picked modem %p for emulator", modem);
 
 	em = ofono_emulator_create(modem, OFONO_EMULATOR_TYPE_HFP);
 	if (em == NULL)
-		return;
-
-	fd = g_io_channel_unix_get_fd(io);
-	g_io_channel_set_close_on_unref(io, FALSE);
+		return __ofono_error_failed(msg);
 
 	ofono_emulator_register(em, fd);
+
+	return dbus_message_new_method_return(msg);
 }
 
+static DBusMessage *hfp_ag_agent_release(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	DBG("");
+
+	return dbus_message_new_method_return(msg);
+}
+
+static GDBusMethodTable agent_methods[] = {
+	{ "NewConnection", "ha{sv}", "", hfp_ag_agent_new_connection,
+		G_DBUS_METHOD_FLAG_ASYNC },
+	{ "Release", "", "", hfp_ag_agent_release },
+	{ NULL, NULL, NULL, NULL }
+};
+
 static void sim_state_watch(enum ofono_sim_state new_state, void *data)
 {
 	struct ofono_modem *modem = data;
 
 	if (new_state != OFONO_SIM_STATE_READY) {
+		if (modems == NULL)
+			return;
+
 		modems = g_list_remove(modems, modem);
-		if (modems == NULL && server != NULL) {
-			bluetooth_unregister_server(server);
-			server = NULL;
-		}
+		if (modems == NULL)
+			bluetooth_unregister_telephony_agent(AGENT_PATH);
 
 		return;
 	}
@@ -138,8 +124,9 @@ static void sim_state_watch(enum ofono_sim_state new_state, void *data)
 	if (modems->next != NULL)
 		return;
 
-	server = bluetooth_register_server(HFP_AG_CHANNEL, hfp_ag_record,
-						hfp_ag_connect_cb, NULL);
+	bluetooth_register_telephony_agent(AGENT_PATH, HFP_AG_UUID,
+						VERSION_1_5, FEATURES,
+						agent_methods, NULL, NULL);
 }
 
 static gboolean sim_watch_remove(gpointer key, gpointer value,
@@ -192,6 +179,9 @@ static void call_modemwatch(struct ofono_modem *modem, void *user)
 
 static int hfp_ag_init(void)
 {
+	if (DBUS_TYPE_UNIX_FD < 0)
+		return -EBADF;
+
 	sim_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
 
 	modemwatch_id = __ofono_modemwatch_add(modem_watch, NULL, NULL);
@@ -203,14 +193,10 @@ static int hfp_ag_init(void)
 static void hfp_ag_exit(void)
 {
 	__ofono_modemwatch_remove(modemwatch_id);
+
 	g_list_free(modems);
 	g_hash_table_foreach_remove(sim_hash, sim_watch_remove, NULL);
 	g_hash_table_destroy(sim_hash);
-
-	if (server) {
-		bluetooth_unregister_server(server);
-		server = NULL;
-	}
 }
 
 OFONO_PLUGIN_DEFINE(hfp_ag, "Hands-Free Audio Gateway Profile Plugins", VERSION,
-- 
1.7.1


  parent reply	other threads:[~2012-04-06 13:17 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-06 13:17 [RFC v4 00/10] org.bluez.Telephony interface integration =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-04-06 13:17 ` [RFC v4 01/10] bluetooth: Add org.bluez.Telephony helpers =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-04-06 13:17 ` [RFC v4 02/10] hfp_hf: Update to org.bluez.Telephony interface =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-04-06 13:17 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis [this message]
2012-04-06 13:17 ` [RFC v4 04/10] bluetooth: Add audio APIs for HFP AG =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-04-06 17:27   ` Denis Kenzior
2012-04-06 13:17 ` [RFC v4 05/10] bluetooth: Add AT+NREC support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-04-06 17:32   ` Denis Kenzior
2012-04-06 13:17 ` [RFC v4 06/10] bluetooth: Add +BSIR support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-04-06 13:17 ` [RFC v4 07/10] bluetooth: Add AT+VGM support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-04-06 13:17 ` [RFC v4 08/10] bluetooth: Add AT+VGS support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-04-06 13:17 ` [RFC v4 09/10] hfp_ag: Add media transport support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-04-06 17:38   ` Denis Kenzior
2012-04-24 16:19     ` Frederic Danis
2012-04-23 19:24       ` Denis Kenzior
2012-04-06 13:17 ` [RFC v4 10/10] emulator: Update supported features =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-04-06 17:38   ` Denis Kenzior
2012-04-23 14:01     ` Frederic Danis
2012-04-23  0:03       ` Denis Kenzior

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=1333718232-8447-4-git-send-email-frederic.danis@linux.intel.com \
    --to=frederic.danis@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