gatt: Add confirmation callback 50/204950/1
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Mon, 19 Mar 2018 12:44:26 +0000 (14:44 +0200)
committerAmit Purwar <amit.purwar@samsung.com>
Fri, 26 Apr 2019 10:53:03 +0000 (16:23 +0530)
This replaces indicate flag with confirmation callback to enable
setting custom callback if necessary.

Change-Id: I2378e4dc42a1a241eb79fe7f947a5ab20bf5c5e0
Signed-off-by: Amit Purwar <amit.purwar@samsung.com>
src/gatt-database.c

index 1adb5b6..f704f3c 100644 (file)
@@ -1137,8 +1137,8 @@ struct notify {
        uint16_t handle, ccc_handle;
        const uint8_t *value;
        uint16_t len;
-       bool indicate;
-       GDBusProxy *proxy;
+       bt_gatt_server_conf_func_t conf;
+       void *user_data;
 };
 
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
@@ -1345,7 +1345,7 @@ static void send_notification_to_device(void *data, void *user_data)
        if (!ccc)
                return;
 
-       if (!ccc->value[0] || (notify->indicate && !(ccc->value[0] & 0x02)))
+       if (!ccc->value[0] || (notify->conf && !(ccc->value[0] & 0x02)))
                return;
 
        device = btd_adapter_get_device(notify->database->adapter,
@@ -1365,7 +1365,7 @@ static void send_notification_to_device(void *data, void *user_data)
         * TODO: If the device is not connected but bonded, send the
         * notification/indication when it becomes connected.
         */
-       if (!notify->indicate) {
+       if (!notify->conf) {
                DBG("GATT server sending notification");
                bt_gatt_server_send_notification(server,
                                        notify->handle, notify->value,
@@ -1375,8 +1375,8 @@ static void send_notification_to_device(void *data, void *user_data)
 
        DBG("GATT server sending indication");
        bt_gatt_server_send_indication(server, notify->handle, notify->value,
-                                                       notify->len, conf_cb,
-                                                       notify->proxy, NULL);
+                                               notify->len, notify->conf,
+                                               notify->user_data, NULL);
 
        return;
 
@@ -1389,10 +1389,16 @@ remove:
        }
 }
 
+static void service_changed_conf(void *user_data)
+{
+       DBG("");
+}
+
 static void send_notification_to_devices(struct btd_gatt_database *database,
                                        uint16_t handle, const uint8_t *value,
                                        uint16_t len, uint16_t ccc_handle,
-                                       bool indicate, GDBusProxy *proxy)
+                                       bt_gatt_server_conf_func_t conf,
+                                       void *user_data)
 {
        struct notify notify;
 
@@ -1403,8 +1409,8 @@ static void send_notification_to_devices(struct btd_gatt_database *database,
        notify.ccc_handle = ccc_handle;
        notify.value = value;
        notify.len = len;
-       notify.indicate = indicate;
-       notify.proxy = proxy;
+       notify.conf = conf;
+       notify.user_data = user_data;
 
        queue_foreach(database->device_states, send_notification_to_device,
                                                                &notify);
@@ -1435,7 +1441,7 @@ static void send_service_changed(struct btd_gatt_database *database,
        put_le16(end, value + 2);
 
        send_notification_to_devices(database, handle, value, sizeof(value),
-                                                       ccc_handle, true, NULL);
+                                       ccc_handle, service_changed_conf, NULL);
 }
 
 static void gatt_db_service_added(struct gatt_db_attribute *attrib,
@@ -2410,8 +2416,8 @@ static bool sock_io_read(struct io *io, void *user_data)
                                gatt_db_attribute_get_handle(chrc->attrib),
                                buf, bytes_read,
                                gatt_db_attribute_get_handle(chrc->ccc),
-                               chrc->props & BT_GATT_CHRC_PROP_INDICATE,
-                               chrc->proxy);
+                               chrc->props & BT_GATT_CHRC_PROP_INDICATE ?
+                               conf_cb : NULL, chrc->proxy);
 
        return true;
 }
@@ -2780,7 +2786,8 @@ static void property_changed_cb(GDBusProxy *proxy, const char *name,
                                gatt_db_attribute_get_handle(chrc->attrib),
                                value, len,
                                gatt_db_attribute_get_handle(chrc->ccc),
-                               chrc->props & BT_GATT_CHRC_PROP_INDICATE, proxy);
+                               chrc->props & BT_GATT_CHRC_PROP_INDICATE ?
+                               conf_cb : NULL, proxy);
 #endif
 }