summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2019-04-03 13:57:13 +0300
committerhimanshu <h.himanshu@samsung.com>2020-02-11 14:27:47 +0530
commitcdb4a1416c459836533f6a4ad43665b1786ecf80 (patch)
tree23a697e4403c773684a9c18df34868b7697bf6a4 /src
parent978d5b2d0f6847f9532fb935f1eff2cb0545737f (diff)
downloadbluez-cdb4a1416c459836533f6a4ad43665b1786ecf80.tar.gz
bluez-cdb4a1416c459836533f6a4ad43665b1786ecf80.tar.bz2
bluez-cdb4a1416c459836533f6a4ad43665b1786ecf80.zip
shared/gatt-db: Skip ahead if handle range is not within service
This checks if a range is within service handles skipping if it is not, it also convert the direct search to use gatt_db_foreach_service_in_range instead so all operation that do lookups in a range can benefit from such optimization. Change-Id: Iaabce05612bc8744159e1f5115eb27d9bbbec7d4 Signed-off-by: himanshu <h.himanshu@samsung.com>
Diffstat (limited to 'src')
-rw-r--r--src/shared/gatt-db.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index d530855d..6b9e5154 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -1187,11 +1187,10 @@ struct find_by_type_value_data {
unsigned int num_of_res;
};
-static void find_by_type(void *data, void *user_data)
+static void find_by_type(struct gatt_db_attribute *attribute, void *user_data)
{
struct find_by_type_value_data *search_data = user_data;
- struct gatt_db_service *service = data;
- struct gatt_db_attribute *attribute;
+ struct gatt_db_service *service = attribute->service;
int i;
if (!service->active)
@@ -1242,7 +1241,8 @@ unsigned int gatt_db_find_by_type(struct gatt_db *db, uint16_t start_handle,
data.func = func;
data.user_data = user_data;
- queue_foreach(db->services, find_by_type, &data);
+ gatt_db_foreach_service_in_range(db, NULL, find_by_type, &data,
+ start_handle, end_handle);
return data.num_of_res;
}
@@ -1266,7 +1266,8 @@ unsigned int gatt_db_find_by_type_value(struct gatt_db *db,
data.value = value;
data.value_len = value_len;
- queue_foreach(db->services, find_by_type, &data);
+ gatt_db_foreach_service_in_range(db, NULL, find_by_type, &data,
+ start_handle, end_handle);
return data.num_of_res;
}
@@ -1278,11 +1279,10 @@ struct read_by_type_data {
uint16_t end_handle;
};
-static void read_by_type(void *data, void *user_data)
+static void read_by_type(struct gatt_db_attribute *attribute, void *user_data)
{
struct read_by_type_data *search_data = user_data;
- struct gatt_db_service *service = data;
- struct gatt_db_attribute *attribute;
+ struct gatt_db_service *service = attribute->service;
int i;
if (!service->active)
@@ -1317,7 +1317,8 @@ void gatt_db_read_by_type(struct gatt_db *db, uint16_t start_handle,
data.end_handle = end_handle;
data.queue = queue;
- queue_foreach(db->services, read_by_type, &data);
+ gatt_db_foreach_service_in_range(db, NULL, read_by_type, &data,
+ start_handle, end_handle);
}
@@ -1327,21 +1328,16 @@ struct find_information_data {
uint16_t end_handle;
};
-static void find_information(void *data, void *user_data)
+static void find_information(struct gatt_db_attribute *attribute,
+ void *user_data)
{
struct find_information_data *search_data = user_data;
- struct gatt_db_service *service = data;
- struct gatt_db_attribute *attribute;
+ struct gatt_db_service *service = attribute->service;
int i;
if (!service->active)
return;
- /* Check if service is in range */
- if ((service->attributes[0]->handle + service->num_handles - 1) <
- search_data->start_handle)
- return;
-
for (i = 0; i < service->num_handles; i++) {
attribute = service->attributes[i];
if (!attribute)
@@ -1367,7 +1363,8 @@ void gatt_db_find_information(struct gatt_db *db, uint16_t start_handle,
data.end_handle = end_handle;
data.queue = queue;
- queue_foreach(db->services, find_information, &data);
+ gatt_db_foreach_service_in_range(db, NULL, find_information, &data,
+ start_handle, end_handle);
}
void gatt_db_foreach_service(struct gatt_db *db, const bt_uuid_t *uuid,
@@ -1389,12 +1386,13 @@ static void foreach_service_in_range(void *data, void *user_data)
{
struct gatt_db_service *service = data;
struct foreach_data *foreach_data = user_data;
- uint16_t svc_start;
+ uint16_t svc_start, svc_end;
bt_uuid_t uuid;
- svc_start = get_handle_at_index(service, 0);
+ gatt_db_service_get_handles(service, &svc_start, &svc_end);
- if (svc_start > foreach_data->end || svc_start < foreach_data->start)
+ /* Check if service is within requested range */
+ if (svc_start > foreach_data->end || svc_end < foreach_data->start)
return;
if (foreach_data->uuid) {