Use Bind in BTA_JvRfcommStartServer and BTA_JvRfcommStopServer
Bug: 68359837
Test: compilation test
Change-Id: I81ee51fc9bfce1ffb19621f5b4eab9028d089421
diff --git a/bta/jv/bta_jv_act.cc b/bta/jv/bta_jv_act.cc
index 9363302..a86714c 100644
--- a/bta/jv/bta_jv_act.cc
+++ b/bta/jv/bta_jv_act.cc
@@ -1646,28 +1646,21 @@
return p_pcb;
}
-/*******************************************************************************
- *
- * Function bta_jv_rfcomm_start_server
- *
- * Description waits for an RFCOMM client to connect
- *
- *
- * Returns void
- *
- ******************************************************************************/
-void bta_jv_rfcomm_start_server(tBTA_JV_MSG* p_data) {
+/* waits for an RFCOMM client to connect */
+void bta_jv_rfcomm_start_server(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
+ uint8_t local_scn, uint8_t max_session,
+ tBTA_JV_RFCOMM_CBACK* p_cback,
+ uint32_t rfcomm_slot_id) {
uint16_t handle = 0;
uint32_t event_mask = BTA_JV_RFC_EV_MASK;
tPORT_STATE port_state;
uint8_t sec_id = 0;
tBTA_JV_RFC_CB* p_cb = NULL;
tBTA_JV_PCB* p_pcb;
- tBTA_JV_API_RFCOMM_SERVER* rs = &(p_data->rfcomm_server);
tBTA_JV_RFCOMM_START evt_data;
/* TODO DM role manager
- L2CA_SetDesireRole(rs->role);
+ L2CA_SetDesireRole(role);
*/
memset(&evt_data, 0, sizeof(evt_data));
evt_data.status = BTA_JV_FAILURE;
@@ -1679,14 +1672,13 @@
sec_id = bta_jv_alloc_sec_id();
if (0 == sec_id ||
- !BTM_SetSecurityLevel(false, "JV PORT", sec_id, rs->sec_mask,
- BT_PSM_RFCOMM, BTM_SEC_PROTO_RFCOMM,
- rs->local_scn)) {
+ !BTM_SetSecurityLevel(false, "JV PORT", sec_id, sec_mask, BT_PSM_RFCOMM,
+ BTM_SEC_PROTO_RFCOMM, local_scn)) {
APPL_TRACE_ERROR("bta_jv_rfcomm_start_server, run out of sec_id");
break;
}
- if (RFCOMM_CreateConnection(sec_id, rs->local_scn, true, BTA_JV_DEF_RFC_MTU,
+ if (RFCOMM_CreateConnection(sec_id, local_scn, true, BTA_JV_DEF_RFC_MTU,
RawAddress::kAny, &handle,
bta_jv_port_mgmt_sr_cback) != PORT_SUCCESS) {
APPL_TRACE_ERROR(
@@ -1701,12 +1693,12 @@
break;
}
- p_cb->max_sess = rs->max_session;
- p_cb->p_cback = rs->p_cback;
+ p_cb->max_sess = max_session;
+ p_cb->p_cback = p_cback;
p_cb->sec_id = sec_id;
- p_cb->scn = rs->local_scn;
+ p_cb->scn = local_scn;
p_pcb->state = BTA_JV_ST_SR_LISTEN;
- p_pcb->rfcomm_slot_id = rs->rfcomm_slot_id;
+ p_pcb->rfcomm_slot_id = rfcomm_slot_id;
evt_data.status = BTA_JV_SUCCESS;
evt_data.handle = p_cb->handle;
evt_data.sec_id = sec_id;
@@ -1724,7 +1716,7 @@
tBTA_JV bta_jv;
bta_jv.rfc_start = evt_data;
- rs->p_cback(BTA_JV_RFCOMM_START_EVT, &bta_jv, rs->rfcomm_slot_id);
+ p_cback(BTA_JV_RFCOMM_START_EVT, &bta_jv, rfcomm_slot_id);
if (bta_jv.rfc_start.status == BTA_JV_SUCCESS) {
PORT_SetDataCOCallback(handle, bta_jv_port_data_co_cback);
} else {
@@ -1733,27 +1725,18 @@
}
}
-/*******************************************************************************
- *
- * Function bta_jv_rfcomm_stop_server
- *
- * Description stops an RFCOMM server
- *
- * Returns void
- *
- ******************************************************************************/
-
-void bta_jv_rfcomm_stop_server(tBTA_JV_MSG* p_data) {
- tBTA_JV_API_RFCOMM_SERVER* ls = &(p_data->rfcomm_server);
- tBTA_JV_RFC_CB* p_cb = NULL;
- tBTA_JV_PCB* p_pcb = NULL;
- APPL_TRACE_DEBUG("bta_jv_rfcomm_stop_server");
- if (!ls->handle) {
+/* stops an RFCOMM server */
+void bta_jv_rfcomm_stop_server(uint32_t handle, uint32_t rfcomm_slot_id) {
+ if (!handle) {
APPL_TRACE_ERROR("bta_jv_rfcomm_stop_server, jv handle is null");
return;
}
- if (!find_rfc_pcb(ls->rfcomm_slot_id, &p_cb, &p_pcb)) return;
+ APPL_TRACE_DEBUG("bta_jv_rfcomm_stop_server");
+ tBTA_JV_RFC_CB* p_cb = NULL;
+ tBTA_JV_PCB* p_pcb = NULL;
+
+ if (!find_rfc_pcb(rfcomm_slot_id, &p_cb, &p_pcb)) return;
APPL_TRACE_DEBUG("bta_jv_rfcomm_stop_server: p_pcb:%p, p_pcb->port_handle:%d",
p_pcb, p_pcb->port_handle);
bta_jv_free_rfc_cb(p_cb, p_pcb);
diff --git a/bta/jv/bta_jv_api.cc b/bta/jv/bta_jv_api.cc
index bc4e8b8..c2c5934 100644
--- a/bta/jv/bta_jv_api.cc
+++ b/bta/jv/bta_jv_api.cc
@@ -653,24 +653,16 @@
if (p_cback == NULL) return BTA_JV_FAILURE; /* Nothing to do */
- tBTA_JV_API_RFCOMM_SERVER* p_msg =
- (tBTA_JV_API_RFCOMM_SERVER*)osi_malloc(sizeof(tBTA_JV_API_RFCOMM_SERVER));
if (max_session == 0) max_session = 1;
if (max_session > BTA_JV_MAX_RFC_SR_SESSION) {
APPL_TRACE_DEBUG("max_session is too big. use max (%d)", max_session,
BTA_JV_MAX_RFC_SR_SESSION);
max_session = BTA_JV_MAX_RFC_SR_SESSION;
}
- p_msg->hdr.event = BTA_JV_API_RFCOMM_START_SERVER_EVT;
- p_msg->sec_mask = sec_mask;
- p_msg->role = role;
- p_msg->local_scn = local_scn;
- p_msg->max_session = max_session;
- p_msg->p_cback = p_cback;
- p_msg->rfcomm_slot_id = rfcomm_slot_id; // caller's private data
- bta_sys_sendmsg(p_msg);
-
+ do_in_bta_thread(FROM_HERE,
+ Bind(&bta_jv_rfcomm_start_server, sec_mask, role, local_scn,
+ max_session, p_cback, rfcomm_slot_id));
return BTA_JV_SUCCESS;
}
@@ -687,17 +679,10 @@
******************************************************************************/
tBTA_JV_STATUS BTA_JvRfcommStopServer(uint32_t handle,
uint32_t rfcomm_slot_id) {
- tBTA_JV_API_RFCOMM_SERVER* p_msg =
- (tBTA_JV_API_RFCOMM_SERVER*)osi_malloc(sizeof(tBTA_JV_API_RFCOMM_SERVER));
-
APPL_TRACE_API("%s", __func__);
- p_msg->hdr.event = BTA_JV_API_RFCOMM_STOP_SERVER_EVT;
- p_msg->handle = handle;
- p_msg->rfcomm_slot_id = rfcomm_slot_id; // caller's private data
-
- bta_sys_sendmsg(p_msg);
-
+ do_in_bta_thread(FROM_HERE,
+ Bind(&bta_jv_rfcomm_stop_server, handle, rfcomm_slot_id));
return BTA_JV_SUCCESS;
}
diff --git a/bta/jv/bta_jv_int.h b/bta/jv/bta_jv_int.h
index 5b8f91e..d7b6764 100644
--- a/bta/jv/bta_jv_int.h
+++ b/bta/jv/bta_jv_int.h
@@ -39,8 +39,6 @@
enum {
/* these events are handled by the state machine */
BTA_JV_API_START_DISCOVERY_EVT = BTA_SYS_EVT_START(BTA_ID_JV),
- BTA_JV_API_RFCOMM_START_SERVER_EVT,
- BTA_JV_API_RFCOMM_STOP_SERVER_EVT,
BTA_JV_API_RFCOMM_WRITE_EVT,
BTA_JV_API_SET_PM_PROFILE_EVT,
BTA_JV_API_PM_STATE_CHANGE_EVT,
@@ -139,18 +137,6 @@
uint32_t l2cap_socket_id;
} tBTA_JV_API_L2CAP_READ;
-/* data type for BTA_JV_API_RFCOMM_SERVER_EVT */
-typedef struct {
- BT_HDR hdr;
- tBTA_SEC sec_mask;
- tBTA_JV_ROLE role;
- uint8_t local_scn;
- uint8_t max_session;
- uint32_t handle;
- tBTA_JV_RFCOMM_CBACK* p_cback;
- uint32_t rfcomm_slot_id;
-} tBTA_JV_API_RFCOMM_SERVER;
-
/* data type for BTA_JV_API_SET_PM_PROFILE_EVT */
typedef struct {
BT_HDR hdr;
@@ -186,7 +172,6 @@
tBTA_JV_API_RFCOMM_WRITE rfcomm_write;
tBTA_JV_API_SET_PM_PROFILE set_pm;
tBTA_JV_API_PM_STATE_CHANGE change_pm_state;
- tBTA_JV_API_RFCOMM_SERVER rfcomm_server;
} tBTA_JV_MSG;
/* JV control block */
@@ -258,8 +243,11 @@
tBTA_JV_RFCOMM_CBACK* p_cback,
uint32_t rfcomm_slot_id);
extern void bta_jv_rfcomm_close(uint32_t handle, uint32_t rfcomm_slot_id);
-extern void bta_jv_rfcomm_start_server(tBTA_JV_MSG* p_data);
-extern void bta_jv_rfcomm_stop_server(tBTA_JV_MSG* p_data);
+extern void bta_jv_rfcomm_start_server(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
+ uint8_t local_scn, uint8_t max_session,
+ tBTA_JV_RFCOMM_CBACK* p_cback,
+ uint32_t rfcomm_slot_id);
+extern void bta_jv_rfcomm_stop_server(uint32_t handle, uint32_t rfcomm_slot_id);
extern void bta_jv_rfcomm_read(tBTA_JV_MSG* p_data);
extern void bta_jv_rfcomm_write(tBTA_JV_MSG* p_data);
extern void bta_jv_set_pm_profile(tBTA_JV_MSG* p_data);
diff --git a/bta/jv/bta_jv_main.cc b/bta/jv/bta_jv_main.cc
index b5dca2b..dcfcdf2 100644
--- a/bta/jv/bta_jv_main.cc
+++ b/bta/jv/bta_jv_main.cc
@@ -42,8 +42,6 @@
/* action function list */
const tBTA_JV_ACTION bta_jv_action[] = {
bta_jv_start_discovery, /* BTA_JV_API_START_DISCOVERY_EVT */
- bta_jv_rfcomm_start_server, /* BTA_JV_API_RFCOMM_START_SERVER_EVT */
- bta_jv_rfcomm_stop_server, /* BTA_JV_API_RFCOMM_STOP_SERVER_EVT */
bta_jv_rfcomm_write, /* BTA_JV_API_RFCOMM_WRITE_EVT */
bta_jv_set_pm_profile, /* BTA_JV_API_SET_PM_PROFILE_EVT */
bta_jv_change_pm_state, /* BTA_JV_API_PM_STATE_CHANGE_EVT */