Merge "Fixed the build error using gcc 13" into tizen accepted/tizen/unified/20230718.162153 accepted/tizen/unified/dev/20230726.115849
authorPyun DoHyun <dh79.pyun@samsung.com>
Fri, 30 Jun 2023 05:22:25 +0000 (05:22 +0000)
committerGerrit Code Review <gerrit@review>
Fri, 30 Jun 2023 05:22:25 +0000 (05:22 +0000)
bt-api/bt-gatt-service.c
bt-service/services/bt-request-handler.c
bt-service/services/gatt/bt-service-gatt.c
bt-service/services/include/bt-service-gatt.h
include/bluetooth-gatt-server-api.h
include/bt-internal-types.h

index aaeb320..65ab79f 100644 (file)
@@ -3021,6 +3021,55 @@ BT_EXPORT_API int bluetooth_gatt_server_unregister(int instance_id)
        return result;
 }
 
+BT_EXPORT_API int bluetooth_gatt_server_set_service_persistence(const char *svc_uuid)
+{
+       BT_CHECK_ENABLED(return);
+       int result;
+       char uuid[BT_GATT_ATT_UUID_LEN_MAX + 1];
+
+       g_strlcpy(uuid, svc_uuid, sizeof(uuid));
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, uuid, BT_GATT_ATT_UUID_LEN_MAX + 1);
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_SERVER_SET_SERVICE_PERSISTENCE,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       if (result != BLUETOOTH_ERROR_NONE)
+               BT_INFO("GATT Server Set service persistence failed result [%d]", result);
+       else
+               BT_INFO("GATT Server Set service persistence successful");
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+       return result;
+}
+
+BT_EXPORT_API int bluetooth_gatt_server_unset_service_persistence(const char *svc_uuid)
+{
+       BT_CHECK_ENABLED(return);
+       int result;
+       char uuid[BT_GATT_ATT_UUID_LEN_MAX + 1];
+
+       g_strlcpy(uuid, svc_uuid, sizeof(uuid));
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, uuid, BT_GATT_ATT_UUID_LEN_MAX + 1);
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_SERVER_UNSET_SERVICE_PERSISTENCE,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       if (result != BLUETOOTH_ERROR_NONE)
+               BT_INFO("GATT Server Unset service persistence failed result [%d]", result);
+       else
+               BT_INFO("GATT Server Unset service persistence successful");
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+       return result;
+}
 
 static gboolean bluetooth_gatt_server_acquire_channel_write_cb(GIOChannel *gio,
                                        GIOCondition cond, gpointer data)
index 9b5d5b2..074813b 100644 (file)
@@ -2624,6 +2624,18 @@ int __bt_bluez_request(int function_name,
                }
                break;
        }
+       case BT_GATT_SERVER_SET_SERVICE_PERSISTENCE: {
+               char *uuid;
+               uuid = (char *)g_variant_get_data(in_param1);
+               result = _bt_gatt_server_set_service_persistence(uuid);
+               break;
+       }
+       case BT_GATT_SERVER_UNSET_SERVICE_PERSISTENCE: {
+               char *uuid;
+               uuid = (char *)g_variant_get_data(in_param1);
+               result = _bt_gatt_server_unset_service_persistence(uuid);
+               break;
+       }
        case BT_GATT_SERVER_SEND_RESPONSE: {
                bluetooth_gatt_server_response_params_t param;
                bluetooth_gatt_att_data_t data;
@@ -5526,6 +5538,8 @@ gboolean __bt_service_check_privilege(int function_name,
        case BT_GATT_SERVER_START_SERVICE:
        case BT_GATT_SERVER_STOP_SERVICE:
        case BT_GATT_SERVER_DELETE_SERVICE:
+       case BT_GATT_SERVER_SET_SERVICE_PERSISTENCE:
+       case BT_GATT_SERVER_UNSET_SERVICE_PERSISTENCE:
        case BT_GATT_SERVER_SEND_RESPONSE:
        case BT_GATT_SERVER_ACQURE_WRITE_RESPONSE:
        case BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE:
index 7b16f3c..ca91725 100644 (file)
@@ -247,6 +247,8 @@ struct gatt_indicate_cfm_result_info_t {
        int completed;                                   /* 1 if last event, otheriwse 0 */
 };
 
+static char service_persistence[BT_UUID_STRING_SIZE + 1];
+
 /* Request Search Utility method */
 static struct gatt_server_req_info *__bt_gatt_server_find_request_info(int request_id,
                bluetooth_gatt_att_request_type_e req_type);
@@ -806,6 +808,71 @@ static int __bt_unregister_gatt_server_instance(int server_instance)
        return BLUETOOTH_ERROR_NONE;
 }
 
+int _bt_gatt_server_set_service_persistence(const char *uuid)
+{
+       int result = BLUETOOTH_ERROR_NONE;
+       BT_DBG("+");
+
+       retv_if(uuid == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
+
+       if (!strncasecmp(service_persistence, uuid, BT_UUID_STRING_SIZE)) {
+               result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
+       } else {
+               g_strlcpy(service_persistence, uuid, sizeof(service_persistence));
+               BT_DBG("Set service(%s) to be persisted not removed", uuid);
+       }
+
+       return result;
+}
+
+int _bt_gatt_server_unset_service_persistence(const char *uuid)
+{
+       int result = BLUETOOTH_ERROR_NONE;
+       BT_DBG("+");
+
+       retv_if(uuid == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
+
+       if (!strncasecmp(service_persistence, uuid, BT_UUID_STRING_SIZE)) {
+               memset(service_persistence, 0, sizeof(service_persistence));
+               BT_DBG("Unset service persistence: %s", uuid);
+       } else {
+               result = BLUETOOTH_ERROR_SERVICE_NOT_FOUND;
+       }
+
+       return result;
+}
+
+char *_bt_gatt_server_get_service_persistence()
+{
+       return service_persistence;
+}
+
+static gboolean __bt_gatt_server_is_service_persistence(int service_handle)
+{
+       GSList *l;
+       bt_service_app_info_t *info = NULL;
+       bt_service_handle_uuid_info_t *uuid_info = NULL;
+
+       for (int k = 1; k < MAX_APPS_SUPPORTED; k++) {
+               info = &numapps[k];
+               for (l = info->service_handle_uuids; l != NULL;) {
+                       uuid_info = l->data;
+                       l = g_slist_next(l);
+                       if (!uuid_info)
+                               continue;
+                       if (uuid_info->service_handle == service_handle) {
+                               char *uuid = _bt_gatt_server_get_service_persistence();
+                               if (!strcasecmp(uuid_info->service_uuid, uuid)) {
+                                       BT_DBG("service(%s) persisted by user. can't be removed", uuid);
+                                       return TRUE;
+                               }
+                       }
+               }
+       }
+
+       return FALSE;
+}
+
 static void __bt_remove_all_service_handles(bt_service_app_info_t *app_info)
 {
        GSList *l;
@@ -824,6 +891,9 @@ static void __bt_remove_all_service_handles(bt_service_app_info_t *app_info)
                l = g_slist_next(l);
 
                if (handle) {
+                       if (__bt_gatt_server_is_service_persistence(*handle))
+                               return;
+
                        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;
@@ -2828,6 +2898,9 @@ int _bt_gatt_server_delete_service(char *sender, int service_handle, int instanc
        int k;
        bt_service_app_info_t *info = NULL;
 
+       if (__bt_gatt_server_is_service_persistence(service_handle))
+               return BLUETOOTH_ERROR_INTERNAL;
+
        ret = gatts_delete_service(instance_id, service_handle);
        if (ret != OAL_STATUS_SUCCESS) {
                BT_ERR("ret: %d", ret);
index a7b93ee..169cc1a 100644 (file)
@@ -94,6 +94,10 @@ int _bt_get_att_mtu(bluetooth_device_address_t *address,
 
 int _bt_gatt_server_acquire_send_response(char *sender, bluetooth_gatt_server_acquire_response_params_t *param, void *);
 
+int _bt_gatt_server_set_service_persistence(const char *uuid);
+
+int _bt_gatt_server_unset_service_persistence(const char *uuid);
+
 //#define __INTEGRATE_GATT_INFO__ // TODO: this feature can be used if easy setup scenario is fully supported
 #ifndef __INTEGRATE_GATT_INFO__
 struct gatt_client_info_t *_bt_find_remote_gatt_client_info(char *address);
index e997afa..4040533 100644 (file)
@@ -320,6 +320,10 @@ int bluetooth_gatt_server_update_multi_adv_instance(const gchar *unique_name, in
 
 int bluetooth_gatt_server_update_characteristic(int instance_id, const bluetooth_gatt_server_update_value_t *value);
 
+int bluetooth_gatt_server_set_service_persistence(const char *svc_uuid);
+
+int bluetooth_gatt_server_unset_service_persistence(const char *svc_uuid);
+
 #ifdef __cplusplus
 }
 #endif
index 9c9b5f5..ed4a017 100644 (file)
@@ -398,6 +398,8 @@ typedef enum {
        BT_GATT_SERVER_START_SERVICE,
        BT_GATT_SERVER_STOP_SERVICE,
        BT_GATT_SERVER_DELETE_SERVICE,
+       BT_GATT_SERVER_SET_SERVICE_PERSISTENCE,
+       BT_GATT_SERVER_UNSET_SERVICE_PERSISTENCE,
        BT_GATT_SERVER_SEND_RESPONSE,
        BT_GATT_SERVER_ACQURE_WRITE_RESPONSE,
        BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE,