Why does `esp_bt_gap_register_callback` reject NULL callback?
Posted: Sun Aug 23, 2020 9:19 am
I'm currently digging into Bluetooth stack of ESP32 and have stumped upon one weird thing: esp_bt_gap_register_callback specifically rejects NULL callback, in turn making it impossible to disable callback completely. Here's esp_bt_gap_register_callback:
The only place callback is retrieved is here:
(Note: inline does not do a thing here) As you can see, there's an explicit check for presence of callback. Moreover, callback is NULL by default and it's possible to manually reset it using btc_profile_cb_set directly!
So what's the reason behind banning such reset using simply esp_bt_gap_register_callback?
- esp_err_t esp_bt_gap_register_callback(esp_bt_gap_cb_t callback)
- {
- if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
- return ESP_ERR_INVALID_STATE;
- }
- if (callback == NULL) {
- return ESP_FAIL;
- }
- btc_profile_cb_set(BTC_PID_GAP_BT, callback);
- return ESP_OK;
- }
- static inline void btc_gap_bt_cb_to_app(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
- {
- esp_bt_gap_cb_t cb = (esp_bt_gap_cb_t)btc_profile_cb_get(BTC_PID_GAP_BT);
- if (cb) {
- cb(event, param);
- }
- }
So what's the reason behind banning such reset using simply esp_bt_gap_register_callback?