From: Wootak Jung Date: Thu, 6 Feb 2020 06:24:27 +0000 (+0900) Subject: Add service removed event handling logic X-Git-Tag: submit/tizen/20200207.062602^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=845f25a75dcc9e0d2e86d0e53a22cd82aa4eb13f;p=platform%2Fcore%2Fapi%2Fbluetooth.git Add service removed event handling logic Change-Id: I7b1ea4afb118393277b7ecbe5a1de2151aae4676 --- diff --git a/include/bluetooth_private.h b/include/bluetooth_private.h index 19fa317..d48f417 100644 --- a/include/bluetooth_private.h +++ b/include/bluetooth_private.h @@ -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); diff --git a/src/bluetooth-common.c b/src/bluetooth-common.c index a86d7a5..bd0b715 100644 --- a/src/bluetooth-common.c +++ b/src/bluetooth-common.c @@ -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 diff --git a/src/bluetooth-gatt.c b/src/bluetooth-gatt.c index d7c5e70..e94df0a 100644 --- a/src/bluetooth-gatt.c +++ b/src/bluetooth-gatt.c @@ -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) {