diff --git a/src/shared/att.c b/src/shared/att.c
index 26b6c5b..447863d 100644
--- a/src/shared/att.c
+++ b/src/shared/att.c
bool writer_active;
struct queue *notify_list; /* List of registered callbacks */
- bool in_notify;
- bool need_notify_cleanup;
-
struct queue *disconn_list; /* List of disconnect handlers */
- bool in_disconn;
- bool need_disconn_cleanup;
bool in_req; /* There's a pending incoming request */
struct att_notify {
unsigned int id;
uint16_t opcode;
- bool removed;
bt_att_notify_func_t callback;
bt_att_destroy_func_t destroy;
void *user_data;
return notify->id == id;
}
-static bool match_notify_removed(const void *a, const void *b)
-{
- const struct att_notify *notify = a;
-
- return notify->removed;
-}
-
-static void mark_notify_removed(void *data, void *user_data)
-{
- struct att_notify *notify = data;
-
- notify->removed = true;
-}
-
struct att_disconn {
unsigned int id;
bool removed;
return disconn->id == id;
}
-static bool match_disconn_removed(const void *a, const void *b)
-{
- const struct att_disconn *disconn = a;
-
- return disconn->removed;
-}
-
-static void mark_disconn_removed(void *data, void *user_data)
-{
- struct att_disconn *disconn = data;
-
- disconn->removed = true;
-}
-
static bool encode_pdu(struct att_send_op *op, const void *pdu,
uint16_t length, uint16_t mtu)
{
bt_att_cancel_all(att);
bt_att_ref(att);
- att->in_disconn = true;
queue_foreach(att->disconn_list, disconn_handler, NULL);
- att->in_disconn = false;
-
- if (att->need_disconn_cleanup) {
- queue_remove_all(att->disconn_list, match_disconn_removed, NULL,
- destroy_att_disconn);
- att->need_disconn_cleanup = false;
- }
-
bt_att_unregister_all(att);
bt_att_unref(att);
struct att_notify *notify = data;
struct notify_data *not_data = user_data;
- if (notify->removed)
- return;
-
if (!opcode_match(notify->opcode, not_data->opcode))
return;
struct notify_data data;
bt_att_ref(att);
- att->in_notify = true;
memset(&data, 0, sizeof(data));
data.opcode = opcode;
queue_foreach(att->notify_list, notify_handler, &data);
- att->in_notify = false;
-
- if (att->need_notify_cleanup) {
- queue_remove_all(att->notify_list, match_notify_removed, NULL,
- destroy_att_notify);
- att->need_notify_cleanup = false;
- }
-
bt_att_unref(att);
/*
if (!disconn)
return false;
- if (!att->in_disconn) {
- queue_remove(att->disconn_list, disconn);
- destroy_att_disconn(disconn);
- return true;
- }
-
- disconn->removed = true;
- att->need_disconn_cleanup = true;
-
+ queue_remove(att->disconn_list, disconn);
+ destroy_att_disconn(disconn);
return true;
}
if (!notify)
return false;
- if (!att->in_notify) {
- queue_remove(att->notify_list, notify);
- destroy_att_notify(notify);
- return true;
- }
-
- notify->removed = true;
- att->need_notify_cleanup = true;
-
+ queue_remove(att->notify_list, notify);
+ destroy_att_notify(notify);
return true;
}
if (!att)
return false;
- if (att->in_notify) {
- queue_foreach(att->notify_list, mark_notify_removed, NULL);
- att->need_notify_cleanup = true;
- } else {
- queue_remove_all(att->notify_list, NULL, NULL,
- destroy_att_notify);
- }
-
- if (att->in_disconn) {
- queue_foreach(att->disconn_list, mark_disconn_removed, NULL);
- att->need_disconn_cleanup = true;
- } else {
- queue_remove_all(att->disconn_list, NULL, NULL,
- destroy_att_disconn);
- }
+ queue_remove_all(att->notify_list, NULL, NULL, destroy_att_notify);
+ queue_remove_all(att->disconn_list, NULL, NULL, destroy_att_disconn);
return true;
}