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

Commit 9fb22b98 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Use std::list in GATT related code

Bug: 67057055
Test: sl4a Gatt* tests
Change-Id: I8201ebdad5ba4c3d5d0a2fd3d0fe9dc900b51d60
parent ccf2e479
Loading
Loading
Loading
Loading
+6 −12
Original line number Original line Diff line number Diff line
@@ -123,7 +123,7 @@ static void bta_gattc_enable() {


  if (bta_gattc_cb.state == BTA_GATTC_STATE_DISABLED) {
  if (bta_gattc_cb.state == BTA_GATTC_STATE_DISABLED) {
    /* initialize control block */
    /* initialize control block */
    memset(&bta_gattc_cb, 0, sizeof(tBTA_GATTC_CB));
    bta_gattc_cb = tBTA_GATTC_CB();
    bta_gattc_cb.state = BTA_GATTC_STATE_ENABLED;
    bta_gattc_cb.state = BTA_GATTC_STATE_ENABLED;
  } else {
  } else {
    APPL_TRACE_DEBUG("GATTC is already enabled");
    APPL_TRACE_DEBUG("GATTC is already enabled");
@@ -167,7 +167,7 @@ void bta_gattc_disable() {


  /* no registered apps, indicate disable completed */
  /* no registered apps, indicate disable completed */
  if (bta_gattc_cb.state != BTA_GATTC_STATE_DISABLING) {
  if (bta_gattc_cb.state != BTA_GATTC_STATE_DISABLING) {
    memset(&bta_gattc_cb, 0, sizeof(tBTA_GATTC_CB));
    bta_gattc_cb = tBTA_GATTC_CB();
    bta_gattc_cb.state = BTA_GATTC_STATE_DISABLED;
    bta_gattc_cb.state = BTA_GATTC_STATE_DISABLED;
  }
  }
}
}
@@ -587,7 +587,7 @@ void bta_gattc_conn(tBTA_GATTC_CLCB* p_clcb, tBTA_GATTC_DATA* p_data) {
  if (p_clcb->p_srcb->mtu == 0) p_clcb->p_srcb->mtu = GATT_DEF_BLE_MTU_SIZE;
  if (p_clcb->p_srcb->mtu == 0) p_clcb->p_srcb->mtu = GATT_DEF_BLE_MTU_SIZE;


  /* start database cache if needed */
  /* start database cache if needed */
  if (p_clcb->p_srcb->p_srvc_cache == NULL ||
  if (p_clcb->p_srcb->srvc_cache.empty() ||
      p_clcb->p_srcb->state != BTA_GATTC_SERV_IDLE) {
      p_clcb->p_srcb->state != BTA_GATTC_SERV_IDLE) {
    if (p_clcb->p_srcb->state == BTA_GATTC_SERV_IDLE) {
    if (p_clcb->p_srcb->state == BTA_GATTC_SERV_IDLE) {
      p_clcb->p_srcb->state = BTA_GATTC_SERV_LOAD;
      p_clcb->p_srcb->state = BTA_GATTC_SERV_LOAD;
@@ -877,10 +877,7 @@ void bta_gattc_disc_cmpl(tBTA_GATTC_CLCB* p_clcb,


  if (p_clcb->status != GATT_SUCCESS) {
  if (p_clcb->status != GATT_SUCCESS) {
    /* clean up cache */
    /* clean up cache */
    if (p_clcb->p_srcb && p_clcb->p_srcb->p_srvc_cache) {
    if (p_clcb->p_srcb) p_clcb->p_srcb->srvc_cache.clear();
      list_free(p_clcb->p_srcb->p_srvc_cache);
      p_clcb->p_srcb->p_srvc_cache = NULL;
    }


    /* used to reset cache in application */
    /* used to reset cache in application */
    bta_gattc_cache_reset(p_clcb->p_srcb->server_bda);
    bta_gattc_cache_reset(p_clcb->p_srcb->server_bda);
@@ -1252,7 +1249,7 @@ void bta_gattc_search(tBTA_GATTC_CLCB* p_clcb, tBTA_GATTC_DATA* p_data) {
  tGATT_STATUS status = GATT_INTERNAL_ERROR;
  tGATT_STATUS status = GATT_INTERNAL_ERROR;
  tBTA_GATTC cb_data;
  tBTA_GATTC cb_data;
  APPL_TRACE_DEBUG("%s: conn_id=%d", __func__, p_clcb->bta_conn_id);
  APPL_TRACE_DEBUG("%s: conn_id=%d", __func__, p_clcb->bta_conn_id);
  if (p_clcb->p_srcb && p_clcb->p_srcb->p_srvc_cache) {
  if (p_clcb->p_srcb && !p_clcb->p_srcb->srvc_cache.empty()) {
    status = GATT_SUCCESS;
    status = GATT_SUCCESS;
    /* search the local cache of a server device */
    /* search the local cache of a server device */
    bta_gattc_search_service(p_clcb, p_data->api_search.p_srvc_uuid);
    bta_gattc_search_service(p_clcb, p_data->api_search.p_srvc_uuid);
@@ -1423,10 +1420,7 @@ void bta_gattc_process_api_refresh(const RawAddress& remote_bda) {
      }
      }
    }
    }
    /* in all other cases, mark it and delete the cache */
    /* in all other cases, mark it and delete the cache */
    if (p_srvc_cb->p_srvc_cache != NULL) {
    p_srvc_cb->srvc_cache.clear();
      list_free(p_srvc_cb->p_srvc_cache);
      p_srvc_cb->p_srvc_cache = NULL;
    }
  }
  }
  /* used to reset cache in application */
  /* used to reset cache in application */
  bta_gattc_cache_reset(remote_bda);
  bta_gattc_cache_reset(remote_bda);
+2 −2
Original line number Original line Diff line number Diff line
@@ -266,10 +266,10 @@ void BTA_GATTC_DiscoverServiceByUuid(uint16_t conn_id,
 *
 *
 * Parameters       conn_id: connection ID which identify the server.
 * Parameters       conn_id: connection ID which identify the server.
 *
 *
 * Returns          returns list_t of tBTA_GATTC_SERVICE or NULL.
 * Returns          returns list of tBTA_GATTC_SERVICE or NULL.
 *
 *
 ******************************************************************************/
 ******************************************************************************/
const list_t* BTA_GATTC_GetServices(uint16_t conn_id) {
const std::list<tBTA_GATTC_SERVICE>* BTA_GATTC_GetServices(uint16_t conn_id) {
  return bta_gattc_get_services(conn_id);
  return bta_gattc_get_services(conn_id);
}
}


+172 −332

File changed.

Preview size limit exceeded, changes collapsed.

+4 −4
Original line number Original line Diff line number Diff line
@@ -223,7 +223,7 @@ typedef struct {


  uint8_t state;
  uint8_t state;


  list_t* p_srvc_cache; /* list of tBTA_GATTC_SERVICE */
  std::list<tBTA_GATTC_SERVICE> srvc_cache;
  uint8_t update_count; /* indication received */
  uint8_t update_count; /* indication received */
  uint8_t num_clcb;     /* number of associated CLCB */
  uint8_t num_clcb;     /* number of associated CLCB */


@@ -450,14 +450,14 @@ extern tGATT_STATUS bta_gattc_discover_pri_service(uint16_t conn_id,
                                                   uint8_t disc_type);
                                                   uint8_t disc_type);
extern void bta_gattc_search_service(tBTA_GATTC_CLCB* p_clcb,
extern void bta_gattc_search_service(tBTA_GATTC_CLCB* p_clcb,
                                     bluetooth::Uuid* p_uuid);
                                     bluetooth::Uuid* p_uuid);
extern const list_t* bta_gattc_get_services(uint16_t conn_id);
extern std::list<tBTA_GATTC_SERVICE>* bta_gattc_get_services(uint16_t conn_id);
extern const tBTA_GATTC_SERVICE* bta_gattc_get_service_for_handle(
extern const tBTA_GATTC_SERVICE* bta_gattc_get_service_for_handle(
    uint16_t conn_id, uint16_t handle);
    uint16_t conn_id, uint16_t handle);
tBTA_GATTC_CHARACTERISTIC* bta_gattc_get_characteristic_srcb(
tBTA_GATTC_CHARACTERISTIC* bta_gattc_get_characteristic_srcb(
    tBTA_GATTC_SERV* p_srcb, uint16_t handle);
    tBTA_GATTC_SERV* p_srcb, uint16_t handle);
extern tBTA_GATTC_CHARACTERISTIC* bta_gattc_get_characteristic(uint16_t conn_id,
extern tBTA_GATTC_CHARACTERISTIC* bta_gattc_get_characteristic(uint16_t conn_id,
                                                               uint16_t handle);
                                                               uint16_t handle);
extern tBTA_GATTC_DESCRIPTOR* bta_gattc_get_descriptor(uint16_t conn_id,
extern const tBTA_GATTC_DESCRIPTOR* bta_gattc_get_descriptor(uint16_t conn_id,
                                                             uint16_t handle);
                                                             uint16_t handle);
extern void bta_gattc_get_gatt_db(uint16_t conn_id, uint16_t start_handle,
extern void bta_gattc_get_gatt_db(uint16_t conn_id, uint16_t start_handle,
                                  uint16_t end_handle, btgatt_db_element_t** db,
                                  uint16_t end_handle, btgatt_db_element_t** db,
+3 −6
Original line number Original line Diff line number Diff line
@@ -203,10 +203,7 @@ void bta_gattc_clcb_dealloc(tBTA_GATTC_CLCB* p_clcb) {
      p_srcb->mtu = 0;
      p_srcb->mtu = 0;


      /* clean up cache */
      /* clean up cache */
      if (p_srcb->p_srvc_cache) {
      p_srcb->srvc_cache.clear();
        list_free(p_srcb->p_srvc_cache);
        p_srcb->p_srvc_cache = NULL;
      }
    }
    }


    osi_free_and_reset((void**)&p_clcb->p_q_cmd);
    osi_free_and_reset((void**)&p_clcb->p_q_cmd);
@@ -300,10 +297,10 @@ tBTA_GATTC_SERV* bta_gattc_srcb_alloc(const RawAddress& bda) {
    p_tcb = p_recycle;
    p_tcb = p_recycle;


  if (p_tcb != NULL) {
  if (p_tcb != NULL) {
    if (p_tcb->p_srvc_cache != NULL) list_free(p_tcb->p_srvc_cache);
    p_tcb->srvc_cache.clear();


    osi_free_and_reset((void**)&p_tcb->p_srvc_list);
    osi_free_and_reset((void**)&p_tcb->p_srvc_list);
    memset(p_tcb, 0, sizeof(tBTA_GATTC_SERV));
    *p_tcb = tBTA_GATTC_SERV();


    p_tcb->in_use = true;
    p_tcb->in_use = true;
    p_tcb->server_bda = bda;
    p_tcb->server_bda = bda;
Loading