diff options
author | Jakub Tyszkowski <jakub.tyszkowski@tieto.com> | 2014-04-01 17:19:23 +0200 |
---|---|---|
committer | Szymon Janc <szymon.janc@tieto.com> | 2014-04-03 16:25:08 +0200 |
commit | b2fb35014af5e4bc90a7841dfa7d1d1e0000a647 (patch) | |
tree | 9ee4e37b3480f536789790162bf2db1d3aa18a96 /android | |
parent | 362f9942dad8e46e31a725a0641d0a903eb68cff (diff) | |
download | bluez-b2fb35014af5e4bc90a7841dfa7d1d1e0000a647.tar.gz |
android/gatt: Add queue for characteristic descriptors caching
This is where descriptors will be cached.
Diffstat (limited to 'android')
-rw-r--r-- | android/gatt.c | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/android/gatt.c b/android/gatt.c index 5069f982f..cb6065a95 100644 --- a/android/gatt.c +++ b/android/gatt.c @@ -67,9 +67,16 @@ struct element_id { uint8_t instance; }; +struct descriptor { + struct element_id id; + uint16_t handle; +}; + struct characteristic { struct element_id id; struct gatt_char ch; + + struct queue *descriptors; }; struct service { @@ -171,6 +178,17 @@ static void element_id_to_hal_gatt_id(const struct element_id *from, uuid2android(&from->uuid, to->uuid); } +static void destroy_characteristic(void *data) +{ + struct characteristic *chars = data; + + if (!chars) + return; + + queue_destroy(chars->descriptors, free); + free(chars); +} + static void destroy_service(void *data) { struct service *srvc = data; @@ -178,7 +196,7 @@ static void destroy_service(void *data) if (!srvc) return; - queue_destroy(srvc->chars, free); + queue_destroy(srvc->chars, destroy_characteristic); free(srvc); } @@ -1257,14 +1275,21 @@ static void cache_all_srvc_chars(GSList *characteristics, struct queue *q) /* Refresh characteristics cache if already exist */ if (!queue_isempty(q)) - queue_remove_all(q, NULL, NULL, free); + queue_remove_all(q, NULL, NULL, destroy_characteristic); for (; characteristics; characteristics = characteristics->next) { struct characteristic *ch; ch = new0(struct characteristic, 1); if (!ch) { - error("gatt: Could not allocate characteristic"); + error("gatt: Error while caching characteristic"); + continue; + } + + ch->descriptors = queue_new(); + if (!ch->descriptors) { + error("gatt: Error while caching characteristic"); + free(ch); continue; } @@ -1280,7 +1305,7 @@ static void cache_all_srvc_chars(GSList *characteristics, struct queue *q) if (!queue_push_tail(q, ch)) { error("gatt: Error while caching characteristic"); - free(ch); + destroy_characteristic(ch); } } } |