Fix the instance id's miss-matching issue 61/224061/6
authorDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 6 Feb 2020 05:23:38 +0000 (14:23 +0900)
committerPyun DoHyun <dh79.pyun@samsung.com>
Mon, 10 Feb 2020 00:17:55 +0000 (00:17 +0000)
Change-Id: I65e2592927aacb2b95c2b51531c44fdc1a21092a
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
bt-service-adaptation/services/gatt/bt-service-gatt.c

index d9e080b..4e113b5 100644 (file)
@@ -237,7 +237,8 @@ static struct gatt_server_req_info *__bt_gatt_server_find_request_info(int reque
 static int __bt_gatt_send_indication_to_all_connected_clients(bluetooth_gatt_att_data_t *data,
                bluetooth_gatt_server_indication_params_t *param);
 
-static void __bt_remove_all_service_handles(int instance_id);
+static void __bt_remove_all_service_handles(bt_service_app_info_t *app_info);
+
 static void __bt_free_service_info(bt_gatt_service_info_t *service_info);
 
 static int __bt_do_unregister_gatt_instance(int instance_id);
@@ -324,7 +325,7 @@ void _bt_check_adv_app_termination(const char *name)
                        if (app->instance_id != -1) {
                                /* GATT server */
                                /* Unregister all service handles with stack */
-                               __bt_remove_all_service_handles(app->instance_id);
+                               __bt_remove_all_service_handles(app);
 
                                /* If Advertising is enabled, stop it */
                                if (app->adv_handle > 0) {
@@ -717,34 +718,37 @@ static int __bt_unregister_gatt_server_instance(int server_instance)
        return BLUETOOTH_ERROR_NONE;
 }
 
-static void __bt_remove_all_service_handles(int instance_id)
+static void __bt_remove_all_service_handles(bt_service_app_info_t *app_info)
 {
        GSList *l;
        int *handle = NULL;
        int ret = OAL_STATUS_SUCCESS;
        int count;
 
-       count = g_slist_length(numapps[instance_id].service_handles);
+       if (app_info == NULL)
+               return;
+
+       count = g_slist_length(app_info->service_handles);
        BT_INFO("Before handle removal: current count [%d]", count);
 
-       for (l = numapps[instance_id].service_handles; l != NULL;) {
+       for (l = app_info->service_handles; l != NULL;) {
                handle = l->data;
                l = g_slist_next(l);
 
                if (handle) {
-                       BT_INFO("Server Handle to be Removed [%d] Instance ID [%d]", *handle, instance_id);
-                       if (_bt_gatt_server_stop_service(numapps[instance_id].sender, *handle, instance_id) != BLUETOOTH_ERROR_NONE)
+                       BT_INFO("Server Handle to be Removed [%d] Instance ID [%d]", *handle, app_info->instance_id);
+                       if (_bt_gatt_server_stop_service(app_info->sender, *handle, app_info->instance_id) != BLUETOOTH_ERROR_NONE)
                                continue;
 
-                       ret = gatts_delete_service(instance_id, *handle);
+                       ret = gatts_delete_service(app_info->instance_id, *handle);
                        if (ret != OAL_STATUS_SUCCESS) {
                                BT_ERR("ret: %d", ret);
                                continue;
                        } else {
-                               numapps[instance_id].service_handles = g_slist_remove(numapps[instance_id].service_handles, handle);
+                               app_info->service_handles = g_slist_remove(app_info->service_handles, handle);
                                g_free(handle);
                                handle = NULL;
-                               count = g_slist_length(numapps[instance_id].service_handles);
+                               count = g_slist_length(app_info->service_handles);
                                BT_INFO("After deleting current count [%d]", count);
                        }
                }
@@ -773,7 +777,7 @@ int _bt_unregister_server_instance(const char *sender, int adv_handle)
                        if (!g_strcmp0(info->sender, sender)) {
                                BT_INFO("Unregister GATT server instance [%d]", info->instance_id);
                                /* Unregister all service handles with stack */
-                               __bt_remove_all_service_handles(info->instance_id);
+                               __bt_remove_all_service_handles(info);
 
                                /* Disable adv if running */
                                BT_INFO("Disable Advertising Adv Handle [%d] sender [%s]",