Linux bluetooth development
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 1/4] android/avrcp-lib: Add status parameter
Date: Mon, 13 Oct 2014 12:55:47 +0300	[thread overview]
Message-ID: <1413194150-21751-1-git-send-email-luiz.dentz@gmail.com> (raw)

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds status parameter for functions generating browsing reponses
as it may not be possible to respond synchronously using the return of
the callback while processing the request.
---
 android/avrcp-lib.c | 91 ++++++++++++++++++++++++++++-------------------------
 android/avrcp-lib.h | 16 +++++-----
 unit/test-avrcp.c   | 13 ++++----
 3 files changed, 64 insertions(+), 56 deletions(-)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index b7d0f5e..f3cdab9 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -3337,6 +3337,20 @@ int avrcp_set_addressed_player_rsp(struct avrcp *session, uint8_t transaction,
 				&iov, 1);
 }
 
+static int avrcp_status_rsp(struct avrcp *session, uint8_t transaction,
+						uint8_t pdu_id, uint8_t status)
+{
+	struct iovec iov;
+
+	if (status > AVRCP_STATUS_ADDRESSED_PLAYER_CHANGED)
+		return -EINVAL;
+
+	iov.iov_base = &status;
+	iov.iov_len = sizeof(status);
+
+	return avrcp_send_browsing(session, transaction, pdu_id, &iov, 1);
+}
+
 int avrcp_set_browsed_player_rsp(struct avrcp *session, uint8_t transaction,
 					uint8_t status, uint16_t counter,
 					uint32_t items, uint8_t depth,
@@ -3347,13 +3361,9 @@ int avrcp_set_browsed_player_rsp(struct avrcp *session, uint8_t transaction,
 	uint16_t len[UINT8_MAX];
 	int i;
 
-	if (status != AVRCP_STATUS_SUCCESS) {
-		iov[0].iov_base = &status;
-		iov[0].iov_len = sizeof(status);
-		return avrcp_send_browsing(session, transaction,
-						AVRCP_SET_BROWSED_PLAYER,
-						iov, 1);
-	}
+	if (status != AVRCP_STATUS_SUCCESS)
+		return avrcp_status_rsp(session, transaction,
+					AVRCP_SET_BROWSED_PLAYER, status);
 
 	rsp.status = status;
 	put_be16(counter, &rsp.counter);
@@ -3390,16 +3400,20 @@ int avrcp_set_browsed_player_rsp(struct avrcp *session, uint8_t transaction,
 }
 
 int avrcp_get_folder_items_rsp(struct avrcp *session, uint8_t transaction,
-					uint16_t counter, uint8_t number,
-					uint8_t *type, uint16_t *len,
-					uint8_t **params)
+					uint8_t status, uint16_t counter,
+					uint8_t number, uint8_t *type,
+					uint16_t *len, uint8_t **params)
 {
 	struct iovec iov[UINT8_MAX * 2 + 1];
 	struct get_folder_items_rsp rsp;
 	uint8_t item[UINT8_MAX][3];
 	int i;
 
-	rsp.status = AVRCP_STATUS_SUCCESS;
+	if (status != AVRCP_STATUS_SUCCESS)
+		return avrcp_status_rsp(session, transaction,
+					AVRCP_GET_FOLDER_ITEMS, status);
+
+	rsp.status = status;
 	put_be16(counter, &rsp.counter);
 	put_be16(number, &rsp.number);
 
@@ -3422,12 +3436,16 @@ int avrcp_get_folder_items_rsp(struct avrcp *session, uint8_t transaction,
 }
 
 int avrcp_change_path_rsp(struct avrcp *session, uint8_t transaction,
-								uint32_t items)
+						uint8_t status, uint32_t items)
 {
 	struct iovec iov;
 	struct change_path_rsp rsp;
 
-	rsp.status = AVRCP_STATUS_SUCCESS;
+	if (status != AVRCP_STATUS_SUCCESS)
+		return avrcp_status_rsp(session, transaction, AVRCP_CHANGE_PATH,
+									status);
+
+	rsp.status = status;
 	put_be32(items, &rsp.items);
 
 	iov.iov_base = &rsp;
@@ -3477,12 +3495,9 @@ int avrcp_get_item_attributes_rsp(struct avrcp *session, uint8_t transaction,
 	if (number > AVRCP_MEDIA_ATTRIBUTE_LAST)
 		return -EINVAL;
 
-	if (status != AVRCP_STATUS_SUCCESS) {
-		iov[0].iov_base = &status;
-		iov[0].iov_len = sizeof(status);
-		return avrcp_send_browsing(session, transaction,
-					AVRCP_GET_ITEM_ATTRIBUTES, iov, 1);
-	}
+	if (status != AVRCP_STATUS_SUCCESS)
+		return avrcp_status_rsp(session, transaction,
+					AVRCP_GET_ITEM_ATTRIBUTES, status);
 
 	rsp.status = status;
 	rsp.number = number;
@@ -3498,27 +3513,24 @@ int avrcp_get_item_attributes_rsp(struct avrcp *session, uint8_t transaction,
 					number * 2 + 1);
 }
 
-int avrcp_play_item_rsp(struct avrcp *session, uint8_t transaction)
+int avrcp_play_item_rsp(struct avrcp *session, uint8_t transaction,
+								uint8_t status)
 {
-	struct iovec iov;
-	struct play_item_rsp rsp;
-
-	rsp.status = AVRCP_STATUS_SUCCESS;
-
-	iov.iov_base = &rsp;
-	iov.iov_len = sizeof(rsp);
-
-	return avrcp_send_browsing(session, transaction, AVRCP_PLAY_ITEM,
-								&iov, 1);
+	return avrcp_status_rsp(session, transaction, AVRCP_PLAY_ITEM,
+								status);
 }
 
-int avrcp_search_rsp(struct avrcp *session, uint8_t transaction,
+int avrcp_search_rsp(struct avrcp *session, uint8_t transaction, uint8_t status,
 					uint16_t counter, uint32_t items)
 {
 	struct iovec iov;
 	struct search_rsp rsp;
 
-	rsp.status = AVRCP_STATUS_SUCCESS;
+	if (status != AVRCP_STATUS_SUCCESS)
+		return avrcp_status_rsp(session, transaction, AVRCP_SEARCH,
+								status);
+
+	rsp.status = status;
 	put_be16(counter, &rsp.counter);
 	put_be32(items, &rsp.items);
 
@@ -3529,18 +3541,11 @@ int avrcp_search_rsp(struct avrcp *session, uint8_t transaction,
 								&iov, 1);
 }
 
-int avrcp_add_to_now_playing_rsp(struct avrcp *session, uint8_t transaction)
+int avrcp_add_to_now_playing_rsp(struct avrcp *session, uint8_t transaction,
+								uint8_t status)
 {
-	struct iovec iov;
-	struct add_to_now_playing_rsp rsp;
-
-	rsp.status = AVRCP_STATUS_SUCCESS;
-
-	iov.iov_base = &rsp;
-	iov.iov_len = sizeof(rsp);
-
-	return avrcp_send_browsing(session, transaction,
-					AVRCP_ADD_TO_NOW_PLAYING, &iov, 1);
+	return avrcp_status_rsp(session, transaction, AVRCP_ADD_TO_NOW_PLAYING,
+								status);
 }
 
 int avrcp_send_passthrough(struct avrcp *session, uint32_t vendor, uint8_t op)
diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index 9985c4a..2299c83 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -327,17 +327,19 @@ int avrcp_set_browsed_player_rsp(struct avrcp *session, uint8_t transaction,
 					uint32_t items, uint8_t depth,
 					const char **folders);
 int avrcp_get_folder_items_rsp(struct avrcp *session, uint8_t transaction,
-					uint16_t counter, uint8_t number,
-					uint8_t *type, uint16_t *len,
-					uint8_t **params);
+					uint8_t status, uint16_t counter,
+					uint8_t number, uint8_t *type,
+					uint16_t *len, uint8_t **params);
 int avrcp_change_path_rsp(struct avrcp *session, uint8_t transaction,
-								uint32_t items);
+						uint8_t status, uint32_t items);
 int avrcp_get_item_attributes_rsp(struct avrcp *session, uint8_t transaction,
 					uint8_t status, uint8_t number,
 					uint32_t *attrs, const char **text);
-int avrcp_play_item_rsp(struct avrcp *session, uint8_t transaction);
-int avrcp_search_rsp(struct avrcp *session, uint8_t transaction,
+int avrcp_play_item_rsp(struct avrcp *session, uint8_t transaction,
+					uint8_t status);
+int avrcp_search_rsp(struct avrcp *session, uint8_t transaction, uint8_t status,
 					uint16_t counter, uint32_t items);
-int avrcp_add_to_now_playing_rsp(struct avrcp *session, uint8_t transaction);
+int avrcp_add_to_now_playing_rsp(struct avrcp *session, uint8_t transaction,
+								uint8_t status);
 
 int avrcp_send_passthrough(struct avrcp *session, uint32_t vendor, uint8_t op);
diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
index 154175e..a6a1872 100644
--- a/unit/test-avrcp.c
+++ b/unit/test-avrcp.c
@@ -719,8 +719,8 @@ static int get_folder_items(struct avrcp *session, uint8_t transaction,
 	if (start > 1)
 		return -ERANGE;
 
-	avrcp_get_folder_items_rsp(session, transaction, 0xabcd, 0, NULL, NULL,
-									NULL);
+	avrcp_get_folder_items_rsp(session, transaction, AVRCP_STATUS_SUCCESS,
+						0xabcd, 0, NULL, NULL, NULL);
 
 	return -EAGAIN;
 }
@@ -734,7 +734,7 @@ static int change_path(struct avrcp *session, uint8_t transaction,
 	if (!uid)
 		return -ENOTDIR;
 
-	avrcp_change_path_rsp(session, transaction, 0);
+	avrcp_change_path_rsp(session, transaction, AVRCP_STATUS_SUCCESS, 0);
 
 	return -EAGAIN;
 }
@@ -768,7 +768,7 @@ static int play_item(struct avrcp *session, uint8_t transaction, uint8_t scope,
 	if (!uid)
 		return -ENOENT;
 
-	avrcp_play_item_rsp(session, transaction);
+	avrcp_play_item_rsp(session, transaction, AVRCP_STATUS_SUCCESS);
 
 	return -EAGAIN;
 }
@@ -778,7 +778,7 @@ static int search(struct avrcp *session, uint8_t transaction,
 {
 	DBG("");
 
-	avrcp_search_rsp(session, transaction, 0xaabb, 0);
+	avrcp_search_rsp(session, transaction, AVRCP_STATUS_SUCCESS, 0xaabb, 0);
 
 	return -EAGAIN;
 }
@@ -792,7 +792,8 @@ static int add_to_now_playing(struct avrcp *session, uint8_t transaction,
 	if (!uid)
 		return -ENOENT;
 
-	avrcp_add_to_now_playing_rsp(session, transaction);
+	avrcp_add_to_now_playing_rsp(session, transaction,
+							AVRCP_STATUS_SUCCESS);
 
 	return -EAGAIN;
 }
-- 
1.9.3


             reply	other threads:[~2014-10-13  9:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-13  9:55 Luiz Augusto von Dentz [this message]
2014-10-13  9:55 ` [PATCH BlueZ 2/4] android/avrcp-lib: Rework callback return Luiz Augusto von Dentz
2014-10-13  9:55 ` [PATCH BlueZ 3/4] android/avrcp-lib: Add checks for unknown events Luiz Augusto von Dentz
2014-10-13  9:55 ` [PATCH BlueZ 4/4] unit/test-avrcp: Add /TP/MCN/NP/BV-07-C test Luiz Augusto von Dentz
2014-10-17  8:14 ` [PATCH BlueZ 1/4] android/avrcp-lib: Add status parameter Luiz Augusto von Dentz

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=1413194150-21751-1-git-send-email-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.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