summaryrefslogtreecommitdiffstats
path: root/btif/src/btif_profile_queue.c
diff options
context:
space:
mode:
authorSharvil Nanavati <sharvil@google.com>2014-04-25 23:16:01 -0700
committerPrerepa Viswanadham <dham@google.com>2014-06-12 01:35:03 +0000
commitfe10dd40a0b5b553467fff293a6addc56e4eae90 (patch)
tree5132fdcea7ae8025e550e5c9038218c86c2d3185 /btif/src/btif_profile_queue.c
parent540e7cab4a9a47dc2d38f96e332e19d16dbfc1d2 (diff)
downloadandroid_system_bt-fe10dd40a0b5b553467fff293a6addc56e4eae90.tar.gz
android_system_bt-fe10dd40a0b5b553467fff293a6addc56e4eae90.tar.bz2
android_system_bt-fe10dd40a0b5b553467fff293a6addc56e4eae90.zip
Update btif_profile_queue to use the list data structure.
The profile queue maintains a list of pending connect operations for each profile. If a connect is followed by a disconnect before the queued connect is dispatched, the disconnect will have no effect and the connect will proceed. This code clearly needs to be re-thought; it may be a good idea to abandon the connect queue entirely in the long-run. Change-Id: Ic0e85654abcf7a47f65953edb301eb9524394950
Diffstat (limited to 'btif/src/btif_profile_queue.c')
-rw-r--r--btif/src/btif_profile_queue.c98
1 files changed, 34 insertions, 64 deletions
diff --git a/btif/src/btif_profile_queue.c b/btif/src/btif_profile_queue.c
index 4af3b53d2..b9bbe1708 100644
--- a/btif/src/btif_profile_queue.c
+++ b/btif/src/btif_profile_queue.c
@@ -30,6 +30,7 @@
#include "btif_common.h"
#include "btif_profile_queue.h"
#include "gki.h"
+#include "list.h"
/*******************************************************************************
** Local type definitions
@@ -37,81 +38,64 @@
typedef enum {
BTIF_QUEUE_CONNECT_EVT,
- BTIF_QUEUE_ADVANCE_EVT
+ BTIF_QUEUE_ADVANCE_EVT,
} btif_queue_event_t;
-typedef struct connect_node_tag
-{
+typedef struct {
bt_bdaddr_t bda;
uint16_t uuid;
- uint16_t busy;
- void *p_cb;
- struct connect_node_tag *p_next;
-} __attribute__((packed))connect_node_t;
-
+ bool busy;
+ btif_connect_cb_t connect_cb;
+} connect_node_t;
/*******************************************************************************
** Static variables
*******************************************************************************/
-static connect_node_t *connect_queue;
-
+static list_t *connect_queue;
/*******************************************************************************
** Queue helper functions
*******************************************************************************/
-static void queue_int_add(connect_node_t *p_param)
-{
- connect_node_t *p_list = connect_queue;
+static void queue_int_add(connect_node_t *p_param) {
connect_node_t *p_node = GKI_getbuf(sizeof(connect_node_t));
ASSERTC(p_node != NULL, "Failed to allocate new list node", 0);
memcpy(p_node, p_param, sizeof(connect_node_t));
- if (connect_queue == NULL)
- {
- connect_queue = p_node;
- return;
+ if (!connect_queue) {
+ connect_queue = list_new(GKI_freebuf);
+ ASSERTC(connect_queue != NULL, "Failed to allocate list", 0);
}
- while (p_list->p_next)
- p_list = p_list->p_next;
- p_list->p_next = p_node;
+ list_append(connect_queue, p_node);
}
-static void queue_int_advance()
-{
- connect_node_t *p_head = connect_queue;
- if (connect_queue == NULL)
- return;
-
- connect_queue = connect_queue->p_next;
- GKI_freebuf(p_head);
+static void queue_int_advance() {
+ if (connect_queue && !list_is_empty(connect_queue))
+ list_remove(connect_queue, list_front(connect_queue));
}
-static bt_status_t queue_int_connect_next()
-{
- connect_node_t* p_head = connect_queue;
-
- if (p_head == NULL)
+static bt_status_t queue_int_connect_next() {
+ if (!connect_queue || list_is_empty(connect_queue))
return BT_STATUS_FAIL;
- /* If the queue is currently busy, we return success anyway,
- * since the connection has been queued... */
- if (p_head->busy != FALSE)
+ connect_node_t *p_head = list_front(connect_queue);
+
+ // If the queue is currently busy, we return success anyway,
+ // since the connection has been queued...
+ if (p_head->busy)
return BT_STATUS_SUCCESS;
- p_head->busy = TRUE;
- return (*(btif_connect_cb_t*)p_head->p_cb)(&p_head->bda);
+ p_head->busy = true;
+ return p_head->connect_cb(&p_head->bda);
}
-static void queue_int_handle_evt(UINT16 event, char *p_param)
-{
- switch(event)
- {
+static void queue_int_handle_evt(UINT16 event, char *p_param) {
+ switch(event) {
case BTIF_QUEUE_CONNECT_EVT:
- queue_int_add((connect_node_t*)p_param);
+ queue_int_add((connect_node_t *)p_param);
break;
case BTIF_QUEUE_ADVANCE_EVT:
@@ -132,17 +116,15 @@ static void queue_int_handle_evt(UINT16 event, char *p_param)
** Returns BT_STATUS_SUCCESS if successful
**
*******************************************************************************/
-bt_status_t btif_queue_connect(uint16_t uuid, const bt_bdaddr_t *bda,
- btif_connect_cb_t *connect_cb)
-{
+bt_status_t btif_queue_connect(uint16_t uuid, const bt_bdaddr_t *bda, btif_connect_cb_t connect_cb) {
connect_node_t node;
memset(&node, 0, sizeof(connect_node_t));
- memcpy(&(node.bda), bda, sizeof(bt_bdaddr_t));
+ memcpy(&node.bda, bda, sizeof(bt_bdaddr_t));
node.uuid = uuid;
- node.p_cb = connect_cb;
+ node.connect_cb = connect_cb;
return btif_transfer_context(queue_int_handle_evt, BTIF_QUEUE_CONNECT_EVT,
- (char*)&node, sizeof(connect_node_t), NULL);
+ (char *)&node, sizeof(connect_node_t), NULL);
}
/*******************************************************************************
@@ -155,13 +137,11 @@ bt_status_t btif_queue_connect(uint16_t uuid, const bt_bdaddr_t *bda,
** Returns void
**
*******************************************************************************/
-void btif_queue_advance()
-{
+void btif_queue_advance() {
btif_transfer_context(queue_int_handle_evt, BTIF_QUEUE_ADVANCE_EVT,
NULL, 0, NULL);
}
-
/*******************************************************************************
**
** Function btif_queue_release
@@ -171,17 +151,7 @@ void btif_queue_advance()
** Returns void
**
*******************************************************************************/
-void btif_queue_release()
-{
- connect_node_t *current = connect_queue;
-
- while (current != NULL)
- {
- connect_node_t *next = current->p_next;
- GKI_freebuf(current);
- current = next;
- }
-
+void btif_queue_release() {
+ list_free(connect_queue);
connect_queue = NULL;
}
-