From 1d8355f54bbc6efdbb81809e3a988e2b8c099f4a Mon Sep 17 00:00:00 2001 From: wangmengyang Date: Thu, 1 Dec 2016 21:46:37 +0800 Subject: [PATCH] component/bt: modify the stack manager API not to use callbacks --- .../bluedroid_demos/app_project/SampleBtSdp.c | 25 ++++++++----------- .../btif/include/btif_stack_manager.h | 2 +- .../bluedroid_demos/btif/stack_manager.c | 24 +++--------------- 3 files changed, 15 insertions(+), 36 deletions(-) diff --git a/examples/09_a2dp/components/bluedroid_demos/app_project/SampleBtSdp.c b/examples/09_a2dp/components/bluedroid_demos/app_project/SampleBtSdp.c index e4eb4d8736..f5311a8ab8 100644 --- a/examples/09_a2dp/components/bluedroid_demos/app_project/SampleBtSdp.c +++ b/examples/09_a2dp/components/bluedroid_demos/app_project/SampleBtSdp.c @@ -30,13 +30,8 @@ typedef union { // 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_state_changed(bt_state_t state); - // 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; @@ -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); } -static void bt_stack_state_changed(bt_state_t state) +void app_main_entry(void) { - if (state == BT_STATE_ON) { - bt_stack_evt(BT_APP_EVT_STACK_ON, NULL); + bt_status_t init, enable; + init = BTIF_InitStack(); + if (init != BT_STATUS_SUCCESS) { + return; } -} -void app_main_entry(void) -{ - bt_status_t stat; - stat = BTIF_InitStack(&bt_callbacks); - if (stat == BT_STATUS_SUCCESS) { - BTIF_EnableStack(); + enable = BTIF_EnableStack(); + if (enable != BT_STATUS_SUCCESS) { + return; } + + bt_stack_evt(BT_APP_EVT_STACK_ON, NULL); } diff --git a/examples/09_a2dp/components/bluedroid_demos/btif/include/btif_stack_manager.h b/examples/09_a2dp/components/bluedroid_demos/btif/include/btif_stack_manager.h index a780fded25..649a05de03 100644 --- a/examples/09_a2dp/components/bluedroid_demos/btif/include/btif_stack_manager.h +++ b/examples/09_a2dp/components/bluedroid_demos/btif/include/btif_stack_manager.h @@ -20,7 +20,7 @@ typedef struct { adapter_state_changed_callback adapter_state_changed_cb; } bt_callbacks_t; -bt_status_t BTIF_InitStack(bt_callbacks_t *cb); +bt_status_t BTIF_InitStack(void); bt_status_t BTIF_EnableStack(void); diff --git a/examples/09_a2dp/components/bluedroid_demos/btif/stack_manager.c b/examples/09_a2dp/components/bluedroid_demos/btif/stack_manager.c index 49facf1ccd..a93c3e8f6f 100644 --- a/examples/09_a2dp/components/bluedroid_demos/btif/stack_manager.c +++ b/examples/09_a2dp/components/bluedroid_demos/btif/stack_manager.c @@ -20,17 +20,14 @@ ************************************************************************************/ static bool stack_is_initialized = false; static bool stack_is_running = false; -static bt_callbacks_t *bt_hal_cbacks = 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_shut_down_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; if (!stack_is_initialized) { @@ -40,7 +37,6 @@ static bt_status_t event_init_stack(bt_callbacks_t *cb) return BT_STATUS_FAIL; } if (ret == BT_STATUS_SUCCESS) { - bt_hal_cbacks = cb; stack_is_initialized = true; } return ret; @@ -74,7 +70,6 @@ static bt_status_t event_start_up_stack(void) stack_is_running = true; LOG_DEBUG("%s finished\n", __func__); - btif_transfer_context(event_signal_stack_up, 0, NULL, 0, NULL); return BT_STATUS_SUCCESS; } @@ -94,7 +89,6 @@ static bt_status_t event_shut_down_stack(void) future_await(hack_future); LOG_DEBUG("%s finished.\n", __func__); - btif_transfer_context(event_signal_stack_down, 0, NULL, 0, NULL); return BT_STATUS_SUCCESS; } @@ -118,19 +112,9 @@ static bt_status_t event_clean_up_stack(void) 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); -} - -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); + return event_init_stack(); } bt_status_t BTIF_EnableStack(void) -- 2.40.0