From 5bf220eb3b86e3d162b1b926c529a975821b6a02 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 22 Aug 2022 14:54:41 -0700 Subject: bthost: Add destroy callback to bthost_add_iso_hook This adds a destroy callback to bthost_add_iso_hook so its user can detect when the hook is freed when the connection is disconnected. --- emulator/bthost.c | 8 +++++++- emulator/bthost.h | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'emulator') diff --git a/emulator/bthost.c b/emulator/bthost.c index f067d39a0..b05198953 100644 --- a/emulator/bthost.c +++ b/emulator/bthost.c @@ -137,6 +137,7 @@ struct rfcomm_chan_hook { struct iso_hook { bthost_cid_hook_func_t func; void *user_data; + bthost_destroy_func_t destroy; }; struct btconn { @@ -306,6 +307,9 @@ static void btconn_free(struct btconn *conn) free(hook); } + if (conn->iso_hook && conn->iso_hook->destroy) + conn->iso_hook->destroy(conn->iso_hook->user_data); + free(conn->iso_hook); free(conn->recv_data); free(conn); @@ -676,7 +680,8 @@ void bthost_add_cid_hook(struct bthost *bthost, uint16_t handle, uint16_t cid, } void bthost_add_iso_hook(struct bthost *bthost, uint16_t handle, - bthost_cid_hook_func_t func, void *user_data) + bthost_iso_hook_func_t func, void *user_data, + bthost_destroy_func_t destroy) { struct iso_hook *hook; struct btconn *conn; @@ -693,6 +698,7 @@ void bthost_add_iso_hook(struct bthost *bthost, uint16_t handle, hook->func = func; hook->user_data = user_data; + hook->destroy = destroy; conn->iso_hook = hook; } diff --git a/emulator/bthost.h b/emulator/bthost.h index 3d7a124f0..2cfdef766 100644 --- a/emulator/bthost.h +++ b/emulator/bthost.h @@ -71,7 +71,8 @@ typedef void (*bthost_iso_hook_func_t)(const void *data, uint16_t len, void *user_data); void bthost_add_iso_hook(struct bthost *bthost, uint16_t handle, - bthost_iso_hook_func_t func, void *user_data); + bthost_iso_hook_func_t func, void *user_data, + bthost_destroy_func_t destroy); void bthost_send_cid(struct bthost *bthost, uint16_t handle, uint16_t cid, const void *data, uint16_t len); -- cgit v1.2.1