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 10/12] android/avrcp-lib: Add support for parsing GetPlayStatus response
Date: Wed, 26 Mar 2014 16:13:50 +0200	[thread overview]
Message-ID: <1395843232-26750-10-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1395843232-26750-1-git-send-email-luiz.dentz@gmail.com>

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

---
 android/avrcp-lib.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++----
 android/avrcp-lib.h |  6 ++++--
 unit/test-avrcp.c   |  2 +-
 3 files changed, 54 insertions(+), 7 deletions(-)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 9ce0aa2..3412354 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -1203,12 +1203,57 @@ int avrcp_set_player_value(struct avrcp *session, uint8_t number,
 				set_value_rsp, session);
 }
 
-int avrcp_get_play_status(struct avrcp *session, avctp_rsp_cb func,
-								void *user_data)
+static gboolean get_play_status_rsp(struct avctp *conn,
+					uint8_t code, uint8_t subunit,
+					uint8_t *operands, size_t operand_count,
+					void *user_data)
+{
+	struct avrcp *session = user_data;
+	struct avrcp_player *player = session->player;
+	struct avrcp_header *pdu;
+	uint8_t status = 0;
+	uint32_t position = 0;
+	uint32_t duration = 0;
+	int err;
+
+	DBG("");
+
+	if (!player || !player->cfm || !player->cfm->get_play_status)
+		return FALSE;
+
+	pdu = parse_pdu(operands, operand_count);
+	if (!pdu) {
+		err = -EPROTO;
+		goto done;
+	}
+
+	if (code == AVC_CTYPE_REJECTED) {
+		err = parse_status(pdu);
+		goto done;
+	}
+
+	if (pdu->params_len < 5) {
+		err = -EPROTO;
+		goto done;
+	}
+
+	duration = bt_get_be32(&pdu->params[0]);
+	position = bt_get_be32(&pdu->params[4]);
+	status = pdu->params[8];
+	err = 0;
+
+done:
+	player->cfm->get_play_status(session, err, status, position, duration,
+							player->user_data);
+
+	return FALSE;
+}
+
+int avrcp_get_play_status(struct avrcp *session)
 {
 	return avrcp_send_req(session, AVC_CTYPE_STATUS, AVC_SUBUNIT_PANEL,
-				AVRCP_GET_PLAY_STATUS, NULL, 0, func,
-				user_data);
+				AVRCP_GET_PLAY_STATUS, NULL, 0,
+				get_play_status_rsp, session);
 }
 
 int avrcp_set_volume(struct avrcp *session, uint8_t volume, avctp_rsp_cb func,
diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index 2a65f16..f5666eb 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -185,6 +185,9 @@ struct avrcp_control_cfm {
 	void (*set_value) (struct avrcp *session, int err,
 					uint8_t number, uint8_t *attrs,
 					uint8_t *values, void *user_data);
+	void (*get_play_status) (struct avrcp *session, int err,
+					uint8_t status, uint32_t position,
+					uint32_t duration, void *user_data);
 };
 
 struct avrcp_passthrough_handler {
@@ -225,8 +228,7 @@ int avrcp_set_player_value(struct avrcp *session, uint8_t number,
 					uint8_t *attrs, uint8_t *values);
 int avrcp_get_current_player_value(struct avrcp *session, uint8_t number,
 							uint8_t *attrs);
-int avrcp_get_play_status(struct avrcp *session, avctp_rsp_cb func,
-							void *user_data);
+int avrcp_get_play_status(struct avrcp *session);
 int avrcp_set_volume(struct avrcp *session, uint8_t volume, avctp_rsp_cb func,
 							void *user_data);
 int avrcp_get_element_attributes(struct avrcp *session, avctp_rsp_cb func,
diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
index 8f74e9c..ad15bb9 100644
--- a/unit/test-avrcp.c
+++ b/unit/test-avrcp.c
@@ -517,7 +517,7 @@ static void test_client(gconstpointer data)
 	}
 
 	if (g_str_equal(context->data->test_name, "/TP/MDI/BV-01-C"))
-		avrcp_get_play_status(context->session, NULL, NULL);
+		avrcp_get_play_status(context->session);
 
 	if (g_str_equal(context->data->test_name, "/TP/MDI/BV-03-C"))
 		avrcp_get_element_attributes(context->session, NULL, NULL);
-- 
1.8.5.3


  parent reply	other threads:[~2014-03-26 14:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-26 14:13 [PATCH BlueZ 01/12] android/avrcp-lib: Add support for parsing GetCapabilities response Luiz Augusto von Dentz
2014-03-26 14:13 ` [PATCH BlueZ 02/12] android/avrcp-lib: Add support for parsing ListPlayerAttributes response Luiz Augusto von Dentz
2014-03-26 14:13 ` [PATCH BlueZ 03/12] android/avrcp-lib: Add support for parsing GetPlayerAttributeText response Luiz Augusto von Dentz
2014-03-26 14:13 ` [PATCH BlueZ 04/12] android/avrcp-lib: Add avrcp_list_player_values Luiz Augusto von Dentz
2014-03-26 14:13 ` [PATCH BlueZ 05/12] android/avrcp-lib: Add support for parsing ListPlayerValues response Luiz Augusto von Dentz
2014-03-26 14:13 ` [PATCH BlueZ 06/12] android/avrcp-lib: Add avrcp_get_player_value_text Luiz Augusto von Dentz
2014-03-26 14:13 ` [PATCH BlueZ 07/12] android/avrcp-lib: Add support for parsing GetPlayerValueText response Luiz Augusto von Dentz
2014-03-26 14:13 ` [PATCH BlueZ 08/12] android/avrcp-lib: Add support for parsing GetCurrentPlayerValue response Luiz Augusto von Dentz
2014-03-27 15:01   ` Szymon Janc
2014-03-26 14:13 ` [PATCH BlueZ 09/12] android/avrcp-lib: Add support for parsing SetPlayerValue response Luiz Augusto von Dentz
2014-03-26 14:13 ` Luiz Augusto von Dentz [this message]
2014-03-26 14:13 ` [PATCH BlueZ 11/12] android/avrcp-lib: Add support for parsing GetElementAttributes response Luiz Augusto von Dentz
2014-03-26 14:13 ` [PATCH BlueZ 12/12] android/avrcp-lib: Add support for parsing RegisterNotification response Luiz Augusto von Dentz
2014-03-27 14:55 ` [PATCH BlueZ 01/12] android/avrcp-lib: Add support for parsing GetCapabilities response Szymon Janc

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=1395843232-26750-10-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