tBTA_GATTC_SERV* p_srvc_cb);
static tGATT_STATUS bta_gattc_sdp_service_disc(uint16_t conn_id,
tBTA_GATTC_SERV* p_server_cb);
-tBTA_GATTC_SERVICE* bta_gattc_find_matching_service(const list_t* services,
- uint16_t handle);
-tBTA_GATTC_DESCRIPTOR* bta_gattc_get_descriptor_srcb(tBTA_GATTC_SERV* p_srcb,
- uint16_t handle);
+tBTA_GATTC_SERVICE* bta_gattc_find_matching_service(
+ std::list<tBTA_GATTC_SERVICE>& services, uint16_t handle);
+const tBTA_GATTC_DESCRIPTOR* bta_gattc_get_descriptor_srcb(
+ tBTA_GATTC_SERV* p_srcb, uint16_t handle);
tBTA_GATTC_CHARACTERISTIC* bta_gattc_get_characteristic_srcb(
tBTA_GATTC_SERV* p_srcb, uint16_t handle);
};
/* utility functions */
-bool display_descriptor(void* data, void* context) {
- tBTA_GATTC_DESCRIPTOR* p_desc = (tBTA_GATTC_DESCRIPTOR*)data;
- APPL_TRACE_ERROR("\t Descriptor handle[%d] uuid[%s]", p_desc->handle,
- p_desc->uuid.ToString().c_str());
- return true;
-}
+/* debug function to display the server cache */
+static void bta_gattc_display_cache_server(
+ const std::list<tBTA_GATTC_SERVICE>& cache) {
+ APPL_TRACE_ERROR("<================Start Server Cache =============>");
-bool display_cache_attribute(void* data, void* context) {
- tBTA_GATTC_CHARACTERISTIC* p_attr = (tBTA_GATTC_CHARACTERISTIC*)data;
- APPL_TRACE_ERROR("\t Characteristic handle[%d] uuid[%s] prop[0x%1x]",
- p_attr->handle, p_attr->uuid.ToString().c_str(),
- p_attr->properties);
- if (!p_attr->descriptors) {
- APPL_TRACE_ERROR("No descriptors");
- return true;
- }
+ for (const tBTA_GATTC_SERVICE& service : cache) {
+ APPL_TRACE_ERROR("Service: handle[%d ~ %d] %s inst[%d]", service.s_handle,
+ service.e_handle, service.uuid.ToString().c_str(),
+ service.handle);
- list_foreach(p_attr->descriptors, display_descriptor, NULL);
- return true;
-}
+ if (service.characteristics.empty()) {
+ APPL_TRACE_ERROR("\t No characteristics");
+ continue;
+ }
-bool display_cache_service(void* data, void* context) {
- tBTA_GATTC_SERVICE* p_cur_srvc = (tBTA_GATTC_SERVICE*)data;
- APPL_TRACE_ERROR("Service: handle[%d ~ %d] %s inst[%d]", p_cur_srvc->s_handle,
- p_cur_srvc->e_handle, p_cur_srvc->uuid.ToString().c_str(),
- p_cur_srvc->handle);
+ for (const tBTA_GATTC_CHARACTERISTIC& c : service.characteristics) {
+ APPL_TRACE_ERROR("\t Characteristic handle[%d] uuid[%s] prop[0x%1x]",
+ c.handle, c.uuid.ToString().c_str(), c.properties);
- if (!p_cur_srvc->characteristics) {
- APPL_TRACE_ERROR("No characteristics");
- return true;
- }
+ if (c.descriptors.empty()) {
+ APPL_TRACE_ERROR("\t\t No descriptors");
+ continue;
+ }
- list_foreach(p_cur_srvc->characteristics, display_cache_attribute, NULL);
- return true;
-}
+ for (const tBTA_GATTC_DESCRIPTOR& d : c.descriptors) {
+ APPL_TRACE_ERROR("\t\t Descriptor handle[%d] uuid[%s]", d.handle,
+ d.uuid.ToString().c_str());
+ }
+ }
+ }
-/*******************************************************************************
- *
- * Function bta_gattc_display_cache_server
- *
- * Description debug function to display the server cache.
- *
- * Returns none.
- *
- ******************************************************************************/
-static void bta_gattc_display_cache_server(list_t* p_cache) {
- APPL_TRACE_ERROR("<================Start Server Cache =============>");
- list_foreach(p_cache, display_cache_service, NULL);
APPL_TRACE_ERROR("<================End Server Cache =============>");
APPL_TRACE_ERROR(" ");
}
*
******************************************************************************/
tGATT_STATUS bta_gattc_init_cache(tBTA_GATTC_SERV* p_srvc_cb) {
- if (p_srvc_cb->p_srvc_cache != NULL) {
- list_free(p_srvc_cb->p_srvc_cache);
- p_srvc_cb->p_srvc_cache = NULL;
- }
+ p_srvc_cb->srvc_cache.clear();
osi_free(p_srvc_cb->p_srvc_list);
p_srvc_cb->p_srvc_list =
return GATT_SUCCESS;
}
-static void characteristic_free(void* ptr) {
- tBTA_GATTC_CHARACTERISTIC* p_char = (tBTA_GATTC_CHARACTERISTIC*)ptr;
- list_free(p_char->descriptors);
- osi_free(p_char);
-}
-
-static void service_free(void* ptr) {
- tBTA_GATTC_SERVICE* srvc = (tBTA_GATTC_SERVICE*)ptr;
- list_free(srvc->characteristics);
- list_free(srvc->included_svc);
- osi_free(srvc);
-}
-
-/*******************************************************************************
- *
- * Function bta_gattc_add_srvc_to_cache
- *
- * Description Add a service into database cache.
- *
- * Returns status
- *
- ******************************************************************************/
-static tGATT_STATUS bta_gattc_add_srvc_to_cache(tBTA_GATTC_SERV* p_srvc_cb,
- uint16_t s_handle,
- uint16_t e_handle,
- const Uuid& uuid,
- bool is_primary) {
+/** Add a service into database cache */
+static void bta_gattc_add_srvc_to_cache(tBTA_GATTC_SERV* p_srvc_cb,
+ uint16_t s_handle, uint16_t e_handle,
+ const Uuid& uuid, bool is_primary) {
#if (BTA_GATT_DEBUG == TRUE)
APPL_TRACE_DEBUG("Add a service into Service");
#endif
- tBTA_GATTC_SERVICE* p_new_srvc =
- (tBTA_GATTC_SERVICE*)osi_malloc(sizeof(tBTA_GATTC_SERVICE));
-
- /* update service information */
- p_new_srvc->s_handle = s_handle;
- p_new_srvc->e_handle = e_handle;
- p_new_srvc->is_primary = is_primary;
- p_new_srvc->uuid = uuid;
- p_new_srvc->handle = s_handle;
- p_new_srvc->characteristics = list_new(characteristic_free);
- p_new_srvc->included_svc = list_new(osi_free);
-
- if (p_srvc_cb->p_srvc_cache == NULL) {
- p_srvc_cb->p_srvc_cache = list_new(service_free);
- }
-
- list_append(p_srvc_cb->p_srvc_cache, p_new_srvc);
- return GATT_SUCCESS;
+ p_srvc_cb->srvc_cache.emplace_back(tBTA_GATTC_SERVICE{
+ .s_handle = s_handle,
+ .e_handle = e_handle,
+ .is_primary = is_primary,
+ .uuid = uuid,
+ .handle = s_handle,
+ });
}
-static tGATT_STATUS bta_gattc_add_char_to_cache(tBTA_GATTC_SERV* p_srvc_cb,
- uint16_t attr_handle,
- uint16_t value_handle,
- const Uuid& uuid,
- uint8_t property) {
+static void bta_gattc_add_char_to_cache(tBTA_GATTC_SERV* p_srvc_cb,
+ uint16_t attr_handle,
+ uint16_t value_handle, const Uuid& uuid,
+ uint8_t property) {
#if (BTA_GATT_DEBUG == TRUE)
APPL_TRACE_DEBUG("%s: Add a characteristic into Service", __func__);
APPL_TRACE_DEBUG("handle=%d uuid16=%s property=0x%x", value_handle,
#endif
tBTA_GATTC_SERVICE* service =
- bta_gattc_find_matching_service(p_srvc_cb->p_srvc_cache, attr_handle);
+ bta_gattc_find_matching_service(p_srvc_cb->srvc_cache, attr_handle);
if (!service) {
APPL_TRACE_ERROR(
"Illegal action to add char/descr/incl srvc for non-existing service!");
- return GATT_WRONG_STATE;
+ return;
}
/* TODO(jpawlowski): We should use attribute handle, not value handle to refer
*/
if (service->e_handle < value_handle) service->e_handle = value_handle;
- tBTA_GATTC_CHARACTERISTIC* characteristic =
- (tBTA_GATTC_CHARACTERISTIC*)osi_malloc(sizeof(tBTA_GATTC_CHARACTERISTIC));
-
- characteristic->handle = value_handle;
- characteristic->properties = property;
- characteristic->descriptors = list_new(osi_free);
- characteristic->uuid = uuid;
-
- characteristic->service = service;
- list_append(service->characteristics, characteristic);
-
- return GATT_SUCCESS;
+ service->characteristics.emplace_back(
+ tBTA_GATTC_CHARACTERISTIC{.handle = value_handle,
+ .properties = property,
+ .uuid = uuid,
+ .service = service});
+ return;
}
-/*******************************************************************************
- *
- * Function bta_gattc_add_attr_to_cache
- *
- * Description Add an attribute into database cache buffer.
- *
- * Returns status
- *
- ******************************************************************************/
-static tGATT_STATUS bta_gattc_add_attr_to_cache(
- tBTA_GATTC_SERV* p_srvc_cb, uint16_t handle, const Uuid& uuid,
- uint8_t property, uint16_t incl_srvc_s_handle, tBTA_GATTC_ATTR_TYPE type) {
+/* Add an attribute into database cache buffer */
+static void bta_gattc_add_attr_to_cache(tBTA_GATTC_SERV* p_srvc_cb,
+ uint16_t handle, const Uuid& uuid,
+ uint8_t property,
+ uint16_t incl_srvc_s_handle,
+ tBTA_GATTC_ATTR_TYPE type) {
#if (BTA_GATT_DEBUG == TRUE)
APPL_TRACE_DEBUG("%s: Add a [%s] into Service", __func__,
bta_gattc_attr_type[type]);
#endif
tBTA_GATTC_SERVICE* service =
- bta_gattc_find_matching_service(p_srvc_cb->p_srvc_cache, handle);
+ bta_gattc_find_matching_service(p_srvc_cb->srvc_cache, handle);
if (!service) {
APPL_TRACE_ERROR(
"Illegal action to add char/descr/incl srvc for non-existing service!");
- return GATT_WRONG_STATE;
+ return;
}
if (type == BTA_GATTC_ATTR_TYPE_INCL_SRVC) {
- tBTA_GATTC_INCLUDED_SVC* isvc =
- (tBTA_GATTC_INCLUDED_SVC*)osi_malloc(sizeof(tBTA_GATTC_INCLUDED_SVC));
-
- isvc->handle = handle;
- isvc->uuid = uuid;
-
- isvc->owning_service = service;
- isvc->included_service = bta_gattc_find_matching_service(
- p_srvc_cb->p_srvc_cache, incl_srvc_s_handle);
- if (!isvc->included_service) {
+ tBTA_GATTC_SERVICE* included_service = bta_gattc_find_matching_service(
+ p_srvc_cb->srvc_cache, incl_srvc_s_handle);
+ if (!included_service) {
APPL_TRACE_ERROR(
"%s: Illegal action to add non-existing included service!", __func__);
- osi_free(isvc);
- return GATT_WRONG_STATE;
+ return;
}
- list_append(service->included_svc, isvc);
+ service->included_svc.emplace_back(tBTA_GATTC_INCLUDED_SVC{
+ .handle = handle,
+ .uuid = uuid,
+ .owning_service = service,
+ .included_service = included_service,
+ });
} else if (type == BTA_GATTC_ATTR_TYPE_CHAR_DESCR) {
- tBTA_GATTC_DESCRIPTOR* descriptor =
- (tBTA_GATTC_DESCRIPTOR*)osi_malloc(sizeof(tBTA_GATTC_DESCRIPTOR));
-
- descriptor->handle = handle;
- descriptor->uuid = uuid;
-
- if (service->characteristics == NULL ||
- list_is_empty(service->characteristics)) {
+ if (service->characteristics.empty()) {
APPL_TRACE_ERROR(
"%s: Illegal action to add descriptor before adding a "
"characteristic!",
__func__);
- osi_free(descriptor);
- return GATT_WRONG_STATE;
+ return;
}
- tBTA_GATTC_CHARACTERISTIC* char_node =
- (tBTA_GATTC_CHARACTERISTIC*)list_back(service->characteristics);
-
- descriptor->characteristic = char_node;
- list_append(char_node->descriptors, descriptor);
+ tBTA_GATTC_CHARACTERISTIC& char_node = service->characteristics.back();
+ char_node.descriptors.emplace_back(tBTA_GATTC_DESCRIPTOR{
+ .handle = handle, .uuid = uuid, .characteristic = &char_node,
+ });
}
- return GATT_SUCCESS;
}
/*******************************************************************************
/* start expore a service if there is service not been explored */
if (p_srvc_cb->cur_srvc_idx < p_srvc_cb->total_srvc) {
/* add the first service into cache */
- if (bta_gattc_add_srvc_to_cache(p_srvc_cb, p_rec->s_handle, p_rec->e_handle,
- p_rec->uuid, p_rec->is_primary) == 0) {
- /* start discovering included services */
- bta_gattc_start_disc_include_srvc(conn_id, p_srvc_cb);
- return;
- }
+ bta_gattc_add_srvc_to_cache(p_srvc_cb, p_rec->s_handle, p_rec->e_handle,
+ p_rec->uuid, p_rec->is_primary);
+
+ /* start discovering included services */
+ bta_gattc_start_disc_include_srvc(conn_id, p_srvc_cb);
+ return;
}
/* no service found at all, the end of server discovery*/
LOG_WARN(LOG_TAG, "%s no more services found", __func__);
#if (BTA_GATT_DEBUG == TRUE)
- bta_gattc_display_cache_server(p_srvc_cb->p_srvc_cache);
+ bta_gattc_display_cache_server(p_srvc_cb->srvc_cache);
#endif
/* save cache to NV */
p_clcb->p_srcb->state = BTA_GATTC_SERV_SAVE;
uint16_t num_attrs = 2;
uint16_t attr_list[2];
-
/*
* On success, cb_data will be freed inside bta_gattc_sdp_callback,
* otherwise it will be freed within this function.
*
******************************************************************************/
void bta_gattc_search_service(tBTA_GATTC_CLCB* p_clcb, Uuid* p_uuid) {
- auto cache = p_clcb->p_srcb->p_srvc_cache;
- if (!cache || list_is_empty(cache)) return;
-
- for (list_node_t* sn = list_begin(cache); sn != list_end(cache);
- sn = list_next(sn)) {
- tBTA_GATTC_SERVICE* p_cache = (tBTA_GATTC_SERVICE*)list_node(sn);
-
- if (p_uuid && *p_uuid != p_cache->uuid) continue;
+ for (const tBTA_GATTC_SERVICE& service : p_clcb->p_srcb->srvc_cache) {
+ if (p_uuid && *p_uuid != service.uuid) continue;
#if (BTA_GATT_DEBUG == TRUE)
APPL_TRACE_DEBUG("found service %s, inst[%d] handle [%d]",
- p_cache->uuid.ToString().c_str(), p_cache->handle,
- p_cache->s_handle);
+ service.uuid.ToString().c_str(), service.handle,
+ service.s_handle);
#endif
if (!p_clcb->p_rcb->p_cback) continue;
tBTA_GATTC cb_data;
memset(&cb_data, 0, sizeof(tBTA_GATTC));
cb_data.srvc_res.conn_id = p_clcb->bta_conn_id;
- cb_data.srvc_res.service_uuid.inst_id = p_cache->handle;
- cb_data.srvc_res.service_uuid.uuid = p_cache->uuid;
+ cb_data.srvc_res.service_uuid.inst_id = service.handle;
+ cb_data.srvc_res.service_uuid.uuid = service.uuid;
(*p_clcb->p_rcb->p_cback)(BTA_GATTC_SEARCH_RES_EVT, &cb_data);
}
}
-list_t* bta_gattc_get_services_srcb(tBTA_GATTC_SERV* p_srcb) {
- if (!p_srcb || !p_srcb->p_srvc_cache || list_is_empty(p_srcb->p_srvc_cache))
- return NULL;
+std::list<tBTA_GATTC_SERVICE>* bta_gattc_get_services_srcb(
+ tBTA_GATTC_SERV* p_srcb) {
+ if (!p_srcb || p_srcb->srvc_cache.empty()) return NULL;
- return p_srcb->p_srvc_cache;
+ return &p_srcb->srvc_cache;
}
-const list_t* bta_gattc_get_services(uint16_t conn_id) {
+std::list<tBTA_GATTC_SERVICE>* bta_gattc_get_services(uint16_t conn_id) {
tBTA_GATTC_CLCB* p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id);
if (p_clcb == NULL) return NULL;
return bta_gattc_get_services_srcb(p_srcb);
}
-tBTA_GATTC_SERVICE* bta_gattc_find_matching_service(const list_t* services,
- uint16_t handle) {
- if (!services || list_is_empty(services)) return NULL;
-
- for (list_node_t* sn = list_begin(services); sn != list_end(services);
- sn = list_next(sn)) {
- tBTA_GATTC_SERVICE* service = (tBTA_GATTC_SERVICE*)list_node(sn);
-
- if (handle >= service->s_handle && handle <= service->e_handle)
- return service;
+tBTA_GATTC_SERVICE* bta_gattc_find_matching_service(
+ std::list<tBTA_GATTC_SERVICE>& services, uint16_t handle) {
+ for (tBTA_GATTC_SERVICE& service : services) {
+ if (handle >= service.s_handle && handle <= service.e_handle)
+ return &service;
}
return NULL;
}
-const tBTA_GATTC_SERVICE* bta_gattc_get_service_for_handle_srcb(
+static tBTA_GATTC_SERVICE* bta_gattc_get_service_for_handle_srcb(
tBTA_GATTC_SERV* p_srcb, uint16_t handle) {
- const list_t* services = bta_gattc_get_services_srcb(p_srcb);
-
- return bta_gattc_find_matching_service(services, handle);
+ std::list<tBTA_GATTC_SERVICE>* services = bta_gattc_get_services_srcb(p_srcb);
+ if (services == NULL) return NULL;
+ return bta_gattc_find_matching_service(*services, handle);
}
const tBTA_GATTC_SERVICE* bta_gattc_get_service_for_handle(uint16_t conn_id,
uint16_t handle) {
- const list_t* services = bta_gattc_get_services(conn_id);
+ std::list<tBTA_GATTC_SERVICE>* services = bta_gattc_get_services(conn_id);
+ if (services == NULL) return NULL;
- return bta_gattc_find_matching_service(services, handle);
+ return bta_gattc_find_matching_service(*services, handle);
}
tBTA_GATTC_CHARACTERISTIC* bta_gattc_get_characteristic_srcb(
tBTA_GATTC_SERV* p_srcb, uint16_t handle) {
- const tBTA_GATTC_SERVICE* service =
+ tBTA_GATTC_SERVICE* service =
bta_gattc_get_service_for_handle_srcb(p_srcb, handle);
if (!service) return NULL;
- for (list_node_t* cn = list_begin(service->characteristics);
- cn != list_end(service->characteristics); cn = list_next(cn)) {
- tBTA_GATTC_CHARACTERISTIC* p_char =
- (tBTA_GATTC_CHARACTERISTIC*)list_node(cn);
- if (handle == p_char->handle) return p_char;
+ for (tBTA_GATTC_CHARACTERISTIC& charac : service->characteristics) {
+ if (handle == charac.handle) return &charac;
}
return NULL;
return bta_gattc_get_characteristic_srcb(p_srcb, handle);
}
-tBTA_GATTC_DESCRIPTOR* bta_gattc_get_descriptor_srcb(tBTA_GATTC_SERV* p_srcb,
- uint16_t handle) {
+const tBTA_GATTC_DESCRIPTOR* bta_gattc_get_descriptor_srcb(
+ tBTA_GATTC_SERV* p_srcb, uint16_t handle) {
const tBTA_GATTC_SERVICE* service =
bta_gattc_get_service_for_handle_srcb(p_srcb, handle);
return NULL;
}
- for (list_node_t* cn = list_begin(service->characteristics);
- cn != list_end(service->characteristics); cn = list_next(cn)) {
- tBTA_GATTC_CHARACTERISTIC* p_char =
- (tBTA_GATTC_CHARACTERISTIC*)list_node(cn);
- for (list_node_t* dn = list_begin(p_char->descriptors);
- dn != list_end(p_char->descriptors); dn = list_next(dn)) {
- tBTA_GATTC_DESCRIPTOR* p_desc = (tBTA_GATTC_DESCRIPTOR*)list_node(dn);
- if (handle == p_desc->handle) return p_desc;
+ for (const tBTA_GATTC_CHARACTERISTIC& charac : service->characteristics) {
+ for (const tBTA_GATTC_DESCRIPTOR& desc : charac.descriptors) {
+ if (handle == desc.handle) return &desc;
}
}
return NULL;
}
-tBTA_GATTC_DESCRIPTOR* bta_gattc_get_descriptor(uint16_t conn_id,
- uint16_t handle) {
+const tBTA_GATTC_DESCRIPTOR* bta_gattc_get_descriptor(uint16_t conn_id,
+ uint16_t handle) {
tBTA_GATTC_CLCB* p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id);
if (p_clcb == NULL) return NULL;
/*******************************************************************************
* Returns number of elements inside db from start_handle to end_handle
******************************************************************************/
-static size_t bta_gattc_get_db_size(list_t* services, uint16_t start_handle,
- uint16_t end_handle) {
- if (!services || list_is_empty(services)) return 0;
+static size_t bta_gattc_get_db_size(
+ const std::list<tBTA_GATTC_SERVICE>& services, uint16_t start_handle,
+ uint16_t end_handle) {
+ if (services.empty()) return 0;
size_t db_size = 0;
- for (list_node_t* sn = list_begin(services); sn != list_end(services);
- sn = list_next(sn)) {
- tBTA_GATTC_SERVICE* p_cur_srvc = (tBTA_GATTC_SERVICE*)list_node(sn);
-
- if (p_cur_srvc->s_handle < start_handle) continue;
+ for (const tBTA_GATTC_SERVICE& service : services) {
+ if (service.s_handle < start_handle) continue;
- if (p_cur_srvc->e_handle > end_handle) break;
+ if (service.e_handle > end_handle) break;
db_size++;
- if (!p_cur_srvc->characteristics ||
- list_is_empty(p_cur_srvc->characteristics))
- continue;
- for (list_node_t* cn = list_begin(p_cur_srvc->characteristics);
- cn != list_end(p_cur_srvc->characteristics); cn = list_next(cn)) {
- tBTA_GATTC_CHARACTERISTIC* p_char =
- (tBTA_GATTC_CHARACTERISTIC*)list_node(cn);
+ for (const tBTA_GATTC_CHARACTERISTIC& charac : service.characteristics) {
db_size++;
- if (p_char->descriptors) db_size += list_length(p_char->descriptors);
+ db_size += charac.descriptors.size();
}
- if (p_cur_srvc->included_svc) {
- db_size += list_length(p_cur_srvc->included_svc);
- }
+ db_size += service.included_svc.size();
}
return db_size;
APPL_TRACE_DEBUG("%s: start_handle 0x%04x, end_handle 0x%04x", __func__,
start_handle, end_handle);
- if (!p_srvc_cb->p_srvc_cache || list_is_empty(p_srvc_cb->p_srvc_cache)) {
+ if (p_srvc_cb->srvc_cache.empty()) {
*count = 0;
*db = NULL;
return;
}
size_t db_size =
- bta_gattc_get_db_size(p_srvc_cb->p_srvc_cache, start_handle, end_handle);
+ bta_gattc_get_db_size(p_srvc_cb->srvc_cache, start_handle, end_handle);
void* buffer = osi_malloc(db_size * sizeof(btgatt_db_element_t));
btgatt_db_element_t* curr_db_attr = (btgatt_db_element_t*)buffer;
- for (list_node_t* sn = list_begin(p_srvc_cb->p_srvc_cache);
- sn != list_end(p_srvc_cb->p_srvc_cache); sn = list_next(sn)) {
- tBTA_GATTC_SERVICE* p_cur_srvc = (tBTA_GATTC_SERVICE*)list_node(sn);
-
- if (p_cur_srvc->s_handle < start_handle) continue;
+ for (const tBTA_GATTC_SERVICE& service : p_srvc_cb->srvc_cache) {
+ if (service.s_handle < start_handle) continue;
- if (p_cur_srvc->e_handle > end_handle) break;
+ if (service.e_handle > end_handle) break;
- bta_gattc_fill_gatt_db_el(
- curr_db_attr, p_cur_srvc->is_primary ? BTGATT_DB_PRIMARY_SERVICE
- : BTGATT_DB_SECONDARY_SERVICE,
- 0 /* att_handle */, p_cur_srvc->s_handle, p_cur_srvc->e_handle,
- p_cur_srvc->s_handle, p_cur_srvc->uuid, 0 /* prop */);
+ bta_gattc_fill_gatt_db_el(curr_db_attr,
+ service.is_primary ? BTGATT_DB_PRIMARY_SERVICE
+ : BTGATT_DB_SECONDARY_SERVICE,
+ 0 /* att_handle */, service.s_handle,
+ service.e_handle, service.s_handle, service.uuid,
+ 0 /* prop */);
curr_db_attr++;
- if (!p_cur_srvc->characteristics ||
- list_is_empty(p_cur_srvc->characteristics))
- continue;
-
- for (list_node_t* cn = list_begin(p_cur_srvc->characteristics);
- cn != list_end(p_cur_srvc->characteristics); cn = list_next(cn)) {
- tBTA_GATTC_CHARACTERISTIC* p_char =
- (tBTA_GATTC_CHARACTERISTIC*)list_node(cn);
-
+ for (const tBTA_GATTC_CHARACTERISTIC& charac : service.characteristics) {
bta_gattc_fill_gatt_db_el(curr_db_attr, BTGATT_DB_CHARACTERISTIC,
- p_char->handle, 0 /* s_handle */,
- 0 /* e_handle */, p_char->handle, p_char->uuid,
- p_char->properties);
+ charac.handle, 0 /* s_handle */,
+ 0 /* e_handle */, charac.handle, charac.uuid,
+ charac.properties);
curr_db_attr++;
- if (!p_char->descriptors || list_is_empty(p_char->descriptors)) continue;
-
- for (list_node_t* dn = list_begin(p_char->descriptors);
- dn != list_end(p_char->descriptors); dn = list_next(dn)) {
- tBTA_GATTC_DESCRIPTOR* p_desc = (tBTA_GATTC_DESCRIPTOR*)list_node(dn);
-
- bta_gattc_fill_gatt_db_el(curr_db_attr, BTGATT_DB_DESCRIPTOR,
- p_desc->handle, 0 /* s_handle */,
- 0 /* e_handle */, p_desc->handle,
- p_desc->uuid, 0 /* property */);
+ for (const tBTA_GATTC_DESCRIPTOR& desc : charac.descriptors) {
+ bta_gattc_fill_gatt_db_el(
+ curr_db_attr, BTGATT_DB_DESCRIPTOR, desc.handle, 0 /* s_handle */,
+ 0 /* e_handle */, desc.handle, desc.uuid, 0 /* property */);
curr_db_attr++;
}
}
- if (!p_cur_srvc->included_svc || list_is_empty(p_cur_srvc->included_svc))
- continue;
-
- for (list_node_t* isn = list_begin(p_cur_srvc->included_svc);
- isn != list_end(p_cur_srvc->included_svc); isn = list_next(isn)) {
- tBTA_GATTC_INCLUDED_SVC* p_isvc =
- (tBTA_GATTC_INCLUDED_SVC*)list_node(isn);
-
+ for (const tBTA_GATTC_INCLUDED_SVC& p_isvc : service.included_svc) {
bta_gattc_fill_gatt_db_el(
- curr_db_attr, BTGATT_DB_INCLUDED_SERVICE, p_isvc->handle,
- p_isvc->included_service ? p_isvc->included_service->s_handle : 0,
- 0 /* e_handle */, p_isvc->handle, p_isvc->uuid, 0 /* property */);
+ curr_db_attr, BTGATT_DB_INCLUDED_SERVICE, p_isvc.handle,
+ p_isvc.included_service ? p_isvc.included_service->s_handle : 0,
+ 0 /* e_handle */, p_isvc.handle, p_isvc.uuid, 0 /* property */);
curr_db_attr++;
}
}
if (!p_clcb->p_srcb ||
p_clcb->p_srcb->p_srvc_list || /* no active discovery */
- !p_clcb->p_srcb->p_srvc_cache) {
+ p_clcb->p_srcb->srvc_cache.empty()) {
APPL_TRACE_ERROR("No server cache available");
return;
}
/* first attribute loading, initialize buffer */
APPL_TRACE_ERROR("%s: bta_gattc_rebuild_cache", __func__);
- list_free(p_srvc_cb->p_srvc_cache);
- p_srvc_cb->p_srvc_cache = NULL;
+ p_srvc_cb->srvc_cache.clear();
while (num_attr > 0 && p_attr != NULL) {
switch (p_attr->attr_type) {
*
******************************************************************************/
void bta_gattc_cache_save(tBTA_GATTC_SERV* p_srvc_cb, uint16_t conn_id) {
- if (!p_srvc_cb->p_srvc_cache || list_is_empty(p_srvc_cb->p_srvc_cache))
- return;
+ if (p_srvc_cb->srvc_cache.empty()) return;
int i = 0;
- size_t db_size =
- bta_gattc_get_db_size(p_srvc_cb->p_srvc_cache, 0x0000, 0xFFFF);
+ size_t db_size = bta_gattc_get_db_size(p_srvc_cb->srvc_cache, 0x0000, 0xFFFF);
tBTA_GATTC_NV_ATTR* nv_attr =
(tBTA_GATTC_NV_ATTR*)osi_malloc(db_size * sizeof(tBTA_GATTC_NV_ATTR));
- for (list_node_t* sn = list_begin(p_srvc_cb->p_srvc_cache);
- sn != list_end(p_srvc_cb->p_srvc_cache); sn = list_next(sn)) {
- tBTA_GATTC_SERVICE* p_cur_srvc = (tBTA_GATTC_SERVICE*)list_node(sn);
-
+ for (const tBTA_GATTC_SERVICE& service : p_srvc_cb->srvc_cache) {
bta_gattc_fill_nv_attr(&nv_attr[i++], BTA_GATTC_ATTR_TYPE_SRVC,
- p_cur_srvc->s_handle, p_cur_srvc->e_handle,
- p_cur_srvc->uuid, 0 /* properties */,
- 0 /* incl_srvc_handle */, p_cur_srvc->is_primary);
+ service.s_handle, service.e_handle, service.uuid,
+ 0 /* properties */, 0 /* incl_srvc_handle */,
+ service.is_primary);
}
- for (list_node_t* sn = list_begin(p_srvc_cb->p_srvc_cache);
- sn != list_end(p_srvc_cb->p_srvc_cache); sn = list_next(sn)) {
- tBTA_GATTC_SERVICE* p_cur_srvc = (tBTA_GATTC_SERVICE*)list_node(sn);
-
- if (!p_cur_srvc->characteristics ||
- list_is_empty(p_cur_srvc->characteristics))
- continue;
-
- for (list_node_t* cn = list_begin(p_cur_srvc->characteristics);
- cn != list_end(p_cur_srvc->characteristics); cn = list_next(cn)) {
- tBTA_GATTC_CHARACTERISTIC* p_char =
- (tBTA_GATTC_CHARACTERISTIC*)list_node(cn);
-
- bta_gattc_fill_nv_attr(
- &nv_attr[i++], BTA_GATTC_ATTR_TYPE_CHAR, p_char->handle, 0,
- p_char->uuid, p_char->properties, 0 /* incl_srvc_handle */, false);
+ for (const tBTA_GATTC_SERVICE& service : p_srvc_cb->srvc_cache) {
+ for (const tBTA_GATTC_CHARACTERISTIC& charac : service.characteristics) {
+ bta_gattc_fill_nv_attr(&nv_attr[i++], BTA_GATTC_ATTR_TYPE_CHAR,
+ charac.handle, 0, charac.uuid, charac.properties,
+ 0 /* incl_srvc_handle */, false);
- if (!p_char->descriptors || list_is_empty(p_char->descriptors)) continue;
-
- for (list_node_t* dn = list_begin(p_char->descriptors);
- dn != list_end(p_char->descriptors); dn = list_next(dn)) {
- tBTA_GATTC_DESCRIPTOR* p_desc = (tBTA_GATTC_DESCRIPTOR*)list_node(dn);
-
- bta_gattc_fill_nv_attr(
- &nv_attr[i++], BTA_GATTC_ATTR_TYPE_CHAR_DESCR, p_desc->handle, 0,
- p_desc->uuid, 0 /* properties */, 0 /* incl_srvc_handle */, false);
+ for (const tBTA_GATTC_DESCRIPTOR& desc : charac.descriptors) {
+ bta_gattc_fill_nv_attr(&nv_attr[i++], BTA_GATTC_ATTR_TYPE_CHAR_DESCR,
+ desc.handle, 0, desc.uuid, 0 /* properties */,
+ 0 /* incl_srvc_handle */, false);
}
}
- if (!p_cur_srvc->included_svc || list_is_empty(p_cur_srvc->included_svc))
- continue;
-
- for (list_node_t* an = list_begin(p_cur_srvc->included_svc);
- an != list_end(p_cur_srvc->included_svc); an = list_next(an)) {
- tBTA_GATTC_INCLUDED_SVC* p_isvc = (tBTA_GATTC_INCLUDED_SVC*)list_node(an);
-
+ for (const tBTA_GATTC_INCLUDED_SVC& p_isvc : service.included_svc) {
bta_gattc_fill_nv_attr(&nv_attr[i++], BTA_GATTC_ATTR_TYPE_INCL_SRVC,
- p_isvc->handle, 0, p_isvc->uuid,
- 0 /* properties */,
- p_isvc->included_service->s_handle, false);
+ p_isvc.handle, 0, p_isvc.uuid, 0 /* properties */,
+ p_isvc.included_service->s_handle, false);
}
}
}
if (num_attr > 0xFFFF) {
- APPL_TRACE_ERROR("%s: more than 0xFFFF GATT attributes: %s", __func__, fname);
+ APPL_TRACE_ERROR("%s: more than 0xFFFF GATT attributes: %s", __func__,
+ fname);
goto done;
}
return NULL;
}
-static tBTA_GATTC_DESCRIPTOR* find_descriptor_by_short_uuid(
+static const tBTA_GATTC_DESCRIPTOR* find_descriptor_by_short_uuid(
uint16_t conn_id, uint16_t char_handle, uint16_t short_uuid) {
const tBTA_GATTC_CHARACTERISTIC* p_char =
BTA_GATTC_GetCharacteristic(conn_id, char_handle);
return NULL;
}
- if (!p_char->descriptors || list_is_empty(p_char->descriptors)) return NULL;
-
- for (list_node_t* dn = list_begin(p_char->descriptors);
- dn != list_end(p_char->descriptors); dn = list_next(dn)) {
- tBTA_GATTC_DESCRIPTOR* p_desc = (tBTA_GATTC_DESCRIPTOR*)list_node(dn);
-
- if (p_desc->uuid == Uuid::From16Bit(short_uuid)) return p_desc;
+ for (const tBTA_GATTC_DESCRIPTOR& desc : p_char->descriptors) {
+ if (desc.uuid == Uuid::From16Bit(short_uuid)) return &desc;
}
return NULL;
bool bta_hh_le_write_ccc(tBTA_HH_DEV_CB* p_cb, uint8_t char_handle,
uint16_t clt_cfg_value, GATT_WRITE_OP_CB cb,
void* cb_data) {
- tBTA_GATTC_DESCRIPTOR* p_desc = find_descriptor_by_short_uuid(
+ const tBTA_GATTC_DESCRIPTOR* p_desc = find_descriptor_by_short_uuid(
p_cb->conn_id, char_handle, GATT_UUID_CHAR_CLIENT_CONFIG);
if (!p_desc) return false;
*
******************************************************************************/
static void bta_hh_le_search_hid_chars(tBTA_HH_DEV_CB* p_dev_cb,
- tBTA_GATTC_SERVICE* service) {
+ const tBTA_GATTC_SERVICE* service) {
tBTA_HH_LE_RPT* p_rpt;
- for (list_node_t* cn = list_begin(service->characteristics);
- cn != list_end(service->characteristics); cn = list_next(cn)) {
- tBTA_GATTC_CHARACTERISTIC* p_char =
- (tBTA_GATTC_CHARACTERISTIC*)list_node(cn);
-
- if (!p_char->uuid.Is16Bit()) continue;
+ for (const tBTA_GATTC_CHARACTERISTIC& charac : service->characteristics) {
+ if (!charac.uuid.Is16Bit()) continue;
- uint16_t uuid16 = p_char->uuid.As16Bit();
+ uint16_t uuid16 = charac.uuid.As16Bit();
LOG_DEBUG(LOG_TAG, "%s: %s %s", __func__, bta_hh_uuid_to_str(uuid16),
- p_char->uuid.ToString().c_str());
+ charac.uuid.ToString().c_str());
switch (uuid16) {
case GATT_UUID_HID_CONTROL_POINT:
- p_dev_cb->hid_srvc.control_point_handle = p_char->handle;
+ p_dev_cb->hid_srvc.control_point_handle = charac.handle;
break;
case GATT_UUID_HID_INFORMATION:
/* only one instance per HID service */
- gatt_queue_read_op(GATT_READ_CHAR, p_dev_cb->conn_id, p_char->handle,
+ gatt_queue_read_op(GATT_READ_CHAR, p_dev_cb->conn_id, charac.handle,
read_hid_info_cb, p_dev_cb);
break;
case GATT_UUID_HID_REPORT_MAP:
/* only one instance per HID service */
- gatt_queue_read_op(GATT_READ_CHAR, p_dev_cb->conn_id, p_char->handle,
+ gatt_queue_read_op(GATT_READ_CHAR, p_dev_cb->conn_id, charac.handle,
read_hid_report_map_cb, p_dev_cb);
/* descriptor is optional */
- bta_hh_le_read_char_descriptor(p_dev_cb, p_char->handle,
+ bta_hh_le_read_char_descriptor(p_dev_cb, charac.handle,
GATT_UUID_EXT_RPT_REF_DESCR,
read_ext_rpt_ref_desc_cb, p_dev_cb);
break;
case GATT_UUID_HID_REPORT:
p_rpt = bta_hh_le_find_alloc_report_entry(
p_dev_cb, p_dev_cb->hid_srvc.srvc_inst_id, GATT_UUID_HID_REPORT,
- p_char->handle);
+ charac.handle);
if (p_rpt == NULL) {
APPL_TRACE_ERROR("%s: Add report entry failed !!!", __func__);
break;
if (p_rpt->rpt_type != BTA_HH_RPTT_INPUT) break;
- bta_hh_le_read_char_descriptor(p_dev_cb, p_char->handle,
+ bta_hh_le_read_char_descriptor(p_dev_cb, charac.handle,
GATT_UUID_RPT_REF_DESCR,
read_report_ref_desc_cb, p_dev_cb);
break;
case GATT_UUID_HID_BT_MOUSE_INPUT:
case GATT_UUID_HID_BT_KB_INPUT:
if (bta_hh_le_find_alloc_report_entry(p_dev_cb, service->handle, uuid16,
- p_char->handle) == NULL)
+ charac.handle) == NULL)
APPL_TRACE_ERROR("%s: Add report entry failed !!!", __func__);
break;
}
/* Make sure PROTO_MODE is processed as last */
- for (list_node_t* cn = list_begin(service->characteristics);
- cn != list_end(service->characteristics); cn = list_next(cn)) {
- tBTA_GATTC_CHARACTERISTIC* p_char =
- (tBTA_GATTC_CHARACTERISTIC*)list_node(cn);
-
- if (p_char->uuid == Uuid::From16Bit(GATT_UUID_HID_PROTO_MODE)) {
- p_dev_cb->hid_srvc.proto_mode_handle = p_char->handle;
+ for (const tBTA_GATTC_CHARACTERISTIC& charac : service->characteristics) {
+ if (charac.uuid == Uuid::From16Bit(GATT_UUID_HID_PROTO_MODE)) {
+ p_dev_cb->hid_srvc.proto_mode_handle = charac.handle;
bta_hh_le_set_protocol_mode(p_dev_cb, p_dev_cb->mode);
break;
}
return;
}
- const list_t* services = BTA_GATTC_GetServices(p_data->conn_id);
+ const std::list<tBTA_GATTC_SERVICE>* services =
+ BTA_GATTC_GetServices(p_data->conn_id);
bool have_hid = false;
- for (list_node_t* sn = list_begin(services); sn != list_end(services);
- sn = list_next(sn)) {
- tBTA_GATTC_SERVICE* service = (tBTA_GATTC_SERVICE*)list_node(sn);
-
- if (service->uuid == Uuid::From16Bit(UUID_SERVCLASS_LE_HID) &&
- service->is_primary && !have_hid) {
+ for (const tBTA_GATTC_SERVICE& service : *services) {
+ if (service.uuid == Uuid::From16Bit(UUID_SERVCLASS_LE_HID) &&
+ service.is_primary && !have_hid) {
have_hid = true;
/* found HID primamry service */
p_dev_cb->hid_srvc.in_use = true;
- p_dev_cb->hid_srvc.srvc_inst_id = service->handle;
+ p_dev_cb->hid_srvc.srvc_inst_id = service.handle;
p_dev_cb->hid_srvc.proto_mode_handle = 0;
p_dev_cb->hid_srvc.control_point_handle = 0;
- bta_hh_le_search_hid_chars(p_dev_cb, service);
+ bta_hh_le_search_hid_chars(p_dev_cb, &service);
APPL_TRACE_DEBUG("%s: have HID service inst_id= %d", __func__,
p_dev_cb->hid_srvc.srvc_inst_id);
- } else if (service->uuid == Uuid::From16Bit(UUID_SERVCLASS_SCAN_PARAM)) {
+ } else if (service.uuid == Uuid::From16Bit(UUID_SERVCLASS_SCAN_PARAM)) {
p_dev_cb->scan_refresh_char_handle = 0;
- for (list_node_t* cn = list_begin(service->characteristics);
- cn != list_end(service->characteristics); cn = list_next(cn)) {
- tBTA_GATTC_CHARACTERISTIC* p_char =
- (tBTA_GATTC_CHARACTERISTIC*)list_node(cn);
- if (p_char->uuid == Uuid::From16Bit(GATT_UUID_SCAN_REFRESH)) {
- p_dev_cb->scan_refresh_char_handle = p_char->handle;
+ for (const tBTA_GATTC_CHARACTERISTIC& charac : service.characteristics) {
+ if (charac.uuid == Uuid::From16Bit(GATT_UUID_SCAN_REFRESH)) {
+ p_dev_cb->scan_refresh_char_handle = charac.handle;
- if (p_char->properties & GATT_CHAR_PROP_BIT_NOTIFY)
+ if (charac.properties & GATT_CHAR_PROP_BIT_NOTIFY)
p_dev_cb->scps_notify |= BTA_HH_LE_SCPS_NOTIFY_SPT;
else
p_dev_cb->scps_notify = BTA_HH_LE_SCPS_NOTIFY_NONE;
break;
}
}
- } else if (service->uuid == Uuid::From16Bit(UUID_SERVCLASS_GAP_SERVER)) {
+ } else if (service.uuid == Uuid::From16Bit(UUID_SERVCLASS_GAP_SERVER)) {
// TODO(jpawlowski): this should be done by GAP profile, remove when GAP
// is fixed.
- for (list_node_t* cn = list_begin(service->characteristics);
- cn != list_end(service->characteristics); cn = list_next(cn)) {
- tBTA_GATTC_CHARACTERISTIC* p_char =
- (tBTA_GATTC_CHARACTERISTIC*)list_node(cn);
- if (p_char->uuid == Uuid::From16Bit(GATT_UUID_GAP_PREF_CONN_PARAM)) {
+ for (const tBTA_GATTC_CHARACTERISTIC& charac : service.characteristics) {
+ if (charac.uuid == Uuid::From16Bit(GATT_UUID_GAP_PREF_CONN_PARAM)) {
/* read the char value */
- gatt_queue_read_op(GATT_READ_CHAR, p_dev_cb->conn_id, p_char->handle,
+ gatt_queue_read_op(GATT_READ_CHAR, p_dev_cb->conn_id, charac.handle,
read_pref_conn_params_cb, p_dev_cb);
break;