From 8045c8b8e0416176c93f6e023f37e07eee88170a Mon Sep 17 00:00:00 2001 From: Wootak Jung Date: Tue, 13 Jun 2023 13:13:59 +0900 Subject: [PATCH] Add internal API to set service persistence Change-Id: Ic1a54af44ac3b2265f37db4c3a8545e189951a38 Signed-off-by: Wootak Jung --- include/bluetooth_internal.h | 38 +++++++++++++++++++++++++ src/bluetooth-gatt.c | 54 ++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/include/bluetooth_internal.h b/include/bluetooth_internal.h index 5009f02..9e5103b 100644 --- a/include/bluetooth_internal.h +++ b/include/bluetooth_internal.h @@ -5645,6 +5645,44 @@ int bt_adapter_le_add_advertising_custom_name(bt_advertiser_h advertiser, int bt_adapter_le_remove_advertising_custom_name(bt_advertiser_h advertiser, bt_adapter_le_packet_type_e pkt_type); +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_SERVER_MODULE + * @brief Sets service to be persisted not removed. + * @since_tizen 8.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] uuid The UUID of service + * + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_ALREADY_DONE Operation is already done + * + * @see bt_gatt_server_unset_service_persistence() + */ +int bt_gatt_server_set_service_persistence(const char *uuid); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_SERVER_MODULE + * @brief Unsets service persistence. + * @since_tizen 8.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] uuid The UUID of service + * + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_SERVICE_NOT_FOUND Service not found + * + * @see bt_gatt_server_unset_service_persistence() + */ +int bt_gatt_server_unset_service_persistence(const char *uuid); + /** * @} */ diff --git a/src/bluetooth-gatt.c b/src/bluetooth-gatt.c index 0f2a7c9..adcf1cf 100644 --- a/src/bluetooth-gatt.c +++ b/src/bluetooth-gatt.c @@ -3676,6 +3676,60 @@ int bt_gatt_server_unset_att_mtu_changed_cb(bt_gatt_server_h server) return BT_ERROR_NONE; } + +int bt_gatt_server_set_service_persistence(const char *uuid) +{ + int error_code = BT_ERROR_NONE; + char *uuid128; + + BT_CHECK_GATT_SERVER_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(uuid); + + uuid128 = _bt_convert_uuid_to_uuid128(uuid); + if (uuid128 == NULL) { + BT_ERR("Wrong type of uuid: %s", uuid); + return BT_ERROR_INVALID_PARAMETER; + } + + BT_INFO("Set service(%s) to be persisted not removed", uuid128); + + error_code = _bt_get_error_code(bluetooth_gatt_server_set_service_persistence(uuid128)); + if (error_code != BT_ERROR_NONE) { /* LCOV_EXCL_LINE */ + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), /* LCOV_EXCL_LINE */ + error_code); /* LCOV_EXCL_LINE */ + return error_code; /* LCOV_EXCL_LINE */ + } + + return BT_ERROR_NONE; +} + +int bt_gatt_server_unset_service_persistence(const char *uuid) +{ + int error_code = BT_ERROR_NONE; + char *uuid128; + + BT_CHECK_GATT_SERVER_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(uuid); + + uuid128 = _bt_convert_uuid_to_uuid128(uuid); + if (uuid128 == NULL) { + BT_ERR("Wrong type of uuid: %s", uuid); + return BT_ERROR_INVALID_PARAMETER; + } + + BT_INFO("Unset service persistence: %s", uuid128); + + error_code = _bt_get_error_code(bluetooth_gatt_server_unset_service_persistence(uuid128)); + if (error_code != BT_ERROR_NONE) { /* LCOV_EXCL_LINE */ + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), /* LCOV_EXCL_LINE */ + error_code); /* LCOV_EXCL_LINE */ + return error_code; /* LCOV_EXCL_LINE */ + } + + return BT_ERROR_NONE; +} /* LCOV_EXCL_STOP */ #ifdef TIZEN_GATT_CLIENT -- 2.34.1