bthost: Add destroy callback to bthost_add_iso_hook
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Mon, 22 Aug 2022 21:54:41 +0000 (14:54 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:54 +0000 (14:55 +0530)
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.

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
emulator/bthost.c
emulator/bthost.h
tools/iso-tester.c

index c106ed1..f81b50b 100755 (executable)
@@ -136,6 +136,7 @@ struct rfcomm_chan_hook {
 struct iso_hook {
        bthost_cid_hook_func_t func;
        void *user_data;
+       bthost_destroy_func_t destroy;
 };
 
 struct btconn {
@@ -305,6 +306,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);
@@ -675,7 +679,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;
@@ -692,6 +697,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;
 }
index 3d7a124..2cfdef7 100755 (executable)
@@ -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);
index 5727f30..8c935b9 100644 (file)
@@ -1137,7 +1137,7 @@ static void iso_send(struct test_data *data, GIOChannel *io)
        tester_print("Writing %zu bytes of data", isodata->send->iov_len);
 
        host = hciemu_client_get_host(data->hciemu);
-       bthost_add_iso_hook(host, data->handle, bthost_recv_data, data);
+       bthost_add_iso_hook(host, data->handle, bthost_recv_data, data, NULL);
 
        ret = writev(sk, isodata->send, 1);
        if (ret < 0 || isodata->send->iov_len != (size_t) ret) {