Modify GATT Service changed event handling logic 16/224216/1
authorWootak Jung <wootak.jung@samsung.com>
Mon, 23 Dec 2019 05:29:36 +0000 (14:29 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Fri, 7 Feb 2020 05:48:01 +0000 (14:48 +0900)
Change-Id: I27ca2b3b20cc0007795be80e0741ea4013fbe703

src/bluetooth-common.c
test/bt_unit_test.c

index 1c42639..b9e4a09 100644 (file)
@@ -2812,6 +2812,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                const GSList *l = NULL;
                bt_gatt_client_s *client = NULL;
                bt_gatt_service_s *svc = NULL;
+               int ret;
 
                BT_INFO("BLUETOOTH_EVENT_GATT_CLIENT_SERVICE_CHANGED");
 
@@ -2843,42 +2844,59 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                                == BLUETOOTH_GATT_SERVICE_CHANGE_TYPE_ADD) {
                        for (l = client->services; l; l = g_slist_next(l)) {
                                svc = l->data;
+#ifdef TIZEN_GATT_CLIENT
+                               if (!g_strcmp0(svc->uuid, service_change->uuid))
+                                       break;
+#else
                                if (!g_strcmp0(svc->path, service_change->svc_path))
                                        break;
+#endif
                        }
                        if (l) {
                                BT_INFO("already added service : %s", svc->path);
                                break;
                        }
 #ifdef TIZEN_GATT_CLIENT
-                       BT_INFO("TODO this task");
+                       BT_INFO("Service(%s) is added", service_change->uuid);
+                       client->services_discovered = false;
+                       ret = _bt_gatt_client_update_services(client);
+                       if (ret != BT_ERROR_NONE) {
+                               BT_ERR("_bt_gatt_client_update_services is failed");
+                               break;
+                       }
 #else
                        svc = _bt_gatt_client_add_service(client,
                                        service_change->svc_path);
-#endif
                        if (svc == NULL) {
                                BT_ERR("_bt_gatt_client_add_service is failed");
                                break;
                        }
+#endif
 
                        if (client->connected && client->service_changed_cb)
                                client->service_changed_cb(client,
                                                BT_GATT_CLIENT_SERVICE_ADDED,
-                                               svc->uuid,
+                                               service_change->uuid,
                                                client->service_changed_user_data);
                } else {
                        char *removed_uuid = NULL;
 
                        for (l = client->services; l; l = g_slist_next(l)) {
                                svc = l->data;
+#ifdef TIZEN_GATT_CLIENT
+                               if (!g_strcmp0(svc->uuid, service_change->uuid))
+                                       break;
+#else
                                if (!g_strcmp0(svc->path, service_change->svc_path))
                                        break;
+#endif
                        }
                        if (!l) {
                                BT_ERR("There is NO matched service");
                                break;
                        }
 
+                       BT_INFO("Service(%s) is removed", svc->uuid);
                        removed_uuid = g_strdup(svc->uuid);
                        bt_gatt_service_destroy((bt_gatt_h)svc);
 
index abf2ec4..504812a 100644 (file)
@@ -2334,7 +2334,9 @@ void __bt_gatt_client_service_changed_cb(bt_gatt_client_h c,
 
        ret = bt_get_uuid_name(uuid, &svc);
        if (ret != BT_ERROR_NONE)
-               TC_PRT("Remote device [%s] : %s is %s", addr, svc,
+               svc = g_strdup(uuid);
+
+       TC_PRT("Remote device [%s] : %s is %s", addr, svc,
                        type == BT_GATT_CLIENT_SERVICE_ADDED ?
                        "Added" : "Removed");
        g_free(svc);