Skip to contentSkip to conversation

android/avrcp-lib: Change API to register callbacks instead of PDU handlers

PATCH In review Luiz Augusto von Dentz 2 participants 3 messages Mar 12, 2014 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 android/avrcp-lib: Change API to register callbacks instead of PDU handlers

From: Luiz Augusto von Dentz <[email protected]>

This adds avrcp_register_player function to register callbacks for requests and responses, the fundamental difference is that the callbacks are called after the original PDU is parsed and the parameter are converted to host byte order making us able to unit test the parsing itself.

---
 android/avrcp-lib.c | 23 +++++++++++++++++
 android/avrcp-lib.h | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+)
android/avrcp-lib.c +23 -0
index befc404..953674b 100644
@@ -73,6 +73,7 @@ struct avrcp_header {
 
 struct avrcp {
 	struct avctp *conn;
+	struct avrcp_player *player;
 
 	size_t tx_mtu;
 	uint8_t *tx_buf;
@@ -89,6 +90,13 @@ struct avrcp {
 	void *destroy_data;
 };
 
+struct avrcp_player {
+	const struct avrcp_control_ind *ind;
+	const struct avrcp_control_cfm *cfm;
+
+	void *user_data;
+};
+
 void avrcp_shutdown(struct avrcp *session)
 {
 	if (session->conn) {
@@ -249,6 +257,21 @@ void avrcp_set_destroy_cb(struct avrcp *session, avrcp_destroy_cb_t cb,
 	session->destroy_data = user_data;
 }
 
+void avrcp_register_player(struct avrcp *session,
+				const struct avrcp_control_ind *ind,
+				const struct avrcp_control_cfm *cfm,
+				void *user_data)
+{
+	struct avrcp_player *player;
+
+	player = g_new0(struct avrcp_player, 1);
+	player->ind = ind;
+	player->cfm = cfm;
+	player->user_data = user_data;
+
+	session->player = player;
+}
+
 void avrcp_set_control_handlers(struct avrcp *session,
 				const struct avrcp_control_handler *handlers,
 				void *user_data)
android/avrcp-lib.h +73 -0

85 lines not on this page · raw message

Signature · 1 line
1.8.5.3
#1 lore raw

Hi Luiz,

Quoted 40 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds avrcp_register_player function to register callbacks for requests and responses, the fundamental difference is that the callbacks are called after the original PDU is parsed and the parameter are converted to host byte order making us able to unit test the parsing itself.

---
 android/avrcp-lib.c | 23 +++++++++++++++++
 android/avrcp-lib.h | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+)
android/avrcp-lib.c +8 -0
index befc404..953674b 100644
@@ -73,6 +73,7 @@ struct avrcp_header {
 
 struct avrcp {
 	struct avctp *conn;
+	struct avrcp_player *player;
 
 	size_t tx_mtu;
 	uint8_t *tx_buf;
@@ -89,6 +90,13 @@ struct avrcp {
 	void *destroy_data;
 };
 
+struct avrcp_player {
+	const struct avrcp_control_ind *ind;
+	const struct avrcp_control_cfm *cfm;
+
+	void *user_data;
+};
+
 void avrcp_shutdown(struct avrcp *session)
 {
 	if (session->conn) {
@@ -249,6 +257,21 @@ void avrcp_set_destroy_cb(struct avrcp *session, avrcp_destroy_cb_t cb,
 	session->destroy_data = user_data;

android/avrcp-lib.c void avrcp_set_destroy_cb(struct avrcp *session, avrcp_destroy_cb_t cb, · line 267

Quoted 10 lines
android/avrcp-lib.c +8 -0
 }
 
+void avrcp_register_player(struct avrcp *session,
+				const struct avrcp_control_ind *ind,
+				const struct avrcp_control_cfm *cfm,
+				void *user_data)
+{
+	struct avrcp_player *player;
+
+	player = g_new0(struct avrcp_player, 1);

where do you free it?

Best regards
Andrei Emeltchenko

Quoted 108 lines
android/avrcp-lib.c +7 -0
+	player->ind = ind;
+	player->cfm = cfm;
+	player->user_data = user_data;
+
+	session->player = player;
+}
+
 void avrcp_set_control_handlers(struct avrcp *session,
 				const struct avrcp_control_handler *handlers,
 				void *user_data)
android/avrcp-lib.h +73 -0
index 91a7d47..62c989d 100644
@@ -99,6 +99,74 @@ struct avrcp_control_handler {
 			uint16_t params_len, uint8_t *params, void *user_data);
 };
 
+struct avrcp_control_ind {
+	int (*get_capabilities) (struct avrcp *session,
+					uint8_t transaction, void *user_data);
+	int (*list_attributes) (struct avrcp *session,
+					uint8_t transaction, void *user_data);
+	int (*get_attribute_text) (struct avrcp *session, uint8_t transaction,
+					uint16_t number, uint8_t *attrs,
+					void *user_data);
+	int (*list_values) (struct avrcp *session, uint8_t transaction,
+					uint8_t attr, void *user_data);
+	int (*get_value_text) (struct avrcp *session, uint8_t transaction,
+					uint8_t attr, void *user_data);
+	int (*get_value) (struct avrcp *session, uint8_t transaction,
+					uint16_t number, uint8_t *attrs,
+					void *user_data);
+	int (*set_value) (struct avrcp *session, uint8_t transaction,
+					uint16_t number, uint8_t *attrs,
+					void *user_data);
+	int (*get_play_status) (struct avrcp *session, uint8_t transaction,
+					void *user_data);
+	int (*get_element_attributes) (struct avrcp *session,
+					uint8_t transaction, uint8_t number,
+					uint32_t *attrs, void *user_data);
+	int (*register_notification) (struct avrcp *session,
+					uint8_t transaction, uint8_t event,
+					uint32_t interval, void *user_data);
+};
+
+struct avrcp_element {
+	uint32_t attr;
+	char *value;
+};
+
+struct avrcp_control_cfm {
+	void (*get_capabilities) (struct avrcp *session, int err,
+					uint8_t *events, void *user_data);
+	void (*list_attributes) (struct avrcp *session, int err,
+					uint8_t number, uint8_t *attrs,
+					void *user_data);
+	void (*get_attribute_text) (struct avrcp *session, int err,
+					uint16_t number, uint8_t *attrs,
+					void *user_data);
+	void (*list_values) (struct avrcp *session, int err,
+					uint8_t number, uint8_t *values,
+					void *user_data);
+	void (*get_value_text) (struct avrcp *session, int err,
+					const char *value, void *user_data);
+	void (*get_value) (struct avrcp *session, int err,
+					uint16_t number, uint8_t *attrs,
+					void *user_data);
+	void (*set_value) (struct avrcp *session, int err,
+					uint16_t number, uint8_t *attrs,
+					void *user_data);
+	void (*get_play_status) (struct avrcp *session, int err,
+					uint32_t position, uint32_t duration,
+					void *user_data);
+	void (*get_element_attributes) (struct avrcp *session, int err,
+					const GSList *elements,
+					void *user_data);
+	void (*status_changed) (struct avrcp *session, int err,
+					uint8_t status, void *user_data);
+	void (*track_changed) (struct avrcp *session, int err,
+					uint64_t uid, void *user_data);
+	void (*settings_changed) (struct avrcp *session, int err,
+					uint8_t number, uint8_t *attrs,
+					void *user_data);
+};
+
 struct avrcp_passthrough_handler {
 	uint8_t op;
 	bool (*func) (struct avrcp *session, bool pressed, void *user_data);
@@ -122,6 +190,11 @@ struct avrcp *avrcp_new(int fd, size_t imtu, size_t omtu, uint16_t version);
 void avrcp_shutdown(struct avrcp *session);
 void avrcp_set_destroy_cb(struct avrcp *session, avrcp_destroy_cb_t cb,
 							void *user_data);
+
+void avrcp_register_player(struct avrcp *session,
+				const struct avrcp_control_ind *ind,
+				const struct avrcp_control_cfm *cfm,
+				void *user_data);
 void avrcp_set_control_handlers(struct avrcp *session,
 				const struct avrcp_control_handler *handlers,
 				void *user_data);
Signature · 6 lines
1.8.5.3

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author maintainer
#2 lore raw

Hi Andrei,

Quoted 45 lines · Andrei Emeltchenko

Hi Luiz,

Quoted 42 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds avrcp_register_player function to register callbacks for requests and responses, the fundamental difference is that the callbacks are called after the original PDU is parsed and the parameter are converted to host byte order making us able to unit test the parsing itself.

---
 android/avrcp-lib.c | 23 +++++++++++++++++
 android/avrcp-lib.h | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+)
android/avrcp-lib.c +8 -0
index befc404..953674b 100644
@@ -73,6 +73,7 @@ struct avrcp_header {
 
 struct avrcp {
      struct avctp *conn;
+     struct avrcp_player *player;
 
      size_t tx_mtu;
      uint8_t *tx_buf;
@@ -89,6 +90,13 @@ struct avrcp {
      void *destroy_data;
 };
 
+struct avrcp_player {
+     const struct avrcp_control_ind *ind;
+     const struct avrcp_control_cfm *cfm;
+
+     void *user_data;
+};
+
 void avrcp_shutdown(struct avrcp *session)
 {
      if (session->conn) {
@@ -249,6 +257,21 @@ void avrcp_set_destroy_cb(struct avrcp *session, avrcp_destroy_cb_t cb,
      session->destroy_data = user_data;
 }
 
Quoted 10 lines

android/avrcp-lib.c void avrcp_set_destroy_cb(struct avrcp *session, avrcp_destroy_cb_t cb, · line 267

Quoted 8 lines
android/avrcp-lib.c +8 -0
+void avrcp_register_player(struct avrcp *session,
+                             const struct avrcp_control_ind *ind,
+                             const struct avrcp_control_cfm *cfm,
+                             void *user_data)
+{
+     struct avrcp_player *player;
+
+     player = g_new0(struct avrcp_player, 1);

where do you free it?

Most likely with the session, this is not the complete implementation just an idea.