summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDoHyun Pyun <dh79.pyun@samsung.com>2018-08-31 02:02:02 +0000
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>2018-08-31 02:02:02 +0000
commit0687574c95ad5c0a58c7638471426e747995eea0 (patch)
tree26ed77649712276bd28199b9b072296ed5ba0885 /src
parente5d0903f2f5b89324d4d316037ab79c17aebb594 (diff)
parent2f540250fa7a0ea037f5ad98150bcaa403468183 (diff)
downloadbluetooth-0687574c95ad5c0a58c7638471426e747995eea0.tar.gz
bluetooth-0687574c95ad5c0a58c7638471426e747995eea0.tar.bz2
bluetooth-0687574c95ad5c0a58c7638471426e747995eea0.zip
Merge "Reduce the complexity of __bt_update_data function" into tizensubmit/tizen/20180831.020217accepted/tizen/unified/20180904.062826
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth-otp.c354
1 files changed, 233 insertions, 121 deletions
diff --git a/src/bluetooth-otp.c b/src/bluetooth-otp.c
index d99c170..ad1983c 100644
--- a/src/bluetooth-otp.c
+++ b/src/bluetooth-otp.c
@@ -502,166 +502,278 @@ int bt_otp_client_unset_connection_state_changed_cb(bt_otp_client_h otp_client)
return BT_ERROR_NONE;
}
-static int __bt_otp_update_data(bt_otp_client_s *otp_client_s, bt_gatt_char_property_t *characteristic)
+static int __bt_opt_update_feature(bt_otp_client_s *otp_client_s, bt_gatt_char_property_t *characteristic)
{
int ret = BLUETOOTH_ERROR_NONE;
- if (g_strstr_len(characteristic->uuid, -1, BT_OTP_FEATURE_UUID)) {
- BT_DBG("OTP feature characteristic discovered");
+ BT_DBG("OTP feature characteristic discovered");
- if (otp_client_s->otp_feature_obj_path)
- g_free(otp_client_s->otp_feature_obj_path);
- otp_client_s->otp_feature_obj_path = g_strdup(characteristic->handle);
+ if (otp_client_s->otp_feature_obj_path)
+ g_free(otp_client_s->otp_feature_obj_path);
- ret = _bt_get_error_code(bluetooth_otp_read_characteristic_value(otp_client_s->otp_feature_obj_path));
- if (ret != BT_ERROR_NONE)
- BT_ERR("Failed to read OTP Feature : %s(0x%08x)", _bt_convert_error_to_string(ret), ret);
+ otp_client_s->otp_feature_obj_path = g_strdup(characteristic->handle);
- BT_DBG("OTP feature handle [%s]", otp_client_s->otp_feature_obj_path);
- } else if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OACP_CONTROL_POINT_UUID)) {
- BT_DBG("OTP OACP Control Point discovered");
- bt_gatt_char_descriptor_property_t desc_property;
- memset(&desc_property, 0x00, sizeof(desc_property));
+ ret = _bt_get_error_code(bluetooth_otp_read_characteristic_value(otp_client_s->otp_feature_obj_path));
+ if (ret != BT_ERROR_NONE)
+ BT_ERR("Failed to read OTP Feature : %s(0x%08x)", _bt_convert_error_to_string(ret), ret);
- /* Get CCCD for Control Point */
- ret = bluetooth_gatt_get_char_descriptor_property(
- characteristic->char_desc_handle.handle[0], &desc_property);
+ BT_DBG("OTP feature handle [%s]", otp_client_s->otp_feature_obj_path);
- if (ret != BLUETOOTH_ERROR_NONE) {
- BT_ERR("Failed to discover CCCD for OACP Control point");
- bluetooth_gatt_free_desc_property(&desc_property);
- return ret;
- }
- if (otp_client_s->otp_oacp_control_point)
- g_free(otp_client_s->otp_oacp_control_point);
- otp_client_s->otp_oacp_control_point = g_strdup(characteristic->handle);
+ return ret;
+}
- if (otp_client_s->otp_oacp_cccd)
- g_free(otp_client_s->otp_oacp_cccd);
- otp_client_s->otp_oacp_cccd = g_strdup(desc_property.handle);
+static int __bt_opt_update_oacp_control_point(bt_otp_client_s *otp_client_s, bt_gatt_char_property_t *characteristic)
+{
+ int ret = BLUETOOTH_ERROR_NONE;
- BT_DBG("OACP Control point handle [%s]", otp_client_s->otp_oacp_control_point);
- BT_DBG("OACP Control point CCCD handle [%s]", otp_client_s->otp_oacp_cccd);
- } else if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OLCP_CONTROL_POINT_UUID)) {
- BT_DBG("OTP OLCP Control Point discovered");
- bt_gatt_char_descriptor_property_t desc_property;
- memset(&desc_property, 0x00, sizeof(desc_property));
+ BT_DBG("OTP OACP Control Point discovered");
+ bt_gatt_char_descriptor_property_t desc_property;
+ memset(&desc_property, 0x00, sizeof(desc_property));
- /* Get CCCD for Control Point */
- ret = bluetooth_gatt_get_char_descriptor_property(
- characteristic->char_desc_handle.handle[0], &desc_property);
+ /* Get CCCD for Control Point */
+ ret = bluetooth_gatt_get_char_descriptor_property(
+ characteristic->char_desc_handle.handle[0], &desc_property);
- if (ret != BLUETOOTH_ERROR_NONE) {
- BT_ERR("Failed to discover CCCD for OLCP Control point");
- bluetooth_gatt_free_desc_property(&desc_property);
- return ret;
- }
- if (otp_client_s->otp_olcp_control_point)
- g_free(otp_client_s->otp_olcp_control_point);
- otp_client_s->otp_olcp_control_point = g_strdup(characteristic->handle);
+ if (ret != BLUETOOTH_ERROR_NONE) {
+ BT_ERR("Failed to discover CCCD for OACP Control point");
+ bluetooth_gatt_free_desc_property(&desc_property);
+ return ret;
+ }
+ if (otp_client_s->otp_oacp_control_point)
+ g_free(otp_client_s->otp_oacp_control_point);
+ otp_client_s->otp_oacp_control_point = g_strdup(characteristic->handle);
- if (otp_client_s->otp_olcp_cccd)
- g_free(otp_client_s->otp_olcp_cccd);
- otp_client_s->otp_olcp_cccd = g_strdup(desc_property.handle);
+ if (otp_client_s->otp_oacp_cccd)
+ g_free(otp_client_s->otp_oacp_cccd);
+ otp_client_s->otp_oacp_cccd = g_strdup(desc_property.handle);
- BT_DBG("OLCP Control point handle [%s]", otp_client_s->otp_olcp_control_point);
- BT_DBG("OLCP Control point CCCD handle [%s]", otp_client_s->otp_olcp_cccd);
- } else if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OBJECT_NAME_UUID)) {
- BT_DBG("OTP Object Name characteristic discovered");
+ BT_DBG("OACP Control point handle [%s]", otp_client_s->otp_oacp_control_point);
+ BT_DBG("OACP Control point CCCD handle [%s]", otp_client_s->otp_oacp_cccd);
- if (otp_client_s->otp_name_obj_path)
- g_free(otp_client_s->otp_name_obj_path);
- otp_client_s->otp_name_obj_path = g_strdup(characteristic->handle);
+ return ret;
+}
- BT_DBG("OTP Object Name handle [%s]", otp_client_s->otp_name_obj_path);
- } else if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OBJECT_TYPE_UUID)) {
- BT_DBG("OTP Object Type characteristic discovered");
+static int __bt_opt_update_olcp_control_point(bt_otp_client_s *otp_client_s, bt_gatt_char_property_t *characteristic)
+{
+ int ret = BLUETOOTH_ERROR_NONE;
- if (otp_client_s->otp_type_obj_path)
- g_free(otp_client_s->otp_type_obj_path);
- otp_client_s->otp_type_obj_path = g_strdup(characteristic->handle);
+ BT_DBG("OTP OLCP Control Point discovered");
+ bt_gatt_char_descriptor_property_t desc_property;
+ memset(&desc_property, 0x00, sizeof(desc_property));
- BT_DBG("OTP Object Type handle [%s]", otp_client_s->otp_type_obj_path);
- } else if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OBJECT_SIZE_UUID)) {
- BT_DBG("OTP Object Size characteristic discovered");
+ /* Get CCCD for Control Point */
+ ret = bluetooth_gatt_get_char_descriptor_property(
+ characteristic->char_desc_handle.handle[0], &desc_property);
- if (otp_client_s->otp_size_obj_path)
- g_free(otp_client_s->otp_size_obj_path);
- otp_client_s->otp_size_obj_path = g_strdup(characteristic->handle);
+ if (ret != BLUETOOTH_ERROR_NONE) {
+ BT_ERR("Failed to discover CCCD for OLCP Control point");
+ bluetooth_gatt_free_desc_property(&desc_property);
+ return ret;
+ }
+ if (otp_client_s->otp_olcp_control_point)
+ g_free(otp_client_s->otp_olcp_control_point);
+ otp_client_s->otp_olcp_control_point = g_strdup(characteristic->handle);
- BT_DBG("OTP Object Size handle [%s]", otp_client_s->otp_size_obj_path);
- } else if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OBJECT_FIRST_CREATED_UUID)) {
- BT_DBG("OTP Object First Created characteristic discovered");
+ if (otp_client_s->otp_olcp_cccd)
+ g_free(otp_client_s->otp_olcp_cccd);
+ otp_client_s->otp_olcp_cccd = g_strdup(desc_property.handle);
- if (otp_client_s->otp_first_created_obj_path)
- g_free(otp_client_s->otp_first_created_obj_path);
- otp_client_s->otp_first_created_obj_path = g_strdup(characteristic->handle);
+ BT_DBG("OLCP Control point handle [%s]", otp_client_s->otp_olcp_control_point);
+ BT_DBG("OLCP Control point CCCD handle [%s]", otp_client_s->otp_olcp_cccd);
- BT_DBG("OTP Object First Created handle [%s]", otp_client_s->otp_first_created_obj_path);
- } else if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OBJECT_LAST_MODIFIED_UUID)) {
- BT_DBG("OTP Object Last Modified characteristic discovered");
+ return ret;
+}
- if (otp_client_s->otp_last_modified_obj_path)
- g_free(otp_client_s->otp_last_modified_obj_path);
- otp_client_s->otp_last_modified_obj_path = g_strdup(characteristic->handle);
+static int __bt_opt_update_object_name(bt_otp_client_s *otp_client_s, bt_gatt_char_property_t *characteristic)
+{
+ BT_DBG("OTP Object Name characteristic discovered");
- BT_DBG("OTP Object Last Modified handle [%s]", otp_client_s->otp_last_modified_obj_path);
- } else if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OBJECT_ID_UUID)) {
- BT_DBG("OTP Object ID characteristic discovered");
+ if (otp_client_s->otp_name_obj_path)
+ g_free(otp_client_s->otp_name_obj_path);
- if (otp_client_s->otp_id_obj_path)
- g_free(otp_client_s->otp_id_obj_path);
- otp_client_s->otp_id_obj_path = g_strdup(characteristic->handle);
+ otp_client_s->otp_name_obj_path = g_strdup(characteristic->handle);
- BT_DBG("OTP Object ID handle [%s]", otp_client_s->otp_id_obj_path);
- } else if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OBJECT_PROP_UUID)) {
- BT_DBG("OTP Object Properties characteristic discovered");
+ BT_DBG("OTP Object Name handle [%s]", otp_client_s->otp_name_obj_path);
- if (otp_client_s->otp_props_obj_path)
- g_free(otp_client_s->otp_props_obj_path);
- otp_client_s->otp_props_obj_path = g_strdup(characteristic->handle);
+ return BLUETOOTH_ERROR_NONE;
+}
- BT_DBG("OTP Object Properties handle [%s]", otp_client_s->otp_props_obj_path);
- } else if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OBJECT_LIST_FILTER_UUID)) {
- BT_DBG("OTP Object List Filter characteristic discovered");
+static int __bt_opt_update_object_type(bt_otp_client_s *otp_client_s, bt_gatt_char_property_t *characteristic)
+{
+ BT_DBG("OTP Object Type characteristic discovered");
- if (otp_client_s->otp_list_filter_obj_path)
- g_free(otp_client_s->otp_list_filter_obj_path);
- otp_client_s->otp_list_filter_obj_path = g_strdup(characteristic->handle);
+ if (otp_client_s->otp_type_obj_path)
+ g_free(otp_client_s->otp_type_obj_path);
- BT_DBG("OTP Object List Filter handle [%s]", otp_client_s->otp_list_filter_obj_path);
- } else if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OBJECT_CHANGED_UUID)) {
- BT_DBG("OTP Object Changed characteristic discovered");
- bt_gatt_char_descriptor_property_t desc_property;
- memset(&desc_property, 0x00, sizeof(desc_property));
+ otp_client_s->otp_type_obj_path = g_strdup(characteristic->handle);
- /* Get CCCD for Object Changed Charc */
- ret = bluetooth_gatt_get_char_descriptor_property(
- characteristic->char_desc_handle.handle[0], &desc_property);
+ BT_DBG("OTP Object Type handle [%s]", otp_client_s->otp_type_obj_path);
- if (ret != BLUETOOTH_ERROR_NONE) {
- BT_ERR("Failed to discover CCCD for Object Changed Charc");
- bluetooth_gatt_free_desc_property(&desc_property);
- return ret;
- }
- if (otp_client_s->otp_obj_changed_obj_path)
- g_free(otp_client_s->otp_obj_changed_obj_path);
- otp_client_s->otp_obj_changed_obj_path = g_strdup(characteristic->handle);
+ return BLUETOOTH_ERROR_NONE;
+}
+
+static int __bt_opt_update_object_size(bt_otp_client_s *otp_client_s, bt_gatt_char_property_t *characteristic)
+{
+ BT_DBG("OTP Object Size characteristic discovered");
+
+ if (otp_client_s->otp_size_obj_path)
+ g_free(otp_client_s->otp_size_obj_path);
+
+ otp_client_s->otp_size_obj_path = g_strdup(characteristic->handle);
+
+ BT_DBG("OTP Object Size handle [%s]", otp_client_s->otp_size_obj_path);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+static int __bt_opt_update_object_first_created(bt_otp_client_s *otp_client_s, bt_gatt_char_property_t *characteristic)
+{
+ BT_DBG("OTP Object First Created characteristic discovered");
+
+ if (otp_client_s->otp_first_created_obj_path)
+ g_free(otp_client_s->otp_first_created_obj_path);
- if (otp_client_s->otp_obj_changed_cccd)
- g_free(otp_client_s->otp_obj_changed_cccd);
- otp_client_s->otp_obj_changed_cccd = g_strdup(desc_property.handle);
+ otp_client_s->otp_first_created_obj_path = g_strdup(characteristic->handle);
+
+ BT_DBG("OTP Object First Created handle [%s]", otp_client_s->otp_first_created_obj_path);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+static int __bt_opt_update_object_last_modified(bt_otp_client_s *otp_client_s, bt_gatt_char_property_t *characteristic)
+{
+ BT_DBG("OTP Object Last Modified characteristic discovered");
+
+ if (otp_client_s->otp_last_modified_obj_path)
+ g_free(otp_client_s->otp_last_modified_obj_path);
+
+ otp_client_s->otp_last_modified_obj_path = g_strdup(characteristic->handle);
+
+ BT_DBG("OTP Object Last Modified handle [%s]", otp_client_s->otp_last_modified_obj_path);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+static int __bt_opt_update_object_id(bt_otp_client_s *otp_client_s, bt_gatt_char_property_t *characteristic)
+{
+ BT_DBG("OTP Object ID characteristic discovered");
- BT_DBG("OTP Object Changed handle [%s]", otp_client_s->otp_obj_changed_obj_path);
- BT_DBG("OTP Object Changed CCCD handle [%s]", otp_client_s->otp_obj_changed_cccd);
- } else {
- BT_DBG("Other OTP Characteristic handle [%s]", characteristic->handle);
- BT_DBG("UUID [%s]", characteristic->uuid);
+ if (otp_client_s->otp_id_obj_path)
+ g_free(otp_client_s->otp_id_obj_path);
+
+ otp_client_s->otp_id_obj_path = g_strdup(characteristic->handle);
+
+ BT_DBG("OTP Object ID handle [%s]", otp_client_s->otp_id_obj_path);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+static int __bt_opt_update_object_properties(bt_otp_client_s *otp_client_s, bt_gatt_char_property_t *characteristic)
+{
+ BT_DBG("OTP Object Properties characteristic discovered");
+
+ if (otp_client_s->otp_props_obj_path)
+ g_free(otp_client_s->otp_props_obj_path);
+
+ otp_client_s->otp_props_obj_path = g_strdup(characteristic->handle);
+
+ BT_DBG("OTP Object Properties handle [%s]", otp_client_s->otp_props_obj_path);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+static int __bt_opt_update_object_list_filter(bt_otp_client_s *otp_client_s, bt_gatt_char_property_t *characteristic)
+{
+ BT_DBG("OTP Object List Filter characteristic discovered");
+
+ if (otp_client_s->otp_list_filter_obj_path)
+ g_free(otp_client_s->otp_list_filter_obj_path);
+
+ otp_client_s->otp_list_filter_obj_path = g_strdup(characteristic->handle);
+
+ BT_DBG("OTP Object List Filter handle [%s]", otp_client_s->otp_list_filter_obj_path);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+static int __bt_opt_update_object_changed(bt_otp_client_s *otp_client_s, bt_gatt_char_property_t *characteristic)
+{
+ int ret = BLUETOOTH_ERROR_NONE;
+
+ BT_DBG("OTP Object Changed characteristic discovered");
+ bt_gatt_char_descriptor_property_t desc_property;
+ memset(&desc_property, 0x00, sizeof(desc_property));
+
+ /* Get CCCD for Object Changed Charc */
+ ret = bluetooth_gatt_get_char_descriptor_property(
+ characteristic->char_desc_handle.handle[0], &desc_property);
+
+ if (ret != BLUETOOTH_ERROR_NONE) {
+ BT_ERR("Failed to discover CCCD for Object Changed Charc");
+ bluetooth_gatt_free_desc_property(&desc_property);
+ return ret;
}
+ if (otp_client_s->otp_obj_changed_obj_path)
+ g_free(otp_client_s->otp_obj_changed_obj_path);
+
+ otp_client_s->otp_obj_changed_obj_path = g_strdup(characteristic->handle);
+
+ if (otp_client_s->otp_obj_changed_cccd)
+ g_free(otp_client_s->otp_obj_changed_cccd);
+
+ otp_client_s->otp_obj_changed_cccd = g_strdup(desc_property.handle);
+
+ BT_DBG("OTP Object Changed handle [%s]", otp_client_s->otp_obj_changed_obj_path);
+ BT_DBG("OTP Object Changed CCCD handle [%s]", otp_client_s->otp_obj_changed_cccd);
+
return ret;
}
+static int __bt_otp_update_data(bt_otp_client_s *otp_client_s, bt_gatt_char_property_t *characteristic)
+{
+ if (g_strstr_len(characteristic->uuid, -1, BT_OTP_FEATURE_UUID))
+ return __bt_opt_update_feature(otp_client_s, characteristic);
+
+ if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OACP_CONTROL_POINT_UUID))
+ return __bt_opt_update_oacp_control_point(otp_client_s, characteristic);
+
+ if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OLCP_CONTROL_POINT_UUID))
+ return __bt_opt_update_olcp_control_point(otp_client_s, characteristic);
+
+ if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OBJECT_NAME_UUID))
+ return __bt_opt_update_object_name(otp_client_s, characteristic);
+
+ if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OBJECT_TYPE_UUID))
+ return __bt_opt_update_object_type(otp_client_s, characteristic);
+
+ if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OBJECT_SIZE_UUID))
+ return __bt_opt_update_object_size(otp_client_s, characteristic);
+
+ if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OBJECT_FIRST_CREATED_UUID))
+ return __bt_opt_update_object_first_created(otp_client_s, characteristic);
+
+ if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OBJECT_LAST_MODIFIED_UUID))
+ return __bt_opt_update_object_last_modified(otp_client_s, characteristic);
+
+ if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OBJECT_ID_UUID))
+ return __bt_opt_update_object_id(otp_client_s, characteristic);
+
+ if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OBJECT_PROP_UUID))
+ return __bt_opt_update_object_properties(otp_client_s, characteristic);
+
+ if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OBJECT_LIST_FILTER_UUID))
+ return __bt_opt_update_object_list_filter(otp_client_s, characteristic);
+
+ if (g_strstr_len(characteristic->uuid, -1, BT_OTP_OBJECT_CHANGED_UUID))
+ return __bt_opt_update_object_changed(otp_client_s, characteristic);
+
+ BT_DBG("Other OTP Characteristic handle [%s]", characteristic->handle);
+ BT_DBG("UUID [%s]", characteristic->uuid);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
static int __bt_update_otp_server_data(bluetooth_device_address_t *address, bt_otp_client_s *otp_client_s)
{
int ret = BLUETOOTH_ERROR_INTERNAL;