Fix bt_gatt_server_register_service() fail issue 94/316794/1
authorWootak Jung <wootak.jung@samsung.com>
Fri, 29 Nov 2024 00:28:50 +0000 (09:28 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Wed, 18 Dec 2024 03:03:01 +0000 (12:03 +0900)
Failed to register GATT service in two processes

Change-Id: I910fa460ff7d0e32416144778e6501077b3b65d4
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
bt-service/services/gatt/bt-service-gatt.c

index 34e9ee9a7794bd67aa97a9901abf995de90ecbc8..8a1b5c4a115b2fa5547d85eb037f11fbc6ff7584 100644 (file)
@@ -198,6 +198,13 @@ typedef struct {
        gboolean is_watcher_enabled;
 } bt_service_app_info_t;
 
+typedef struct {
+       char sender[BT_SENDER_MAX_LENGTH];
+       int svc_handle;
+       int char_handle;
+       int desc_handle;
+} bt_service_server_info_t;
+
 /* GATT Server Request Info Structure */
 struct gatt_server_req_info {
        int connection_id;                               /* This value will uniquely identify a GATT client-server connection */
@@ -1231,18 +1238,55 @@ static void __bt_gatt_handle_pending_request_info(int result,
                        }
                        break;
                }
-               case BT_GATT_SERVER_ADD_SERVICE:
-               case BT_GATT_SERVER_ADD_DESCRIPTOR:
+               case BT_GATT_SERVER_ADD_SERVICE: {
+                       bt_service_server_info_t *param = (bt_service_server_info_t *)data;
+                       int handle = param->svc_handle;
+
+                       if (!g_strcmp0(req_info->sender, param->sender) && handle > 0) {
+                               BT_DBG("GATT Server app [%s] added service handle [%d] Reply DBUS",
+                                               req_info->sender, handle);
+
+                               out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
+                               g_array_append_vals(out_param, &handle, sizeof(int));
+                               _bt_service_method_return(req_info->context, out_param, result);
+
+                               _bt_free_info_from_invocation_list(req_info);
+                               g_array_free(out_param, TRUE);
+                       }
+                       break;
+               }
+               case BT_GATT_SERVER_ADD_DESCRIPTOR: {
+                       bt_service_server_info_t *param = (bt_service_server_info_t *)data;
+                       int handle = param->desc_handle;
+
+                       if (!g_strcmp0(req_info->sender, param->sender) && handle > 0) {
+                               BT_DBG("GATT Server app [%s] added descriptor handle [%d] Reply DBUS",
+                                               req_info->sender, handle);
+
+                               out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
+                               g_array_append_vals(out_param, &handle, sizeof(int));
+                               _bt_service_method_return(req_info->context, out_param, result);
+
+                               _bt_free_info_from_invocation_list(req_info);
+                               g_array_free(out_param, TRUE);
+                       }
+                       break;
+               }
                case BT_GATT_SERVER_ADD_CHARACTERISTIC: {
-                       int *handle = (int*)data;
-                       BT_DBG("Characteristic added: Handle [%d]", *handle);
-                       out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
+                       bt_service_server_info_t *param = (bt_service_server_info_t *)data;
+                       int handle = param->char_handle;
 
-                       g_array_append_vals(out_param, handle, sizeof(int));
-                       _bt_service_method_return(req_info->context, out_param, result);
+                       if (!g_strcmp0(req_info->sender, param->sender) && handle > 0) {
+                               BT_DBG("GATT Server app [%s] added characteristic handle [%d] Reply DBUS",
+                                               req_info->sender, handle);
 
-                       _bt_free_info_from_invocation_list(req_info);
-                       g_array_free(out_param, TRUE);
+                               out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
+                               g_array_append_vals(out_param, &handle, sizeof(int));
+                               _bt_service_method_return(req_info->context, out_param, result);
+
+                               _bt_free_info_from_invocation_list(req_info);
+                               g_array_free(out_param, TRUE);
+                       }
                        break;
                }
 #endif
@@ -1494,9 +1538,17 @@ static void __bt_handle_gatt_server_service_added(event_gatts_srvc_prm_t *event)
                info = &numapps[k];
 
                if (info->instance_id == event->gatt_srvc_stat.server_inst) {
-                       BT_INFO("numapps[%d] Found GATT Server.. UUID [%s], sender [%s]", k, info->uuid, info->sender);
+                       bt_service_server_info_t server_info;
+                       BT_INFO("numapps[%d] Found GATT Server.. UUID [%s], svc_handle [%d] sender [%s]",
+                                       k, info->uuid, svc_handle, info->sender);
+
+                       g_strlcpy(server_info.sender, info->sender, sizeof(info->sender));
+                       server_info.svc_handle = svc_handle;
+                       server_info.char_handle = -1;
+                       server_info.desc_handle = -1;
+
                        __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_ADD_SERVICE,
-                                       (int*)&svc_handle, sizeof(int));
+                                       (void *)&server_info, sizeof(bt_service_server_info_t));
 
                        /* Add Service Handle */
                        if (svc_handle > 0) {
@@ -1546,9 +1598,17 @@ static void __bt_handle_gatt_server_characteristic_added(event_gatts_srvc_charct
                info = &numapps[k];
 
                if (info->instance_id == event->gatt_srvc_stat.server_inst) {
-                       BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
+                       bt_service_server_info_t server_info;
+                       BT_INFO("numapps[%d] Found GATT Server.. UUID [%s], char_handle [%d] sender [%s]",
+                                       k, info->uuid, char_handle, info->sender);
+
+                       g_strlcpy(server_info.sender, info->sender, sizeof(info->sender));
+                       server_info.svc_handle = -1;
+                       server_info.char_handle = char_handle;
+                       server_info.desc_handle = -1;
+
                        __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_ADD_CHARACTERISTIC,
-                                       (int*)&char_handle, sizeof(int));
+                                       (void *)&server_info, sizeof(bt_service_server_info_t));
                        break;
                }
        }
@@ -1586,9 +1646,17 @@ static void __bt_handle_gatt_server_descriptor_added(event_gatts_srvc_descr_t* e
                info = &numapps[k];
 
                if (info->instance_id == event->gatt_srvc_stat.server_inst) {
-                       BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
+                       bt_service_server_info_t server_info ;
+                       BT_INFO("numapps[%d] Found GATT Server.. UUID [%s], desc_handle [%d] sender [%s]",
+                                       k, info->uuid, desc_handle, info->sender);
+
+                       g_strlcpy(server_info.sender, info->sender, sizeof(info->sender));
+                       server_info.svc_handle = -1;
+                       server_info.char_handle = -1;
+                       server_info.desc_handle = desc_handle;
+
                        __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_ADD_DESCRIPTOR,
-                                       (int*)&desc_handle, sizeof(int));
+                                       (void *)&server_info, sizeof(bt_service_server_info_t));
                        break;
                }
        }
@@ -2948,7 +3016,8 @@ int _bt_gatt_server_add_characteristic(char *sender, char *char_uuid,
 
        oal_uuid_t uuid = {{0} };
 
-       BT_INFO("Char UUID [%s] Instance ID [%d]", char_uuid, param->instance_id);
+       BT_INFO("Char UUID [%s] Instance ID [%d] service handle [%d] uuid [%s]",
+                       char_uuid, param->instance_id, param->service_handle, char_uuid);
        _bt_string_to_uuid(char_uuid, (service_uuid_t*)&uuid);
 
        BT_INFO("Char permission From API [0x%x]", param->permissions);