All of lore.kernel.org
 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 02/10] hfp_hf: Update to org.bluez.Telephony interface
Date: Fri, 06 Apr 2012 15:17:04 +0200	[thread overview]
Message-ID: <1333718232-8447-3-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: 7474 bytes --]

Bluez moves agent registration from a per device interface to
a per adapter interface.
Update hfp_hf modem to reflect this change.
---
 plugins/hfp_hf.c |  165 ++++++++++++++++++++---------------------------------
 1 files changed, 62 insertions(+), 103 deletions(-)

diff --git a/plugins/hfp_hf.c b/plugins/hfp_hf.c
index 48a734a..7c3747b 100644
--- a/plugins/hfp_hf.c
+++ b/plugins/hfp_hf.c
@@ -51,7 +51,7 @@
 
 #define	BLUEZ_GATEWAY_INTERFACE		BLUEZ_SERVICE ".HandsfreeGateway"
 
-#define HFP_AGENT_INTERFACE "org.bluez.HandsfreeAgent"
+#define HFP_AGENT_PATH "/hfp_hf"
 #define HFP_AGENT_ERROR_INTERFACE "org.bluez.Error"
 
 #ifndef DBUS_TYPE_UNIX_FD
@@ -66,7 +66,6 @@ struct hfp_data {
 	char *handsfree_path;
 	char *handsfree_address;
 	DBusMessage *slc_msg;
-	gboolean agent_registered;
 	DBusPendingCall *call;
 };
 
@@ -158,52 +157,6 @@ static int service_level_connection(struct ofono_modem *modem, int fd)
 	return -EINPROGRESS;
 }
 
-static DBusMessage *hfp_agent_new_connection(DBusConnection *conn,
-						DBusMessage *msg, void *data)
-{
-	int fd, err;
-	struct ofono_modem *modem = data;
-	struct hfp_data *hfp_data = ofono_modem_get_data(modem);
-	guint16 version;
-
-	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_UNIX_FD, &fd,
-				DBUS_TYPE_UINT16, &version, DBUS_TYPE_INVALID))
-		return __ofono_error_invalid_args(msg);
-
-	hfp_slc_info_init(&hfp_data->info, version);
-
-	err = service_level_connection(modem, fd);
-	if (err < 0 && err != -EINPROGRESS)
-		return __ofono_error_failed(msg);
-
-	hfp_data->slc_msg = msg;
-	dbus_message_ref(msg);
-
-	return NULL;
-}
-
-static DBusMessage *hfp_agent_release(DBusConnection *conn,
-					DBusMessage *msg, void *data)
-{
-	struct ofono_modem *modem = data;
-	struct hfp_data *hfp_data = ofono_modem_get_data(modem);
-	const char *obj_path = ofono_modem_get_path(modem);
-
-	g_dbus_unregister_interface(connection, obj_path, HFP_AGENT_INTERFACE);
-	hfp_data->agent_registered = FALSE;
-
-	ofono_modem_remove(modem);
-
-	return dbus_message_new_method_return(msg);
-}
-
-static GDBusMethodTable agent_methods[] = {
-	{ "NewConnection", "hq", "", hfp_agent_new_connection,
-		G_DBUS_METHOD_FLAG_ASYNC },
-	{ "Release", "", "", hfp_agent_release },
-	{ NULL, NULL, NULL, NULL }
-};
-
 static int hfp_hf_probe(const char *device, const char *dev_addr,
 				const char *adapter_addr, const char *alias)
 {
@@ -295,77 +248,23 @@ static void hfp_hf_set_alias(const char *device, const char *alias)
 	ofono_modem_set_name(modem, alias);
 }
 
-static int hfp_register_ofono_handsfree(struct ofono_modem *modem)
-{
-	const char *obj_path = ofono_modem_get_path(modem);
-	struct hfp_data *data = ofono_modem_get_data(modem);
-	DBusMessage *msg;
-
-	DBG("Registering oFono Agent to bluetooth daemon");
-
-	msg = dbus_message_new_method_call(BLUEZ_SERVICE, data->handsfree_path,
-				BLUEZ_GATEWAY_INTERFACE, "RegisterAgent");
-	if (msg == NULL)
-		return -ENOMEM;
-
-	dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH, &obj_path,
-				DBUS_TYPE_INVALID);
-
-	g_dbus_send_message(connection, msg);
-	return 0;
-}
-
-static int hfp_unregister_ofono_handsfree(struct ofono_modem *modem)
-{
-	const char *obj_path = ofono_modem_get_path(modem);
-	struct hfp_data *data = ofono_modem_get_data(modem);
-	DBusMessage *msg;
-
-	DBG("Unregistering oFono Agent from bluetooth daemon");
-
-	msg = dbus_message_new_method_call(BLUEZ_SERVICE, data->handsfree_path,
-				BLUEZ_GATEWAY_INTERFACE, "UnregisterAgent");
-	if (msg == NULL)
-		return -ENOMEM;
-
-	dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH, &obj_path,
-				DBUS_TYPE_INVALID);
-
-	g_dbus_send_message(connection, msg);
-	return 0;
-}
-
 static int hfp_probe(struct ofono_modem *modem)
 {
-	const char *obj_path = ofono_modem_get_path(modem);
 	struct hfp_data *data = ofono_modem_get_data(modem);
 
 	if (data == NULL)
 		return -EINVAL;
 
-	g_dbus_register_interface(connection, obj_path, HFP_AGENT_INTERFACE,
-			agent_methods, NULL, NULL, modem, NULL);
-
-	data->agent_registered = TRUE;
-
-	if (hfp_register_ofono_handsfree(modem) != 0)
-		return -EINVAL;
-
 	return 0;
 }
 
 static void hfp_remove(struct ofono_modem *modem)
 {
 	struct hfp_data *data = ofono_modem_get_data(modem);
-	const char *obj_path = ofono_modem_get_path(modem);
 
 	if (data->call != NULL)
 		dbus_pending_call_cancel(data->call);
 
-	if (g_dbus_unregister_interface(connection, obj_path,
-					HFP_AGENT_INTERFACE))
-		hfp_unregister_ofono_handsfree(modem);
-
 	g_hash_table_remove(modem_hash, data->handsfree_path);
 
 	g_free(data->handsfree_address);
@@ -465,7 +364,7 @@ static int hfp_disable(struct ofono_modem *modem)
 	g_at_chat_unref(data->info.chat);
 	data->info.chat = NULL;
 
-	if (data->agent_registered) {
+	if (ofono_modem_get_powered(modem)) {
 		status = bluetooth_send_with_reply(data->handsfree_path,
 					BLUEZ_GATEWAY_INTERFACE, "Disconnect",
 					&data->call, hfp_power_down,
@@ -497,6 +396,59 @@ static void hfp_post_sim(struct ofono_modem *modem)
 	DBG("%p", modem);
 }
 
+static DBusMessage *hfp_agent_new_connection(DBusConnection *conn,
+						DBusMessage *msg, void *data)
+{
+	int fd, err;
+	struct ofono_modem *modem;
+	struct hfp_data *hfp_data;
+	const char *device, *uuid;
+	const char *path = NULL;
+	guint16 features = 0;
+	guint16 version = 0;
+
+	fd = bluetooth_parse_newconnection_message(msg, &device, &uuid,
+						&version, &features, &path);
+	if (fd < 0)
+		return __ofono_error_invalid_args(msg);
+
+	DBG("New connection for %s on %s (version 0x%04X, features 0x%02X, " \
+					"media transport path: %s)",
+					device, uuid, version, features, path);
+
+	modem = g_hash_table_lookup(modem_hash, device);
+	if (modem == NULL)
+		return __ofono_error_invalid_args(msg);
+
+	hfp_data = ofono_modem_get_data(modem);
+
+	hfp_slc_info_init(&hfp_data->info, version);
+
+	err = service_level_connection(modem, fd);
+	if (err < 0 && err != -EINPROGRESS)
+		return __ofono_error_failed(msg);
+
+	hfp_data->slc_msg = msg;
+	dbus_message_ref(msg);
+
+	return NULL;
+}
+
+static DBusMessage *hfp_agent_release(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	DBG("");
+
+	return dbus_message_new_method_return(msg);
+}
+
+static GDBusMethodTable agent_methods[] = {
+	{ "NewConnection", "ha{sv}", "", hfp_agent_new_connection,
+		G_DBUS_METHOD_FLAG_ASYNC },
+	{ "Release", "", "", hfp_agent_release },
+	{ NULL, NULL, NULL, NULL }
+};
+
 static struct ofono_modem_driver hfp_driver = {
 	.name		= "hfp",
 	.modem_type	= OFONO_MODEM_TYPE_HFP,
@@ -517,6 +469,8 @@ static struct bluetooth_profile hfp_hf = {
 
 static int hfp_init(void)
 {
+	dbus_uint16_t features = HFP_HF_FEATURE_3WAY | HFP_HF_FEATURE_CLIP |
+					HFP_HF_FEATURE_REMOTE_VOLUME_CONTROL;
 	int err;
 
 	if (DBUS_TYPE_UNIX_FD < 0)
@@ -537,11 +491,16 @@ static int hfp_init(void)
 	modem_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
 						g_free, NULL);
 
+	bluetooth_register_telephony_agent(HFP_AGENT_PATH, HFP_HS_UUID,
+						HFP_VERSION_1_5, features,
+						agent_methods, NULL, NULL);
+
 	return 0;
 }
 
 static void hfp_exit(void)
 {
+	bluetooth_unregister_telephony_agent(HFP_AGENT_PATH);
 	bluetooth_unregister_uuid(HFP_AG_UUID);
 	ofono_modem_driver_unregister(&hfp_driver);
 
-- 
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 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis [this message]
2012-04-06 13:17 ` [RFC v4 03/10] hfp_ag: Update to org.bluez.Telephony interface =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
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-3-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.