* [PATCH BlueZ 2/4] android/avctp: Make handler return ssize_t
2014-02-28 13:42 [PATCH BlueZ 1/4] android/avrcp-lib: Add avrcp_send function Luiz Augusto von Dentz
@ 2014-02-28 13:42 ` Luiz Augusto von Dentz
2014-02-28 13:42 ` [PATCH BlueZ 3/4] android/avrcp-lib: Rework handler callback parameters Luiz Augusto von Dentz
2014-02-28 13:42 ` [PATCH BlueZ 4/4] android/avrcp-lib: Embed response code into handler table Luiz Augusto von Dentz
2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2014-02-28 13:42 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This makes possible to return errors such as -EAGAIN to indicate the
request would block and a response will be sent asynchronously.
---
android/avctp.c | 17 ++++++++++++-----
android/avctp.h | 2 +-
android/avrcp-lib.c | 2 +-
unit/test-avctp.c | 2 +-
4 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/android/avctp.c b/android/avctp.c
index bc1bd80..aa5abc9 100644
--- a/android/avctp.c
+++ b/android/avctp.c
@@ -311,7 +311,7 @@ static gboolean auto_release(gpointer user_data)
return FALSE;
}
-static size_t handle_panel_passthrough(struct avctp *session,
+static ssize_t handle_panel_passthrough(struct avctp *session,
uint8_t transaction, uint8_t *code,
uint8_t *subunit, uint8_t *operands,
size_t operand_count, void *user_data)
@@ -402,7 +402,7 @@ done:
return operand_count;
}
-static size_t handle_unit_info(struct avctp *session,
+static ssize_t handle_unit_info(struct avctp *session,
uint8_t transaction, uint8_t *code,
uint8_t *subunit, uint8_t *operands,
size_t operand_count, void *user_data)
@@ -428,7 +428,7 @@ static size_t handle_unit_info(struct avctp *session,
return operand_count;
}
-static size_t handle_subunit_info(struct avctp *session,
+static ssize_t handle_subunit_info(struct avctp *session,
uint8_t transaction, uint8_t *code,
uint8_t *subunit, uint8_t *operands,
size_t operand_count, void *user_data)
@@ -849,8 +849,9 @@ static gboolean session_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
uint8_t *operands, code, subunit;
struct avctp_header *avctp;
struct avc_header *avc;
- int ret, packet_size, operand_count, sock;
+ int packet_size, operand_count, sock;
struct avctp_pdu_handler *handler;
+ ssize_t ret;
if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL))
goto failed;
@@ -910,10 +911,16 @@ static gboolean session_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
code = avc->code;
subunit = avc->subunit_type;
- packet_size += handler->cb(session, avctp->transaction, &code,
+ ret = handler->cb(session, avctp->transaction, &code,
&subunit, operands, operand_count,
handler->user_data);
+ if (ret < 0) {
+ if (ret == -EAGAIN)
+ return TRUE;
+ goto failed;
+ }
+ packet_size += ret;
avc->code = code;
avc->subunit_type = subunit;
diff --git a/android/avctp.h b/android/avctp.h
index dfa0ca6..2f419a2 100644
--- a/android/avctp.h
+++ b/android/avctp.h
@@ -113,7 +113,7 @@ struct avctp;
typedef bool (*avctp_passthrough_cb) (struct avctp *session,
uint8_t op, bool pressed,
void *user_data);
-typedef size_t (*avctp_control_pdu_cb) (struct avctp *session,
+typedef ssize_t (*avctp_control_pdu_cb) (struct avctp *session,
uint8_t transaction, uint8_t *code,
uint8_t *subunit, uint8_t *operands,
size_t operand_count, void *user_data);
diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index b1085f2..88d8875 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -129,7 +129,7 @@ void avrcp_shutdown(struct avrcp *session)
g_free(session);
}
-static size_t handle_vendordep_pdu(struct avctp *conn, uint8_t transaction,
+static ssize_t handle_vendordep_pdu(struct avctp *conn, uint8_t transaction,
uint8_t *code, uint8_t *subunit,
uint8_t *operands, size_t operand_count,
void *user_data)
diff --git a/unit/test-avctp.c b/unit/test-avctp.c
index be1dfd7..0759731 100644
--- a/unit/test-avctp.c
+++ b/unit/test-avctp.c
@@ -227,7 +227,7 @@ static void execute_context(struct context *context)
destroy_context(context);
}
-static size_t handler(struct avctp *session,
+static ssize_t handler(struct avctp *session,
uint8_t transaction, uint8_t *code,
uint8_t *subunit, uint8_t *operands,
size_t operand_count, void *user_data)
--
1.8.5.3
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH BlueZ 3/4] android/avrcp-lib: Rework handler callback parameters
2014-02-28 13:42 [PATCH BlueZ 1/4] android/avrcp-lib: Add avrcp_send function Luiz Augusto von Dentz
2014-02-28 13:42 ` [PATCH BlueZ 2/4] android/avctp: Make handler return ssize_t Luiz Augusto von Dentz
@ 2014-02-28 13:42 ` Luiz Augusto von Dentz
2014-02-28 13:42 ` [PATCH BlueZ 4/4] android/avrcp-lib: Embed response code into handler table Luiz Augusto von Dentz
2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2014-02-28 13:42 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This rework handler callback parameters to make it able to return
proper error such as -EAGAIN to implement asynchronous responses.
---
android/avrcp-lib.c | 12 +++++++++---
android/avrcp-lib.h | 5 +++--
unit/test-avrcp.c | 42 +++++++++++++++++++++---------------------
3 files changed, 33 insertions(+), 26 deletions(-)
diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 88d8875..ea36063 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -139,6 +139,7 @@ static ssize_t handle_vendordep_pdu(struct avctp *conn, uint8_t transaction,
struct avrcp_header *pdu = (void *) operands;
uint32_t company_id = ntoh24(pdu->company_id);
uint16_t params_len = ntohs(pdu->params_len);
+ ssize_t ret;
if (company_id != IEEEID_BTSIG) {
*code = AVC_CTYPE_NOT_IMPLEMENTED;
@@ -173,12 +174,17 @@ static ssize_t handle_vendordep_pdu(struct avctp *conn, uint8_t transaction,
goto reject;
}
- *code = handler->func(session, transaction, ¶ms_len,
+ ret = handler->func(session, transaction, code, params_len,
pdu->params, session->control_data);
+ if (ret < 0) {
+ if (ret == -EAGAIN)
+ return ret;
+ goto reject;
+ }
- pdu->params_len = htons(params_len);
+ pdu->params_len = htons(ret);
- return AVRCP_HEADER_LENGTH + params_len;
+ return AVRCP_HEADER_LENGTH + ret;
reject:
pdu->params_len = htons(1);
diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index 86e07bc..5cb0065 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -82,8 +82,9 @@ struct avrcp;
struct avrcp_control_handler {
uint8_t id;
uint8_t code;
- uint8_t (*func) (struct avrcp *session, uint8_t transaction,
- uint16_t *params_len, uint8_t *params, void *user_data);
+ ssize_t (*func) (struct avrcp *session, uint8_t transaction,
+ uint8_t *code, uint16_t params_len, uint8_t *params,
+ void *user_data);
};
struct avrcp_passthrough_handler {
diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
index db9cb92..160f1ce 100644
--- a/unit/test-avrcp.c
+++ b/unit/test-avrcp.c
@@ -305,54 +305,54 @@ static const struct avrcp_passthrough_handler passthrough_handlers[] = {
{ },
};
-static uint8_t avrcp_handle_get_capabilities(struct avrcp *session,
- uint8_t transaction, uint16_t *params_len,
- uint8_t *params, void *user_data)
+static ssize_t avrcp_handle_get_capabilities(struct avrcp *session,
+ uint8_t transaction, uint8_t *code,
+ uint16_t params_len, uint8_t *params,
+ void *user_data)
{
uint32_t id = 0x001958;
- DBG("params[0] %d params_len %d", params[0], *params_len);
-
- if (*params_len != 1)
+ if (params_len != 1)
goto fail;
switch (params[0]) {
case CAP_COMPANY_ID:
- *params_len = 5;
params[1] = 1;
hton24(¶ms[2], id);
- return AVC_CTYPE_STABLE;
+ *code = AVC_CTYPE_STABLE;
+ return 5;
}
fail:
- *params_len = 1;
params[0] = AVRCP_STATUS_INVALID_PARAM;
-
- return AVC_CTYPE_REJECTED;
+ *code = AVC_CTYPE_REJECTED;
+ return 1;
}
-static uint8_t avrcp_handle_list_attributes(struct avrcp *session,
- uint8_t transaction, uint16_t *params_len,
- uint8_t *params, void *user_data)
+static ssize_t avrcp_handle_list_attributes(struct avrcp *session,
+ uint8_t transaction, uint8_t *code,
+ uint16_t params_len, uint8_t *params,
+ void *user_data)
{
DBG("");
- *params_len = 1;
params[0] = 0;
+ *code = AVC_CTYPE_STABLE;
- return AVC_CTYPE_STABLE;
+ return 1;
}
-static uint8_t avrcp_handle_get_player_attr_text(struct avrcp *session,
- uint8_t transaction, uint16_t *params_len,
- uint8_t *params, void *user_data)
+static ssize_t avrcp_handle_get_player_attr_text(struct avrcp *session,
+ uint8_t transaction, uint8_t *code,
+ uint16_t params_len, uint8_t *params,
+ void *user_data)
{
DBG("");
- *params_len = 1;
params[0] = 0;
+ *code = AVC_CTYPE_STABLE;
- return AVC_CTYPE_STABLE;
+ return 1;
}
static const struct avrcp_control_handler control_handlers[] = {
--
1.8.5.3
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH BlueZ 4/4] android/avrcp-lib: Embed response code into handler table
2014-02-28 13:42 [PATCH BlueZ 1/4] android/avrcp-lib: Add avrcp_send function Luiz Augusto von Dentz
2014-02-28 13:42 ` [PATCH BlueZ 2/4] android/avctp: Make handler return ssize_t Luiz Augusto von Dentz
2014-02-28 13:42 ` [PATCH BlueZ 3/4] android/avrcp-lib: Rework handler callback parameters Luiz Augusto von Dentz
@ 2014-02-28 13:42 ` Luiz Augusto von Dentz
2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2014-02-28 13:42 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This makes the handlers code simpler as they don't need to care about
the response or reject opcode.
---
android/avrcp-lib.c | 16 ++++++++++++----
android/avrcp-lib.h | 4 ++--
unit/test-avrcp.c | 41 +++++++++++++++++++++--------------------
3 files changed, 35 insertions(+), 26 deletions(-)
diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index ea36063..34498d3 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -174,14 +174,22 @@ static ssize_t handle_vendordep_pdu(struct avctp *conn, uint8_t transaction,
goto reject;
}
- ret = handler->func(session, transaction, code, params_len,
- pdu->params, session->control_data);
+ ret = handler->func(session, transaction, params_len, pdu->params,
+ session->control_data);
if (ret < 0) {
- if (ret == -EAGAIN)
+ switch (ret) {
+ case -EAGAIN:
return ret;
- goto reject;
+ case -EINVAL:
+ pdu->params[0] = AVRCP_STATUS_INVALID_PARAM;
+ goto reject;
+ default:
+ pdu->params[0] = AVRCP_STATUS_INTERNAL_ERROR;
+ goto reject;
+ }
}
+ *code = handler->rsp;
pdu->params_len = htons(ret);
return AVRCP_HEADER_LENGTH + ret;
diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index 5cb0065..6738703 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -82,9 +82,9 @@ struct avrcp;
struct avrcp_control_handler {
uint8_t id;
uint8_t code;
+ uint8_t rsp;
ssize_t (*func) (struct avrcp *session, uint8_t transaction,
- uint8_t *code, uint16_t params_len, uint8_t *params,
- void *user_data);
+ uint16_t params_len, uint8_t *params, void *user_data);
};
struct avrcp_passthrough_handler {
diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
index 160f1ce..c3b4f39 100644
--- a/unit/test-avrcp.c
+++ b/unit/test-avrcp.c
@@ -31,6 +31,7 @@
#include <inttypes.h>
#include <string.h>
#include <fcntl.h>
+#include <errno.h>
#include <sys/socket.h>
#include <glib.h>
@@ -306,61 +307,61 @@ static const struct avrcp_passthrough_handler passthrough_handlers[] = {
};
static ssize_t avrcp_handle_get_capabilities(struct avrcp *session,
- uint8_t transaction, uint8_t *code,
- uint16_t params_len, uint8_t *params,
- void *user_data)
+ uint8_t transaction,
+ uint16_t params_len,
+ uint8_t *params,
+ void *user_data)
{
uint32_t id = 0x001958;
if (params_len != 1)
- goto fail;
+ return -EINVAL;
switch (params[0]) {
case CAP_COMPANY_ID:
params[1] = 1;
hton24(¶ms[2], id);
- *code = AVC_CTYPE_STABLE;
return 5;
}
-fail:
- params[0] = AVRCP_STATUS_INVALID_PARAM;
- *code = AVC_CTYPE_REJECTED;
- return 1;
+ return -EINVAL;
}
static ssize_t avrcp_handle_list_attributes(struct avrcp *session,
- uint8_t transaction, uint8_t *code,
- uint16_t params_len, uint8_t *params,
- void *user_data)
+ uint8_t transaction,
+ uint16_t params_len,
+ uint8_t *params,
+ void *user_data)
{
DBG("");
params[0] = 0;
- *code = AVC_CTYPE_STABLE;
return 1;
}
static ssize_t avrcp_handle_get_player_attr_text(struct avrcp *session,
- uint8_t transaction, uint8_t *code,
- uint16_t params_len, uint8_t *params,
- void *user_data)
+ uint8_t transaction,
+ uint16_t params_len,
+ uint8_t *params,
+ void *user_data)
{
DBG("");
params[0] = 0;
- *code = AVC_CTYPE_STABLE;
return 1;
}
static const struct avrcp_control_handler control_handlers[] = {
- { AVRCP_GET_CAPABILITIES, AVC_CTYPE_STATUS,
+ { AVRCP_GET_CAPABILITIES,
+ AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
avrcp_handle_get_capabilities },
- { AVRCP_LIST_PLAYER_ATTRIBUTES, AVC_CTYPE_STATUS,
+ { AVRCP_LIST_PLAYER_ATTRIBUTES,
+ AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
avrcp_handle_list_attributes },
- { AVRCP_GET_PLAYER_ATTRIBUTE_TEXT, AVC_CTYPE_STATUS,
+ { AVRCP_GET_PLAYER_ATTRIBUTE_TEXT,
+ AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
avrcp_handle_get_player_attr_text },
{ },
};
--
1.8.5.3
^ permalink raw reply related [flat|nested] 4+ messages in thread