All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v0 0/8] handsfree-audio: Audio Card registration
@ 2013-02-25 14:34 Claudio Takahasi
  2013-02-25 14:34 ` [PATCH v0 1/8] handsfree-audio: Add atom modem tracking Claudio Takahasi
                   ` (8 more replies)
  0 siblings, 9 replies; 20+ messages in thread
From: Claudio Takahasi @ 2013-02-25 14:34 UTC (permalink / raw)
  To: ofono

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

This patch series adds the initial Handsfree Audio Card hierarchy
implementation.

Open issues:
* Define Audio Card object path: it is using modem path in this series

Not implemented in this series:
* SCO audio connection
* LocalAddress property

Claudio Takahasi (8):
  handsfree-audio: Add atom modem tracking
  handsfree-audio: Add Audio Card registration
  handsfree-audio: Add Audio Card GetProperties
  handsfree-audio: Add emitting CardAdded
  handsfree-audio: Add function to append properties
  handsfree-audio: Add emitting CardRemoved
  handsfree-audio: Add registered cards tracking
  handsfree-audio: Add GetCards

 src/handsfree-audio.c | 196 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 194 insertions(+), 2 deletions(-)

-- 
1.7.11.7


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v0 1/8] handsfree-audio: Add atom modem tracking
  2013-02-25 14:34 [PATCH v0 0/8] handsfree-audio: Audio Card registration Claudio Takahasi
@ 2013-02-25 14:34 ` Claudio Takahasi
  2013-02-25 14:34 ` [PATCH v0 2/8] handsfree-audio: Add Audio Card registration Claudio Takahasi
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Claudio Takahasi @ 2013-02-25 14:34 UTC (permalink / raw)
  To: ofono

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

This patch adds atom watch for handsfree modem in order to be able to
register the Handsfree Audio Card.
---
 src/handsfree-audio.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 4e2cf93..a8680b1 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -51,6 +51,7 @@ struct agent {
 };
 
 static struct agent *agent = NULL;
+static unsigned int modemwatch_id;
 static int ref_count = 0;
 
 static void agent_free(struct agent *agent)
@@ -171,6 +172,20 @@ static const GDBusMethodTable am_methods[] = {
 	{ }
 };
 
+static void handsfree_modem_watch(struct ofono_atom *atom,
+			enum ofono_atom_watch_condition cond, void *user_data)
+{
+}
+
+static void modem_watch(struct ofono_modem *modem, gboolean added, void *user)
+{
+	if (added == FALSE)
+		return;
+
+	__ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_HANDSFREE,
+					handsfree_modem_watch, modem, NULL);
+}
+
 void ofono_handsfree_audio_ref(void)
 {
 	ref_count += 1;
@@ -180,8 +195,12 @@ void ofono_handsfree_audio_ref(void)
 
 	if (!g_dbus_register_interface(ofono_dbus_get_connection(),
 					"/", HFP_AUDIO_MANAGER_INTERFACE,
-					am_methods, NULL, NULL, NULL, NULL))
+					am_methods, NULL, NULL, NULL, NULL)) {
 		ofono_error("Unable to register Handsfree Audio Manager");
+		return;
+	}
+
+	modemwatch_id = __ofono_modemwatch_add(modem_watch, NULL, NULL);
 }
 
 void ofono_handsfree_audio_unref(void)
@@ -196,6 +215,8 @@ void ofono_handsfree_audio_unref(void)
 	if (ref_count > 0)
 		return;
 
+	__ofono_modemwatch_remove(modemwatch_id);
+
 	g_dbus_unregister_interface(ofono_dbus_get_connection(), "/",
 						HFP_AUDIO_MANAGER_INTERFACE);
 
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v0 2/8] handsfree-audio: Add Audio Card registration
  2013-02-25 14:34 [PATCH v0 0/8] handsfree-audio: Audio Card registration Claudio Takahasi
  2013-02-25 14:34 ` [PATCH v0 1/8] handsfree-audio: Add atom modem tracking Claudio Takahasi
@ 2013-02-25 14:34 ` Claudio Takahasi
  2013-02-25 14:34 ` [PATCH v0 3/8] handsfree-audio: Add Audio Card GetProperties Claudio Takahasi
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Claudio Takahasi @ 2013-02-25 14:34 UTC (permalink / raw)
  To: ofono

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

This patch adds the Handsfree Audio Card registration based on the
registered Handsfree modem.
---
 src/handsfree-audio.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index a8680b1..d14a767 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -35,6 +35,7 @@
 
 #define HFP_AUDIO_MANAGER_INTERFACE	OFONO_SERVICE ".HandsfreeAudioManager"
 #define HFP_AUDIO_AGENT_INTERFACE	OFONO_SERVICE ".HandsfreeAudioAgent"
+#define HFP_AUDIO_CARD_INTERFACE	OFONO_SERVICE ".HandsfreeAudioCard"
 
 /* Supported agent codecs */
 enum hfp_codec {
@@ -172,9 +173,35 @@ static const GDBusMethodTable am_methods[] = {
 	{ }
 };
 
+static DBusMessage *card_get_properties(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	return __ofono_error_not_implemented(msg);
+}
+
+static const GDBusMethodTable card_methods[] = {
+	{ GDBUS_METHOD("GetProperties",
+				NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
+				card_get_properties) },
+	{ }
+};
+
 static void handsfree_modem_watch(struct ofono_atom *atom,
 			enum ofono_atom_watch_condition cond, void *user_data)
 {
+	const char *path = __ofono_atom_get_path(atom);
+
+	if (cond == OFONO_ATOM_WATCH_CONDITION_REGISTERED) {
+		g_dbus_register_interface(ofono_dbus_get_connection(), path,
+					HFP_AUDIO_CARD_INTERFACE, card_methods,
+					NULL, NULL, NULL, NULL);
+
+		DBG("Audio Card added: %s", path);
+	} else {
+		g_dbus_unregister_interface(ofono_dbus_get_connection(), path,
+						HFP_AUDIO_CARD_INTERFACE);
+		DBG("Audio Card removed: %s", path);
+	}
 }
 
 static void modem_watch(struct ofono_modem *modem, gboolean added, void *user)
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v0 3/8] handsfree-audio: Add Audio Card GetProperties
  2013-02-25 14:34 [PATCH v0 0/8] handsfree-audio: Audio Card registration Claudio Takahasi
  2013-02-25 14:34 ` [PATCH v0 1/8] handsfree-audio: Add atom modem tracking Claudio Takahasi
  2013-02-25 14:34 ` [PATCH v0 2/8] handsfree-audio: Add Audio Card registration Claudio Takahasi
@ 2013-02-25 14:34 ` Claudio Takahasi
  2013-02-25 14:34 ` [PATCH v0 4/8] handsfree-audio: Add emitting CardAdded Claudio Takahasi
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Claudio Takahasi @ 2013-02-25 14:34 UTC (permalink / raw)
  To: ofono

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

This patch adds the initial implementation of the GetProperties method
of the Handsfree Audio Card. Only the Bluetooth address of the remote
peer is supported, the local adapter address requires changes in
hfp_hf_bluez5 plugin.
---
 src/handsfree-audio.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index d14a767..cdb8f8f 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -176,7 +176,30 @@ static const GDBusMethodTable am_methods[] = {
 static DBusMessage *card_get_properties(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
-	return __ofono_error_not_implemented(msg);
+	struct ofono_modem *modem = user_data;
+	const char *address;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	DBusMessageIter dict;
+
+	reply = dbus_message_new_method_return(msg);
+	if (reply == NULL)
+		return NULL;
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+					OFONO_PROPERTIES_ARRAY_SIGNATURE,
+					&dict);
+
+	address = ofono_modem_get_string(modem, "Remote");
+
+	ofono_dbus_dict_append(&dict, "RemoteAddress",
+					DBUS_TYPE_STRING, &address);
+
+	dbus_message_iter_close_container(&iter, &dict);
+
+	return reply;
 }
 
 static const GDBusMethodTable card_methods[] = {
@@ -189,12 +212,13 @@ static const GDBusMethodTable card_methods[] = {
 static void handsfree_modem_watch(struct ofono_atom *atom,
 			enum ofono_atom_watch_condition cond, void *user_data)
 {
+	struct ofono_modem *modem = user_data;
 	const char *path = __ofono_atom_get_path(atom);
 
 	if (cond == OFONO_ATOM_WATCH_CONDITION_REGISTERED) {
 		g_dbus_register_interface(ofono_dbus_get_connection(), path,
 					HFP_AUDIO_CARD_INTERFACE, card_methods,
-					NULL, NULL, NULL, NULL);
+					NULL, NULL, modem, NULL);
 
 		DBG("Audio Card added: %s", path);
 	} else {
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v0 4/8] handsfree-audio: Add emitting CardAdded
  2013-02-25 14:34 [PATCH v0 0/8] handsfree-audio: Audio Card registration Claudio Takahasi
                   ` (2 preceding siblings ...)
  2013-02-25 14:34 ` [PATCH v0 3/8] handsfree-audio: Add Audio Card GetProperties Claudio Takahasi
@ 2013-02-25 14:34 ` Claudio Takahasi
  2013-02-25 14:34 ` [PATCH v0 5/8] handsfree-audio: Add function to append properties Claudio Takahasi
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Claudio Takahasi @ 2013-02-25 14:34 UTC (permalink / raw)
  To: ofono

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

Handsfree Audio Manager needs to send the CardAdded signal when a new
handsfree modem is registered.
---
 src/handsfree-audio.c | 62 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 54 insertions(+), 8 deletions(-)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index cdb8f8f..64d1ed0 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -173,6 +173,12 @@ static const GDBusMethodTable am_methods[] = {
 	{ }
 };
 
+static const GDBusSignalTable am_signals[] = {
+	{ GDBUS_SIGNAL("CardAdded",
+		GDBUS_ARGS({ "path", "o" }, { "properties", "a{sv}" })) },
+	{ }
+};
+
 static DBusMessage *card_get_properties(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
@@ -209,19 +215,58 @@ static const GDBusMethodTable card_methods[] = {
 	{ }
 };
 
+static void am_emit_card_added(const char *path, struct ofono_modem *modem)
+{
+	DBusMessage *signal;
+	DBusMessageIter iter;
+	DBusMessageIter dict;
+	const char *address;
+
+	signal = dbus_message_new_signal("/", HFP_AUDIO_MANAGER_INTERFACE,
+								"CardAdded");
+	if (signal == NULL) {
+		ofono_error("Unable to allocate new CardAdded signal");
+		return;
+	}
+
+	dbus_message_iter_init_append(signal, &iter);
+
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &path);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+					OFONO_PROPERTIES_ARRAY_SIGNATURE,
+					&dict);
+
+	address = ofono_modem_get_string(modem, "Remote");
+
+	ofono_dbus_dict_append(&dict, "RemoteAddress",
+					DBUS_TYPE_STRING, &address);
+
+	dbus_message_iter_close_container(&iter, &dict);
+
+	g_dbus_send_message(ofono_dbus_get_connection(), signal);
+}
+
+static void am_card_add(const char *path, struct ofono_modem *modem)
+{
+	g_dbus_register_interface(ofono_dbus_get_connection(), path,
+					HFP_AUDIO_CARD_INTERFACE, card_methods,
+					NULL, NULL, modem, NULL);
+
+	am_emit_card_added(path, modem);
+
+	DBG("Audio Card added: %s", path);
+}
+
 static void handsfree_modem_watch(struct ofono_atom *atom,
 			enum ofono_atom_watch_condition cond, void *user_data)
 {
 	struct ofono_modem *modem = user_data;
 	const char *path = __ofono_atom_get_path(atom);
 
-	if (cond == OFONO_ATOM_WATCH_CONDITION_REGISTERED) {
-		g_dbus_register_interface(ofono_dbus_get_connection(), path,
-					HFP_AUDIO_CARD_INTERFACE, card_methods,
-					NULL, NULL, modem, NULL);
-
-		DBG("Audio Card added: %s", path);
-	} else {
+	if (cond == OFONO_ATOM_WATCH_CONDITION_REGISTERED)
+		am_card_add(path, modem);
+	else {
 		g_dbus_unregister_interface(ofono_dbus_get_connection(), path,
 						HFP_AUDIO_CARD_INTERFACE);
 		DBG("Audio Card removed: %s", path);
@@ -246,7 +291,8 @@ void ofono_handsfree_audio_ref(void)
 
 	if (!g_dbus_register_interface(ofono_dbus_get_connection(),
 					"/", HFP_AUDIO_MANAGER_INTERFACE,
-					am_methods, NULL, NULL, NULL, NULL)) {
+					am_methods, am_signals, NULL,
+					NULL, NULL)) {
 		ofono_error("Unable to register Handsfree Audio Manager");
 		return;
 	}
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v0 5/8] handsfree-audio: Add function to append properties
  2013-02-25 14:34 [PATCH v0 0/8] handsfree-audio: Audio Card registration Claudio Takahasi
                   ` (3 preceding siblings ...)
  2013-02-25 14:34 ` [PATCH v0 4/8] handsfree-audio: Add emitting CardAdded Claudio Takahasi
@ 2013-02-25 14:34 ` Claudio Takahasi
  2013-02-25 14:34 ` [PATCH v0 6/8] handsfree-audio: Add emitting CardRemoved Claudio Takahasi
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Claudio Takahasi @ 2013-02-25 14:34 UTC (permalink / raw)
  To: ofono

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

Adds a common function to append Handsfree Audio Card properties used
when replying GetProperties and emitting CardAdded signal.
---
 src/handsfree-audio.c | 44 ++++++++++++++++++++------------------------
 1 file changed, 20 insertions(+), 24 deletions(-)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 64d1ed0..2a4b3d5 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -84,6 +84,24 @@ static void agent_disconnect(DBusConnection *conn, void *user_data)
 	agent = NULL;
 }
 
+static void card_append_properties(DBusMessageIter *iter,
+						struct ofono_modem *modem)
+{
+	DBusMessageIter dict;
+	const char *address;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+					OFONO_PROPERTIES_ARRAY_SIGNATURE,
+					&dict);
+
+	address = ofono_modem_get_string(modem, "Remote");
+
+	ofono_dbus_dict_append(&dict, "RemoteAddress",
+					DBUS_TYPE_STRING, &address);
+
+	dbus_message_iter_close_container(iter, &dict);
+}
+
 static DBusMessage *am_get_cards(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
@@ -183,10 +201,8 @@ static DBusMessage *card_get_properties(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
 	struct ofono_modem *modem = user_data;
-	const char *address;
 	DBusMessage *reply;
 	DBusMessageIter iter;
-	DBusMessageIter dict;
 
 	reply = dbus_message_new_method_return(msg);
 	if (reply == NULL)
@@ -194,16 +210,7 @@ static DBusMessage *card_get_properties(DBusConnection *conn,
 
 	dbus_message_iter_init_append(reply, &iter);
 
-	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
-					OFONO_PROPERTIES_ARRAY_SIGNATURE,
-					&dict);
-
-	address = ofono_modem_get_string(modem, "Remote");
-
-	ofono_dbus_dict_append(&dict, "RemoteAddress",
-					DBUS_TYPE_STRING, &address);
-
-	dbus_message_iter_close_container(&iter, &dict);
+	card_append_properties(&iter, modem);
 
 	return reply;
 }
@@ -219,8 +226,6 @@ static void am_emit_card_added(const char *path, struct ofono_modem *modem)
 {
 	DBusMessage *signal;
 	DBusMessageIter iter;
-	DBusMessageIter dict;
-	const char *address;
 
 	signal = dbus_message_new_signal("/", HFP_AUDIO_MANAGER_INTERFACE,
 								"CardAdded");
@@ -233,16 +238,7 @@ static void am_emit_card_added(const char *path, struct ofono_modem *modem)
 
 	dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &path);
 
-	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
-					OFONO_PROPERTIES_ARRAY_SIGNATURE,
-					&dict);
-
-	address = ofono_modem_get_string(modem, "Remote");
-
-	ofono_dbus_dict_append(&dict, "RemoteAddress",
-					DBUS_TYPE_STRING, &address);
-
-	dbus_message_iter_close_container(&iter, &dict);
+	card_append_properties(&iter, modem);
 
 	g_dbus_send_message(ofono_dbus_get_connection(), signal);
 }
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v0 6/8] handsfree-audio: Add emitting CardRemoved
  2013-02-25 14:34 [PATCH v0 0/8] handsfree-audio: Audio Card registration Claudio Takahasi
                   ` (4 preceding siblings ...)
  2013-02-25 14:34 ` [PATCH v0 5/8] handsfree-audio: Add function to append properties Claudio Takahasi
@ 2013-02-25 14:34 ` Claudio Takahasi
  2013-02-25 14:34 ` [PATCH v0 7/8] handsfree-audio: Add registered cards tracking Claudio Takahasi
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Claudio Takahasi @ 2013-02-25 14:34 UTC (permalink / raw)
  To: ofono

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

Handsfree Audio Manager needs to send the CardRemoved signal
when the handsfree modem is unregistered.
---
 src/handsfree-audio.c | 38 +++++++++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 2a4b3d5..674a289 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -194,6 +194,8 @@ static const GDBusMethodTable am_methods[] = {
 static const GDBusSignalTable am_signals[] = {
 	{ GDBUS_SIGNAL("CardAdded",
 		GDBUS_ARGS({ "path", "o" }, { "properties", "a{sv}" })) },
+	{ GDBUS_SIGNAL("CardRemoved",
+		GDBUS_ARGS({ "path", "o" })) },
 	{ }
 };
 
@@ -243,6 +245,25 @@ static void am_emit_card_added(const char *path, struct ofono_modem *modem)
 	g_dbus_send_message(ofono_dbus_get_connection(), signal);
 }
 
+static void am_emit_card_removed(const char *path, struct ofono_modem *modem)
+{
+	DBusMessage *signal;
+	DBusMessageIter iter;
+
+	signal = dbus_message_new_signal("/", HFP_AUDIO_MANAGER_INTERFACE,
+								"CardRemoved");
+	if (signal == NULL) {
+		ofono_error("Unable to allocate new CardRemoved signal");
+		return;
+	}
+
+	dbus_message_iter_init_append(signal, &iter);
+
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &path);
+
+	g_dbus_send_message(ofono_dbus_get_connection(), signal);
+}
+
 static void am_card_add(const char *path, struct ofono_modem *modem)
 {
 	g_dbus_register_interface(ofono_dbus_get_connection(), path,
@@ -254,6 +275,16 @@ static void am_card_add(const char *path, struct ofono_modem *modem)
 	DBG("Audio Card added: %s", path);
 }
 
+static void am_card_remove(const char *path, struct ofono_modem *modem)
+{
+	am_emit_card_removed(path, modem);
+
+	g_dbus_unregister_interface(ofono_dbus_get_connection(), path,
+						HFP_AUDIO_CARD_INTERFACE);
+
+	DBG("Audio Card removed: %s", path);
+}
+
 static void handsfree_modem_watch(struct ofono_atom *atom,
 			enum ofono_atom_watch_condition cond, void *user_data)
 {
@@ -262,11 +293,8 @@ static void handsfree_modem_watch(struct ofono_atom *atom,
 
 	if (cond == OFONO_ATOM_WATCH_CONDITION_REGISTERED)
 		am_card_add(path, modem);
-	else {
-		g_dbus_unregister_interface(ofono_dbus_get_connection(), path,
-						HFP_AUDIO_CARD_INTERFACE);
-		DBG("Audio Card removed: %s", path);
-	}
+	else
+		am_card_remove(path, modem);
 }
 
 static void modem_watch(struct ofono_modem *modem, gboolean added, void *user)
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v0 7/8] handsfree-audio: Add registered cards tracking
  2013-02-25 14:34 [PATCH v0 0/8] handsfree-audio: Audio Card registration Claudio Takahasi
                   ` (5 preceding siblings ...)
  2013-02-25 14:34 ` [PATCH v0 6/8] handsfree-audio: Add emitting CardRemoved Claudio Takahasi
@ 2013-02-25 14:34 ` Claudio Takahasi
  2013-02-25 14:34 ` [PATCH v0 8/8] handsfree-audio: Add GetCards Claudio Takahasi
  2013-02-26 13:50 ` [PATCH v1 0/9] handsfree-audio: Audio Card registration Claudio Takahasi
  8 siblings, 0 replies; 20+ messages in thread
From: Claudio Takahasi @ 2013-02-25 14:34 UTC (permalink / raw)
  To: ofono

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

This patch creates a modem list of the registed Handsfree Audio
Cards required to fill the array of cards in the GetCards method.
---
 src/handsfree-audio.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 674a289..9db2a83 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -51,6 +51,7 @@ struct agent {
 	guint watch;
 };
 
+static GSList *cards = NULL;
 static struct agent *agent = NULL;
 static unsigned int modemwatch_id;
 static int ref_count = 0;
@@ -266,9 +267,10 @@ static void am_emit_card_removed(const char *path, struct ofono_modem *modem)
 
 static void am_card_add(const char *path, struct ofono_modem *modem)
 {
-	g_dbus_register_interface(ofono_dbus_get_connection(), path,
+	if (!g_dbus_register_interface(ofono_dbus_get_connection(), path,
 					HFP_AUDIO_CARD_INTERFACE, card_methods,
-					NULL, NULL, modem, NULL);
+					NULL, NULL, modem, NULL))
+		return;
 
 	am_emit_card_added(path, modem);
 
@@ -291,10 +293,13 @@ static void handsfree_modem_watch(struct ofono_atom *atom,
 	struct ofono_modem *modem = user_data;
 	const char *path = __ofono_atom_get_path(atom);
 
-	if (cond == OFONO_ATOM_WATCH_CONDITION_REGISTERED)
+	if (cond == OFONO_ATOM_WATCH_CONDITION_REGISTERED) {
 		am_card_add(path, modem);
-	else
+		cards = g_slist_append(cards, atom);
+	} else {
 		am_card_remove(path, modem);
+		cards = g_slist_remove(cards, atom);
+	}
 }
 
 static void modem_watch(struct ofono_modem *modem, gboolean added, void *user)
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v0 8/8] handsfree-audio: Add GetCards
  2013-02-25 14:34 [PATCH v0 0/8] handsfree-audio: Audio Card registration Claudio Takahasi
                   ` (6 preceding siblings ...)
  2013-02-25 14:34 ` [PATCH v0 7/8] handsfree-audio: Add registered cards tracking Claudio Takahasi
@ 2013-02-25 14:34 ` Claudio Takahasi
  2013-02-26 13:50 ` [PATCH v1 0/9] handsfree-audio: Audio Card registration Claudio Takahasi
  8 siblings, 0 replies; 20+ messages in thread
From: Claudio Takahasi @ 2013-02-25 14:34 UTC (permalink / raw)
  To: ofono

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

This patch adds the Handsfree Audio Manager GetCards() method
implementation. It returns an array of Audio Cards, where each entry in
the array is the object path of the Audio Card and a dictionary of it's
properties.
---
 src/handsfree-audio.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 9db2a83..623cfe5 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -103,10 +103,55 @@ static void card_append_properties(DBusMessageIter *iter,
 	dbus_message_iter_close_container(iter, &dict);
 }
 
+static void append_card(gpointer data, gpointer user_data)
+{
+	struct ofono_atom *atom = data;
+	DBusMessageIter *array = user_data;
+	const char *path = __ofono_atom_get_path(atom);
+	DBusMessageIter entry;
+
+	dbus_message_iter_open_container(array, DBUS_TYPE_STRUCT,
+							NULL, &entry);
+
+	dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH, &path);
+
+	card_append_properties(&entry, __ofono_atom_get_modem(atom));
+
+	dbus_message_iter_close_container(array, &entry);
+}
+
 static DBusMessage *am_get_cards(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
-	return __ofono_error_not_implemented(msg);
+	DBusMessage *reply;
+	DBusMessageIter iter, array;
+
+	reply = dbus_message_new_method_return(msg);
+	if (reply == NULL)
+		return NULL;
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	/*
+	 * a{oa{sv}}: Array of cards containing the object path of the
+	 * Audio Card and a dictionary of it's properties
+	 */
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+					DBUS_STRUCT_BEGIN_CHAR_AS_STRING
+					DBUS_TYPE_OBJECT_PATH_AS_STRING
+					DBUS_TYPE_ARRAY_AS_STRING
+					DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+					DBUS_TYPE_STRING_AS_STRING
+					DBUS_TYPE_VARIANT_AS_STRING
+					DBUS_DICT_ENTRY_END_CHAR_AS_STRING
+					DBUS_STRUCT_END_CHAR_AS_STRING,
+					&array);
+
+	g_slist_foreach(cards, append_card, &array);
+
+	dbus_message_iter_close_container(&iter, &array);
+
+	return reply;
 }
 
 static DBusMessage *am_agent_register(DBusConnection *conn,
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v1 0/9] handsfree-audio: Audio Card registration
  2013-02-25 14:34 [PATCH v0 0/8] handsfree-audio: Audio Card registration Claudio Takahasi
                   ` (7 preceding siblings ...)
  2013-02-25 14:34 ` [PATCH v0 8/8] handsfree-audio: Add GetCards Claudio Takahasi
@ 2013-02-26 13:50 ` Claudio Takahasi
  2013-02-26 13:50   ` [PATCH v1 1/9] handsfree-audio: Add creating Audio Card Claudio Takahasi
                     ` (9 more replies)
  8 siblings, 10 replies; 20+ messages in thread
From: Claudio Takahasi @ 2013-02-26 13:50 UTC (permalink / raw)
  To: ofono

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

This patch series adds the initial Handsfree Audio Card hierarchy
implementation.

Not implemented in this series:
* SCO audio connection
* LocalAddress property

Changes from v0-v1:
* Changed Audio Card object path: it is now using sequential name "device%d"
* Replaced atom modem tracking by handsfree_audio_create and handsfree_audio_remove functions

Claudio Takahasi (9):
  handsfree-audio: Add creating Audio Card
  handsfree-audio: Add removing Audio Card
  handsfree-audio: Add emitting CardAdded
  handsfree-audio: Add emitting CardRemoved
  handsfree-audio: Remove Audio Card when HFP is removed
  handsfree-audio: Remove Audio Card for local initiated disconnection
  handsfree-audio: Add Audio Card GetProperties
  handsfree-audio: Add Audio Cards hash table
  handsfree-audio: Add Audio Manager GetCards

 include/handsfree-audio.h |   2 +
 plugins/hfp_hf_bluez5.c   |  22 ++++++
 src/handsfree-audio.c     | 195 +++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 217 insertions(+), 2 deletions(-)

-- 
1.7.11.7


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v1 1/9] handsfree-audio: Add creating Audio Card
  2013-02-26 13:50 ` [PATCH v1 0/9] handsfree-audio: Audio Card registration Claudio Takahasi
@ 2013-02-26 13:50   ` Claudio Takahasi
  2013-02-26 13:50   ` [PATCH v1 2/9] handsfree-audio: Add removing " Claudio Takahasi
                     ` (8 subsequent siblings)
  9 siblings, 0 replies; 20+ messages in thread
From: Claudio Takahasi @ 2013-02-26 13:50 UTC (permalink / raw)
  To: ofono

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

This patch adds the Handsfree Audio Card registration when the service
level connection is established.
---
 include/handsfree-audio.h |  1 +
 plugins/hfp_hf_bluez5.c   |  4 ++++
 src/handsfree-audio.c     | 41 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+)

diff --git a/include/handsfree-audio.h b/include/handsfree-audio.h
index d6e2d0d..0572965 100644
--- a/include/handsfree-audio.h
+++ b/include/handsfree-audio.h
@@ -30,6 +30,7 @@ extern "C" {
 
 void ofono_handsfree_audio_ref(void);
 void ofono_handsfree_audio_unref(void);
+char *ofono_handsfree_card_create(const char *remote);
 
 #ifdef __cplusplus
 }
diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index 7057d71..eb2648e 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -46,6 +46,7 @@
 #include <ofono/netreg.h>
 #include <ofono/voicecall.h>
 #include <ofono/call-volume.h>
+#include <ofono/handsfree-audio.h>
 #include <ofono/handsfree.h>
 
 #include <drivers/hfpmodem/slc.h>
@@ -61,6 +62,7 @@
 struct hfp {
 	struct hfp_slc_info info;
 	DBusMessage *msg;
+	char *card;
 };
 
 static GDBusClient *bluez = NULL;
@@ -78,6 +80,7 @@ static void slc_established(gpointer userdata)
 {
 	struct ofono_modem *modem = userdata;
 	struct hfp *hfp = ofono_modem_get_data(modem);
+	const char *remote = ofono_modem_get_string(modem, "Remote");
 	DBusMessage *msg;
 
 	ofono_modem_set_powered(modem, TRUE);
@@ -88,6 +91,7 @@ static void slc_established(gpointer userdata)
 	hfp->msg = NULL;
 
 	ofono_info("Service level connection established");
+	hfp->card = ofono_handsfree_card_create(remote);
 }
 
 static void slc_failed(gpointer userdata)
diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 4e2cf93..d4d9796 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -35,6 +35,7 @@
 
 #define HFP_AUDIO_MANAGER_INTERFACE	OFONO_SERVICE ".HandsfreeAudioManager"
 #define HFP_AUDIO_AGENT_INTERFACE	OFONO_SERVICE ".HandsfreeAudioAgent"
+#define HFP_AUDIO_CARD_INTERFACE	OFONO_SERVICE ".HandsfreeAudioCard"
 
 /* Supported agent codecs */
 enum hfp_codec {
@@ -50,6 +51,10 @@ struct agent {
 	guint watch;
 };
 
+struct audio_card {
+	char *remote;
+};
+
 static struct agent *agent = NULL;
 static int ref_count = 0;
 
@@ -205,6 +210,42 @@ void ofono_handsfree_audio_unref(void)
 	}
 }
 
+static DBusMessage *card_get_properties(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	return __ofono_error_not_implemented(msg);
+}
+
+static const GDBusMethodTable card_methods[] = {
+	{ GDBUS_METHOD("GetProperties",
+			NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
+			card_get_properties) },
+	{ }
+};
+
+char *ofono_handsfree_card_create(const char *remote)
+{
+	static int audio_card_id = 0;
+	struct audio_card *card;
+	char *path;
+
+	path = g_strdup_printf("/device%d", audio_card_id++);
+	card = g_new0(struct audio_card, 1);
+
+	if (!g_dbus_register_interface(ofono_dbus_get_connection(), path,
+				HFP_AUDIO_CARD_INTERFACE, card_methods,
+				NULL, NULL, card, NULL)) {
+		g_free(path);
+		g_free(card);
+		return NULL;
+	}
+
+	card->remote = g_strdup(remote);
+	DBG("Audio Card added: %s", path);
+
+	return path;
+}
+
 int __ofono_handsfree_audio_manager_init(void)
 {
 	return 0;
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v1 2/9] handsfree-audio: Add removing Audio Card
  2013-02-26 13:50 ` [PATCH v1 0/9] handsfree-audio: Audio Card registration Claudio Takahasi
  2013-02-26 13:50   ` [PATCH v1 1/9] handsfree-audio: Add creating Audio Card Claudio Takahasi
@ 2013-02-26 13:50   ` Claudio Takahasi
  2013-02-26 13:50   ` [PATCH v1 3/9] handsfree-audio: Add emitting CardAdded Claudio Takahasi
                     ` (7 subsequent siblings)
  9 siblings, 0 replies; 20+ messages in thread
From: Claudio Takahasi @ 2013-02-26 13:50 UTC (permalink / raw)
  To: ofono

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

This patch removes a registered Handsfree Audio Card when the service
level connection is disconnected.
---
 include/handsfree-audio.h |  1 +
 plugins/hfp_hf_bluez5.c   |  5 +++++
 src/handsfree-audio.c     | 18 +++++++++++++++++-
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/include/handsfree-audio.h b/include/handsfree-audio.h
index 0572965..af3c4c0 100644
--- a/include/handsfree-audio.h
+++ b/include/handsfree-audio.h
@@ -31,6 +31,7 @@ extern "C" {
 void ofono_handsfree_audio_ref(void);
 void ofono_handsfree_audio_unref(void);
 char *ofono_handsfree_card_create(const char *remote);
+void ofono_handsfree_card_remove(const char *path);
 
 #ifdef __cplusplus
 }
diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index eb2648e..f22b030 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -126,6 +126,11 @@ static void hfp_disconnected_cb(gpointer user_data)
 
 	ofono_modem_set_powered(modem, FALSE);
 
+	if (hfp->card) {
+		ofono_handsfree_card_remove(hfp->card);
+		g_free(hfp->card);
+	}
+
 	g_at_chat_unref(info->chat);
 	info->chat = NULL;
 }
diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index d4d9796..a9eb7c9 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -69,6 +69,14 @@ static void agent_free(struct agent *agent)
 	g_free(agent);
 }
 
+static void audio_card_free(gpointer data)
+{
+	struct audio_card *card = data;
+
+	g_free(card->remote);
+	g_free(card);
+}
+
 static void agent_release(struct agent *agent)
 {
 	DBusMessage *msg;
@@ -234,7 +242,7 @@ char *ofono_handsfree_card_create(const char *remote)
 
 	if (!g_dbus_register_interface(ofono_dbus_get_connection(), path,
 				HFP_AUDIO_CARD_INTERFACE, card_methods,
-				NULL, NULL, card, NULL)) {
+				NULL, NULL, card, audio_card_free)) {
 		g_free(path);
 		g_free(card);
 		return NULL;
@@ -246,6 +254,14 @@ char *ofono_handsfree_card_create(const char *remote)
 	return path;
 }
 
+void ofono_handsfree_card_remove(const char *path)
+{
+	g_dbus_unregister_interface(ofono_dbus_get_connection(), path,
+						HFP_AUDIO_CARD_INTERFACE);
+
+	DBG("Audio Card removed: %s", path);
+}
+
 int __ofono_handsfree_audio_manager_init(void)
 {
 	return 0;
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v1 3/9] handsfree-audio: Add emitting CardAdded
  2013-02-26 13:50 ` [PATCH v1 0/9] handsfree-audio: Audio Card registration Claudio Takahasi
  2013-02-26 13:50   ` [PATCH v1 1/9] handsfree-audio: Add creating Audio Card Claudio Takahasi
  2013-02-26 13:50   ` [PATCH v1 2/9] handsfree-audio: Add removing " Claudio Takahasi
@ 2013-02-26 13:50   ` Claudio Takahasi
  2013-02-26 13:50   ` [PATCH v1 4/9] handsfree-audio: Add emitting CardRemoved Claudio Takahasi
                     ` (6 subsequent siblings)
  9 siblings, 0 replies; 20+ messages in thread
From: Claudio Takahasi @ 2013-02-26 13:50 UTC (permalink / raw)
  To: ofono

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

Emits the CardAdded signal using the Handfree Audio Manager interface
when a new Audio Card is created.
---
 src/handsfree-audio.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index a9eb7c9..39d90c5 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -95,6 +95,21 @@ static void agent_disconnect(DBusConnection *conn, void *user_data)
 	agent = NULL;
 }
 
+static void card_append_properties(DBusMessageIter *iter,
+						struct audio_card *card)
+{
+	DBusMessageIter dict;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+					OFONO_PROPERTIES_ARRAY_SIGNATURE,
+					&dict);
+
+	ofono_dbus_dict_append(&dict, "RemoteAddress",
+					DBUS_TYPE_STRING, &card->remote);
+
+	dbus_message_iter_close_container(iter, &dict);
+}
+
 static DBusMessage *am_get_cards(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
@@ -184,6 +199,33 @@ static const GDBusMethodTable am_methods[] = {
 	{ }
 };
 
+static const GDBusSignalTable am_signals[] = {
+	{ GDBUS_SIGNAL("CardAdded",
+		GDBUS_ARGS({ "path", "o" }, { "properties", "a{sv}" })) },
+	{ }
+};
+
+static void am_emit_card_added(const char *path, struct audio_card *card)
+{
+	DBusMessage *signal;
+	DBusMessageIter iter;
+
+	signal = dbus_message_new_signal("/", HFP_AUDIO_MANAGER_INTERFACE,
+								"CardAdded");
+	if (signal == NULL) {
+		ofono_error("Unable to allocate new CardAdded signal");
+		return;
+	}
+
+	dbus_message_iter_init_append(signal, &iter);
+
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &path);
+
+	card_append_properties(&iter, card);
+
+	g_dbus_send_message(ofono_dbus_get_connection(), signal);
+}
+
 void ofono_handsfree_audio_ref(void)
 {
 	ref_count += 1;
@@ -193,7 +235,8 @@ void ofono_handsfree_audio_ref(void)
 
 	if (!g_dbus_register_interface(ofono_dbus_get_connection(),
 					"/", HFP_AUDIO_MANAGER_INTERFACE,
-					am_methods, NULL, NULL, NULL, NULL))
+					am_methods, am_signals, NULL,
+					NULL, NULL))
 		ofono_error("Unable to register Handsfree Audio Manager");
 }
 
@@ -249,6 +292,8 @@ char *ofono_handsfree_card_create(const char *remote)
 	}
 
 	card->remote = g_strdup(remote);
+	am_emit_card_added(path, card);
+
 	DBG("Audio Card added: %s", path);
 
 	return path;
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v1 4/9] handsfree-audio: Add emitting CardRemoved
  2013-02-26 13:50 ` [PATCH v1 0/9] handsfree-audio: Audio Card registration Claudio Takahasi
                     ` (2 preceding siblings ...)
  2013-02-26 13:50   ` [PATCH v1 3/9] handsfree-audio: Add emitting CardAdded Claudio Takahasi
@ 2013-02-26 13:50   ` Claudio Takahasi
  2013-02-26 13:50   ` [PATCH v1 5/9] handsfree-audio: Remove Audio Card when HFP is removed Claudio Takahasi
                     ` (5 subsequent siblings)
  9 siblings, 0 replies; 20+ messages in thread
From: Claudio Takahasi @ 2013-02-26 13:50 UTC (permalink / raw)
  To: ofono

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

Emits the CardAdded signal using the Handfree Audio Manager interface
when a Audio Card is removed. The common way to trigger this action is
when the service level connection is disconnected.
---
 src/handsfree-audio.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 39d90c5..fcebce8 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -202,6 +202,8 @@ static const GDBusMethodTable am_methods[] = {
 static const GDBusSignalTable am_signals[] = {
 	{ GDBUS_SIGNAL("CardAdded",
 		GDBUS_ARGS({ "path", "o" }, { "properties", "a{sv}" })) },
+	{ GDBUS_SIGNAL("CardRemoved",
+		GDBUS_ARGS({ "path", "o" })) },
 	{ }
 };
 
@@ -226,6 +228,25 @@ static void am_emit_card_added(const char *path, struct audio_card *card)
 	g_dbus_send_message(ofono_dbus_get_connection(), signal);
 }
 
+static void am_emit_card_removed(const char *path)
+{
+	DBusMessage *signal;
+	DBusMessageIter iter;
+
+	signal = dbus_message_new_signal("/", HFP_AUDIO_MANAGER_INTERFACE,
+								"CardRemoved");
+	if (signal == NULL) {
+		ofono_error("Unable to allocate new CardRemoved signal");
+		return;
+	}
+
+	dbus_message_iter_init_append(signal, &iter);
+
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &path);
+
+	g_dbus_send_message(ofono_dbus_get_connection(), signal);
+}
+
 void ofono_handsfree_audio_ref(void)
 {
 	ref_count += 1;
@@ -301,6 +322,8 @@ char *ofono_handsfree_card_create(const char *remote)
 
 void ofono_handsfree_card_remove(const char *path)
 {
+	am_emit_card_removed(path);
+
 	g_dbus_unregister_interface(ofono_dbus_get_connection(), path,
 						HFP_AUDIO_CARD_INTERFACE);
 
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v1 5/9] handsfree-audio: Remove Audio Card when HFP is removed
  2013-02-26 13:50 ` [PATCH v1 0/9] handsfree-audio: Audio Card registration Claudio Takahasi
                     ` (3 preceding siblings ...)
  2013-02-26 13:50   ` [PATCH v1 4/9] handsfree-audio: Add emitting CardRemoved Claudio Takahasi
@ 2013-02-26 13:50   ` Claudio Takahasi
  2013-02-26 13:50   ` [PATCH v1 6/9] handsfree-audio: Remove Audio Card for local initiated disconnection Claudio Takahasi
                     ` (4 subsequent siblings)
  9 siblings, 0 replies; 20+ messages in thread
From: Claudio Takahasi @ 2013-02-26 13:50 UTC (permalink / raw)
  To: ofono

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

This patch removes a registered Handsfree Audio Card when the HFP remove
callback gets called.
---
 plugins/hfp_hf_bluez5.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index f22b030..26946af 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -129,6 +129,7 @@ static void hfp_disconnected_cb(gpointer user_data)
 	if (hfp->card) {
 		ofono_handsfree_card_remove(hfp->card);
 		g_free(hfp->card);
+		hfp->card = NULL;
 	}
 
 	g_at_chat_unref(info->chat);
@@ -216,6 +217,12 @@ static void hfp_remove(struct ofono_modem *modem)
 	if (hfp->msg)
 		dbus_message_unref(hfp->msg);
 
+	if (hfp->card) {
+		ofono_handsfree_card_remove(hfp->card);
+		g_free(hfp->card);
+		hfp->card = NULL;
+	}
+
 	g_at_chat_unref(info->chat);
 
 	g_free(hfp);
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v1 6/9] handsfree-audio: Remove Audio Card for local initiated disconnection
  2013-02-26 13:50 ` [PATCH v1 0/9] handsfree-audio: Audio Card registration Claudio Takahasi
                     ` (4 preceding siblings ...)
  2013-02-26 13:50   ` [PATCH v1 5/9] handsfree-audio: Remove Audio Card when HFP is removed Claudio Takahasi
@ 2013-02-26 13:50   ` Claudio Takahasi
  2013-02-26 13:50   ` [PATCH v1 7/9] handsfree-audio: Add Audio Card GetProperties Claudio Takahasi
                     ` (3 subsequent siblings)
  9 siblings, 0 replies; 20+ messages in thread
From: Claudio Takahasi @ 2013-02-26 13:50 UTC (permalink / raw)
  To: ofono

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

This patch removes a registered Handsfree Audio Card when the local host
requests disconnection of the service level connection.
---
 plugins/hfp_hf_bluez5.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index 26946af..494f33c 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -427,6 +427,12 @@ static DBusMessage *profile_disconnection(DBusConnection *conn,
 	hfp = ofono_modem_get_data(modem);
 	info = &hfp->info;
 
+	if (hfp->card) {
+		ofono_handsfree_card_remove(hfp->card);
+		g_free(hfp->card);
+		hfp->card = NULL;
+	}
+
 	g_at_chat_unref(info->chat);
 	info->chat = NULL;
 
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v1 7/9] handsfree-audio: Add Audio Card GetProperties
  2013-02-26 13:50 ` [PATCH v1 0/9] handsfree-audio: Audio Card registration Claudio Takahasi
                     ` (5 preceding siblings ...)
  2013-02-26 13:50   ` [PATCH v1 6/9] handsfree-audio: Remove Audio Card for local initiated disconnection Claudio Takahasi
@ 2013-02-26 13:50   ` Claudio Takahasi
  2013-02-26 13:50   ` [PATCH v1 8/9] handsfree-audio: Add Audio Cards hash table Claudio Takahasi
                     ` (2 subsequent siblings)
  9 siblings, 0 replies; 20+ messages in thread
From: Claudio Takahasi @ 2013-02-26 13:50 UTC (permalink / raw)
  To: ofono

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

This patch adds the initial implementation of the GetProperties method
of the Handsfree Audio Card. This version supports the Bluetooth address
of the remote peer only.
---
 src/handsfree-audio.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index fcebce8..f8c598f 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -285,7 +285,19 @@ void ofono_handsfree_audio_unref(void)
 static DBusMessage *card_get_properties(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
-	return __ofono_error_not_implemented(msg);
+	struct audio_card *card = user_data;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+
+	reply = dbus_message_new_method_return(msg);
+	if (reply == NULL)
+		return NULL;
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	card_append_properties(&iter, card);
+
+	return reply;
 }
 
 static const GDBusMethodTable card_methods[] = {
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v1 8/9] handsfree-audio: Add Audio Cards hash table
  2013-02-26 13:50 ` [PATCH v1 0/9] handsfree-audio: Audio Card registration Claudio Takahasi
                     ` (6 preceding siblings ...)
  2013-02-26 13:50   ` [PATCH v1 7/9] handsfree-audio: Add Audio Card GetProperties Claudio Takahasi
@ 2013-02-26 13:50   ` Claudio Takahasi
  2013-02-26 13:50   ` [PATCH v1 9/9] handsfree-audio: Add Audio Manager GetCards Claudio Takahasi
  2013-02-26 22:08   ` [PATCH v1 0/9] handsfree-audio: Audio Card registration Claudio Takahasi
  9 siblings, 0 replies; 20+ messages in thread
From: Claudio Takahasi @ 2013-02-26 13:50 UTC (permalink / raw)
  To: ofono

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

This patch adds a hash table to store the created Audio Cards. This
hash is required to create Audio Manager GetCards() reply.
---
 src/handsfree-audio.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index f8c598f..d839131 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -57,6 +57,7 @@ struct audio_card {
 
 static struct agent *agent = NULL;
 static int ref_count = 0;
+static GHashTable *cards_hash = NULL;
 
 static void agent_free(struct agent *agent)
 {
@@ -327,6 +328,8 @@ char *ofono_handsfree_card_create(const char *remote)
 	card->remote = g_strdup(remote);
 	am_emit_card_added(path, card);
 
+	g_hash_table_insert(cards_hash, g_strdup(path), card);
+
 	DBG("Audio Card added: %s", path);
 
 	return path;
@@ -334,6 +337,9 @@ char *ofono_handsfree_card_create(const char *remote)
 
 void ofono_handsfree_card_remove(const char *path)
 {
+	if (!g_hash_table_remove(cards_hash, path))
+		return;
+
 	am_emit_card_removed(path);
 
 	g_dbus_unregister_interface(ofono_dbus_get_connection(), path,
@@ -344,6 +350,8 @@ void ofono_handsfree_card_remove(const char *path)
 
 int __ofono_handsfree_audio_manager_init(void)
 {
+	cards_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+							g_free, NULL);
 	return 0;
 }
 
@@ -357,4 +365,6 @@ void __ofono_handsfree_audio_manager_cleanup(void)
 
 	ref_count = 1;
 	ofono_handsfree_audio_unref();
+
+	g_hash_table_destroy(cards_hash);
 }
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v1 9/9] handsfree-audio: Add Audio Manager GetCards
  2013-02-26 13:50 ` [PATCH v1 0/9] handsfree-audio: Audio Card registration Claudio Takahasi
                     ` (7 preceding siblings ...)
  2013-02-26 13:50   ` [PATCH v1 8/9] handsfree-audio: Add Audio Cards hash table Claudio Takahasi
@ 2013-02-26 13:50   ` Claudio Takahasi
  2013-02-26 22:08   ` [PATCH v1 0/9] handsfree-audio: Audio Card registration Claudio Takahasi
  9 siblings, 0 replies; 20+ messages in thread
From: Claudio Takahasi @ 2013-02-26 13:50 UTC (permalink / raw)
  To: ofono

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

This patch adds the Handsfree Audio Manager GetCards() method
implementation. It returns an array of Audio Cards, where each
entry is composed by the object path of the Audio Card, and a
dictionary of it's properties.
---
 src/handsfree-audio.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index d839131..b562859 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -111,10 +111,54 @@ static void card_append_properties(DBusMessageIter *iter,
 	dbus_message_iter_close_container(iter, &dict);
 }
 
+static void hash_card_entry(gpointer key, gpointer value, gpointer user_data)
+{
+	const char *path = key;
+	struct audio_card *card = value;
+	DBusMessageIter entry, *array = user_data;
+
+	dbus_message_iter_open_container(array, DBUS_TYPE_STRUCT,
+							NULL, &entry);
+
+	dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH, &path);
+
+	card_append_properties(&entry, card);
+
+	dbus_message_iter_close_container(array, &entry);
+}
+
 static DBusMessage *am_get_cards(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
-	return __ofono_error_not_implemented(msg);
+	DBusMessage *reply;
+	DBusMessageIter iter, array;
+
+	reply = dbus_message_new_method_return(msg);
+	if (reply == NULL)
+		return NULL;
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	/*
+	 * a{oa{sv}}: Array of cards containing the object path of the
+	 * Audio Card and a dictionary of it's properties
+	 */
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+					DBUS_STRUCT_BEGIN_CHAR_AS_STRING
+					DBUS_TYPE_OBJECT_PATH_AS_STRING
+					DBUS_TYPE_ARRAY_AS_STRING
+					DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+					DBUS_TYPE_STRING_AS_STRING
+					DBUS_TYPE_VARIANT_AS_STRING
+					DBUS_DICT_ENTRY_END_CHAR_AS_STRING
+					DBUS_STRUCT_END_CHAR_AS_STRING,
+					&array);
+
+	g_hash_table_foreach(cards_hash, hash_card_entry, &iter);
+
+	dbus_message_iter_close_container(&iter, &array);
+
+	return reply;
 }
 
 static DBusMessage *am_agent_register(DBusConnection *conn,
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH v1 0/9] handsfree-audio: Audio Card registration
  2013-02-26 13:50 ` [PATCH v1 0/9] handsfree-audio: Audio Card registration Claudio Takahasi
                     ` (8 preceding siblings ...)
  2013-02-26 13:50   ` [PATCH v1 9/9] handsfree-audio: Add Audio Manager GetCards Claudio Takahasi
@ 2013-02-26 22:08   ` Claudio Takahasi
  9 siblings, 0 replies; 20+ messages in thread
From: Claudio Takahasi @ 2013-02-26 22:08 UTC (permalink / raw)
  To: ofono

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

Hi:

On Tue, Feb 26, 2013 at 10:50 AM, Claudio Takahasi
<claudio.takahasi@openbossa.org> wrote:
> This patch series adds the initial Handsfree Audio Card hierarchy
> implementation.
>
> Not implemented in this series:
> * SCO audio connection
> * LocalAddress property
>
> Changes from v0-v1:
> * Changed Audio Card object path: it is now using sequential name "device%d"
> * Replaced atom modem tracking by handsfree_audio_create and handsfree_audio_remove functions
>
> Claudio Takahasi (9):
>   handsfree-audio: Add creating Audio Card
>   handsfree-audio: Add removing Audio Card
>   handsfree-audio: Add emitting CardAdded
>   handsfree-audio: Add emitting CardRemoved
>   handsfree-audio: Remove Audio Card when HFP is removed
>   handsfree-audio: Remove Audio Card for local initiated disconnection
>   handsfree-audio: Add Audio Card GetProperties
>   handsfree-audio: Add Audio Cards hash table
>   handsfree-audio: Add Audio Manager GetCards
>
>  include/handsfree-audio.h |   2 +
>  plugins/hfp_hf_bluez5.c   |  22 ++++++
>  src/handsfree-audio.c     | 195 +++++++++++++++++++++++++++++++++++++++++++++-
>  3 files changed, 217 insertions(+), 2 deletions(-)
>
> --
> 1.7.11.7
>

Ignore this patch series. Denis pushed his own version.

Claudio.

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2013-02-26 22:08 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-25 14:34 [PATCH v0 0/8] handsfree-audio: Audio Card registration Claudio Takahasi
2013-02-25 14:34 ` [PATCH v0 1/8] handsfree-audio: Add atom modem tracking Claudio Takahasi
2013-02-25 14:34 ` [PATCH v0 2/8] handsfree-audio: Add Audio Card registration Claudio Takahasi
2013-02-25 14:34 ` [PATCH v0 3/8] handsfree-audio: Add Audio Card GetProperties Claudio Takahasi
2013-02-25 14:34 ` [PATCH v0 4/8] handsfree-audio: Add emitting CardAdded Claudio Takahasi
2013-02-25 14:34 ` [PATCH v0 5/8] handsfree-audio: Add function to append properties Claudio Takahasi
2013-02-25 14:34 ` [PATCH v0 6/8] handsfree-audio: Add emitting CardRemoved Claudio Takahasi
2013-02-25 14:34 ` [PATCH v0 7/8] handsfree-audio: Add registered cards tracking Claudio Takahasi
2013-02-25 14:34 ` [PATCH v0 8/8] handsfree-audio: Add GetCards Claudio Takahasi
2013-02-26 13:50 ` [PATCH v1 0/9] handsfree-audio: Audio Card registration Claudio Takahasi
2013-02-26 13:50   ` [PATCH v1 1/9] handsfree-audio: Add creating Audio Card Claudio Takahasi
2013-02-26 13:50   ` [PATCH v1 2/9] handsfree-audio: Add removing " Claudio Takahasi
2013-02-26 13:50   ` [PATCH v1 3/9] handsfree-audio: Add emitting CardAdded Claudio Takahasi
2013-02-26 13:50   ` [PATCH v1 4/9] handsfree-audio: Add emitting CardRemoved Claudio Takahasi
2013-02-26 13:50   ` [PATCH v1 5/9] handsfree-audio: Remove Audio Card when HFP is removed Claudio Takahasi
2013-02-26 13:50   ` [PATCH v1 6/9] handsfree-audio: Remove Audio Card for local initiated disconnection Claudio Takahasi
2013-02-26 13:50   ` [PATCH v1 7/9] handsfree-audio: Add Audio Card GetProperties Claudio Takahasi
2013-02-26 13:50   ` [PATCH v1 8/9] handsfree-audio: Add Audio Cards hash table Claudio Takahasi
2013-02-26 13:50   ` [PATCH v1 9/9] handsfree-audio: Add Audio Manager GetCards Claudio Takahasi
2013-02-26 22:08   ` [PATCH v1 0/9] handsfree-audio: Audio Card registration Claudio Takahasi

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.