Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e16123c5 authored by Zach Johnson's avatar Zach Johnson
Browse files

Pull BTA_DM_INQUIRY_CMPL_EVT out of state machine

Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I0d3baa7bd74709ebd07eee5f7db9ab1e9f23690a
parent 3af4ffd3
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -844,6 +844,19 @@ void bta_dm_search_start(tBTA_DM_MSG* p_data) {
  }
}

static void on_inquiry_complete(tBTA_DM_MSG* message) {
  switch (bta_dm_search_get_state()) {
    case BTA_DM_SEARCH_ACTIVE:
      bta_dm_inq_cmpl(message);
      break;
    case BTA_DM_SEARCH_CANCELLING:
      bta_dm_search_set_state(BTA_DM_SEARCH_IDLE);
      bta_dm_search_cancel_cmpl();
      break;
  }
  osi_free(message);
}

/*******************************************************************************
 *
 * Function         bta_dm_search_cancel
@@ -882,7 +895,7 @@ void bta_dm_search_cancel(UNUSED_ATTR tBTA_DM_MSG* p_data) {
    p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG));
    p_msg->hdr.event = BTA_DM_INQUIRY_CMPL_EVT;
    p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT;
    bta_sys_sendmsg(p_msg);
    on_inquiry_complete(p_msg);
  }

  if (bta_dm_search_cb.gatt_disc_active) {
@@ -1946,15 +1959,15 @@ static void bta_dm_inq_cmpl_cb(void* p_result) {
  if (!bta_dm_search_cb.cancel_pending) {
    p_msg->inq_cmpl.hdr.event = BTA_DM_INQUIRY_CMPL_EVT;
    p_msg->inq_cmpl.num = ((tBTM_INQUIRY_CMPL*)p_result)->num_resp;
    on_inquiry_complete(p_msg);
  } else {
    bta_dm_search_cb.cancel_pending = false;
    bta_dm_search_cancel_notify();
    p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT;
    p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT;
  }

    bta_sys_sendmsg(p_msg);
  }
}

/*******************************************************************************
 *
+3 −0
Original line number Diff line number Diff line
@@ -529,5 +529,8 @@ extern void bta_dm_disc_rmt_name(tBTA_DM_MSG* p_data);
extern tBTA_DM_PEER_DEVICE* bta_dm_find_peer_device(
    const RawAddress& peer_addr);

uint8_t bta_dm_search_get_state();
void bta_dm_search_set_state(uint8_t state);

void bta_dm_eir_update_uuid(uint16_t uuid16, bool adding);
#endif /* BTA_DM_INT_H */
+1 −7
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ tBTA_DM_DI_CB bta_dm_di_cb;
void bta_dm_search_sm_disable() { bta_sys_deregister(BTA_ID_DM_SEARCH); }

void bta_dm_search_set_state(uint8_t state) { bta_dm_search_cb.state = state; }
uint8_t bta_dm_search_get_state() { return bta_dm_search_cb.state; }

/*******************************************************************************
 *
@@ -95,9 +96,6 @@ bool bta_dm_search_sm_execute(BT_HDR* p_msg) {
          bta_dm_search_set_state(BTA_DM_SEARCH_CANCELLING);
          bta_dm_search_cancel(message);
          break;
        case BTA_DM_INQUIRY_CMPL_EVT:
          bta_dm_inq_cmpl(message);
          break;
        case BTA_DM_REMT_NAME_EVT:
          bta_dm_rmt_name(message);
          break;
@@ -128,10 +126,6 @@ bool bta_dm_search_sm_execute(BT_HDR* p_msg) {
        case BTA_DM_API_DISCOVER_EVT:
          bta_dm_queue_disc(message);
          break;
        case BTA_DM_INQUIRY_CMPL_EVT:
          bta_dm_search_set_state(BTA_DM_SEARCH_IDLE);
          bta_dm_search_cancel_cmpl();
          break;
        case BTA_DM_SDP_RESULT_EVT:
        case BTA_DM_REMT_NAME_EVT:
        case BTA_DM_SEARCH_CMPL_EVT: