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 {
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;
if (!srvc)
return;
- queue_destroy(srvc->chars, free);
+ queue_destroy(srvc->chars, destroy_characteristic);
free(srvc);
}
/* 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;
}
if (!queue_push_tail(q, ch)) {
error("gatt: Error while caching characteristic");
- free(ch);
+ destroy_characteristic(ch);
}
}
}