Add service removed event handling logic 18/224218/1
authorWootak Jung <wootak.jung@samsung.com>
Thu, 6 Feb 2020 06:24:27 +0000 (15:24 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Fri, 7 Feb 2020 05:48:17 +0000 (14:48 +0900)
Change-Id: I7b1ea4afb118393277b7ecbe5a1de2151aae4676

include/bluetooth_private.h
src/bluetooth-common.c
src/bluetooth-gatt.c

index 19fa317..d48f417 100644 (file)
@@ -835,6 +835,8 @@ bt_gatt_h _bt_gatt_client_add_service(bt_gatt_client_h client,
 bt_gatt_h _bt_gatt_client_add_service(bt_gatt_client_h client, const char *path);
 #endif
 
+int _bt_gatt_client_remove_service(bt_gatt_client_h client, const char *uuid);
+
 int _bt_gatt_client_update_services(bt_gatt_client_h client);
 
 int _bt_gatt_client_update_include_services(bt_gatt_h service);
index a86d7a5..bd0b715 100644 (file)
@@ -2858,6 +2858,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
 #ifdef TIZEN_GATT_CLIENT
                        BT_INFO("Service(%s) is added", service_change->uuid);
                        client->services_discovered = false;
+                       // TODO: Update for only added service
                        ret = _bt_gatt_client_update_services(client);
                        if (ret != BT_ERROR_NONE) {
                                BT_ERR("_bt_gatt_client_update_services is failed");
@@ -2895,9 +2896,9 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
 #ifdef TIZEN_GATT_CLIENT
                        BT_INFO("Service(%s) is removed", svc->uuid);
                        client->services_discovered = false;
-                       ret = _bt_gatt_client_update_services(client);
+                       ret = _bt_gatt_client_remove_service(client, svc->uuid);
                        if (ret != BT_ERROR_NONE) {
-                               BT_ERR("_bt_gatt_client_update_services is failed");
+                               BT_ERR("_bt_gatt_client_remove_service is failed");
                                break;
                        }
 #else
index d7c5e70..e94df0a 100644 (file)
@@ -316,6 +316,28 @@ bt_gatt_h _bt_gatt_client_add_service(bt_gatt_client_h client, const char *path)
 }
 #endif
 
+int _bt_gatt_client_remove_service(bt_gatt_client_h client, const char *uuid)
+{
+       bt_gatt_client_s *client_s = client;
+       bt_gatt_service_s *svc;
+       GSList *l;
+
+       for (l = client_s->services; l != NULL; l = g_slist_next(l)) {
+               svc = (bt_gatt_service_s *)l->data;
+               if (svc == NULL)
+                       continue;
+
+               if (!g_ascii_strcasecmp(svc->uuid, uuid)) {
+                       BT_DBG("Free removed service");
+                       client_s->services = g_slist_remove(client_s->services, svc);
+                       __bt_gatt_free_service(svc);
+                       break;
+               }
+       }
+
+       return BT_ERROR_NONE;
+}
+
 #ifdef TIZEN_GATT_CLIENT
 int _bt_gatt_client_update_services(bt_gatt_client_h client)
 {