mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
component/bt: clean up profile call/callback handlers
1. remove the empty function btc_gap_bt_cb_handler(); 2. separate the a2dp profile call/callback handers
This commit is contained in:
parent
07548918df
commit
18814c03d4
@ -96,18 +96,13 @@ esp_err_t esp_a2d_sink_disconnect(esp_bd_addr_t remote_bda)
|
||||
}
|
||||
|
||||
bt_status_t stat;
|
||||
btc_av_args_t arg;
|
||||
btc_msg_t msg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_A2DP;
|
||||
msg.act = BTC_AV_DISCONNECT_REQ_EVT;
|
||||
msg.act = BTC_AV_SINK_API_DISCONNECT_EVT;
|
||||
|
||||
memset(&arg, 0, sizeof(btc_av_args_t));
|
||||
|
||||
// CHECK_BTAV_INIT(); // todo: move this function
|
||||
memcpy(&(arg.disconnect), remote_bda, sizeof(bt_bdaddr_t));
|
||||
/* Switch to BTC context */
|
||||
stat = btc_transfer_context(&msg, &arg, sizeof(btc_av_args_t), NULL);
|
||||
stat = btc_transfer_context(&msg, NULL, 0, NULL);
|
||||
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ static btc_func_t profile_tab[BTC_PID_NUM] = {
|
||||
[BTC_PID_GATTS] = {btc_gatts_call_handler, btc_gatts_cb_handler },
|
||||
[BTC_PID_GATTC] = {btc_gattc_call_handler, btc_gattc_cb_handler },
|
||||
[BTC_PID_GAP_BLE] = {btc_gap_ble_call_handler, btc_gap_ble_cb_handler },
|
||||
[BTC_PID_GAP_BT] = {btc_gap_bt_call_handler, btc_gap_bt_cb_handler },
|
||||
[BTC_PID_GAP_BT] = {btc_gap_bt_call_handler, NULL },
|
||||
[BTC_PID_SDP] = {NULL, NULL},
|
||||
[BTC_PID_BLE_HID] = {NULL, NULL},
|
||||
[BTC_PID_BT_HID] = {NULL, NULL},
|
||||
@ -49,8 +49,8 @@ static btc_func_t profile_tab[BTC_PID_NUM] = {
|
||||
[BTC_PID_BLUFI] = {btc_blufi_call_handler, btc_blufi_cb_handler },
|
||||
[BTC_PID_DM_SEC] = {NULL, btc_dm_sec_cb_handler },
|
||||
[BTC_PID_PRF_QUE] = {btc_profile_queue_handler, NULL },
|
||||
[BTC_PID_A2DP] = {btc_a2dp_evt_handler, btc_a2dp_evt_handler },
|
||||
[BTC_PID_AVRC] = {btc_avrc_evt_handler, NULL }
|
||||
[BTC_PID_A2DP] = {btc_a2dp_call_handler, btc_a2dp_cb_handler },
|
||||
[BTC_PID_AVRC] = {btc_avrc_call_handler, NULL }
|
||||
};
|
||||
|
||||
/*****************************************************************************
|
||||
|
@ -89,15 +89,11 @@ static btc_av_cb_t btc_av_cb = {0};
|
||||
static TIMER_LIST_ENT tle_av_open_on_rc;
|
||||
|
||||
/* both interface and media task needs to be ready to alloc incoming request */
|
||||
#define CHECK_BTAV_INIT() if (btc_av_cb.sm_handle == NULL)\
|
||||
{\
|
||||
LOG_WARN("%s: BTAV not initialized\n", __FUNCTION__);\
|
||||
return ESP_ERR_INVALID_STATE;\
|
||||
}\
|
||||
else\
|
||||
{\
|
||||
LOG_INFO("%s\n", __FUNCTION__);\
|
||||
}
|
||||
#define CHECK_BTAV_INIT() do \
|
||||
{ \
|
||||
assert (btc_av_cb.sm_handle != NULL); \
|
||||
} while (0)
|
||||
|
||||
|
||||
/* Helper macro to avoid code duplication in the state machine handlers */
|
||||
#define CHECK_RC_EVENT(e, d) \
|
||||
@ -865,7 +861,7 @@ static void bte_av_callback(tBTA_AV_EVT event, tBTA_AV *p_data)
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_A2DP;
|
||||
msg.act = (uint8_t) event;
|
||||
stat = btc_transfer_context(&msg, (btc_av_args_t *)p_data, sizeof(tBTA_AV), btc_av_event_deep_copy);
|
||||
stat = btc_transfer_context(&msg, p_data, sizeof(tBTA_AV), btc_av_event_deep_copy);
|
||||
|
||||
if (stat) {
|
||||
LOG_ERROR("%s transfer failed\n", __func__);
|
||||
@ -923,7 +919,7 @@ static void bte_av_media_callback(tBTA_AV_EVT event, tBTA_AV_MEDIA *p_data)
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
||||
bt_status_t btc_av_init()
|
||||
bt_status_t btc_av_init(void)
|
||||
{
|
||||
if (btc_av_cb.sm_handle == NULL) {
|
||||
if (!btc_a2dp_start_media_task()) {
|
||||
@ -956,11 +952,9 @@ bt_status_t btc_av_init()
|
||||
*******************************************************************************/
|
||||
bt_status_t btc_a2d_sink_init(void)
|
||||
{
|
||||
LOG_INFO("%s()\n", __func__);
|
||||
LOG_DEBUG("%s()\n", __func__);
|
||||
|
||||
bt_status_t status = btc_av_init();
|
||||
|
||||
return status;
|
||||
return btc_av_init();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
@ -987,7 +981,7 @@ static bt_status_t connect_int(bt_bdaddr_t *bd_addr, uint16_t uuid)
|
||||
|
||||
bt_status_t btc_a2d_sink_connect(bt_bdaddr_t* remote_bda)
|
||||
{
|
||||
LOG_INFO("%s\n", __FUNCTION__);
|
||||
LOG_DEBUG("%s\n", __FUNCTION__);
|
||||
CHECK_BTAV_INIT();
|
||||
|
||||
return btc_queue_connect(UUID_SERVCLASS_AUDIO_SINK, remote_bda, connect_int);
|
||||
@ -1204,32 +1198,41 @@ void btc_av_clear_remote_suspend_flag(void)
|
||||
btc_av_cb.flags &= ~BTC_AV_FLAG_REMOTE_SUSPEND;
|
||||
}
|
||||
|
||||
void btc_a2dp_evt_handler(btc_msg_t *msg)
|
||||
void btc_a2dp_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
if (msg->act < BTC_AV_MAX_SM_EVT) {
|
||||
btc_av_args_t *arg = (btc_av_args_t *)(msg->arg);
|
||||
switch (msg->act) {
|
||||
case BTC_AV_SINK_CONFIG_REQ_EVT: {
|
||||
btc_sm_dispatch(btc_av_cb.sm_handle, msg->act, (void *)(msg->arg));
|
||||
} else {
|
||||
btc_av_args_t *arg = (btc_av_args_t *)(msg->arg);
|
||||
switch (msg->act) {
|
||||
case BTC_AV_SINK_API_INIT_EVT: {
|
||||
btc_a2d_sink_init();
|
||||
// todo: callback to application
|
||||
break;
|
||||
}
|
||||
case BTC_AV_SINK_API_DEINIT_EVT: {
|
||||
btc_a2d_sink_deinit();
|
||||
// todo: callback to application
|
||||
break;
|
||||
}
|
||||
case BTC_AV_SINK_API_CONNECT_EVT: {
|
||||
btc_a2d_sink_connect(&arg->connect);
|
||||
// todo: callback to application
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_WARN("%s : unhandled event: %d\n", __FUNCTION__, msg->act);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_AV_SINK_API_INIT_EVT: {
|
||||
btc_a2d_sink_init();
|
||||
// todo: callback to application
|
||||
break;
|
||||
}
|
||||
case BTC_AV_SINK_API_DEINIT_EVT: {
|
||||
btc_a2d_sink_deinit();
|
||||
// todo: callback to application
|
||||
break;
|
||||
}
|
||||
case BTC_AV_SINK_API_CONNECT_EVT: {
|
||||
btc_a2d_sink_connect(&arg->connect);
|
||||
// todo: callback to application
|
||||
break;
|
||||
}
|
||||
case BTC_AV_SINK_API_DISCONNECT_EVT: {
|
||||
CHECK_BTAV_INIT();
|
||||
btc_sm_dispatch(btc_av_cb.sm_handle, BTC_AV_DISCONNECT_REQ_EVT, NULL);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_WARN("%s : unhandled event: %d\n", __FUNCTION__, msg->act);
|
||||
}
|
||||
}
|
||||
|
||||
void btc_a2dp_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
btc_sm_dispatch(btc_av_cb.sm_handle, msg->act, (void *)(msg->arg));
|
||||
btc_av_event_free_data(msg->act, msg->arg);
|
||||
}
|
||||
|
@ -441,7 +441,7 @@ static bt_status_t btc_avrc_ct_send_passthrough_cmd(uint8_t tl, uint8_t key_code
|
||||
return status;
|
||||
}
|
||||
|
||||
void btc_avrc_evt_handler(btc_msg_t *msg)
|
||||
void btc_avrc_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
btc_avrc_args_t *arg = (btc_avrc_args_t *)(msg->arg);
|
||||
switch (msg->act) {
|
||||
|
@ -85,8 +85,3 @@ void btc_gap_bt_call_handler(btc_msg_t *msg)
|
||||
}
|
||||
btc_gap_bt_arg_deep_free(msg);
|
||||
}
|
||||
|
||||
void btc_gap_bt_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
// todo
|
||||
}
|
||||
|
@ -43,32 +43,30 @@ typedef enum {
|
||||
BTC_AV_STOP_STREAM_REQ_EVT,
|
||||
BTC_AV_SUSPEND_STREAM_REQ_EVT,
|
||||
BTC_AV_SINK_CONFIG_REQ_EVT,
|
||||
BTC_AV_MAX_SM_EVT
|
||||
} btc_av_sm_event_t;
|
||||
|
||||
typedef enum {
|
||||
BTC_AV_SINK_API_INIT_EVT = BTC_AV_MAX_SM_EVT + 1,
|
||||
BTC_AV_SINK_API_INIT_EVT = 0,
|
||||
BTC_AV_SINK_API_DEINIT_EVT,
|
||||
BTC_AV_SINK_API_CONNECT_EVT,
|
||||
BTC_AV_SINK_API_DISCONNECT_EVT
|
||||
} btc_av_act_t;
|
||||
|
||||
/* btc_av_args_t */
|
||||
typedef union {
|
||||
// BTC_AV_SINK_CONFIG_REQ_EVT
|
||||
// BTC_AV_SINK_CONFIG_REQ_EVT -- internal event
|
||||
esp_a2d_mcc_t mcc;
|
||||
// BTC_AV_DISCONNECT_REQ_EVT
|
||||
bt_bdaddr_t disconnect;
|
||||
// BTC_AV_SINK_API_CONNECT_EVT
|
||||
bt_bdaddr_t connect;
|
||||
// Event set--tBTA_AV_EVT
|
||||
tBTA_AV data;
|
||||
} btc_av_args_t;
|
||||
|
||||
/*******************************************************************************
|
||||
** BTC AV API
|
||||
********************************************************************************/
|
||||
|
||||
void btc_a2dp_evt_handler(btc_msg_t *msg);
|
||||
void btc_a2dp_call_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_a2dp_cb_handler(btc_msg_t *msg);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
|
@ -69,6 +69,6 @@ BOOLEAN btc_rc_get_connected_peer(BD_ADDR peer_addr);
|
||||
/*******************************************************************************
|
||||
** BTC AVRC API
|
||||
********************************************************************************/
|
||||
void btc_avrc_evt_handler(btc_msg_t *msg);
|
||||
void btc_avrc_call_handler(btc_msg_t *msg);
|
||||
|
||||
#endif /* __BTC_AVRC_H__ */
|
||||
|
@ -38,7 +38,6 @@ typedef union {
|
||||
} btc_gap_bt_args_t;
|
||||
|
||||
void btc_gap_bt_call_handler(btc_msg_t *msg);
|
||||
void btc_gap_bt_cb_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_gap_bt_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user