component/bt: modify the stack manager API not to use callbacks

This commit is contained in:
wangmengyang 2016-12-01 21:46:37 +08:00
parent 38cc22a85c
commit 1d8355f54b
3 changed files with 16 additions and 37 deletions

View file

@ -30,13 +30,8 @@ typedef union {
// extern const btav_interface_t *btif_av_get_sink_interface(void); // extern const btav_interface_t *btif_av_get_sink_interface(void);
static void bt_stack_evt(tBT_APP_EVT event, tBT_APP_EVT_DATA *p_data); static void bt_stack_evt(tBT_APP_EVT event, tBT_APP_EVT_DATA *p_data);
static void bt_stack_state_changed(bt_state_t state);
// static bt_bdaddr_t peer_bd_addr = {{0x00, 0x1b, 0xdc, 0x08, 0x0f, 0xe7}}; // static bt_bdaddr_t peer_bd_addr = {{0x00, 0x1b, 0xdc, 0x08, 0x0f, 0xe7}};
static bt_callbacks_t bt_callbacks = {
bt_stack_state_changed
};
osi_alarm_t *app_alarm = NULL; osi_alarm_t *app_alarm = NULL;
@ -112,19 +107,19 @@ static void bt_stack_evt(tBT_APP_EVT event, tBT_APP_EVT_DATA *p_data)
(void *)p_data, sizeof(tBT_APP_EVT_DATA), NULL); (void *)p_data, sizeof(tBT_APP_EVT_DATA), NULL);
} }
static void bt_stack_state_changed(bt_state_t state)
{
if (state == BT_STATE_ON) {
bt_stack_evt(BT_APP_EVT_STACK_ON, NULL);
}
}
void app_main_entry(void) void app_main_entry(void)
{ {
bt_status_t stat; bt_status_t init, enable;
stat = BTIF_InitStack(&bt_callbacks); init = BTIF_InitStack();
if (stat == BT_STATUS_SUCCESS) { if (init != BT_STATUS_SUCCESS) {
BTIF_EnableStack(); return;
} }
enable = BTIF_EnableStack();
if (enable != BT_STATUS_SUCCESS) {
return;
}
bt_stack_evt(BT_APP_EVT_STACK_ON, NULL);
} }

View file

@ -20,7 +20,7 @@ typedef struct {
adapter_state_changed_callback adapter_state_changed_cb; adapter_state_changed_callback adapter_state_changed_cb;
} bt_callbacks_t; } bt_callbacks_t;
bt_status_t BTIF_InitStack(bt_callbacks_t *cb); bt_status_t BTIF_InitStack(void);
bt_status_t BTIF_EnableStack(void); bt_status_t BTIF_EnableStack(void);

View file

@ -20,17 +20,14 @@
************************************************************************************/ ************************************************************************************/
static bool stack_is_initialized = false; static bool stack_is_initialized = false;
static bool stack_is_running = false; static bool stack_is_running = false;
static bt_callbacks_t *bt_hal_cbacks = NULL;
static future_t *hack_future = NULL; static future_t *hack_future = NULL;
static bt_status_t event_init_stack(bt_callbacks_t *cb); static bt_status_t event_init_stack(void);
static bt_status_t event_start_up_stack(void); static bt_status_t event_start_up_stack(void);
static bt_status_t event_shut_down_stack(void); static bt_status_t event_shut_down_stack(void);
static bt_status_t event_clean_up_stack(void); static bt_status_t event_clean_up_stack(void);
static void event_signal_stack_up(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param);
static void event_signal_stack_down(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param);
static bt_status_t event_init_stack(bt_callbacks_t *cb) static bt_status_t event_init_stack(void)
{ {
bt_status_t ret; bt_status_t ret;
if (!stack_is_initialized) { if (!stack_is_initialized) {
@ -40,7 +37,6 @@ static bt_status_t event_init_stack(bt_callbacks_t *cb)
return BT_STATUS_FAIL; return BT_STATUS_FAIL;
} }
if (ret == BT_STATUS_SUCCESS) { if (ret == BT_STATUS_SUCCESS) {
bt_hal_cbacks = cb;
stack_is_initialized = true; stack_is_initialized = true;
} }
return ret; return ret;
@ -74,7 +70,6 @@ static bt_status_t event_start_up_stack(void)
stack_is_running = true; stack_is_running = true;
LOG_DEBUG("%s finished\n", __func__); LOG_DEBUG("%s finished\n", __func__);
btif_transfer_context(event_signal_stack_up, 0, NULL, 0, NULL);
return BT_STATUS_SUCCESS; return BT_STATUS_SUCCESS;
} }
@ -94,7 +89,6 @@ static bt_status_t event_shut_down_stack(void)
future_await(hack_future); future_await(hack_future);
LOG_DEBUG("%s finished.\n", __func__); LOG_DEBUG("%s finished.\n", __func__);
btif_transfer_context(event_signal_stack_down, 0, NULL, 0, NULL);
return BT_STATUS_SUCCESS; return BT_STATUS_SUCCESS;
} }
@ -118,19 +112,9 @@ static bt_status_t event_clean_up_stack(void)
return BT_STATUS_SUCCESS; return BT_STATUS_SUCCESS;
} }
static void event_signal_stack_up(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param) bt_status_t BTIF_InitStack(void)
{ {
HAL_CBACK(bt_hal_cbacks, adapter_state_changed_cb, BT_STATE_ON); return event_init_stack();
}
static void event_signal_stack_down(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param)
{
HAL_CBACK(bt_hal_cbacks, adapter_state_changed_cb, BT_STATE_OFF);
}
bt_status_t BTIF_InitStack(bt_callbacks_t *cb)
{
return event_init_stack(cb);
} }
bt_status_t BTIF_EnableStack(void) bt_status_t BTIF_EnableStack(void)