From 51bb3535e2d15ab68f1181e90b77340e2362ae4d Mon Sep 17 00:00:00 2001 From: Wootak Jung Date: Wed, 5 Aug 2020 16:40:14 +0900 Subject: [PATCH] Add notify_char_changed callback handling logic In case fd is acquired, just write on the fd. so, need to generate callback after write(). Change-Id: Ica4972f447737b381da448173123f4ec21e38f4a Signed-off-by: Wootak Jung --- src/bluetooth-gatt.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/bluetooth-gatt.c b/src/bluetooth-gatt.c index 89c8c7c..9fd356e 100644 --- a/src/bluetooth-gatt.c +++ b/src/bluetooth-gatt.c @@ -53,6 +53,13 @@ static void __bt_gatt_free_descriptor(bt_gatt_h gatt_handle); static void __bt_gatt_free_characteristic(bt_gatt_h gatt_handle); static void __bt_gatt_free_service(bt_gatt_h gatt_handle); +struct notify_char_changed_cb_s { + char *device_address; + bt_gatt_characteristic_s *chr; + bt_gatt_server_notification_sent_cb callback; + void *user_data; +}; + #define BT_CHECK_GATT_SUPPORT() \ { \ BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_LE); \ @@ -3200,6 +3207,28 @@ int bt_gatt_server_send_response(int request_id, bt_gatt_att_request_type_e requ return ret; } /* LCOV_EXCL_STOP */ +static gboolean __notify_characteristic_changed_value_cb(gpointer user_data) +{ + struct notify_char_changed_cb_s *cb_data = user_data; + bt_gatt_characteristic_s *chr = cb_data->chr; + bt_gatt_service_s *service = chr->parent; + bt_gatt_server_s *server; + + if (!service) { + g_free(cb_data->device_address); + g_free(cb_data); + return FALSE; + } + server = service->parent; + + if (cb_data->callback) + cb_data->callback(BT_ERROR_NONE, cb_data->device_address, server, cb_data->chr, TRUE, cb_data->user_data); + + g_free(cb_data->device_address); + g_free(cb_data); + return FALSE; +} + int bt_gatt_server_notify_characteristic_changed_value(bt_gatt_h characteristic, bt_gatt_server_notification_sent_cb callback, const char *device_address, void *user_data) @@ -3268,6 +3297,7 @@ int bt_gatt_server_notify_characteristic_changed_value(bt_gatt_h characteristic, BT_DBG("Enable Notifcation for the characteristic [%d]", attribute_handle); } param.instance_id = instance_id; + param.fd = -1; ret = _bt_get_error_code(bluetooth_gatt_server_send_indication(&addr_hex, ¶m, &indication)); BT_INFO("Sent Indication to Remote GATT client: result [%d]", ret); @@ -3276,6 +3306,15 @@ int bt_gatt_server_notify_characteristic_changed_value(bt_gatt_h characteristic, _bt_convert_error_to_string(ret), ret); return BT_ERROR_OPERATION_FAILED; } + + if (param.fd > -1 && callback) { + struct notify_char_changed_cb_s *cb_data = g_malloc0(sizeof(struct notify_char_changed_cb_s)); + cb_data->device_address = g_strdup(device_address); + cb_data->chr = chr; + cb_data->callback = callback; + cb_data->user_data = user_data; + g_idle_add(__notify_characteristic_changed_value_cb, cb_data); + } } } -- 2.7.4